diff --git a/lib/coffee-script/browser.js b/lib/coffee-script/browser.js index cb5e501d98..c471d4ee9a 100644 --- a/lib/coffee-script/browser.js +++ b/lib/coffee-script/browser.js @@ -6,7 +6,7 @@ CoffeeScript.require = require; - CoffeeScript.eval = function(code, options) { + CoffeeScript["eval"] = function(code, options) { return eval(CoffeeScript.compile(code, options)); }; diff --git a/lib/coffee-script/cake.js b/lib/coffee-script/cake.js index e7cb2a1dd3..8e8d9a0d42 100644 --- a/lib/coffee-script/cake.js +++ b/lib/coffee-script/cake.js @@ -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]; diff --git a/lib/coffee-script/coffee-script.js b/lib/coffee-script/coffee-script.js index 7907251350..fd676ba47f 100644 --- a/lib/coffee-script/coffee-script.js +++ b/lib/coffee-script/coffee-script.js @@ -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; diff --git a/lib/coffee-script/command.js b/lib/coffee-script/command.js index b7dc1b9815..b47fabe63a 100644 --- a/lib/coffee-script/command.js +++ b/lib/coffee-script/command.js @@ -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; diff --git a/lib/coffee-script/lexer.js b/lib/coffee-script/lexer.js index 0f7904c0a8..e2503c9a8b 100644 --- a/lib/coffee-script/lexer.js +++ b/lib/coffee-script/lexer.js @@ -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']; + + STRICT_PROSCRIBED = ['arguments', 'eval']; + + JS_FORBIDDEN = JS_KEYWORDS.concat(RESERVED).concat(STRICT_PROSCRIBED); - JS_FORBIDDEN = JS_KEYWORDS.concat(RESERVED); + exports.RESERVED = RESERVED.concat(JS_KEYWORDS).concat(COFFEE_KEYWORDS).concat(STRICT_PROSCRIBED); - exports.RESERVED = RESERVED.concat(JS_KEYWORDS).concat(COFFEE_KEYWORDS); + exports.STRICT_PROSCRIBED = STRICT_PROSCRIBED; IDENTIFIER = /^([$A-Za-z_\x7f-\uffff][$\w\x7f-\uffff]*)([^\n\S]*:(?!:))?/; diff --git a/lib/coffee-script/nodes.js b/lib/coffee-script/nodes.js index ae4beffea4..b992b52c83 100644 --- a/lib/coffee-script/nodes.js +++ b/lib/coffee-script/nodes.js @@ -1,15 +1,15 @@ // Generated by CoffeeScript 1.2.1-pre (function() { - var Access, Arr, Assign, Base, Block, Call, Class, Closure, Code, Comment, Existence, Extends, For, IDENTIFIER, IDENTIFIER_STR, IS_STRING, If, In, Index, LEVEL_ACCESS, LEVEL_COND, LEVEL_LIST, LEVEL_OP, LEVEL_PAREN, LEVEL_TOP, Literal, METHOD_DEF, NEGATE, NO, Obj, Op, Param, Parens, RESERVED, Range, Return, SIMPLENUM, Scope, Slice, Splat, Switch, TAB, THIS, Throw, Try, UTILITIES, Value, While, YES, compact, del, ends, extend, flatten, last, merge, multident, starts, unfoldSoak, utility, _ref, + var Access, Arr, Assign, Base, Block, Call, Class, Closure, Code, Comment, Existence, Extends, For, IDENTIFIER, IDENTIFIER_STR, IS_STRING, If, In, Index, LEVEL_ACCESS, LEVEL_COND, LEVEL_LIST, LEVEL_OP, LEVEL_PAREN, LEVEL_TOP, Literal, METHOD_DEF, NEGATE, NO, Obj, Op, Param, Parens, RESERVED, Range, Return, SIMPLENUM, STRICT_PROSCRIBED, Scope, Slice, Splat, Switch, TAB, THIS, Throw, Try, UTILITIES, Value, While, YES, compact, del, ends, extend, flatten, last, merge, multident, starts, unfoldSoak, utility, _ref, _ref2, __hasProp = {}.hasOwnProperty, __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor; child.__super__ = parent.prototype; return child; }, __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; }; Scope = require('./scope').Scope; - RESERVED = require('./lexer').RESERVED; + _ref = require('./lexer'), RESERVED = _ref.RESERVED, STRICT_PROSCRIBED = _ref.STRICT_PROSCRIBED; - _ref = require('./helpers'), compact = _ref.compact, flatten = _ref.flatten, extend = _ref.extend, merge = _ref.merge, del = _ref.del, starts = _ref.starts, ends = _ref.ends, last = _ref.last; + _ref2 = require('./helpers'), compact = _ref2.compact, flatten = _ref2.flatten, extend = _ref2.extend, merge = _ref2.merge, del = _ref2.del, starts = _ref2.starts, ends = _ref2.ends, last = _ref2.last; exports.extend = extend; @@ -132,15 +132,15 @@ }; Base.prototype.eachChild = function(func) { - var attr, child, _i, _j, _len, _len2, _ref2, _ref3; + var attr, child, _i, _j, _len, _len2, _ref3, _ref4; if (!this.children) return this; - _ref2 = this.children; - for (_i = 0, _len = _ref2.length; _i < _len; _i++) { - attr = _ref2[_i]; + _ref3 = this.children; + for (_i = 0, _len = _ref3.length; _i < _len; _i++) { + attr = _ref3[_i]; if (this[attr]) { - _ref3 = flatten([this[attr]]); - for (_j = 0, _len2 = _ref3.length; _j < _len2; _j++) { - child = _ref3[_j]; + _ref4 = flatten([this[attr]]); + for (_j = 0, _len2 = _ref4.length; _j < _len2; _j++) { + child = _ref4[_j]; if (func(child) === false) return this; } } @@ -229,20 +229,20 @@ }; Block.prototype.isStatement = function(o) { - var exp, _i, _len, _ref2; - _ref2 = this.expressions; - for (_i = 0, _len = _ref2.length; _i < _len; _i++) { - exp = _ref2[_i]; + var exp, _i, _len, _ref3; + _ref3 = this.expressions; + for (_i = 0, _len = _ref3.length; _i < _len; _i++) { + exp = _ref3[_i]; if (exp.isStatement(o)) return true; } return false; }; Block.prototype.jumps = function(o) { - var exp, _i, _len, _ref2; - _ref2 = this.expressions; - for (_i = 0, _len = _ref2.length; _i < _len; _i++) { - exp = _ref2[_i]; + var exp, _i, _len, _ref3; + _ref3 = this.expressions; + for (_i = 0, _len = _ref3.length; _i < _len; _i++) { + exp = _ref3[_i]; if (exp.jumps(o)) return exp; } }; @@ -273,13 +273,13 @@ }; Block.prototype.compileNode = function(o) { - var code, codes, node, top, _i, _len, _ref2; + var code, codes, node, top, _i, _len, _ref3; this.tab = o.indent; top = o.level === LEVEL_TOP; codes = []; - _ref2 = this.expressions; - for (_i = 0, _len = _ref2.length; _i < _len; _i++) { - node = _ref2[_i]; + _ref3 = this.expressions; + for (_i = 0, _len = _ref3.length; _i < _len; _i++) { + node = _ref3[_i]; node = node.unwrapAll(); node = node.unfoldSoak(o) || node; if (node instanceof Block) { @@ -320,11 +320,11 @@ prelude = ""; if (!o.bare) { preludeExps = (function() { - var _i, _len, _ref2, _results; - _ref2 = this.expressions; + var _i, _len, _ref3, _results; + _ref3 = this.expressions; _results = []; - for (i = _i = 0, _len = _ref2.length; _i < _len; i = ++_i) { - exp = _ref2[i]; + for (i = _i = 0, _len = _ref3.length; _i < _len; i = ++_i) { + exp = _ref3[i]; if (!(exp.unwrap() instanceof Comment)) break; _results.push(exp); } @@ -345,11 +345,11 @@ }; Block.prototype.compileWithDeclarations = function(o) { - var assigns, code, declars, exp, i, post, rest, scope, spaced, _i, _len, _ref2, _ref3, _ref4; + var assigns, code, declars, exp, i, post, rest, scope, spaced, _i, _len, _ref3, _ref4, _ref5; code = post = ''; - _ref2 = this.expressions; - for (i = _i = 0, _len = _ref2.length; _i < _len; i = ++_i) { - exp = _ref2[i]; + _ref3 = this.expressions; + for (i = _i = 0, _len = _ref3.length; _i < _len; i = ++_i) { + exp = _ref3[i]; exp = exp.unwrap(); if (!(exp instanceof Comment || exp instanceof Literal)) break; } @@ -358,8 +358,8 @@ }); if (i) { rest = this.expressions.splice(i, 9e9); - _ref3 = [this.spaced, false], spaced = _ref3[0], this.spaced = _ref3[1]; - _ref4 = [this.compileNode(o), spaced], code = _ref4[0], this.spaced = _ref4[1]; + _ref4 = [this.spaced, false], spaced = _ref4[0], this.spaced = _ref4[1]; + _ref5 = [this.compileNode(o), spaced], code = _ref5[0], this.spaced = _ref5[1]; this.expressions = rest; } post = this.compileNode(o); @@ -413,8 +413,8 @@ }; Literal.prototype.isStatement = function() { - var _ref2; - return (_ref2 = this.value) === 'break' || _ref2 === 'continue' || _ref2 === 'debugger'; + var _ref3; + return (_ref3 = this.value) === 'break' || _ref3 === 'continue' || _ref3 === 'debugger'; }; Literal.prototype.isComplex = NO; @@ -431,8 +431,8 @@ }; Literal.prototype.compileNode = function(o) { - var code, _ref2, _ref3; - code = this.isUndefined ? o.level >= LEVEL_ACCESS ? '(void 0)' : 'void 0' : this.value === 'this' ? ((_ref2 = o.scope.method) != null ? _ref2.bound : void 0) ? o.scope.method.context : this.value : this.value.reserved && ((_ref3 = "" + this.value) !== 'eval' && _ref3 !== 'arguments') ? "\"" + this.value + "\"" : this.value; + var code, _ref3; + code = this.isUndefined ? o.level >= LEVEL_ACCESS ? '(void 0)' : 'void 0' : this.value === 'this' ? ((_ref3 = o.scope.method) != null ? _ref3.bound : void 0) ? o.scope.method.context : this.value : this.value.reserved ? "\"" + this.value + "\"" : this.value; if (this.isStatement()) { return "" + this.tab + code + ";"; } else { @@ -467,8 +467,8 @@ Return.prototype.jumps = THIS; Return.prototype.compile = function(o, level) { - var expr, _ref2; - expr = (_ref2 = this.expression) != null ? _ref2.makeReturn() : void 0; + var expr, _ref3; + expr = (_ref3 = this.expression) != null ? _ref3.makeReturn() : void 0; if (expr && !(expr instanceof Return)) { return expr.compile(o, level); } else { @@ -530,10 +530,10 @@ }; Value.prototype.isAtomic = function() { - var node, _i, _len, _ref2; - _ref2 = this.properties.concat(this.base); - for (_i = 0, _len = _ref2.length; _i < _len; _i++) { - node = _ref2[_i]; + var node, _i, _len, _ref3; + _ref3 = this.properties.concat(this.base); + for (_i = 0, _len = _ref3.length; _i < _len; _i++) { + node = _ref3[_i]; if (node.soak || node instanceof Call) return false; } return true; @@ -608,14 +608,14 @@ _this = this; if (this.unfoldedSoak != null) return this.unfoldedSoak; result = (function() { - var fst, i, ifn, prop, ref, snd, _i, _len, _ref2; + var fst, i, ifn, prop, ref, snd, _i, _len, _ref3; if (ifn = _this.base.unfoldSoak(o)) { Array.prototype.push.apply(ifn.body.properties, _this.properties); return ifn; } - _ref2 = _this.properties; - for (i = _i = 0, _len = _ref2.length; _i < _len; i = ++_i) { - prop = _ref2[i]; + _ref3 = _this.properties; + for (i = _i = 0, _len = _ref3.length; _i < _len; i = ++_i) { + prop = _ref3[i]; if (!prop.soak) continue; prop.soak = false; fst = new Value(_this.base, _this.properties.slice(0, i)); @@ -680,8 +680,8 @@ Call.prototype.children = ['variable', 'args']; Call.prototype.newInstance = function() { - var base, _ref2; - base = ((_ref2 = this.variable) != null ? _ref2.base : void 0) || this.variable; + var base, _ref3; + base = ((_ref3 = this.variable) != null ? _ref3.base : void 0) || this.variable; if (base instanceof Call && !base.isNew) { base.newInstance(); } else { @@ -700,7 +700,9 @@ } if (method.klass) { accesses = [new Access(new Literal('__super__'))]; - if (method.static) accesses.push(new Access(new Literal('constructor'))); + if (method["static"]) { + accesses.push(new Access(new Literal('constructor'))); + } accesses.push(new Access(new Literal(name))); return (new Value(new Literal(method.klass), accesses)).compile(o); } else { @@ -709,11 +711,11 @@ }; Call.prototype.unfoldSoak = function(o) { - var call, ifn, left, list, rite, _i, _len, _ref2, _ref3; + var call, ifn, left, list, rite, _i, _len, _ref3, _ref4; if (this.soak) { if (this.variable) { if (ifn = unfoldSoak(o, this, 'variable')) return ifn; - _ref2 = new Value(this.variable).cacheReference(o), left = _ref2[0], rite = _ref2[1]; + _ref3 = new Value(this.variable).cacheReference(o), left = _ref3[0], rite = _ref3[1]; } else { left = new Literal(this.superReference(o)); rite = new Value(left); @@ -737,9 +739,9 @@ list.push(call); if (!((call = call.variable.base) instanceof Call)) break; } - _ref3 = list.reverse(); - for (_i = 0, _len = _ref3.length; _i < _len; _i++) { - call = _ref3[_i]; + _ref4 = list.reverse(); + for (_i = 0, _len = _ref4.length; _i < _len; _i++) { + call = _ref4[_i]; if (ifn) { if (call.variable instanceof Call) { call.variable = ifn; @@ -753,7 +755,7 @@ }; Call.prototype.filterImplicitObjects = function(list) { - var node, nodes, obj, prop, properties, _i, _j, _len, _len2, _ref2; + var node, nodes, obj, prop, properties, _i, _j, _len, _len2, _ref3; nodes = []; for (_i = 0, _len = list.length; _i < _len; _i++) { node = list[_i]; @@ -762,9 +764,9 @@ continue; } obj = null; - _ref2 = node.base.properties; - for (_j = 0, _len2 = _ref2.length; _j < _len2; _j++) { - prop = _ref2[_j]; + _ref3 = node.base.properties; + for (_j = 0, _len2 = _ref3.length; _j < _len2; _j++) { + prop = _ref3[_j]; if (prop instanceof Assign || prop instanceof Comment) { if (!obj) nodes.push(obj = new Obj(properties = [], true)); properties.push(prop); @@ -778,8 +780,8 @@ }; Call.prototype.compileNode = function(o) { - var arg, args, code, _ref2; - if ((_ref2 = this.variable) != null) _ref2.front = this.front; + var arg, args, code, _ref3; + if ((_ref3 = this.variable) != null) _ref3.front = this.front; if (code = Splat.compileSplattedArray(o, this.args, true)) { return this.compileSplat(o, code); } @@ -925,21 +927,21 @@ } Range.prototype.compileVariables = function(o) { - var step, _ref2, _ref3, _ref4, _ref5; + var step, _ref3, _ref4, _ref5, _ref6; o = merge(o, { top: true }); - _ref2 = this.from.cache(o, LEVEL_LIST), this.fromC = _ref2[0], this.fromVar = _ref2[1]; - _ref3 = this.to.cache(o, LEVEL_LIST), this.toC = _ref3[0], this.toVar = _ref3[1]; + _ref3 = this.from.cache(o, LEVEL_LIST), this.fromC = _ref3[0], this.fromVar = _ref3[1]; + _ref4 = this.to.cache(o, LEVEL_LIST), this.toC = _ref4[0], this.toVar = _ref4[1]; if (step = del(o, 'step')) { - _ref4 = step.cache(o, LEVEL_LIST), this.step = _ref4[0], this.stepVar = _ref4[1]; + _ref5 = step.cache(o, LEVEL_LIST), this.step = _ref5[0], this.stepVar = _ref5[1]; } - _ref5 = [this.fromVar.match(SIMPLENUM), this.toVar.match(SIMPLENUM)], this.fromNum = _ref5[0], this.toNum = _ref5[1]; + _ref6 = [this.fromVar.match(SIMPLENUM), this.toVar.match(SIMPLENUM)], this.fromNum = _ref6[0], this.toNum = _ref6[1]; if (this.stepVar) return this.stepNum = this.stepVar.match(SIMPLENUM); }; Range.prototype.compileNode = function(o) { - var cond, condPart, from, gt, idx, idxName, known, lt, namedIndex, stepPart, to, varPart, _ref2, _ref3; + var cond, condPart, from, gt, idx, idxName, known, lt, namedIndex, stepPart, to, varPart, _ref3, _ref4; if (!this.fromVar) this.compileVariables(o); if (!o.index) return this.compileArray(o); known = this.fromNum && this.toNum; @@ -949,8 +951,8 @@ varPart = "" + idx + " = " + this.fromC; if (this.toC !== this.toVar) varPart += ", " + this.toC; if (this.step !== this.stepVar) varPart += ", " + this.step; - _ref2 = ["" + idx + " <" + this.equals, "" + idx + " >" + this.equals], lt = _ref2[0], gt = _ref2[1]; - condPart = this.stepNum ? +this.stepNum > 0 ? "" + lt + " " + this.toVar : "" + gt + " " + this.toVar : known ? ((_ref3 = [+this.fromNum, +this.toNum], from = _ref3[0], to = _ref3[1], _ref3), from <= to ? "" + lt + " " + to : "" + gt + " " + to) : (cond = "" + this.fromVar + " <= " + this.toVar, "" + cond + " ? " + lt + " " + this.toVar + " : " + gt + " " + this.toVar); + _ref3 = ["" + idx + " <" + this.equals, "" + idx + " >" + this.equals], lt = _ref3[0], gt = _ref3[1]; + condPart = this.stepNum ? +this.stepNum > 0 ? "" + lt + " " + this.toVar : "" + gt + " " + this.toVar : known ? ((_ref4 = [+this.fromNum, +this.toNum], from = _ref4[0], to = _ref4[1], _ref4), from <= to ? "" + lt + " " + to : "" + gt + " " + to) : (cond = "" + this.fromVar + " <= " + this.toVar, "" + cond + " ? " + lt + " " + this.toVar + " : " + gt + " " + this.toVar); stepPart = this.stepVar ? "" + idx + " += " + this.stepVar : known ? namedIndex ? from <= to ? "++" + idx : "--" + idx : from <= to ? "" + idx + "++" : "" + idx + "--" : namedIndex ? "" + cond + " ? ++" + idx + " : --" + idx : "" + cond + " ? " + idx + "++ : " + idx + "--"; if (namedIndex) varPart = "" + idxName + " = " + varPart; if (namedIndex) stepPart = "" + idxName + " = " + stepPart; @@ -958,11 +960,11 @@ }; Range.prototype.compileArray = function(o) { - var args, body, cond, hasArgs, i, idt, post, pre, range, result, vars, _i, _ref2, _ref3, _results; + var args, body, cond, hasArgs, i, idt, post, pre, range, result, vars, _i, _ref3, _ref4, _results; if (this.fromNum && this.toNum && Math.abs(this.fromNum - this.toNum) <= 20) { range = (function() { _results = []; - for (var _i = _ref2 = +this.fromNum, _ref3 = +this.toNum; _ref2 <= _ref3 ? _i <= _ref3 : _i >= _ref3; _ref2 <= _ref3 ? _i++ : _i--){ _results.push(_i); } + for (var _i = _ref3 = +this.fromNum, _ref4 = +this.toNum; _ref3 <= _ref4 ? _i <= _ref4 : _i >= _ref4; _ref3 <= _ref4 ? _i++ : _i--){ _results.push(_i); } return _results; }).apply(this); if (this.exclusive) range.pop(); @@ -1008,8 +1010,8 @@ } Slice.prototype.compileNode = function(o) { - var compiled, from, fromStr, to, toStr, _ref2; - _ref2 = this.range, to = _ref2.to, from = _ref2.from; + var compiled, from, fromStr, to, toStr, _ref3; + _ref3 = this.range, to = _ref3.to, from = _ref3.from; fromStr = from && from.compile(o, LEVEL_PAREN) || '0'; compiled = to && to.compile(o, LEVEL_ACCESS); if (to && !(!this.range.exclusive && +compiled === -1)) { @@ -1036,12 +1038,25 @@ Obj.prototype.children = ['properties']; Obj.prototype.compileNode = function(o) { - var i, idt, indent, join, lastNoncom, node, obj, prop, props, _i, _len; + var i, idt, indent, join, lastNoncom, node, obj, prop, propName, propNames, props, _i, _j, _len, _len2, _ref3; props = this.properties; + propNames = []; + _ref3 = this.properties; + for (_i = 0, _len = _ref3.length; _i < _len; _i++) { + prop = _ref3[_i]; + if (prop.isComplex()) prop = prop.variable; + if (prop != null) { + propName = prop.unwrapAll().value.toString(); + if (__indexOf.call(propNames, propName) >= 0) { + throw SyntaxError("multiple object literal properties named \"" + propName + "\""); + } + propNames.push(propName); + } + } if (!props.length) return (this.front ? '({})' : '{}'); if (this.generated) { - for (_i = 0, _len = props.length; _i < _len; _i++) { - node = props[_i]; + for (_j = 0, _len2 = props.length; _j < _len2; _j++) { + node = props[_j]; if (node instanceof Value) { throw new Error('cannot have an implicit value in an implicit object'); } @@ -1050,9 +1065,9 @@ idt = o.indent += TAB; lastNoncom = this.lastNonComment(this.properties); props = (function() { - var _j, _len2, _results; + var _k, _len3, _results; _results = []; - for (i = _j = 0, _len2 = props.length; _j < _len2; i = ++_j) { + for (i = _k = 0, _len3 = props.length; _k < _len3; i = ++_k) { prop = props[i]; join = i === props.length - 1 ? '' : prop === lastNoncom || prop instanceof Comment ? '\n' : ',\n'; indent = prop instanceof Comment ? '' : idt; @@ -1077,10 +1092,10 @@ }; Obj.prototype.assigns = function(name) { - var prop, _i, _len, _ref2; - _ref2 = this.properties; - for (_i = 0, _len = _ref2.length; _i < _len; _i++) { - prop = _ref2[_i]; + var prop, _i, _len, _ref3; + _ref3 = this.properties; + for (_i = 0, _len = _ref3.length; _i < _len; _i++) { + prop = _ref3[_i]; if (prop.assigns(name)) return true; } return false; @@ -1127,10 +1142,10 @@ }; Arr.prototype.assigns = function(name) { - var obj, _i, _len, _ref2; - _ref2 = this.objects; - for (_i = 0, _len = _ref2.length; _i < _len; _i++) { - obj = _ref2[_i]; + var obj, _i, _len, _ref3; + _ref3 = this.objects; + for (_i = 0, _len = _ref3.length; _i < _len; _i++) { + obj = _ref3[_i]; if (obj.assigns(name)) return true; } return false; @@ -1160,6 +1175,9 @@ var decl, tail; if (!this.variable) return null; decl = (tail = last(this.variable.properties)) ? tail instanceof Access && tail.name.value : this.variable.base.value; + if (__indexOf.call(STRICT_PROSCRIBED, decl) >= 0) { + throw SyntaxError("variable name may not be " + decl); + } return decl && (decl = IDENTIFIER.test(decl) && decl); }; @@ -1176,12 +1194,12 @@ }; Class.prototype.addBoundFunctions = function(o) { - var bvar, lhs, _i, _len, _ref2, _results; + var bvar, lhs, _i, _len, _ref3, _results; if (this.boundFuncs.length) { - _ref2 = this.boundFuncs; + _ref3 = this.boundFuncs; _results = []; - for (_i = 0, _len = _ref2.length; _i < _len; _i++) { - bvar = _ref2[_i]; + for (_i = 0, _len = _ref3.length; _i < _len; _i++) { + bvar = _ref3[_i]; lhs = (new Value(new Literal("this"), [new Access(bvar)])).compile(o); _results.push(this.ctor.body.unshift(new Literal("" + lhs + " = " + (utility('bind')) + "(" + lhs + ", this)"))); } @@ -1215,7 +1233,7 @@ } } else { if (assign.variable["this"]) { - func.static = true; + func["static"] = true; if (func.bound) func.context = name; } else { assign.variable = new Value(new Literal(name), [new Access(new Literal('prototype')), new Access(base)]); @@ -1236,12 +1254,12 @@ Class.prototype.walkBody = function(name, o) { var _this = this; return this.traverseChildren(false, function(child) { - var exps, i, node, _i, _len, _ref2; + var exps, i, node, _i, _len, _ref3; if (child instanceof Class) return false; if (child instanceof Block) { - _ref2 = exps = child.expressions; - for (i = _i = 0, _len = _ref2.length; _i < _len; i = ++_i) { - node = _ref2[i]; + _ref3 = exps = child.expressions; + for (i = _i = 0, _len = _ref3.length; _i < _len; i = ++_i) { + node = _ref3[i]; if (node instanceof Value && node.isObject(true)) { exps[i] = _this.addProperties(node, name, o); } @@ -1279,7 +1297,7 @@ }; Class.prototype.compileNode = function(o) { - var call, decl, klass, lname, name, params, _ref2; + var call, decl, klass, lname, name, params, _ref3; decl = this.determineName(); name = decl || '_Class'; if (name.reserved) name = "_" + name; @@ -1294,7 +1312,7 @@ this.body.expressions.unshift(new Assign(new Value(new Literal(name), [new Access(new Literal('name'))]), new Literal("'" + name + "'"))); } this.body.expressions.push(lname); - (_ref2 = this.body.expressions).unshift.apply(_ref2, this.directives); + (_ref3 = this.body.expressions).unshift.apply(_ref3, this.directives); this.addBoundFunctions(o); call = Closure.wrap(this.body); if (this.parent) { @@ -1320,11 +1338,15 @@ Assign.name = 'Assign'; function Assign(variable, value, context, options) { + var name, _ref3; this.variable = variable; this.value = value; this.context = context; this.param = options && options.param; this.subpattern = options && options.subpattern; + if (name = (_ref3 = this.variable.unwrapAll().value, __indexOf.call(STRICT_PROSCRIBED, _ref3) >= 0)) { + throw SyntaxError("variable name may not be \"" + name + "\""); + } } Assign.prototype.children = ['variable', 'value']; @@ -1342,13 +1364,13 @@ }; Assign.prototype.compileNode = function(o) { - var isValue, match, name, val, varBase, _ref2, _ref3, _ref4, _ref5; + var isValue, match, name, val, varBase, _ref3, _ref4, _ref5, _ref6; if (isValue = this.variable instanceof Value) { if (this.variable.isArray() || this.variable.isObject()) { return this.compilePatternMatch(o); } if (this.variable.isSplice()) return this.compileSplice(o); - if ((_ref2 = this.context) === '||=' || _ref2 === '&&=' || _ref2 === '?=') { + if ((_ref3 = this.context) === '||=' || _ref3 === '&&=' || _ref3 === '?=') { return this.compileConditional(o); } } @@ -1367,7 +1389,7 @@ } if (this.value instanceof Code && (match = METHOD_DEF.exec(name))) { if (match[1]) this.value.klass = match[1]; - this.value.name = (_ref3 = (_ref4 = (_ref5 = match[2]) != null ? _ref5 : match[3]) != null ? _ref4 : match[4]) != null ? _ref3 : match[5]; + this.value.name = (_ref4 = (_ref5 = (_ref6 = match[2]) != null ? _ref6 : match[3]) != null ? _ref5 : match[4]) != null ? _ref4 : match[5]; } val = this.value.compile(o, LEVEL_LIST); if (this.context === 'object') return "" + name + ": " + val; @@ -1380,7 +1402,7 @@ }; Assign.prototype.compilePatternMatch = function(o) { - var acc, assigns, code, i, idx, isObject, ivar, name, obj, objects, olen, ref, rest, splat, top, val, value, vvar, _i, _len, _ref2, _ref3, _ref4, _ref5, _ref6, _ref7, _ref8; + var acc, assigns, code, i, idx, isObject, ivar, name, obj, objects, olen, ref, rest, splat, top, val, value, vvar, _i, _len, _ref3, _ref4, _ref5, _ref6, _ref7, _ref8, _ref9; top = o.level === LEVEL_TOP; value = this.value; objects = this.variable.base.objects; @@ -1395,10 +1417,10 @@ isObject = this.variable.isObject(); if (top && olen === 1 && !((obj = objects[0]) instanceof Splat)) { if (obj instanceof Assign) { - _ref2 = obj, (_ref3 = _ref2.variable, idx = _ref3.base), obj = _ref2.value; + _ref3 = obj, (_ref4 = _ref3.variable, idx = _ref4.base), obj = _ref3.value; } else { if (obj.base instanceof Parens) { - _ref4 = new Value(obj.unwrapAll()).cacheReference(o), obj = _ref4[0], idx = _ref4[1]; + _ref5 = new Value(obj.unwrapAll()).cacheReference(o), obj = _ref5[0], idx = _ref5[1]; } else { idx = isObject ? obj["this"] ? obj.properties[0].name : obj : new Literal(0); } @@ -1406,7 +1428,7 @@ acc = IDENTIFIER.test(idx.unwrap().value || 0); value = new Value(value); value.properties.push(new (acc ? Access : Index)(idx)); - if (_ref5 = obj.unwrap().value, __indexOf.call(['arguments', 'eval'].concat(RESERVED), _ref5) >= 0) { + if (_ref6 = obj.unwrap().value, __indexOf.call(RESERVED, _ref6) >= 0) { throw new SyntaxError("assignment to a reserved word: " + (obj.compile(o)) + " = " + (value.compile(o))); } return new Assign(obj, value, null, { @@ -1425,10 +1447,10 @@ idx = i; if (isObject) { if (obj instanceof Assign) { - _ref6 = obj, (_ref7 = _ref6.variable, idx = _ref7.base), obj = _ref6.value; + _ref7 = obj, (_ref8 = _ref7.variable, idx = _ref8.base), obj = _ref7.value; } else { if (obj.base instanceof Parens) { - _ref8 = new Value(obj.unwrapAll()).cacheReference(o), obj = _ref8[0], idx = _ref8[1]; + _ref9 = new Value(obj.unwrapAll()).cacheReference(o), obj = _ref9[0], idx = _ref9[1]; } else { idx = obj["this"] ? obj.properties[0].name : obj; } @@ -1460,7 +1482,7 @@ } val = new Value(new Literal(vvar), [new (acc ? Access : Index)(idx)]); } - if ((name != null) && __indexOf.call(['arguments', 'eval'].concat(RESERVED), name) >= 0) { + if ((name != null) && __indexOf.call(RESERVED, name) >= 0) { throw new SyntaxError("assignment to a reserved word: " + (obj.compile(o)) + " = " + (val.compile(o))); } assigns.push(new Assign(obj, val, null, { @@ -1478,17 +1500,17 @@ }; Assign.prototype.compileConditional = function(o) { - var left, rite, _ref2; - _ref2 = this.variable.cacheReference(o), left = _ref2[0], rite = _ref2[1]; + var left, rite, _ref3; + _ref3 = this.variable.cacheReference(o), left = _ref3[0], rite = _ref3[1]; if (__indexOf.call(this.context, "?") >= 0) o.isExistentialEquals = true; return new Op(this.context.slice(0, -1), left, new Assign(rite, this.value, '=')).compile(o); }; Assign.prototype.compileSplice = function(o) { - var code, exclusive, from, fromDecl, fromRef, name, to, valDef, valRef, _ref2, _ref3, _ref4; - _ref2 = this.variable.properties.pop().range, from = _ref2.from, to = _ref2.to, exclusive = _ref2.exclusive; + var code, exclusive, from, fromDecl, fromRef, name, to, valDef, valRef, _ref3, _ref4, _ref5; + _ref3 = this.variable.properties.pop().range, from = _ref3.from, to = _ref3.to, exclusive = _ref3.exclusive; name = this.variable.compile(o); - _ref3 = (from != null ? from.cache(o, LEVEL_OP) : void 0) || ['0', '0'], fromDecl = _ref3[0], fromRef = _ref3[1]; + _ref4 = (from != null ? from.cache(o, LEVEL_OP) : void 0) || ['0', '0'], fromDecl = _ref4[0], fromRef = _ref4[1]; if (to) { if ((from != null ? from.isSimpleNumber() : void 0) && to.isSimpleNumber()) { to = +to.compile(o) - +fromRef; @@ -1500,7 +1522,7 @@ } else { to = "9e9"; } - _ref4 = this.value.cache(o, LEVEL_LIST), valDef = _ref4[0], valRef = _ref4[1]; + _ref5 = this.value.cache(o, LEVEL_LIST), valDef = _ref5[0], valRef = _ref5[1]; code = "[].splice.apply(" + name + ", [" + fromDecl + ", " + to + "].concat(" + valDef + ")), " + valRef; if (o.level > LEVEL_TOP) { return "(" + code + ")"; @@ -1535,37 +1557,42 @@ Code.prototype.jumps = NO; Code.prototype.compileNode = function(o) { - var code, exprs, i, idt, lit, p, param, ref, splats, v, val, vars, wasEmpty, _i, _j, _k, _l, _len, _len2, _len3, _len4, _ref2, _ref3, _ref4, _ref5, _ref6; + var code, exprs, i, idt, lit, name, p, param, params, ref, splats, uniqs, val, wasEmpty, _i, _j, _k, _l, _len, _len2, _len3, _len4, _len5, _len6, _m, _n, _ref3, _ref4, _ref5, _ref6, _ref7, _ref8, _ref9; o.scope = new Scope(o.scope, this.body, this); o.scope.shared = del(o, 'sharedScope'); o.indent += TAB; delete o.bare; - vars = []; + params = []; exprs = []; - _ref2 = this.params; - for (_i = 0, _len = _ref2.length; _i < _len; _i++) { - param = _ref2[_i]; + _ref3 = this.paramNames(); + for (_i = 0, _len = _ref3.length; _i < _len; _i++) { + name = _ref3[_i]; + if (!o.scope.check(name)) o.scope.parameter(name); + } + _ref4 = this.params; + for (_j = 0, _len2 = _ref4.length; _j < _len2; _j++) { + param = _ref4[_j]; if (!param.splat) continue; - _ref3 = this.params; - for (_j = 0, _len2 = _ref3.length; _j < _len2; _j++) { - p = _ref3[_j]; + _ref5 = this.params; + for (_k = 0, _len3 = _ref5.length; _k < _len3; _k++) { + p = _ref5[_k]; if (p.name.value) o.scope.add(p.name.value, 'var', true); } splats = new Assign(new Value(new Arr((function() { - var _k, _len3, _ref4, _results; - _ref4 = this.params; + var _l, _len4, _ref6, _results; + _ref6 = this.params; _results = []; - for (_k = 0, _len3 = _ref4.length; _k < _len3; _k++) { - p = _ref4[_k]; + for (_l = 0, _len4 = _ref6.length; _l < _len4; _l++) { + p = _ref6[_l]; _results.push(p.asReference(o)); } return _results; }).call(this))), new Value(new Literal('arguments'))); break; } - _ref4 = this.params; - for (_k = 0, _len3 = _ref4.length; _k < _len3; _k++) { - param = _ref4[_k]; + _ref6 = this.params; + for (_l = 0, _len4 = _ref6.length; _l < _len4; _l++) { + param = _ref6[_l]; if (param.isComplex()) { val = ref = param.asReference(o); if (param.value) val = new Op('?', ref, param.value); @@ -1580,31 +1607,38 @@ exprs.push(new If(lit, val)); } } - if (!splats) vars.push(ref); + if (!splats) params.push(ref); } wasEmpty = this.body.isEmpty(); if (splats) exprs.unshift(splats); if (exprs.length) { - (_ref5 = this.body.expressions).unshift.apply(_ref5, exprs); - } - if (!splats) { - for (i = _l = 0, _len4 = vars.length; _l < _len4; i = ++_l) { - v = vars[i]; - o.scope.parameter(vars[i] = v.compile(o)); + (_ref7 = this.body.expressions).unshift.apply(_ref7, exprs); + } + for (i = _m = 0, _len5 = params.length; _m < _len5; i = ++_m) { + p = params[i]; + o.scope.parameter(params[i] = p.compile(o)); + } + uniqs = []; + _ref8 = this.paramNames(); + for (_n = 0, _len6 = _ref8.length; _n < _len6; _n++) { + name = _ref8[_n]; + if (__indexOf.call(uniqs, name) >= 0) { + throw SyntaxError("multiple parameters named '" + name + "'"); } + uniqs.push(name); } if (!(wasEmpty || this.noReturn)) this.body.makeReturn(); if (this.bound) { - if ((_ref6 = o.scope.parent.method) != null ? _ref6.bound : void 0) { + if ((_ref9 = o.scope.parent.method) != null ? _ref9.bound : void 0) { this.bound = this.context = o.scope.parent.method.context; - } else if (!this.static) { + } else if (!this["static"]) { o.scope.parent.assign('_this', 'this'); } } idt = o.indent; code = 'function'; if (this.ctor) code += ' ' + this.name; - code += '(' + vars.join(', ') + ') {'; + code += '(' + params.join(', ') + ') {'; if (!this.body.isEmpty()) { code += "\n" + (this.body.compileWithDeclarations(o)) + "\n" + this.tab; } @@ -1617,6 +1651,17 @@ } }; + Code.prototype.paramNames = function() { + var names, param, _i, _len, _ref3; + names = []; + _ref3 = this.params; + for (_i = 0, _len = _ref3.length; _i < _len; _i++) { + param = _ref3[_i]; + names.push.apply(names, param.names()); + } + return names; + }; + Code.prototype.traverseChildren = function(crossScope, func) { if (crossScope) { return Code.__super__.traverseChildren.call(this, crossScope, func); @@ -1634,9 +1679,13 @@ Param.name = 'Param'; function Param(name, value, splat) { + var _ref3; this.name = name; this.value = value; this.splat = splat; + if (name = (_ref3 = this.name.unwrapAll().value, __indexOf.call(STRICT_PROSCRIBED, _ref3) >= 0)) { + throw SyntaxError("parameter name \"" + name + "\" is not allowed"); + } } Param.prototype.children = ['name', 'value']; @@ -1651,7 +1700,9 @@ node = this.name; if (node["this"]) { node = node.properties[0].name; - if (node.value.reserved) node = new Literal('_' + node.value); + if (node.value.reserved) { + node = new Literal(o.scope.freeVariable(node.value)); + } } else if (node.isComplex()) { node = new Literal(o.scope.freeVariable('arg')); } @@ -1664,6 +1715,37 @@ return this.name.isComplex(); }; + Param.prototype.names = function(name) { + var atParam, names, obj, _i, _len, _ref3; + if (name == null) name = this.name; + atParam = function(obj) { + var value; + value = obj.properties[0].name.value; + if (value.reserved) { + return []; + } else { + return [value]; + } + }; + if (name instanceof Literal) return [name.value]; + if (name instanceof Value) return atParam(name); + names = []; + _ref3 = name.objects; + for (_i = 0, _len = _ref3.length; _i < _len; _i++) { + obj = _ref3[_i]; + if (obj instanceof Assign) { + names.push(obj.variable.base.value); + } else if (obj.isArray() || obj.isObject()) { + names.push.apply(names, this.names(obj.base)); + } else if (obj["this"]) { + names.push.apply(names, atParam(obj)); + } else { + names.push(obj.base.value); + } + } + return names; + }; + return Param; })(Base); @@ -1720,11 +1802,11 @@ return args[0] + (".concat(" + (args.slice(1).join(', ')) + ")"); } base = (function() { - var _j, _len2, _ref2, _results; - _ref2 = list.slice(0, index); + var _j, _len2, _ref3, _results; + _ref3 = list.slice(0, index); _results = []; - for (_j = 0, _len2 = _ref2.length; _j < _len2; _j++) { - node = _ref2[_j]; + for (_j = 0, _len2 = _ref3.length; _j < _len2; _j++) { + node = _ref3[_j]; _results.push(node.compile(o, LEVEL_LIST)); } return _results; @@ -1855,17 +1937,17 @@ }; Op.prototype.isComplex = function() { - var _ref2; - return !(this.isUnary() && ((_ref2 = this.operator) === '+' || _ref2 === '-')) || this.first.isComplex(); + var _ref3; + return !(this.isUnary() && ((_ref3 = this.operator) === '+' || _ref3 === '-')) || this.first.isComplex(); }; Op.prototype.isChainable = function() { - var _ref2; - return (_ref2 = this.operator) === '<' || _ref2 === '>' || _ref2 === '>=' || _ref2 === '<=' || _ref2 === '===' || _ref2 === '!=='; + var _ref3; + return (_ref3 = this.operator) === '<' || _ref3 === '>' || _ref3 === '>=' || _ref3 === '<=' || _ref3 === '===' || _ref3 === '!=='; }; Op.prototype.invert = function() { - var allInvertable, curr, fst, op, _ref2; + var allInvertable, curr, fst, op, _ref3; if (this.isChainable() && this.first.isChainable()) { allInvertable = true; curr = this; @@ -1887,7 +1969,7 @@ return this; } else if (this.second) { return new Parens(this).invert(); - } else if (this.operator === '!' && (fst = this.first.unwrap()) instanceof Op && ((_ref2 = fst.operator) === '!' || _ref2 === 'in' || _ref2 === 'instanceof')) { + } else if (this.operator === '!' && (fst = this.first.unwrap()) instanceof Op && ((_ref3 = fst.operator) === '!' || _ref3 === 'in' || _ref3 === 'instanceof')) { return fst; } else { return new Op('!', this); @@ -1895,17 +1977,17 @@ }; Op.prototype.unfoldSoak = function(o) { - var _ref2; - return ((_ref2 = this.operator) === '++' || _ref2 === '--' || _ref2 === 'delete') && unfoldSoak(o, this, 'first'); + var _ref3; + return ((_ref3 = this.operator) === '++' || _ref3 === '--' || _ref3 === 'delete') && unfoldSoak(o, this, 'first'); }; Op.prototype.generateDo = function(exp) { - var call, func, param, passedParams, ref, _i, _len, _ref2; + var call, func, param, passedParams, ref, _i, _len, _ref3; passedParams = []; func = exp instanceof Assign && (ref = exp.value.unwrap()) instanceof Code ? ref : exp; - _ref2 = func.params || []; - for (_i = 0, _len = _ref2.length; _i < _len; _i++) { - param = _ref2[_i]; + _ref3 = func.params || []; + for (_i = 0, _len = _ref3.length; _i < _len; _i++) { + param = _ref3[_i]; if (param.value) { passedParams.push(param.value); delete param.value; @@ -1919,9 +2001,15 @@ }; Op.prototype.compileNode = function(o) { - var code, isChain; + var code, isChain, _ref3, _ref4; isChain = this.isChainable() && this.first.isChainable(); if (!isChain) this.first.front = this.front; + if (this.operator === 'delete' && o.scope.check(this.first.unwrapAll().value)) { + throw SyntaxError('delete operand may not be argument or var'); + } + if (((_ref3 = this.operator) === '--' || _ref3 === '++') && (_ref4 = this.first.unwrapAll().value, __indexOf.call(STRICT_PROSCRIBED, _ref4) >= 0)) { + throw SyntaxError('prefix increment/decrement may not have eval or arguments operand'); + } if (this.isUnary()) return this.compileUnary(o); if (isChain) return this.compileChain(o); if (this.operator === '?') return this.compileExistence(o); @@ -1934,8 +2022,8 @@ }; Op.prototype.compileChain = function(o) { - var code, fst, shared, _ref2; - _ref2 = this.first.second.cache(o), this.first.second = _ref2[0], shared = _ref2[1]; + var code, fst, shared, _ref3; + _ref3 = this.first.second.cache(o), this.first.second = _ref3[0], shared = _ref3[1]; fst = this.first.compile(o, LEVEL_OP); code = "" + fst + " " + (this.invert ? '&&' : '||') + " " + (shared.compile(o)) + " " + this.operator + " " + (this.second.compile(o, LEVEL_OP)); return "(" + code + ")"; @@ -1994,11 +2082,11 @@ In.prototype.invert = NEGATE; In.prototype.compileNode = function(o) { - var hasSplat, obj, _i, _len, _ref2; + var hasSplat, obj, _i, _len, _ref3; if (this.array instanceof Value && this.array.isArray()) { - _ref2 = this.array.base.objects; - for (_i = 0, _len = _ref2.length; _i < _len; _i++) { - obj = _ref2[_i]; + _ref3 = this.array.base.objects; + for (_i = 0, _len = _ref3.length; _i < _len; _i++) { + obj = _ref3[_i]; if (!(obj instanceof Splat)) continue; hasSplat = true; break; @@ -2009,16 +2097,16 @@ }; In.prototype.compileOrTest = function(o) { - var cmp, cnj, i, item, ref, sub, tests, _ref2, _ref3; + var cmp, cnj, i, item, ref, sub, tests, _ref3, _ref4; if (this.array.base.objects.length === 0) return "" + (!!this.negated); - _ref2 = this.object.cache(o, LEVEL_OP), sub = _ref2[0], ref = _ref2[1]; - _ref3 = this.negated ? [' !== ', ' && '] : [' === ', ' || '], cmp = _ref3[0], cnj = _ref3[1]; + _ref3 = this.object.cache(o, LEVEL_OP), sub = _ref3[0], ref = _ref3[1]; + _ref4 = this.negated ? [' !== ', ' && '] : [' === ', ' || '], cmp = _ref4[0], cnj = _ref4[1]; tests = (function() { - var _i, _len, _ref4, _results; - _ref4 = this.array.base.objects; + var _i, _len, _ref5, _results; + _ref5 = this.array.base.objects; _results = []; - for (i = _i = 0, _len = _ref4.length; _i < _len; i = ++_i) { - item = _ref4[i]; + for (i = _i = 0, _len = _ref5.length; _i < _len; i = ++_i) { + item = _ref5[i]; _results.push((i ? ref : sub) + cmp + item.compile(o, LEVEL_ACCESS)); } return _results; @@ -2032,8 +2120,8 @@ }; In.prototype.compileLoopTest = function(o) { - var code, ref, sub, _ref2; - _ref2 = this.object.cache(o, LEVEL_LIST), sub = _ref2[0], ref = _ref2[1]; + var code, ref, sub, _ref3; + _ref3 = this.object.cache(o, LEVEL_LIST), sub = _ref3[0], ref = _ref3[1]; code = utility('indexOf') + (".call(" + (this.array.compile(o, LEVEL_LIST)) + ", " + ref + ") ") + (this.negated ? '< 0' : '>= 0'); if (sub === ref) return code; code = sub + ', ' + code; @@ -2070,8 +2158,8 @@ Try.prototype.isStatement = YES; Try.prototype.jumps = function(o) { - var _ref2; - return this.attempt.jumps(o) || ((_ref2 = this.recovery) != null ? _ref2.jumps(o) : void 0); + var _ref3; + return this.attempt.jumps(o) || ((_ref3 = this.recovery) != null ? _ref3.jumps(o) : void 0); }; Try.prototype.makeReturn = function(res) { @@ -2085,7 +2173,20 @@ o.indent += TAB; errorPart = this.error ? " (" + (this.error.compile(o)) + ") " : ' '; tryPart = this.attempt.compile(o, LEVEL_TOP); - catchPart = this.recovery ? (!o.scope.check(this.error.value) ? o.scope.add(this.error.value, 'param') : void 0, " catch" + errorPart + "{\n" + (this.recovery.compile(o, LEVEL_TOP)) + "\n" + this.tab + "}") : !(this.ensure || this.recovery) ? ' catch (_error) {}' : void 0; + catchPart = (function() { + var _ref3; + if (this.recovery) { + if (_ref3 = this.error.value, __indexOf.call(STRICT_PROSCRIBED, _ref3) >= 0) { + throw SyntaxError("catch variable may not be \"" + this.error.value + "\""); + } + if (!o.scope.check(this.error.value)) { + o.scope.add(this.error.value, 'param'); + } + return " catch" + errorPart + "{\n" + (this.recovery.compile(o, LEVEL_TOP)) + "\n" + this.tab + "}"; + } else if (!(this.ensure || this.recovery)) { + return ' catch (_error) {}'; + } + }).call(this); ensurePart = this.ensure ? " finally {\n" + (this.ensure.compile(o, LEVEL_TOP)) + "\n" + this.tab + "}" : ''; return "" + this.tab + "try {\n" + tryPart + "\n" + this.tab + "}" + (catchPart || '') + ensurePart; }; @@ -2135,11 +2236,11 @@ Existence.prototype.invert = NEGATE; Existence.prototype.compileNode = function(o) { - var cmp, cnj, code, _ref2; + var cmp, cnj, code, _ref3; this.expression.front = this.front; code = this.expression.compile(o, LEVEL_OP); if (IDENTIFIER.test(code) && !o.scope.check(code)) { - _ref2 = this.negated ? ['===', '||'] : ['!==', '&&'], cmp = _ref2[0], cnj = _ref2[1]; + _ref3 = this.negated ? ['===', '||'] : ['!==', '&&'], cmp = _ref3[0], cnj = _ref3[1]; code = "typeof " + code + " " + cmp + " \"undefined\" " + cnj + " " + code + " " + cmp + " null"; } else { code = "" + code + " " + (this.negated ? '==' : '!=') + " null"; @@ -2202,13 +2303,13 @@ For.name = 'For'; function For(body, source) { - var _ref2; + var _ref3; this.source = source.source, this.guard = source.guard, this.step = source.step, this.name = source.name, this.index = source.index; this.body = Block.wrap([body]); this.own = !!source.own; this.object = !!source.object; if (this.object) { - _ref2 = [this.index, this.name], this.name = _ref2[0], this.index = _ref2[1]; + _ref3 = [this.index, this.name], this.name = _ref3[0], this.index = _ref3[1]; } if (this.index instanceof Value) { throw SyntaxError('index cannot be a pattern matching expression'); @@ -2227,9 +2328,9 @@ For.prototype.children = ['body', 'source', 'guard', 'step']; For.prototype.compileNode = function(o) { - var body, defPart, forPart, forVarPart, guardPart, idt1, index, ivar, kvar, kvarAssign, lastJumps, lvar, name, namePart, ref, resultPart, returnResult, rvar, scope, source, stepPart, stepvar, svar, varPart, _ref2; + var body, defPart, forPart, forVarPart, guardPart, idt1, index, ivar, kvar, kvarAssign, lastJumps, lvar, name, namePart, ref, resultPart, returnResult, rvar, scope, source, stepPart, stepvar, svar, varPart, _ref3; body = Block.wrap([this.body]); - lastJumps = (_ref2 = last(body.expressions)) != null ? _ref2.jumps() : void 0; + lastJumps = (_ref3 = last(body.expressions)) != null ? _ref3.jumps() : void 0; if (lastJumps && lastJumps instanceof Return) this.returns = false; source = this.range ? this.source.base : this.source; scope = o.scope; @@ -2311,21 +2412,21 @@ }; For.prototype.pluckDirectCall = function(o, body) { - var base, defs, expr, fn, idx, ref, val, _i, _len, _ref2, _ref3, _ref4, _ref5, _ref6, _ref7; + var base, defs, expr, fn, idx, ref, val, _i, _len, _ref3, _ref4, _ref5, _ref6, _ref7, _ref8; defs = ''; - _ref2 = body.expressions; - for (idx = _i = 0, _len = _ref2.length; _i < _len; idx = ++_i) { - expr = _ref2[idx]; + _ref3 = body.expressions; + for (idx = _i = 0, _len = _ref3.length; _i < _len; idx = ++_i) { + expr = _ref3[idx]; expr = expr.unwrapAll(); if (!(expr instanceof Call)) continue; val = expr.variable.unwrapAll(); - if (!((val instanceof Code) || (val instanceof Value && ((_ref3 = val.base) != null ? _ref3.unwrapAll() : void 0) instanceof Code && val.properties.length === 1 && ((_ref4 = (_ref5 = val.properties[0].name) != null ? _ref5.value : void 0) === 'call' || _ref4 === 'apply')))) { + if (!((val instanceof Code) || (val instanceof Value && ((_ref4 = val.base) != null ? _ref4.unwrapAll() : void 0) instanceof Code && val.properties.length === 1 && ((_ref5 = (_ref6 = val.properties[0].name) != null ? _ref6.value : void 0) === 'call' || _ref5 === 'apply')))) { continue; } - fn = ((_ref6 = val.base) != null ? _ref6.unwrapAll() : void 0) || val; + fn = ((_ref7 = val.base) != null ? _ref7.unwrapAll() : void 0) || val; ref = new Literal(o.scope.freeVariable('fn')); base = new Value(ref); - if (val.base) _ref7 = [base, val], val.base = _ref7[0], base = _ref7[1]; + if (val.base) _ref8 = [base, val], val.base = _ref8[0], base = _ref8[1]; body.expressions[idx] = new Call(base, expr.args); defs += this.tab + new Assign(ref, fn).compile(o, LEVEL_TOP) + ';\n'; } @@ -2353,45 +2454,45 @@ Switch.prototype.isStatement = YES; Switch.prototype.jumps = function(o) { - var block, conds, _i, _len, _ref2, _ref3, _ref4; + var block, conds, _i, _len, _ref3, _ref4, _ref5; if (o == null) { o = { block: true }; } - _ref2 = this.cases; - for (_i = 0, _len = _ref2.length; _i < _len; _i++) { - _ref3 = _ref2[_i], conds = _ref3[0], block = _ref3[1]; + _ref3 = this.cases; + for (_i = 0, _len = _ref3.length; _i < _len; _i++) { + _ref4 = _ref3[_i], conds = _ref4[0], block = _ref4[1]; if (block.jumps(o)) return block; } - return (_ref4 = this.otherwise) != null ? _ref4.jumps(o) : void 0; + return (_ref5 = this.otherwise) != null ? _ref5.jumps(o) : void 0; }; Switch.prototype.makeReturn = function(res) { - var pair, _i, _len, _ref2, _ref3; - _ref2 = this.cases; - for (_i = 0, _len = _ref2.length; _i < _len; _i++) { - pair = _ref2[_i]; + var pair, _i, _len, _ref3, _ref4; + _ref3 = this.cases; + for (_i = 0, _len = _ref3.length; _i < _len; _i++) { + pair = _ref3[_i]; pair[1].makeReturn(res); } if (res) { this.otherwise || (this.otherwise = new Block([new Literal('void 0')])); } - if ((_ref3 = this.otherwise) != null) _ref3.makeReturn(res); + if ((_ref4 = this.otherwise) != null) _ref4.makeReturn(res); return this; }; Switch.prototype.compileNode = function(o) { - var block, body, code, cond, conditions, expr, i, idt1, idt2, _i, _j, _len, _len2, _ref2, _ref3, _ref4, _ref5; + var block, body, code, cond, conditions, expr, i, idt1, idt2, _i, _j, _len, _len2, _ref3, _ref4, _ref5, _ref6; idt1 = o.indent + TAB; idt2 = o.indent = idt1 + TAB; - code = this.tab + ("switch (" + (((_ref2 = this.subject) != null ? _ref2.compile(o, LEVEL_PAREN) : void 0) || false) + ") {\n"); - _ref3 = this.cases; - for (i = _i = 0, _len = _ref3.length; _i < _len; i = ++_i) { - _ref4 = _ref3[i], conditions = _ref4[0], block = _ref4[1]; - _ref5 = flatten([conditions]); - for (_j = 0, _len2 = _ref5.length; _j < _len2; _j++) { - cond = _ref5[_j]; + code = this.tab + ("switch (" + (((_ref3 = this.subject) != null ? _ref3.compile(o, LEVEL_PAREN) : void 0) || false) + ") {\n"); + _ref4 = this.cases; + for (i = _i = 0, _len = _ref4.length; _i < _len; i = ++_i) { + _ref5 = _ref4[i], conditions = _ref5[0], block = _ref5[1]; + _ref6 = flatten([conditions]); + for (_j = 0, _len2 = _ref6.length; _j < _len2; _j++) { + cond = _ref6[_j]; if (!this.subject) cond = cond.invert(); code += idt1 + ("case " + (cond.compile(o, LEVEL_PAREN)) + ":\n"); } @@ -2431,13 +2532,13 @@ If.prototype.children = ['condition', 'body', 'elseBody']; If.prototype.bodyNode = function() { - var _ref2; - return (_ref2 = this.body) != null ? _ref2.unwrap() : void 0; + var _ref3; + return (_ref3 = this.body) != null ? _ref3.unwrap() : void 0; }; If.prototype.elseBodyNode = function() { - var _ref2; - return (_ref2 = this.elseBody) != null ? _ref2.unwrap() : void 0; + var _ref3; + return (_ref3 = this.elseBody) != null ? _ref3.unwrap() : void 0; }; If.prototype.addElse = function(elseBody) { @@ -2451,13 +2552,13 @@ }; If.prototype.isStatement = function(o) { - var _ref2; - return (o != null ? o.level : void 0) === LEVEL_TOP || this.bodyNode().isStatement(o) || ((_ref2 = this.elseBodyNode()) != null ? _ref2.isStatement(o) : void 0); + var _ref3; + return (o != null ? o.level : void 0) === LEVEL_TOP || this.bodyNode().isStatement(o) || ((_ref3 = this.elseBodyNode()) != null ? _ref3.isStatement(o) : void 0); }; If.prototype.jumps = function(o) { - var _ref2; - return this.body.jumps(o) || ((_ref2 = this.elseBody) != null ? _ref2.jumps(o) : void 0); + var _ref3; + return this.body.jumps(o) || ((_ref3 = this.elseBody) != null ? _ref3.jumps(o) : void 0); }; If.prototype.compileNode = function(o) { @@ -2486,7 +2587,7 @@ }; If.prototype.compileStatement = function(o) { - var body, bodyc, child, cond, exeq, ifPart, _ref2; + var body, bodyc, child, cond, exeq, ifPart, _ref3; child = del(o, 'chainChild'); exeq = del(o, 'isExistentialEquals'); if (exeq) { @@ -2498,7 +2599,7 @@ o.indent += TAB; body = this.ensureBlock(this.body); bodyc = body.compile(o); - if (1 === ((_ref2 = body.expressions) != null ? _ref2.length : void 0) && !this.elseBody && !child && bodyc && cond && -1 === (bodyc.indexOf('\n')) && 80 > cond.length + bodyc.length) { + if (1 === ((_ref3 = body.expressions) != null ? _ref3.length : void 0) && !this.elseBody && !child && bodyc && cond && -1 === (bodyc.indexOf('\n')) && 80 > cond.length + bodyc.length) { return "" + this.tab + "if (" + cond + ") " + (bodyc.replace(/^\s+/, '')); } if (bodyc) bodyc = "\n" + bodyc + "\n" + this.tab; diff --git a/lib/coffee-script/optparse.js b/lib/coffee-script/optparse.js index 71d90ebdef..58b9e4c290 100644 --- a/lib/coffee-script/optparse.js +++ b/lib/coffee-script/optparse.js @@ -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; } } diff --git a/lib/coffee-script/repl.js b/lib/coffee-script/repl.js index 0cf7eccb49..e1d26e2a59 100644 --- a/lib/coffee-script/repl.js +++ b/lib/coffee-script/repl.js @@ -167,7 +167,7 @@ backlog = ''; try { _ = global._; - returnValue = CoffeeScript.eval("_=(" + code + "\n)", { + returnValue = CoffeeScript["eval"]("_=(" + code + "\n)", { filename: 'repl', modulename: 'repl' }); diff --git a/src/nodes.coffee b/src/nodes.coffee index b9c8b52907..19ac3c52b6 100644 --- a/src/nodes.coffee +++ b/src/nodes.coffee @@ -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 diff --git a/test/strict.coffee b/test/strict.coffee index 059b08e585..b5a27745a0 100644 --- a/test/strict.coffee +++ b/test/strict.coffee @@ -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}'