Skip to content
Browse files

recompile after big rebase, all tests pass.

  • Loading branch information...
1 parent 8323d3c commit a80740f484288a2a2b59666b1b5bc65a14a548bb @maxtaco committed Jan 24, 2012
Showing with 433 additions and 295 deletions.
  1. +1 −1 lib/coffee-script/cake.js
  2. +1 −1 lib/coffee-script/coffee-script.js
  3. +28 −10 lib/coffee-script/lexer.js
  4. +403 −283 lib/coffee-script/nodes.js
View
2 lib/coffee-script/cake.js
@@ -57,7 +57,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
2 lib/coffee-script/coffee-script.js
@@ -95,7 +95,7 @@
}
};
- exports.eval = function(code, options) {
+ exports["eval"] = function(code, options) {
var Module, Script, js, k, o, r, sandbox, v, _k, _len3, _module, _ref2, _ref3, _require;
if (options == null) options = {};
if (!(code = code.trim())) return;
View
38 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;
@@ -94,7 +94,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);
@@ -134,19 +134,31 @@
};
Lexer.prototype.numberToken = function() {
- var binaryLiteral, lexedLength, match, number;
+ var binaryLiteral, lexedLength, match, number, octalLiteral;
if (!(match = NUMBER.exec(this.chunk))) return 0;
number = match[0];
+ if (/E/.test(number)) {
+ this.error("exponential notation '" + number + "' must be indicated with a lowercase 'e'");
+ } else if (/[BOX]/.test(number)) {
+ this.error("radix prefixes must be lowercase '" + number + "'");
+ } else if (/^0[89]/.test(number)) {
+ this.error("decimal literals '" + number + "' must not be prefixed with '0'");
+ } else if (/^0[0-7]/.test(number)) {
+ this.error("octal literals '" + number + "' must be prefixed with '0o'");
+ }
lexedLength = number.length;
- if (binaryLiteral = /0b([01]+)/i.exec(number)) {
+ if (octalLiteral = /0o([0-7]+)/.exec(number)) {
+ number = (parseInt(octalLiteral[1], 8)).toString();
+ }
+ if (binaryLiteral = /0b([01]+)/.exec(number)) {
number = (parseInt(binaryLiteral[1], 2)).toString();
}
this.token('NUMBER', number);
return lexedLength;
};
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;
@@ -163,6 +175,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;
};
@@ -196,7 +211,6 @@
herecomment: true,
indent: Array(this.indent + 1).join(' ')
}));
- this.token('TERMINATOR', '\n');
}
this.line += count(comment, '\n');
return comment.length;
@@ -648,15 +662,19 @@
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]*:(?!:))?/;
- NUMBER = /^0x[\da-f]+|^0b[01]+|^\d*\.?\d+(?:e[+-]?\d+)?/i;
+ NUMBER = /^0b[01]+|^0o[0-7]+|^0x[\da-f]+|^\d*\.?\d+(?:e[+-]?\d+)?/i;
HEREDOC = /^("""|''')([\s\S]*?)(?:\n[^\n\S]*)?\1/;
View
686 lib/coffee-script/nodes.js
@@ -1,17 +1,17 @@
// Generated by CoffeeScript 1.2.1-pre
(function() {
- var Access, Arr, Assign, Await, Base, Block, Call, Class, Closure, Code, Comment, CpsCascade, Defer, Existence, Extends, For, IDENTIFIER, IDENTIFIER_STR, IS_STRING, If, In, Index, InlineDeferral, LEVEL_ACCESS, LEVEL_COND, LEVEL_LIST, LEVEL_OP, LEVEL_PAREN, LEVEL_TOP, Literal, METHOD_DEF, NEGATE, NO, NULL, Obj, Op, Param, Parens, RESERVED, Range, Return, SIMPLENUM, Scope, Slice, Slot, Splat, Switch, TAB, THIS, TameRequire, TameReturnValue, TameTailCall, Throw, Try, UTILITIES, Value, While, YES, compact, del, ends, extend, flatten, last, merge, multident, starts, tame, unfoldSoak, utility, _ref,
+ var Access, Arr, Assign, Await, Base, Block, Call, Class, Closure, Code, Comment, CpsCascade, Defer, Existence, Extends, For, IDENTIFIER, IDENTIFIER_STR, IS_STRING, If, In, Index, InlineDeferral, LEVEL_ACCESS, LEVEL_COND, LEVEL_LIST, LEVEL_OP, LEVEL_PAREN, LEVEL_TOP, Literal, METHOD_DEF, NEGATE, NO, NULL, Obj, Op, Param, Parens, RESERVED, Range, Return, SIMPLENUM, STRICT_PROSCRIBED, Scope, Slice, Slot, Splat, Switch, TAB, THIS, TameRequire, TameReturnValue, TameTailCall, Throw, Try, UTILITIES, Value, While, YES, compact, del, ends, extend, flatten, last, merge, multident, starts, tame, 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;
tame = require('./tame');
- _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;
@@ -155,7 +155,7 @@
};
Base.prototype.toString = function(idt, name) {
- var b, extras, pidt, tree, _i, _len, _ref2;
+ var b, extras, pidt, tree, _i, _len, _ref3;
if (idt == null) idt = '';
if (name == null) name = this.constructor.name;
extras = "";
@@ -168,9 +168,9 @@
tree = '\n' + idt + name;
if (this.soak) tree += '?';
tree += extras;
- _ref2 = this.tamePrequels;
- for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
- b = _ref2[_i];
+ _ref3 = this.tamePrequels;
+ for (_i = 0, _len = _ref3.length; _i < _len; _i++) {
+ b = _ref3[_i];
pidt = idt + TAB;
tree += '\n' + pidt + "Prequel";
tree += b.block.toString(pidt + TAB);
@@ -187,15 +187,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;
}
}
@@ -224,15 +224,15 @@
};
Base.prototype.flattenChildren = function() {
- var attr, child, out, _i, _j, _len, _len2, _ref2, _ref3;
+ var attr, child, out, _i, _j, _len, _len2, _ref3, _ref4;
out = [];
- _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];
out.push(child);
}
}
@@ -241,37 +241,37 @@
};
Base.prototype.tameWalkAst = function(p, o) {
- var child, _i, _len, _ref2;
+ var child, _i, _len, _ref3;
this.tameParentAwait = p;
this.tameHasAutocbFlag = o.foundAutocb;
- _ref2 = this.flattenChildren();
- for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
- child = _ref2[_i];
+ _ref3 = this.flattenChildren();
+ for (_i = 0, _len = _ref3.length; _i < _len; _i++) {
+ child = _ref3[_i];
if (child.tameWalkAst(p, o)) this.tameNodeFlag = true;
}
return this.tameNodeFlag;
};
Base.prototype.tameWalkAstLoops = function(flood) {
- var child, _i, _len, _ref2;
+ var child, _i, _len, _ref3;
if (this.isLoop() && this.tameNodeFlag) flood = true;
this.tameLoopFlag = flood;
- _ref2 = this.flattenChildren();
- for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
- child = _ref2[_i];
+ _ref3 = this.flattenChildren();
+ for (_i = 0, _len = _ref3.length; _i < _len; _i++) {
+ child = _ref3[_i];
if (child.tameWalkAstLoops(flood)) this.tameLoopFlag = true;
}
return this.tameLoopFlag;
};
Base.prototype.tameWalkCpsPivots = function() {
- var child, _i, _len, _ref2;
+ var child, _i, _len, _ref3;
if (this.tameNodeFlag || (this.tameLoopFlag && this.tameIsJump())) {
this.tameCpsPivotFlag = true;
}
- _ref2 = this.flattenChildren();
- for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
- child = _ref2[_i];
+ _ref3 = this.flattenChildren();
+ for (_i = 0, _len = _ref3.length; _i < _len; _i++) {
+ child = _ref3[_i];
if (child.tameWalkCpsPivots()) this.tameCpsPivotFlag = true;
}
return this.tameCpsPivotFlag;
@@ -288,10 +288,10 @@
Base.prototype.children = [];
Base.prototype.tameCpsRotate = function() {
- var child, _i, _len, _ref2;
- _ref2 = this.flattenChildren();
- for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
- child = _ref2[_i];
+ var child, _i, _len, _ref3;
+ _ref3 = this.flattenChildren();
+ for (_i = 0, _len = _ref3.length; _i < _len; _i++) {
+ child = _ref3[_i];
child.tameCpsRotate();
}
return this;
@@ -318,8 +318,8 @@
};
Base.prototype.tameHasContinuation = function() {
- var _ref2;
- return !!this.tameContinuationBlock || ((_ref2 = this.tamePrequels) != null ? _ref2.length : void 0);
+ var _ref3;
+ return !!this.tameContinuationBlock || ((_ref3 = this.tamePrequels) != null ? _ref3.length : void 0);
};
Base.prototype.tameCallContinuation = function() {
@@ -427,20 +427,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;
}
};
@@ -504,13 +504,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) {
@@ -551,11 +551,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);
}
@@ -576,11 +576,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;
}
@@ -589,8 +589,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);
@@ -613,11 +613,11 @@
};
Block.prototype.tameCpsRotate = function() {
- var child, e, i, pivot, rest, _i, _j, _len, _len2, _ref2;
+ var child, e, i, pivot, rest, _i, _j, _len, _len2, _ref3;
pivot = null;
- _ref2 = this.expressions;
- for (i = _i = 0, _len = _ref2.length; _i < _len; i = ++_i) {
- e = _ref2[i];
+ _ref3 = this.expressions;
+ for (i = _i = 0, _len = _ref3.length; _i < _len; i = ++_i) {
+ e = _ref3[i];
if (e.tameIsCpsPivot()) {
pivot = e;
pivot.tameCallContinuation();
@@ -652,8 +652,8 @@
};
Block.prototype.endsInAwait = function() {
- var _ref2;
- return ((_ref2 = this.expressions) != null ? _ref2.length : void 0) && this.expressions[this.expressions.length - 1] instanceof Await;
+ var _ref3;
+ return ((_ref3 = this.expressions) != null ? _ref3.length : void 0) && this.expressions[this.expressions.length - 1] instanceof Await;
};
Block.prototype.tameAddRuntime = function() {
@@ -701,8 +701,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;
@@ -735,8 +735,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.tameLoopFlag && this.tameIsJump() ? this.compileTame(o) : 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.tameLoopFlag && this.tameIsJump() ? this.compileTame(o) : this.value;
if (this.isStatement()) {
return "" + this.tab + code + ";";
} else {
@@ -773,8 +773,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 {
@@ -846,11 +846,15 @@
return this.base instanceof Literal && SIMPLENUM.test(this.base.value);
};
+ Value.prototype.isString = function() {
+ return this.base instanceof Literal && IS_STRING.test(this.base.value);
+ };
+
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;
@@ -917,16 +921,16 @@
Value.prototype.tameWrapContinuation = YES;
Value.prototype.tameCpsRotate = function() {
- var nv, p, _i, _len, _ref2, _results;
+ var nv, p, _i, _len, _ref3, _results;
if (!this.properties.length) {
Value.__super__.tameCpsRotate.call(this);
return;
}
if ((nv = this.tameCpsExprRotate(this.base))) this.base = nv;
- _ref2 = this.properties;
+ _ref3 = this.properties;
_results = [];
- for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
- p = _ref2[_i];
+ for (_i = 0, _len = _ref3.length; _i < _len; _i++) {
+ p = _ref3[_i];
if ((p.index != null) && this.tameCpsExprRotate(p.index)) {
_results.push(p.index = v);
} else {
@@ -956,14 +960,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));
@@ -1003,7 +1007,7 @@
Comment.prototype.compileNode = function(o, level) {
var code;
- code = '/*' + multident(this.comment, this.tab) + ("\n" + this.tab + "*/");
+ code = '/*' + multident(this.comment, this.tab) + ("\n" + this.tab + "*/\n");
if ((level || o.level) === LEVEL_TOP) code = o.indent + code;
return code;
};
@@ -1030,8 +1034,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 {
@@ -1050,7 +1054,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 {
@@ -1061,10 +1067,10 @@
Call.prototype.tameWrapContinuation = YES;
Call.prototype.tameCpsRotate = function() {
- var a, i, v, _i, _len, _ref2;
- _ref2 = this.args;
- for (i = _i = 0, _len = _ref2.length; _i < _len; i = ++_i) {
- a = _ref2[i];
+ var a, i, v, _i, _len, _ref3;
+ _ref3 = this.args;
+ for (i = _i = 0, _len = _ref3.length; _i < _len; i = ++_i) {
+ a = _ref3[i];
if ((v = this.tameCpsExprRotate(a))) this.args[i] = v;
}
if (this.variable && (v = this.tameCpsExprRotate(this.variable))) {
@@ -1073,11 +1079,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);
@@ -1101,9 +1107,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;
@@ -1117,7 +1123,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];
@@ -1126,9 +1132,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);
@@ -1142,8 +1148,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);
}
@@ -1293,21 +1299,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;
@@ -1317,20 +1323,20 @@
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;
return "" + varPart + "; " + condPart + "; " + stepPart;
};
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();
@@ -1376,12 +1382,12 @@
}
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);
+ compiled = to && to.compile(o, LEVEL_PAREN);
if (to && !(!this.range.exclusive && +compiled === -1)) {
- toStr = ', ' + (this.range.exclusive ? compiled : SIMPLENUM.test(compiled) ? (+compiled + 1).toString() : "" + compiled + " + 1 || 9e9");
+ toStr = ', ' + (this.range.exclusive ? compiled : SIMPLENUM.test(compiled) ? "" + (+compiled + 1) : (compiled = to.compile(o, LEVEL_ACCESS), "" + compiled + " + 1 || 9e9"));
}
return ".slice(" + fromStr + (toStr || '') + ")";
};
@@ -1407,11 +1413,11 @@
Obj.prototype.tameWrapContinuation = YES;
Obj.prototype.tameCpsRotate = function() {
- var prop, v, _i, _len, _ref2, _results;
- _ref2 = this.properties;
+ var prop, v, _i, _len, _ref3, _results;
+ _ref3 = this.properties;
_results = [];
- for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
- prop = _ref2[_i];
+ for (_i = 0, _len = _ref3.length; _i < _len; _i++) {
+ prop = _ref3[_i];
if (prop instanceof Assign) {
if ((v = this.tameCpsExprRotate(prop.value))) {
_results.push(prop.value = v);
@@ -1424,12 +1430,25 @@
};
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');
}
@@ -1438,9 +1457,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;
@@ -1465,10 +1484,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;
@@ -1496,11 +1515,11 @@
Arr.prototype.tameWrapContinuation = YES;
Arr.prototype.tameCpsRotate = function() {
- var i, o, v, _i, _len, _ref2, _results;
- _ref2 = this.objects;
+ var i, o, v, _i, _len, _ref3, _results;
+ _ref3 = this.objects;
_results = [];
- for (i = _i = 0, _len = _ref2.length; _i < _len; i = ++_i) {
- o = _ref2[i];
+ for (i = _i = 0, _len = _ref3.length; _i < _len; i = ++_i) {
+ o = _ref3[i];
if ((v = this.tameCpsExprRotate(o))) {
_results.push(this.objects[i] = v);
} else {
@@ -1533,10 +1552,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;
@@ -1567,6 +1586,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);
};
@@ -1583,12 +1605,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)")));
}
@@ -1622,7 +1644,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)]);
@@ -1643,12 +1665,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);
}
@@ -1658,6 +1680,16 @@
});
};
+ Class.prototype.hoistDirectivePrologue = function() {
+ var expressions, index, node;
+ index = 0;
+ expressions = this.body.expressions;
+ while ((node = expressions[index]) && node instanceof Comment || node instanceof Value && node.isString()) {
+ ++index;
+ }
+ return this.directives = expressions.splice(0, index);
+ };
+
Class.prototype.ensureConstructor = function(name) {
if (!this.ctor) {
this.ctor = new Code;
@@ -1676,11 +1708,12 @@
};
Class.prototype.compileNode = function(o) {
- var call, decl, klass, lname, name, params;
+ var call, decl, klass, lname, name, params, _ref3;
decl = this.determineName();
name = decl || '_Class';
if (name.reserved) name = "_" + name;
lname = new Literal(name);
+ this.hoistDirectivePrologue();
this.setContext(name);
this.walkBody(name, o);
this.ensureConstructor(name);
@@ -1690,6 +1723,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);
+ (_ref3 = this.body.expressions).unshift.apply(_ref3, this.directives);
this.addBoundFunctions(o);
call = Closure.wrap(this.body);
if (this.parent) {
@@ -1715,12 +1749,17 @@
Assign.name = 'Assign';
function Assign(variable, value, context, options) {
+ var forbidden, name, _ref3;
this.variable = variable;
this.value = value;
this.context = context;
Assign.__super__.constructor.call(this);
this.param = options && options.param;
this.subpattern = options && options.subpattern;
+ forbidden = (_ref3 = (name = this.variable.unwrapAll().value), __indexOf.call(STRICT_PROSCRIBED, _ref3) >= 0);
+ if (forbidden && this.context !== 'object') {
+ throw SyntaxError("variable name may not be \"" + name + "\"");
+ }
this.tamelocal = options && options.tamelocal;
}
@@ -1744,13 +1783,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);
}
}
@@ -1769,7 +1808,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;
@@ -1782,7 +1821,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;
@@ -1797,18 +1836,18 @@
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);
}
}
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, {
@@ -1827,10 +1866,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;
}
@@ -1862,7 +1901,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, {
@@ -1880,17 +1919,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;
@@ -1902,7 +1941,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 + ")";
@@ -1939,37 +1978,42 @@
Code.prototype.jumps = NO;
Code.prototype.compileNode = function(o) {
- var code, exprs, i, idt, k_id, lit, p, param, ref, rhs, splats, v, val, vars, wasEmpty, _i, _j, _k, _l, _len, _len2, _len3, _len4, _ref2, _ref3, _ref4, _ref5, _ref6;
+ var code, exprs, i, idt, k_id, lit, name, p, param, params, ref, rhs, 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') || this.tamegen;
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);
@@ -1984,32 +2028,40 @@
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);
+ (_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));
}
- if (!splats) {
- for (i = _l = 0, _len4 = vars.length; _l < _len4; i = ++_l) {
- v = vars[i];
- o.scope.parameter(vars[i] = v.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 (this.tameHasAutocbFlag) wasEmpty = false;
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.tameNodeFlag) o.tamed_scope = o.scope;
if (!this.tamegen && this.tameNodeFlag && this.tameHasAutocbFlag) {
rhs = new Value(new Literal(tame["const"].autocb));
k_id = new Value(new Literal(tame["const"].k));
@@ -2029,20 +2081,31 @@
}
};
+ 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);
}
};
Code.prototype.tameWalkAst = function(parent, o) {
- var fa_prev, param, _i, _len, _ref2;
+ var fa_prev, param, _i, _len, _ref3;
this.tameParentAwait = parent;
fa_prev = o.foundAutocb;
o.foundAutocb = false;
- _ref2 = this.params;
- for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
- param = _ref2[_i];
+ _ref3 = this.params;
+ for (_i = 0, _len = _ref3.length; _i < _len; _i++) {
+ param = _ref3[_i];
if (param.name instanceof Literal && param.name.value === tame["const"].autocb) {
o.foundAutocb = true;
break;
@@ -2077,10 +2140,14 @@
Param.name = 'Param';
function Param(name, value, splat) {
+ var _ref3, _ref4;
this.name = name;
this.value = value;
this.splat = splat;
Param.__super__.constructor.call(this);
+ if (name = (_ref3 = (_ref4 = this.name) != null ? _ref4.unwrapAll().value : void 0, __indexOf.call(STRICT_PROSCRIBED, _ref3) >= 0)) {
+ throw SyntaxError("parameter name \"" + name + "\" is not allowed");
+ }
}
Param.prototype.children = ['name', 'value'];
@@ -2095,7 +2162,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'));
}
@@ -2108,6 +2177,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);
@@ -2169,11 +2269,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;
@@ -2399,13 +2499,13 @@
};
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.tameCpsRotate = function() {
@@ -2419,7 +2519,7 @@
};
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;
@@ -2441,25 +2541,25 @@
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);
}
};
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;
@@ -2473,9 +2573,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);
@@ -2488,8 +2594,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 + ")";
@@ -2511,6 +2617,7 @@
Op.prototype.compileUnary = function(o) {
var op, parts, plusMinus;
+ if (o.level >= LEVEL_ACCESS) return (new Parens(this)).compile(o);
parts = [op = this.operator];
plusMinus = op === '+' || op === '-';
if ((op === 'new' || op === 'typeof' || op === 'delete') || plusMinus && this.first instanceof Op && this.first.operator === op) {
@@ -2549,11 +2656,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;
@@ -2564,16 +2671,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;
@@ -2587,8 +2694,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;
@@ -2658,14 +2765,14 @@
};
Defer.prototype.makeAssignFn = function(o) {
- var a, args, assign, assignments, block, call, func, i, i_lit, inner_fn, lit, outer_block, outer_fn, prop, s, slot, _i, _len, _ref2;
+ var a, args, assign, assignments, block, call, func, i, i_lit, inner_fn, lit, outer_block, outer_fn, prop, s, slot, _i, _len, _ref3;
if (this.slots.length === 0) return null;
assignments = [];
args = [];
i = 0;
- _ref2 = this.slots;
- for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
- s = _ref2[_i];
+ _ref3 = this.slots;
+ for (_i = 0, _len = _ref3.length; _i < _len; _i++) {
+ s = _ref3[_i];
a = new Value(new Literal("arguments"));
i_lit = new Value(new Literal(i));
if (s.splat) {
@@ -2723,11 +2830,11 @@
};
Defer.prototype.compileNode = function(o) {
- var call, name, scope, v, _i, _len, _ref2;
+ var call, name, scope, v, _i, _len, _ref3;
call = this.transform(o);
- _ref2 = this.vars;
- for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
- v = _ref2[_i];
+ _ref3 = this.vars;
+ for (_i = 0, _len = _ref3.length; _i < _len; _i++) {
+ v = _ref3[_i];
name = v.compile(o, LEVEL_LIST);
scope = o.scope;
scope.add(name, 'var');
@@ -2885,8 +2992,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) {
@@ -2900,7 +3007,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;
};
@@ -2952,11 +3072,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";
@@ -3020,15 +3140,15 @@
For.name = 'For';
function For(body, source) {
- var _ref2;
+ var _ref3;
For.__super__.constructor.call(this);
this.condition = null;
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');
@@ -3124,9 +3244,9 @@
};
For.prototype.compileNode = function(o) {
- var body, code, 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, code, 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;
@@ -3216,21 +3336,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';
}
@@ -3259,55 +3379,55 @@
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.tameCallContinuation = function() {
- var block, condition, _i, _len, _ref2, _ref3, _ref4;
- _ref2 = this.cases;
- for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
- _ref3 = _ref2[_i], condition = _ref3[0], block = _ref3[1];
+ var block, condition, _i, _len, _ref3, _ref4, _ref5;
+ _ref3 = this.cases;
+ for (_i = 0, _len = _ref3.length; _i < _len; _i++) {
+ _ref4 = _ref3[_i], condition = _ref4[0], block = _ref4[1];
block.tameThreadReturn();
}
- return (_ref4 = this.otherwise) != null ? _ref4.tameThreadReturn() : void 0;
+ return (_ref5 = this.otherwise) != null ? _ref5.tameThreadReturn() : void 0;
};
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");
}
@@ -3348,13 +3468,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) {
@@ -3378,13 +3498,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) || this.tameHasContinuation();
+ var _ref3;
+ return (o != null ? o.level : void 0) === LEVEL_TOP || this.bodyNode().isStatement(o) || ((_ref3 = this.elseBodyNode()) != null ? _ref3.isStatement(o) : void 0) || this.tameHasContinuation();
};
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) {
@@ -3413,7 +3533,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) {
@@ -3425,7 +3545,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;

0 comments on commit a80740f

Please sign in to comment.
Something went wrong with that request. Please try again.