Issue #1547 'use strict' style tweaks, cleanup, and compiled output

This commit is contained in:
Gerald Lewis
2012-01-11 18:04:14 -05:00
parent 4372138fdd
commit bf8e0aa1ea
10 changed files with 349 additions and 241 deletions

View File

@@ -6,7 +6,7 @@
CoffeeScript.require = require;
CoffeeScript.eval = function(code, options) {
CoffeeScript["eval"] = function(code, options) {
return eval(CoffeeScript.compile(code, options));
};

View File

@@ -56,7 +56,7 @@
} catch (e) {
return fatalError("" + e);
}
_ref = options.arguments;
_ref = options["arguments"];
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
arg = _ref[_i];

View File

@@ -76,7 +76,7 @@
}
};
exports.eval = function(code, options) {
exports["eval"] = function(code, options) {
var Module, Script, js, k, o, r, sandbox, v, _i, _len, _module, _ref2, _ref3, _require;
if (options == null) options = {};
if (!(code = code.trim())) return;

View File

@@ -54,7 +54,7 @@
return printWarn("The --watch feature depends on Node v0.6.0+. You are running " + process.version + ".");
}
if (opts.stdio) return compileStdio();
if (opts.eval) return compileScript(null, sources[0]);
if (opts["eval"]) return compileScript(null, sources[0]);
if (!sources.length) return require('./repl');
if (opts.run) opts.literals = sources.splice(1).concat(opts.literals);
process.argv = process.argv.slice(0, 2).concat(opts.literals);
@@ -396,8 +396,8 @@
o = opts = optionParser.parse(process.argv.slice(2));
o.compile || (o.compile = !!o.output);
o.run = !(o.compile || o.print || o.lint);
o.print = !!(o.print || (o.eval || o.stdio && o.compile));
sources = o.arguments;
o.print = !!(o.print || (o["eval"] || o.stdio && o.compile));
sources = o["arguments"];
for (i = _i = 0, _len = sources.length; _i < _len; i = ++_i) {
source = sources[i];
sourceCode[i] = null;

View File

@@ -1,6 +1,6 @@
// Generated by CoffeeScript 1.2.1-pre
(function() {
var BOOL, CALLABLE, CODE, COFFEE_ALIASES, COFFEE_ALIAS_MAP, COFFEE_KEYWORDS, COMMENT, COMPARE, COMPOUND_ASSIGN, HEREDOC, HEREDOC_ILLEGAL, HEREDOC_INDENT, HEREGEX, HEREGEX_OMIT, IDENTIFIER, INDEXABLE, INVERSES, JSTOKEN, JS_FORBIDDEN, JS_KEYWORDS, LINE_BREAK, LINE_CONTINUER, LOGIC, Lexer, MATH, MULTILINER, MULTI_DENT, NOT_REGEX, NOT_SPACED_REGEX, NUMBER, OPERATOR, REGEX, RELATION, RESERVED, Rewriter, SHIFT, SIMPLESTR, TRAILING_SPACES, UNARY, WHITESPACE, compact, count, key, last, starts, _ref, _ref2,
var BOOL, CALLABLE, CODE, COFFEE_ALIASES, COFFEE_ALIAS_MAP, COFFEE_KEYWORDS, COMMENT, COMPARE, COMPOUND_ASSIGN, HEREDOC, HEREDOC_ILLEGAL, HEREDOC_INDENT, HEREGEX, HEREGEX_OMIT, IDENTIFIER, INDEXABLE, INVERSES, JSTOKEN, JS_FORBIDDEN, JS_KEYWORDS, LINE_BREAK, LINE_CONTINUER, LOGIC, Lexer, MATH, MULTILINER, MULTI_DENT, NOT_REGEX, NOT_SPACED_REGEX, NUMBER, OPERATOR, REGEX, RELATION, RESERVED, Rewriter, SHIFT, SIMPLESTR, STRICT_PROSCRIBED, TRAILING_SPACES, UNARY, WHITESPACE, compact, count, key, last, starts, _ref, _ref2,
__indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
_ref = require('./rewriter'), Rewriter = _ref.Rewriter, INVERSES = _ref.INVERSES;
@@ -69,7 +69,7 @@
}
}
}
if (__indexOf.call(['eval', 'arguments'].concat(JS_FORBIDDEN), id) >= 0) {
if (__indexOf.call(JS_FORBIDDEN, id) >= 0) {
if (forcedIdentifier) {
tag = 'IDENTIFIER';
id = new String(id);
@@ -129,7 +129,7 @@
};
Lexer.prototype.stringToken = function() {
var match, string;
var match, octalEsc, string;
switch (this.chunk.charAt(0)) {
case "'":
if (!(match = SIMPLESTR.exec(this.chunk))) return 0;
@@ -146,6 +146,9 @@
default:
return 0;
}
if (octalEsc = /^(?:\\.|[^\\])*\\[0-7]/.test(string)) {
this.error("octal escape sequences " + string + " are not allowed");
}
this.line += count(string, '\n');
return string.length;
};
@@ -630,11 +633,15 @@
COFFEE_KEYWORDS = COFFEE_KEYWORDS.concat(COFFEE_ALIASES);
RESERVED = ['case', 'default', 'function', 'var', 'void', 'with', 'const', 'let', 'enum', 'export', 'import', 'native', '__hasProp', '__extends', '__slice', '__bind', '__indexOf'];
RESERVED = ['case', 'default', 'function', 'var', 'void', 'with', 'const', 'let', 'enum', 'export', 'import', 'native', '__hasProp', '__extends', '__slice', '__bind', '__indexOf', 'implements', 'interface', 'let', 'package', 'private', 'protected', 'public', 'static', 'yield'];
JS_FORBIDDEN = JS_KEYWORDS.concat(RESERVED);
STRICT_PROSCRIBED = ['arguments', 'eval'];
exports.RESERVED = RESERVED.concat(JS_KEYWORDS).concat(COFFEE_KEYWORDS);
JS_FORBIDDEN = JS_KEYWORDS.concat(RESERVED).concat(STRICT_PROSCRIBED);
exports.RESERVED = RESERVED.concat(JS_KEYWORDS).concat(COFFEE_KEYWORDS).concat(STRICT_PROSCRIBED);
exports.STRICT_PROSCRIBED = STRICT_PROSCRIBED;
IDENTIFIER = /^([$A-Za-z_\x7f-\uffff][$\w\x7f-\uffff]*)([^\n\S]*:(?!:))?/;

File diff suppressed because it is too large Load Diff

View File

@@ -14,7 +14,7 @@
OptionParser.prototype.parse = function(args) {
var arg, i, isOption, matchedRule, options, originalArgs, pos, rule, skippingArgument, value, _i, _j, _len, _len2, _ref;
options = {
arguments: [],
"arguments": [],
literals: []
};
skippingArgument = false;
@@ -28,7 +28,7 @@
}
if (arg === '--') {
pos = originalArgs.indexOf('--');
options.arguments = [originalArgs[1 + pos]];
options["arguments"] = [originalArgs[1 + pos]];
options.literals = originalArgs.slice(2 + pos);
break;
}
@@ -48,7 +48,7 @@
throw new Error("unrecognized option: " + arg);
}
if (!isOption) {
options.arguments = originalArgs.slice(originalArgs.indexOf(arg));
options["arguments"] = originalArgs.slice(originalArgs.indexOf(arg));
break;
}
}

View File

@@ -167,7 +167,7 @@
backlog = '';
try {
_ = global._;
returnValue = CoffeeScript.eval("_=(" + code + "\n)", {
returnValue = CoffeeScript["eval"]("_=(" + code + "\n)", {
filename: 'repl',
modulename: 'repl'
});

View File

@@ -786,7 +786,7 @@ exports.Obj = class Obj extends Base
if prop?
propName = prop.unwrapAll().value.toString()
if propName in propNames
throw SyntaxError "duplicate data property #{propName} in object literals are not allowed"
throw SyntaxError "multiple object literal properties named \"#{propName}\""
propNames.push propName
return (if @front then '({})' else '{}') unless props.length
if @generated
@@ -863,7 +863,7 @@ exports.Class = class Class extends Base
else
@variable.base.value
if decl in STRICT_PROSCRIBED
throw SyntaxError 'variable name may not be eval or arguments'
throw SyntaxError "variable name may not be #{decl}"
decl and= IDENTIFIER.test(decl) and decl
# For all `this`-references and bound functions in the class definition,
@@ -992,8 +992,8 @@ exports.Assign = class Assign extends Base
constructor: (@variable, @value, @context, options) ->
@param = options and options.param
@subpattern = options and options.subpattern
if @variable.unwrapAll().value in STRICT_PROSCRIBED
throw SyntaxError 'variable name may not be "eval" or "arguments"'
if name = @variable.unwrapAll().value in STRICT_PROSCRIBED
throw SyntaxError "variable name may not be \"#{name}\""
children: ['variable', 'value']
@@ -1166,8 +1166,8 @@ exports.Code = class Code extends Base
o.scope.shared = del(o, 'sharedScope')
o.indent += TAB
delete o.bare
params = []
exprs = []
params = []
exprs = []
for name in @paramNames() # this step must be performed before the others
unless o.scope.check name then o.scope.parameter name
for param in @params when param.splat
@@ -1228,8 +1228,8 @@ exports.Code = class Code extends Base
# as well as be a splat, gathering up a group of parameters into an array.
exports.Param = class Param extends Base
constructor: (@name, @value, @splat) ->
if @name.unwrapAll().value in STRICT_PROSCRIBED
throw SyntaxError 'parameter name eval or arguments is not allowed'
if name = @name.unwrapAll().value in STRICT_PROSCRIBED
throw SyntaxError "parameter name \"#{name}\" is not allowed"
children: ['name', 'value']
@@ -1582,7 +1582,7 @@ exports.Try = class Try extends Base
catchPart = if @recovery
if @error.value in STRICT_PROSCRIBED
throw SyntaxError "catch variable may not be eval or arguments"
throw SyntaxError "catch variable may not be \"#{@error.value}\""
o.scope.add @error.value, 'param' unless o.scope.check @error.value
" catch#{errorPart}{\n#{ @recovery.compile o, LEVEL_TOP }\n#{@tab}}"
else unless @ensure or @recovery

View File

@@ -23,7 +23,7 @@ strictOk = (code, msg) ->
doesNotThrow (-> CoffeeScript.compile code), msg
test "Octal Integer Literals prohibited", ->
test "octal integer literals prohibited", ->
strict '01'
strict '07777'
# decimals with a leading '0' are also prohibited
@@ -31,7 +31,7 @@ test "Octal Integer Literals prohibited", ->
strict '079'
strictOk '`01`'
test "Octal Escape Sequences prohibited", ->
test "octal escape sequences prohibited", ->
strict '"\\0"'
strict '"\\7"'
strict '"\\000"'
@@ -47,7 +47,7 @@ test "Octal Escape Sequences prohibited", ->
strictOk "`'\\0'`"
test "duplicate property definitions in `Object Literal`s are prohibited", ->
test "duplicate property definitions in object literals are prohibited", ->
strict 'o = {x:1,x:1}'
strict 'x = 1; o = {x, x: 2}'