Merging in Stan's temporary_junk improvements.
This commit is contained in:
commit
a16594ed7b
|
@ -19,9 +19,9 @@
|
|||
return xhr.send(null);
|
||||
};
|
||||
processScripts = function() {
|
||||
var _i, _l, _ref, script;
|
||||
var _i, _len, _ref, script;
|
||||
_ref = document.getElementsByTagName('script');
|
||||
for (_i = 0, _l = _ref.length; _i < _l; _i++) {
|
||||
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
||||
script = _ref[_i];
|
||||
if (script.type === 'text/coffeescript') {
|
||||
if (script.src) {
|
||||
|
|
|
@ -35,7 +35,7 @@
|
|||
});
|
||||
exports.run = function() {
|
||||
return path.exists('Cakefile', function(exists) {
|
||||
var _i, _l, _ref, _result, arg, args;
|
||||
var _i, _len, _ref, _result, arg, args;
|
||||
if (!(exists)) {
|
||||
throw new Error("Cakefile not found in " + (process.cwd()));
|
||||
}
|
||||
|
@ -49,7 +49,7 @@
|
|||
}
|
||||
options = oparse.parse(args);
|
||||
_result = []; _ref = options.arguments;
|
||||
for (_i = 0, _l = _ref.length; _i < _l; _i++) {
|
||||
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
||||
arg = _ref[_i];
|
||||
_result.push(invoke(arg));
|
||||
}
|
||||
|
|
|
@ -1,16 +1,16 @@
|
|||
(function() {
|
||||
var BANNER, CoffeeScript, EventEmitter, SWITCHES, _ref, _ref2, _ref3, compileOptions, compileScript, compileScripts, compileStdio, exec, fs, helpers, lint, optionParser, optparse, opts, parseOptions, path, printTokens, sources, spawn, usage, version, watch, writeJs;
|
||||
var BANNER, CoffeeScript, EventEmitter, SWITCHES, _ref, compileOptions, compileScript, compileScripts, compileStdio, exec, fs, helpers, lint, optionParser, optparse, opts, parseOptions, path, printTokens, sources, spawn, usage, version, watch, writeJs;
|
||||
fs = require('fs');
|
||||
path = require('path');
|
||||
optparse = require('./optparse');
|
||||
CoffeeScript = require('./coffee-script');
|
||||
_ref = require('./helpers');
|
||||
helpers = _ref.helpers;
|
||||
_ref2 = require('child_process');
|
||||
spawn = _ref2.spawn;
|
||||
exec = _ref2.exec;
|
||||
_ref3 = require('events');
|
||||
EventEmitter = _ref3.EventEmitter;
|
||||
_ref = require('child_process');
|
||||
spawn = _ref.spawn;
|
||||
exec = _ref.exec;
|
||||
_ref = require('events');
|
||||
EventEmitter = _ref.EventEmitter;
|
||||
helpers.extend(CoffeeScript, new EventEmitter());
|
||||
global.CoffeeScript = CoffeeScript;
|
||||
BANNER = 'coffee compiles CoffeeScript source files into JavaScript.\n\nUsage:\n coffee path/to/script.coffee';
|
||||
|
@ -53,12 +53,12 @@
|
|||
return compileScripts();
|
||||
};
|
||||
compileScripts = function() {
|
||||
var _i, _l, _ref4, _result;
|
||||
_result = []; _ref4 = sources;
|
||||
for (_i = 0, _l = _ref4.length; _i < _l; _i++) {
|
||||
var _i, _len, _ref2, _result;
|
||||
_result = []; _ref2 = sources;
|
||||
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
|
||||
(function() {
|
||||
var base, compile;
|
||||
var source = _ref4[_i];
|
||||
var source = _ref2[_i];
|
||||
return _result.push((function() {
|
||||
base = source;
|
||||
compile = function(source, topLevel) {
|
||||
|
@ -69,10 +69,10 @@
|
|||
return fs.stat(source, function(err, stats) {
|
||||
if (stats.isDirectory()) {
|
||||
return fs.readdir(source, function(err, files) {
|
||||
var _i2, _l2, _ref5, _result2, file;
|
||||
_result2 = []; _ref5 = files;
|
||||
for (_i2 = 0, _l2 = _ref5.length; _i2 < _l2; _i2++) {
|
||||
file = _ref5[_i2];
|
||||
var _i2, _len2, _ref3, _result2, file;
|
||||
_result2 = []; _ref3 = files;
|
||||
for (_i2 = 0, _len2 = _ref3.length; _i2 < _len2; _i2++) {
|
||||
file = _ref3[_i2];
|
||||
_result2.push(compile(path.join(source, file)));
|
||||
}
|
||||
return _result2;
|
||||
|
@ -95,13 +95,13 @@
|
|||
return _result;
|
||||
};
|
||||
compileScript = function(file, input, base) {
|
||||
var _i, _l, _ref4, o, options, req, t, task;
|
||||
var _i, _len, _ref2, o, options, req, t, task;
|
||||
o = opts;
|
||||
options = compileOptions(file);
|
||||
if (o.require) {
|
||||
_ref4 = o.require;
|
||||
for (_i = 0, _l = _ref4.length; _i < _l; _i++) {
|
||||
req = _ref4[_i];
|
||||
_ref2 = o.require;
|
||||
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
|
||||
req = _ref2[_i];
|
||||
require(helpers.starts(req, '.') ? fs.realpathSync(req) : req);
|
||||
}
|
||||
}
|
||||
|
@ -204,15 +204,15 @@
|
|||
return jsl.stdin.end();
|
||||
};
|
||||
printTokens = function(tokens) {
|
||||
var _i, _l, _ref4, _ref5, _result, strings, tag, token, value;
|
||||
var _i, _len, _ref2, _ref3, _result, strings, tag, token, value;
|
||||
strings = (function() {
|
||||
_result = []; _ref4 = tokens;
|
||||
for (_i = 0, _l = _ref4.length; _i < _l; _i++) {
|
||||
token = _ref4[_i];
|
||||
_result = []; _ref2 = tokens;
|
||||
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
|
||||
token = _ref2[_i];
|
||||
_result.push((function() {
|
||||
_ref5 = [token[0], token[1].toString().replace(/\n/, '\\n')];
|
||||
tag = _ref5[0];
|
||||
value = _ref5[1];
|
||||
_ref3 = [token[0], token[1].toString().replace(/\n/, '\\n')];
|
||||
tag = _ref3[0];
|
||||
value = _ref3[1];
|
||||
return "[" + (tag) + " " + (value) + "]";
|
||||
})());
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
(function() {
|
||||
var Parser, _i, _i2, _l, _l2, _ref, _ref2, _ref3, _result, alt, alternatives, grammar, name, o, operators, token, tokens, unwrap;
|
||||
var Parser, _i, _i2, _len, _len2, _ref, _ref2, _ref3, _result, alt, alternatives, grammar, name, o, operators, token, tokens, unwrap;
|
||||
var __hasProp = Object.prototype.hasOwnProperty;
|
||||
Parser = require('jison').Parser;
|
||||
unwrap = /function\s*\(\)\s*\{\s*return\s*([\s\S]*);\s*\}/;
|
||||
|
@ -618,11 +618,11 @@
|
|||
alternatives = _ref[name];
|
||||
grammar[name] = (function() {
|
||||
_result = []; _ref2 = alternatives;
|
||||
for (_i = 0, _l = _ref2.length; _i < _l; _i++) {
|
||||
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
|
||||
alt = _ref2[_i];
|
||||
_result.push((function() {
|
||||
_ref3 = alt[0].split(' ');
|
||||
for (_i2 = 0, _l2 = _ref3.length; _i2 < _l2; _i2++) {
|
||||
for (_i2 = 0, _len2 = _ref3.length; _i2 < _len2; _i2++) {
|
||||
token = _ref3[_i2];
|
||||
if (!(grammar[token])) {
|
||||
tokens.push(token);
|
||||
|
|
|
@ -5,12 +5,12 @@
|
|||
}
|
||||
helpers = (exports.helpers = {});
|
||||
helpers.indexOf = (indexOf = function(array, item, from) {
|
||||
var _l, _ref, index, other;
|
||||
var _len, _ref, index, other;
|
||||
if (array.indexOf) {
|
||||
return array.indexOf(item, from);
|
||||
}
|
||||
_ref = array;
|
||||
for (index = 0, _l = _ref.length; index < _l; index++) {
|
||||
for (index = 0, _len = _ref.length; index < _len; index++) {
|
||||
other = _ref[index];
|
||||
if (other === item && (!from || (from <= index))) {
|
||||
return index;
|
||||
|
@ -30,9 +30,9 @@
|
|||
return string.substring(start, start + literal.length) === literal;
|
||||
});
|
||||
helpers.compact = (compact = function(array) {
|
||||
var _i, _l, _ref, _result, item;
|
||||
var _i, _len, _ref, _result, item;
|
||||
_result = []; _ref = array;
|
||||
for (_i = 0, _l = _ref.length; _i < _l; _i++) {
|
||||
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
||||
item = _ref[_i];
|
||||
if (item) {
|
||||
_result.push(item);
|
||||
|
@ -51,7 +51,7 @@
|
|||
return num;
|
||||
});
|
||||
helpers.merge = (merge = function(options, overrides) {
|
||||
var _ref, _ref2, fresh, key, val;
|
||||
var _ref, fresh, key, val;
|
||||
fresh = {};
|
||||
_ref = options;
|
||||
for (key in _ref) {
|
||||
|
@ -59,9 +59,9 @@
|
|||
(fresh[key] = val);
|
||||
}
|
||||
if (overrides) {
|
||||
_ref2 = overrides;
|
||||
for (key in _ref2) {
|
||||
val = _ref2[key];
|
||||
_ref = overrides;
|
||||
for (key in _ref) {
|
||||
val = _ref[key];
|
||||
(fresh[key] = val);
|
||||
}
|
||||
}
|
||||
|
@ -77,10 +77,10 @@
|
|||
return _result;
|
||||
});
|
||||
helpers.flatten = (flatten = function(array) {
|
||||
var _i, _l, _ref, item, memo;
|
||||
var _i, _len, _ref, item, memo;
|
||||
memo = [];
|
||||
_ref = array;
|
||||
for (_i = 0, _l = _ref.length; _i < _l; _i++) {
|
||||
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
||||
item = _ref[_i];
|
||||
if (item instanceof Array) {
|
||||
memo = memo.concat(item);
|
||||
|
|
68
lib/lexer.js
68
lib/lexer.js
|
@ -1,21 +1,21 @@
|
|||
(function() {
|
||||
var ASSIGNED, CALLABLE, CODE, COFFEE_ALIASES, COFFEE_KEYWORDS, COMMENT, COMPARE, COMPOUND_ASSIGN, CONVERSIONS, HEREDOC, HEREDOC_INDENT, IDENTIFIER, JS_CLEANER, JS_FORBIDDEN, JS_KEYWORDS, LAST_DENT, LAST_DENTS, LINE_BREAK, LOGIC, Lexer, MATH, MULTILINER, MULTI_DENT, NEXT_CHARACTER, NOT_REGEX, NO_NEWLINE, NUMBER, OPERATOR, REGEX_END, REGEX_ESCAPE, REGEX_INTERPOLATION, REGEX_START, RESERVED, Rewriter, SHIFT, UNARY, WHITESPACE, _ref, _ref2, _ref3, compact, count, helpers, include, starts;
|
||||
var ASSIGNED, CALLABLE, CODE, COFFEE_ALIASES, COFFEE_KEYWORDS, COMMENT, COMPARE, COMPOUND_ASSIGN, CONVERSIONS, HEREDOC, HEREDOC_INDENT, IDENTIFIER, JS_CLEANER, JS_FORBIDDEN, JS_KEYWORDS, LAST_DENT, LAST_DENTS, LINE_BREAK, LOGIC, Lexer, MATH, MULTILINER, MULTI_DENT, NEXT_CHARACTER, NOT_REGEX, NO_NEWLINE, NUMBER, OPERATOR, REGEX_END, REGEX_ESCAPE, REGEX_INTERPOLATION, REGEX_START, RESERVED, Rewriter, SHIFT, UNARY, WHITESPACE, _ref, compact, count, helpers, include, starts;
|
||||
var __slice = Array.prototype.slice;
|
||||
if (typeof process !== "undefined" && process !== null) {
|
||||
_ref = require('./rewriter');
|
||||
Rewriter = _ref.Rewriter;
|
||||
_ref2 = require('./helpers');
|
||||
helpers = _ref2.helpers;
|
||||
_ref = require('./helpers');
|
||||
helpers = _ref.helpers;
|
||||
} else {
|
||||
this.exports = this;
|
||||
Rewriter = this.Rewriter;
|
||||
helpers = this.helpers;
|
||||
}
|
||||
_ref3 = helpers;
|
||||
include = _ref3.include;
|
||||
count = _ref3.count;
|
||||
starts = _ref3.starts;
|
||||
compact = _ref3.compact;
|
||||
_ref = helpers;
|
||||
include = _ref.include;
|
||||
count = _ref.count;
|
||||
starts = _ref.starts;
|
||||
compact = _ref.compact;
|
||||
exports.Lexer = (function() {
|
||||
Lexer = function() {};
|
||||
Lexer.prototype.tokenize = function(code, options) {
|
||||
|
@ -192,11 +192,11 @@
|
|||
return true;
|
||||
};
|
||||
Lexer.prototype.regexToken = function() {
|
||||
var _ref4, end, first, flags, regex, str;
|
||||
var _ref2, end, first, flags, regex, str;
|
||||
if (!(first = this.chunk.match(REGEX_START))) {
|
||||
return false;
|
||||
}
|
||||
if (first[1] === ' ' && !('CALL_START' === (_ref4 = this.tag()) || '=' === _ref4)) {
|
||||
if (first[1] === ' ' && !('CALL_START' === (_ref2 = this.tag()) || '=' === _ref2)) {
|
||||
return false;
|
||||
}
|
||||
if (include(NOT_REGEX, this.tag())) {
|
||||
|
@ -320,7 +320,7 @@
|
|||
return true;
|
||||
};
|
||||
Lexer.prototype.literalToken = function() {
|
||||
var _ref4, match, prev, space, spaced, tag, value;
|
||||
var _ref2, match, prev, space, spaced, tag, value;
|
||||
match = this.chunk.match(OPERATOR);
|
||||
value = match && match[1];
|
||||
space = match && match[2];
|
||||
|
@ -335,7 +335,7 @@
|
|||
if (include(JS_FORBIDDEN, this.value())) {
|
||||
this.assignmentError();
|
||||
}
|
||||
if (('or' === (_ref4 = this.value()) || 'and' === _ref4)) {
|
||||
if (('or' === (_ref2 = this.value()) || 'and' === _ref2)) {
|
||||
this.tokens.splice(this.tokens.length - 1, 1, ['COMPOUND_ASSIGN', CONVERSIONS[this.value()] + '=', prev[2]]);
|
||||
return true;
|
||||
}
|
||||
|
@ -395,14 +395,14 @@
|
|||
return accessor ? 'accessor' : false;
|
||||
};
|
||||
Lexer.prototype.sanitizeHeredoc = function(doc, options) {
|
||||
var _ref4, attempt, indent, match;
|
||||
var _ref2, attempt, indent, match;
|
||||
indent = options.indent;
|
||||
if (options.herecomment && !include(doc, '\n')) {
|
||||
return doc;
|
||||
}
|
||||
if (!(options.herecomment)) {
|
||||
while ((match = HEREDOC_INDENT.exec(doc)) !== null) {
|
||||
attempt = (typeof (_ref4 = match[2]) !== "undefined" && _ref4 !== null) ? match[2] : match[3];
|
||||
attempt = (typeof (_ref2 = match[2]) !== "undefined" && _ref2 !== null) ? match[2] : match[3];
|
||||
if (!(typeof indent !== "undefined" && indent !== null) || attempt.length < indent.length) {
|
||||
indent = attempt;
|
||||
}
|
||||
|
@ -451,7 +451,7 @@
|
|||
throw new Error("SyntaxError: Reserved word \"" + (this.value()) + "\" on line " + (this.line + 1) + " can't be assigned");
|
||||
};
|
||||
Lexer.prototype.balancedString = function(str, delimited, options) {
|
||||
var _i, _l, _ref4, _ref5, close, i, levels, open, pair, slash;
|
||||
var _i, _len, _ref2, _ref3, close, i, levels, open, pair, slash;
|
||||
options || (options = {});
|
||||
slash = delimited[0][0] === '/';
|
||||
levels = [];
|
||||
|
@ -460,12 +460,12 @@
|
|||
if (levels.length && starts(str, '\\', i)) {
|
||||
i += 1;
|
||||
} else {
|
||||
_ref4 = delimited;
|
||||
for (_i = 0, _l = _ref4.length; _i < _l; _i++) {
|
||||
pair = _ref4[_i];
|
||||
_ref5 = pair;
|
||||
open = _ref5[0];
|
||||
close = _ref5[1];
|
||||
_ref2 = delimited;
|
||||
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
|
||||
pair = _ref2[_i];
|
||||
_ref3 = pair;
|
||||
open = _ref3[0];
|
||||
close = _ref3[1];
|
||||
if (levels.length && starts(str, close, i) && levels[levels.length - 1] === pair) {
|
||||
levels.pop();
|
||||
i += close.length - 1;
|
||||
|
@ -494,7 +494,7 @@
|
|||
return !i ? false : str.substring(0, i);
|
||||
};
|
||||
Lexer.prototype.interpolateString = function(str, options) {
|
||||
var _l, _l2, _ref4, _ref5, _ref6, _ref7, escaped, expr, i, idx, inner, interpolated, lexer, nested, pi, quote, tag, tok, token, tokens, value;
|
||||
var _len, _ref2, _ref3, escaped, expr, i, idx, inner, interpolated, lexer, nested, pi, quote, tag, tok, token, tokens, value;
|
||||
options || (options = {});
|
||||
if (str.length < 3 || !starts(str, '"')) {
|
||||
return this.token('STRING', str);
|
||||
|
@ -502,9 +502,9 @@
|
|||
lexer = new Lexer();
|
||||
tokens = [];
|
||||
quote = str.substring(0, 1);
|
||||
_ref4 = [1, 1];
|
||||
i = _ref4[0];
|
||||
pi = _ref4[1];
|
||||
_ref2 = [1, 1];
|
||||
i = _ref2[0];
|
||||
pi = _ref2[1];
|
||||
while (i < str.length - 1) {
|
||||
if (starts(str, '\\', i)) {
|
||||
i += 1;
|
||||
|
@ -520,9 +520,9 @@
|
|||
nested = lexer.tokenize("(" + (inner) + ")", {
|
||||
line: this.line
|
||||
});
|
||||
_ref5 = nested;
|
||||
for (idx = 0, _l = _ref5.length; idx < _l; idx++) {
|
||||
tok = _ref5[idx];
|
||||
_ref2 = nested;
|
||||
for (idx = 0, _len = _ref2.length; idx < _len; idx++) {
|
||||
tok = _ref2[idx];
|
||||
if (tok[0] === 'CALL_END') {
|
||||
(tok[0] = ')');
|
||||
}
|
||||
|
@ -547,12 +547,12 @@
|
|||
if (interpolated) {
|
||||
this.token('(', '(');
|
||||
}
|
||||
_ref6 = tokens;
|
||||
for (i = 0, _l2 = _ref6.length; i < _l2; i++) {
|
||||
token = _ref6[i];
|
||||
_ref7 = token;
|
||||
tag = _ref7[0];
|
||||
value = _ref7[1];
|
||||
_ref2 = tokens;
|
||||
for (i = 0, _len = _ref2.length; i < _len; i++) {
|
||||
token = _ref2[i];
|
||||
_ref3 = token;
|
||||
tag = _ref3[0];
|
||||
value = _ref3[1];
|
||||
if (tag === 'TOKENS') {
|
||||
this.tokens = this.tokens.concat(value);
|
||||
} else if (tag === 'STRING' && options.escapeQuotes) {
|
||||
|
|
204
lib/nodes.js
204
lib/nodes.js
|
@ -31,7 +31,7 @@
|
|||
return this;
|
||||
};
|
||||
BaseNode.prototype.compile = function(o) {
|
||||
var closure, top;
|
||||
var closure, code, top;
|
||||
this.options = merge(o || {});
|
||||
this.tab = o.indent;
|
||||
if (!(this instanceof AccessorNode || this instanceof IndexNode)) {
|
||||
|
@ -39,7 +39,14 @@
|
|||
}
|
||||
top = this.topSensitive() ? this.options.top : del(this.options, 'top');
|
||||
closure = this.isStatement(o) && !this.isPureStatement() && !top && !this.options.asStatement && !(this instanceof CommentNode) && !this.containsPureStatement();
|
||||
return closure ? this.compileClosure(this.options) : this.compileNode(this.options);
|
||||
if (!o.keepLevel) {
|
||||
o.scope.startLevel();
|
||||
}
|
||||
code = closure ? this.compileClosure(this.options) : this.compileNode(this.options);
|
||||
if (!o.keepLevel) {
|
||||
o.scope.endLevel();
|
||||
}
|
||||
return code;
|
||||
};
|
||||
BaseNode.prototype.compileClosure = function(o) {
|
||||
this.tab = o.indent;
|
||||
|
@ -102,11 +109,11 @@
|
|||
return this.traverseChildren(true, block);
|
||||
};
|
||||
BaseNode.prototype.toString = function(idt, override) {
|
||||
var _i, _l, _ref2, _result, child, children;
|
||||
var _i, _len, _ref2, _result, child, children;
|
||||
idt || (idt = '');
|
||||
children = (function() {
|
||||
_result = []; _ref2 = this.collectChildren();
|
||||
for (_i = 0, _l = _ref2.length; _i < _l; _i++) {
|
||||
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
|
||||
child = _ref2[_i];
|
||||
_result.push(child.toString(idt + TAB));
|
||||
}
|
||||
|
@ -115,16 +122,16 @@
|
|||
return '\n' + idt + (override || this["class"]) + children;
|
||||
};
|
||||
BaseNode.prototype.eachChild = function(func) {
|
||||
var _i, _i2, _l, _l2, _ref2, _ref3, _result, attr, child;
|
||||
var _i, _i2, _len, _len2, _ref2, _ref3, _result, attr, child;
|
||||
if (!(this.children)) {
|
||||
return null;
|
||||
}
|
||||
_result = []; _ref2 = this.children;
|
||||
for (_i = 0, _l = _ref2.length; _i < _l; _i++) {
|
||||
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
|
||||
attr = _ref2[_i];
|
||||
if (this[attr]) {
|
||||
_ref3 = flatten([this[attr]]);
|
||||
for (_i2 = 0, _l2 = _ref3.length; _i2 < _l2; _i2++) {
|
||||
for (_i2 = 0, _len2 = _ref3.length; _i2 < _len2; _i2++) {
|
||||
child = _ref3[_i2];
|
||||
if (func(child) === false) {
|
||||
return null;
|
||||
|
@ -210,10 +217,10 @@
|
|||
return o.scope ? Expressions.__super__.compile.call(this, o) : this.compileRoot(o);
|
||||
};
|
||||
Expressions.prototype.compileNode = function(o) {
|
||||
var _i, _l, _ref2, _result, node;
|
||||
var _i, _len, _ref2, _result, node;
|
||||
return (function() {
|
||||
_result = []; _ref2 = this.expressions;
|
||||
for (_i = 0, _l = _ref2.length; _i < _l; _i++) {
|
||||
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
|
||||
node = _ref2[_i];
|
||||
_result.push(this.compileExpression(node, merge(o)));
|
||||
}
|
||||
|
@ -355,25 +362,25 @@
|
|||
return this.base instanceof LiteralNode && this.base.value.match(NUMBER);
|
||||
};
|
||||
ValueNode.prototype.cacheIndexes = function(o) {
|
||||
var _i, _l, _ref2, _ref3, copy, i;
|
||||
var _i, _len, _ref2, copy, i;
|
||||
copy = new ValueNode(this.base, this.properties.slice(0));
|
||||
if (this.base instanceof CallNode) {
|
||||
_ref2 = this.base.compileReference(o);
|
||||
this.base = _ref2[0];
|
||||
copy.base = _ref2[1];
|
||||
}
|
||||
_ref3 = copy.properties;
|
||||
for (_i = 0, _l = _ref3.length; _i < _l; _i++) {
|
||||
_ref2 = copy.properties;
|
||||
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
|
||||
(function() {
|
||||
var _ref4, index, indexVar;
|
||||
var _ref3, index, indexVar;
|
||||
var i = _i;
|
||||
var prop = _ref3[_i];
|
||||
var prop = _ref2[_i];
|
||||
if (prop instanceof IndexNode && prop.contains(function(n) {
|
||||
return n instanceof CallNode;
|
||||
})) {
|
||||
_ref4 = prop.index.compileReference(o);
|
||||
index = _ref4[0];
|
||||
indexVar = _ref4[1];
|
||||
_ref3 = prop.index.compileReference(o);
|
||||
index = _ref3[0];
|
||||
indexVar = _ref3[1];
|
||||
this.properties[i] = new IndexNode(index);
|
||||
return (copy.properties[i] = new IndexNode(indexVar));
|
||||
}
|
||||
|
@ -385,22 +392,22 @@
|
|||
return !o.top || this.properties.length ? ValueNode.__super__.compile.call(this, o) : this.base.compile(o);
|
||||
};
|
||||
ValueNode.prototype.compileNode = function(o) {
|
||||
var _i, _l, _l2, _ref2, _ref3, _ref4, baseline, complete, copy, hasSoak, i, me, only, op, part, prop, props, temp;
|
||||
var _i, _len, _ref2, baseline, complete, copy, hasSoak, i, me, only, op, part, prop, props, temp;
|
||||
only = del(o, 'onlyFirst');
|
||||
op = this.tags.operation;
|
||||
props = only ? this.properties.slice(0, this.properties.length - 1) : this.properties;
|
||||
o.chainRoot || (o.chainRoot = this);
|
||||
_ref2 = props;
|
||||
for (_i = 0, _l = _ref2.length; _i < _l; _i++) {
|
||||
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
|
||||
prop = _ref2[_i];
|
||||
if (prop.soakNode) {
|
||||
hasSoak = true;
|
||||
}
|
||||
}
|
||||
if (hasSoak && this.containsType(CallNode)) {
|
||||
_ref3 = this.cacheIndexes(o);
|
||||
me = _ref3[0];
|
||||
copy = _ref3[1];
|
||||
_ref2 = this.cacheIndexes(o);
|
||||
me = _ref2[0];
|
||||
copy = _ref2[1];
|
||||
}
|
||||
if (this.parenthetical && !props.length) {
|
||||
this.base.parenthetical = true;
|
||||
|
@ -410,9 +417,9 @@
|
|||
baseline = ("(" + (baseline) + ")");
|
||||
}
|
||||
complete = (this.last = baseline);
|
||||
_ref4 = props;
|
||||
for (i = 0, _l2 = _ref4.length; i < _l2; i++) {
|
||||
prop = _ref4[i];
|
||||
_ref2 = props;
|
||||
for (i = 0, _len = _ref2.length; i < _len; i++) {
|
||||
prop = _ref2[i];
|
||||
this.source = baseline;
|
||||
if (prop.soakNode) {
|
||||
if (this.base.containsType(CallNode) && i === 0) {
|
||||
|
@ -497,7 +504,7 @@
|
|||
})());
|
||||
};
|
||||
CallNode.prototype.compileNode = function(o) {
|
||||
var _i, _i2, _l, _l2, _ref2, _ref3, _ref4, _ref5, _result, arg, args, code, first, meth, methodAccessor, op;
|
||||
var _i, _len, _ref2, _result, arg, args, code, first, meth, methodAccessor, op;
|
||||
if (!(o.chainRoot)) {
|
||||
o.chainRoot = this;
|
||||
}
|
||||
|
@ -511,29 +518,29 @@
|
|||
this.first = new ValueNode(first, [methodAccessor]).compile(o);
|
||||
this.meth = new ValueNode(meth, [methodAccessor]).compile(o);
|
||||
} else {
|
||||
_ref3 = this.variable.compileReference(o, {
|
||||
_ref2 = this.variable.compileReference(o, {
|
||||
precompile: true
|
||||
});
|
||||
this.first = _ref3[0];
|
||||
this.meth = _ref3[1];
|
||||
this.first = _ref2[0];
|
||||
this.meth = _ref2[1];
|
||||
}
|
||||
this.first = ("(typeof " + (this.first) + " === \"function\" ? ");
|
||||
this.last = " : undefined)";
|
||||
} else if (this.variable) {
|
||||
this.meth = this.variable.compile(o);
|
||||
}
|
||||
_ref4 = this.args;
|
||||
for (_i = 0, _l = _ref4.length; _i < _l; _i++) {
|
||||
arg = _ref4[_i];
|
||||
_ref2 = this.args;
|
||||
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
|
||||
arg = _ref2[_i];
|
||||
if (arg instanceof SplatNode) {
|
||||
code = this.compileSplat(o);
|
||||
}
|
||||
}
|
||||
if (!code) {
|
||||
args = (function() {
|
||||
_result = []; _ref5 = this.args;
|
||||
for (_i2 = 0, _l2 = _ref5.length; _i2 < _l2; _i2++) {
|
||||
arg = _ref5[_i2];
|
||||
_result = []; _ref2 = this.args;
|
||||
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
|
||||
arg = _ref2[_i];
|
||||
_result.push((function() {
|
||||
arg.parenthetical = true;
|
||||
return arg.compile(o);
|
||||
|
@ -549,7 +556,7 @@
|
|||
return "" + (this.superReference(o)) + ".call(this" + (args.length ? ', ' : '') + (args) + ")";
|
||||
};
|
||||
CallNode.prototype.compileSplat = function(o) {
|
||||
var _i, _l, _ref2, a, b, c, mentionsArgs, meth, obj, temp;
|
||||
var _i, _len, _ref2, a, b, c, mentionsArgs, meth, obj, temp;
|
||||
meth = this.meth || this.superReference(o);
|
||||
obj = this.variable && this.variable.source || 'this';
|
||||
if (obj.match(/\(/)) {
|
||||
|
@ -560,7 +567,7 @@
|
|||
if (this.isNew) {
|
||||
mentionsArgs = false;
|
||||
_ref2 = this.args;
|
||||
for (_i = 0, _l = _ref2.length; _i < _l; _i++) {
|
||||
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
|
||||
(function() {
|
||||
var arg = _ref2[_i];
|
||||
return arg.contains(function(n) {
|
||||
|
@ -570,7 +577,7 @@
|
|||
}
|
||||
utility('extends');
|
||||
a = o.scope.freeVariable('ctor');
|
||||
b = o.scope.freeVariable('instance');
|
||||
b = o.scope.freeVariable('ref');
|
||||
c = o.scope.freeVariable('result');
|
||||
return "" + (this.first) + "(function() {\n" + (this.idt(1)) + "var ctor = function(){};\n" + (this.idt(1)) + "__extends(ctor, " + (a) + " = " + (meth) + ");\n" + (this.idt(1)) + "return typeof (" + (c) + " = " + (a) + ".apply(" + (b) + " = new ctor, " + (this.compileSplatArguments(o)) + ")) === \"object\" ? " + (c) + " : " + (b) + ";\n" + (this.tab) + "})." + (mentionsArgs ? 'apply(this, arguments)' : 'call(this)') + (this.last);
|
||||
} else {
|
||||
|
@ -647,7 +654,7 @@
|
|||
RangeNode.prototype["class"] = 'RangeNode';
|
||||
RangeNode.prototype.children = ['from', 'to'];
|
||||
RangeNode.prototype.compileVariables = function(o) {
|
||||
var _ref2, _ref3, _ref4, parts;
|
||||
var _ref2, parts;
|
||||
o = merge(o, {
|
||||
top: true
|
||||
});
|
||||
|
@ -656,14 +663,14 @@
|
|||
});
|
||||
this.from = _ref2[0];
|
||||
this.fromVar = _ref2[1];
|
||||
_ref3 = this.to.compileReference(o, {
|
||||
_ref2 = this.to.compileReference(o, {
|
||||
precompile: true
|
||||
});
|
||||
this.to = _ref3[0];
|
||||
this.toVar = _ref3[1];
|
||||
_ref4 = [this.fromVar.match(SIMPLENUM), this.toVar.match(SIMPLENUM)];
|
||||
this.fromNum = _ref4[0];
|
||||
this.toNum = _ref4[1];
|
||||
this.to = _ref2[0];
|
||||
this.toVar = _ref2[1];
|
||||
_ref2 = [this.fromVar.match(SIMPLENUM), this.toVar.match(SIMPLENUM)];
|
||||
this.fromNum = _ref2[0];
|
||||
this.toNum = _ref2[1];
|
||||
parts = [];
|
||||
if (this.from !== this.fromVar) {
|
||||
parts.push(this.from);
|
||||
|
@ -766,12 +773,12 @@
|
|||
return true;
|
||||
};
|
||||
ObjectNode.prototype.compileNode = function(o) {
|
||||
var _i, _l, _l2, _ref2, _ref3, _result, _result2, i, indent, join, lastNoncom, nonComments, obj, prop, props, top;
|
||||
var _i, _len, _ref2, _result, i, indent, join, lastNoncom, nonComments, obj, prop, props, top;
|
||||
top = del(o, 'top');
|
||||
o.indent = this.idt(1);
|
||||
nonComments = (function() {
|
||||
_result = []; _ref2 = this.properties;
|
||||
for (_i = 0, _l = _ref2.length; _i < _l; _i++) {
|
||||
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
|
||||
prop = _ref2[_i];
|
||||
if (!(prop instanceof CommentNode)) {
|
||||
_result.push(prop);
|
||||
|
@ -781,10 +788,10 @@
|
|||
}).call(this);
|
||||
lastNoncom = nonComments[nonComments.length - 1];
|
||||
props = (function() {
|
||||
_result2 = []; _ref3 = this.properties;
|
||||
for (i = 0, _l2 = _ref3.length; i < _l2; i++) {
|
||||
prop = _ref3[i];
|
||||
_result2.push((function() {
|
||||
_result = []; _ref2 = this.properties;
|
||||
for (i = 0, _len = _ref2.length; i < _len; i++) {
|
||||
prop = _ref2[i];
|
||||
_result.push((function() {
|
||||
join = ",\n";
|
||||
if ((prop === lastNoncom) || (prop instanceof CommentNode)) {
|
||||
join = "\n";
|
||||
|
@ -799,7 +806,7 @@
|
|||
return indent + prop.compile(o) + join;
|
||||
}).call(this));
|
||||
}
|
||||
return _result2;
|
||||
return _result;
|
||||
}).call(this);
|
||||
props = props.join('');
|
||||
obj = '{' + (props ? '\n' + props + '\n' + this.idt() : '') + '}';
|
||||
|
@ -821,11 +828,11 @@
|
|||
ArrayNode.prototype["class"] = 'ArrayNode';
|
||||
ArrayNode.prototype.children = ['objects'];
|
||||
ArrayNode.prototype.compileNode = function(o) {
|
||||
var _l, _ref2, code, i, obj, objects;
|
||||
var _len, _ref2, code, i, obj, objects;
|
||||
o.indent = this.idt(1);
|
||||
objects = [];
|
||||
_ref2 = this.objects;
|
||||
for (i = 0, _l = _ref2.length; i < _l; i++) {
|
||||
for (i = 0, _len = _ref2.length; i < _len; i++) {
|
||||
obj = _ref2[i];
|
||||
code = obj.compile(o);
|
||||
if (obj instanceof SplatNode) {
|
||||
|
@ -864,7 +871,7 @@
|
|||
return this;
|
||||
};
|
||||
ClassNode.prototype.compileNode = function(o) {
|
||||
var _i, _l, _ref2, _ref3, access, applied, className, constScope, construct, constructor, extension, func, me, pname, prop, props, pvar, returns, val;
|
||||
var _i, _len, _ref2, _ref3, access, applied, className, constScope, construct, constructor, extension, func, me, pname, prop, props, pvar, returns, val;
|
||||
if (this.variable === '__temp__') {
|
||||
this.variable = literal(o.scope.freeVariable('ctor'));
|
||||
}
|
||||
|
@ -881,7 +888,7 @@
|
|||
constructor = new CodeNode();
|
||||
}
|
||||
_ref2 = this.properties;
|
||||
for (_i = 0, _l = _ref2.length; _i < _l; _i++) {
|
||||
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
|
||||
prop = _ref2[_i];
|
||||
_ref3 = [prop.variable, prop.value];
|
||||
pvar = _ref3[0];
|
||||
|
@ -996,7 +1003,7 @@
|
|||
return top || this.parenthetical ? val : ("(" + (val) + ")");
|
||||
};
|
||||
AssignNode.prototype.compilePatternMatch = function(o) {
|
||||
var _l, _ref2, _ref3, accessClass, assigns, code, i, idx, isString, obj, oindex, olength, splat, val, valVar, value;
|
||||
var _len, _ref2, _ref3, accessClass, assigns, code, i, idx, isString, obj, oindex, olength, splat, val, valVar, value;
|
||||
valVar = o.scope.freeVariable('ref');
|
||||
value = this.value.isStatement(o) ? ClosureNode.wrap(this.value) : this.value;
|
||||
assigns = [("" + (this.tab) + (valVar) + " = " + (value.compile(o)) + ";")];
|
||||
|
@ -1004,7 +1011,7 @@
|
|||
o.asStatement = true;
|
||||
splat = false;
|
||||
_ref2 = this.variable.base.objects;
|
||||
for (i = 0, _l = _ref2.length; i < _l; i++) {
|
||||
for (i = 0, _len = _ref2.length; i < _len; i++) {
|
||||
obj = _ref2[i];
|
||||
idx = i;
|
||||
if (this.variable.isObject()) {
|
||||
|
@ -1067,7 +1074,7 @@
|
|||
CodeNode.prototype["class"] = 'CodeNode';
|
||||
CodeNode.prototype.children = ['params', 'body'];
|
||||
CodeNode.prototype.compileNode = function(o) {
|
||||
var _i, _i2, _l, _l2, _l3, _ref2, _ref3, _ref4, _ref5, _ref6, _result, code, empty, func, i, param, params, sharedScope, splat, top, value;
|
||||
var _i, _len, _ref2, _ref3, _result, code, empty, func, i, param, params, sharedScope, splat, top, value;
|
||||
sharedScope = del(o, 'sharedScope');
|
||||
top = del(o, 'top');
|
||||
o.scope = sharedScope || new Scope(o.scope, this.body, this);
|
||||
|
@ -1079,7 +1086,7 @@
|
|||
splat = undefined;
|
||||
params = [];
|
||||
_ref2 = this.params;
|
||||
for (i = 0, _l = _ref2.length; i < _l; i++) {
|
||||
for (i = 0, _len = _ref2.length; i < _len; i++) {
|
||||
param = _ref2[i];
|
||||
if (splat) {
|
||||
if (param.attach) {
|
||||
|
@ -1091,9 +1098,9 @@
|
|||
if (param.attach) {
|
||||
_ref3 = param;
|
||||
value = _ref3.value;
|
||||
_ref4 = [literal(o.scope.freeVariable('arg')), param.splat];
|
||||
param = _ref4[0];
|
||||
param.splat = _ref4[1];
|
||||
_ref3 = [literal(o.scope.freeVariable('arg')), param.splat];
|
||||
param = _ref3[0];
|
||||
param.splat = _ref3[1];
|
||||
this.body.unshift(new AssignNode(new ValueNode(literal('this'), [new AccessorNode(value)]), param));
|
||||
}
|
||||
if (param.splat) {
|
||||
|
@ -1108,9 +1115,9 @@
|
|||
}
|
||||
}
|
||||
params = (function() {
|
||||
_result = []; _ref5 = params;
|
||||
for (_i = 0, _l2 = _ref5.length; _i < _l2; _i++) {
|
||||
param = _ref5[_i];
|
||||
_result = []; _ref2 = params;
|
||||
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
|
||||
param = _ref2[_i];
|
||||
_result.push(param.compile(o));
|
||||
}
|
||||
return _result;
|
||||
|
@ -1118,9 +1125,9 @@
|
|||
if (!(empty)) {
|
||||
this.body.makeReturn();
|
||||
}
|
||||
_ref6 = params;
|
||||
for (_i2 = 0, _l3 = _ref6.length; _i2 < _l3; _i2++) {
|
||||
param = _ref6[_i2];
|
||||
_ref2 = params;
|
||||
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
|
||||
param = _ref2[_i];
|
||||
(o.scope.parameter(param));
|
||||
}
|
||||
code = this.body.expressions.length ? ("\n" + (this.body.compileWithDeclarations(o)) + "\n") : '';
|
||||
|
@ -1139,11 +1146,11 @@
|
|||
}
|
||||
};
|
||||
CodeNode.prototype.toString = function(idt) {
|
||||
var _i, _l, _ref2, _result, child, children;
|
||||
var _i, _len, _ref2, _result, child, children;
|
||||
idt || (idt = '');
|
||||
children = (function() {
|
||||
_result = []; _ref2 = this.collectChildren();
|
||||
for (_i = 0, _l = _ref2.length; _i < _l; _i++) {
|
||||
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
|
||||
child = _ref2[_i];
|
||||
_result.push(child.toString(idt + TAB));
|
||||
}
|
||||
|
@ -1190,18 +1197,18 @@
|
|||
return (typeof (_ref2 = this.index) !== "undefined" && _ref2 !== null) ? this.compileParam(o) : this.name.compile(o);
|
||||
};
|
||||
SplatNode.prototype.compileParam = function(o) {
|
||||
var _l, _ref2, assign, end, idx, len, name, pos, trailing, variadic;
|
||||
var _len, _ref2, assign, end, idx, len, name, pos, trailing, variadic;
|
||||
name = this.name.compile(o);
|
||||
o.scope.find(name);
|
||||
end = '';
|
||||
if (this.trailings.length) {
|
||||
len = o.scope.freeVariable('ref');
|
||||
len = o.scope.freeVariable('len');
|
||||
o.scope.assign(len, "arguments.length");
|
||||
variadic = o.scope.freeVariable('result');
|
||||
o.scope.assign(variadic, len + ' >= ' + this.arglength);
|
||||
end = this.trailings.length ? (", " + (len) + " - " + (this.trailings.length)) : null;
|
||||
_ref2 = this.trailings;
|
||||
for (idx = 0, _l = _ref2.length; idx < _l; idx++) {
|
||||
for (idx = 0, _len = _ref2.length; idx < _len; idx++) {
|
||||
trailing = _ref2[idx];
|
||||
if (trailing.attach) {
|
||||
assign = trailing.assign;
|
||||
|
@ -1220,10 +1227,10 @@
|
|||
return "" + (utility('slice')) + ".call(" + (name) + ", " + (index) + (trail) + ")";
|
||||
};
|
||||
SplatNode.compileSplattedArray = function(list, o) {
|
||||
var _l, _ref2, arg, args, code, i, last, prev;
|
||||
var _len, _ref2, arg, args, code, i, last, prev;
|
||||
args = [];
|
||||
_ref2 = list;
|
||||
for (i = 0, _l = _ref2.length; i < _l; i++) {
|
||||
for (i = 0, _len = _ref2.length; i < _len; i++) {
|
||||
arg = _ref2[i];
|
||||
code = arg.compile(o);
|
||||
prev = args[(last = args.length - 1)];
|
||||
|
@ -1377,17 +1384,17 @@
|
|||
return [this.first.compile(o), this.operator, this.second.compile(o)].join(' ');
|
||||
};
|
||||
OpNode.prototype.compileChain = function(o) {
|
||||
var _ref2, _ref3, first, second, shared;
|
||||
var _ref2, first, second, shared;
|
||||
shared = this.first.unwrap().second;
|
||||
if (shared.containsType(CallNode)) {
|
||||
_ref2 = shared.compileReference(o);
|
||||
this.first.second = _ref2[0];
|
||||
shared = _ref2[1];
|
||||
}
|
||||
_ref3 = [this.first.compile(o), this.second.compile(o), shared.compile(o)];
|
||||
first = _ref3[0];
|
||||
second = _ref3[1];
|
||||
shared = _ref3[2];
|
||||
_ref2 = [this.first.compile(o), this.second.compile(o), shared.compile(o)];
|
||||
first = _ref2[0];
|
||||
second = _ref2[1];
|
||||
shared = _ref2[2];
|
||||
return "(" + (first) + ") && (" + (shared) + " " + (this.operator) + " " + (second) + ")";
|
||||
};
|
||||
OpNode.prototype.compileAssignment = function(o) {
|
||||
|
@ -1451,10 +1458,10 @@
|
|||
return this.isArray() ? this.compileOrTest(o) : this.compileLoopTest(o);
|
||||
};
|
||||
InNode.prototype.compileOrTest = function(o) {
|
||||
var _l, _ref2, _result, i, item, tests;
|
||||
var _len, _ref2, _result, i, item, tests;
|
||||
tests = (function() {
|
||||
_result = []; _ref2 = this.array.base.objects;
|
||||
for (i = 0, _l = _ref2.length; i < _l; i++) {
|
||||
for (i = 0, _len = _ref2.length; i < _len; i++) {
|
||||
item = _ref2[i];
|
||||
_result.push("" + (item.compile(o)) + " === " + (i ? this.obj2 : this.obj1));
|
||||
}
|
||||
|
@ -1463,15 +1470,15 @@
|
|||
return "(" + (tests.join(' || ')) + ")";
|
||||
};
|
||||
InNode.prototype.compileLoopTest = function(o) {
|
||||
var _ref2, _ref3, i, l, prefix;
|
||||
var _ref2, i, l, prefix;
|
||||
_ref2 = this.array.compileReference(o, {
|
||||
precompile: true
|
||||
});
|
||||
this.arr1 = _ref2[0];
|
||||
this.arr2 = _ref2[1];
|
||||
_ref3 = [o.scope.freeVariable('i'), o.scope.freeVariable('l')];
|
||||
i = _ref3[0];
|
||||
l = _ref3[1];
|
||||
_ref2 = [o.scope.freeVariable('i'), o.scope.freeVariable('len')];
|
||||
i = _ref2[0];
|
||||
l = _ref2[1];
|
||||
prefix = this.obj1 !== this.obj2 ? this.obj1 + '; ' : '';
|
||||
return "(function(){ " + (prefix) + "for (var " + (i) + "=0, " + (l) + "=" + (this.arr1) + ".length; " + (i) + "<" + (l) + "; " + (i) + "++) { if (" + (this.arr2) + "[" + (i) + "] === " + (this.obj2) + ") return true; } return false; }).call(this)";
|
||||
};
|
||||
|
@ -1686,7 +1693,8 @@
|
|||
if (this.pattern) {
|
||||
namePart = new AssignNode(this.name, literal("" + (svar) + "[" + (ivar) + "]")).compile(merge(o, {
|
||||
indent: this.idt(1),
|
||||
top: true
|
||||
top: true,
|
||||
keepLevel: true
|
||||
})) + '\n';
|
||||
} else {
|
||||
if (name) {
|
||||
|
@ -1694,7 +1702,7 @@
|
|||
}
|
||||
}
|
||||
if (!(this.object)) {
|
||||
lvar = scope.freeVariable('l');
|
||||
lvar = scope.freeVariable('len');
|
||||
stepPart = this.step ? ("" + (ivar) + " += " + (this.step.compile(o))) : ("" + (ivar) + "++");
|
||||
forPart = ("" + (ivar) + " = 0, " + (lvar) + " = " + (svar) + ".length; " + (ivar) + " < " + (lvar) + "; " + (stepPart));
|
||||
}
|
||||
|
@ -1754,9 +1762,9 @@
|
|||
return true;
|
||||
};
|
||||
SwitchNode.prototype.makeReturn = function() {
|
||||
var _i, _l, _ref2, pair;
|
||||
var _i, _len, _ref2, pair;
|
||||
_ref2 = this.cases;
|
||||
for (_i = 0, _l = _ref2.length; _i < _l; _i++) {
|
||||
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
|
||||
pair = _ref2[_i];
|
||||
pair[1].makeReturn();
|
||||
}
|
||||
|
@ -1766,20 +1774,20 @@
|
|||
return this;
|
||||
};
|
||||
SwitchNode.prototype.compileNode = function(o) {
|
||||
var _i, _i2, _l, _l2, _ref2, _ref3, _ref4, block, code, condition, conditions, exprs, idt, pair;
|
||||
var _i, _i2, _len, _len2, _ref2, _ref3, block, code, condition, conditions, exprs, idt, pair;
|
||||
idt = (o.indent = this.idt(1));
|
||||
o.top = true;
|
||||
code = ("" + (this.tab) + "switch (" + (this.subject.compile(o)) + ") {");
|
||||
_ref2 = this.cases;
|
||||
for (_i = 0, _l = _ref2.length; _i < _l; _i++) {
|
||||
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
|
||||
pair = _ref2[_i];
|
||||
_ref3 = pair;
|
||||
conditions = _ref3[0];
|
||||
block = _ref3[1];
|
||||
exprs = block.expressions;
|
||||
_ref4 = flatten([conditions]);
|
||||
for (_i2 = 0, _l2 = _ref4.length; _i2 < _l2; _i2++) {
|
||||
condition = _ref4[_i2];
|
||||
_ref3 = flatten([conditions]);
|
||||
for (_i2 = 0, _len2 = _ref3.length; _i2 < _len2; _i2++) {
|
||||
condition = _ref3[_i2];
|
||||
if (this.tags.subjectless) {
|
||||
condition = new OpNode('!!', new ParentheticalNode(condition));
|
||||
}
|
||||
|
@ -1844,14 +1852,14 @@
|
|||
return this.statement || (this.statement = (!!((o && o.top) || this.tags.statement || this.bodyNode().isStatement(o) || (this.elseBody && this.elseBodyNode().isStatement(o)))));
|
||||
};
|
||||
IfNode.prototype.compileCondition = function(o) {
|
||||
var _i, _l, _ref2, _result, cond, conditions;
|
||||
var _i, _len, _ref2, _result, cond, conditions;
|
||||
conditions = flatten([this.condition]);
|
||||
if (conditions.length === 1) {
|
||||
conditions[0].parenthetical = true;
|
||||
}
|
||||
return (function() {
|
||||
_result = []; _ref2 = conditions;
|
||||
for (_i = 0, _l = _ref2.length; _i < _l; _i++) {
|
||||
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
|
||||
cond = _ref2[_i];
|
||||
_result.push(cond.compile(o));
|
||||
}
|
||||
|
|
|
@ -7,18 +7,18 @@
|
|||
return this;
|
||||
};
|
||||
OptionParser.prototype.parse = function(args) {
|
||||
var _i, _l, _l2, _ref, _ref2, arg, i, isOption, matchedRule, options, rule, value;
|
||||
var _i, _len, _len2, _ref, _ref2, arg, i, isOption, matchedRule, options, rule, value;
|
||||
options = {
|
||||
arguments: []
|
||||
};
|
||||
args = normalizeArguments(args);
|
||||
_ref = args;
|
||||
for (i = 0, _l = _ref.length; i < _l; i++) {
|
||||
for (i = 0, _len = _ref.length; i < _len; i++) {
|
||||
arg = _ref[i];
|
||||
isOption = !!(arg.match(LONG_FLAG) || arg.match(SHORT_FLAG));
|
||||
matchedRule = false;
|
||||
_ref2 = this.rules;
|
||||
for (_i = 0, _l2 = _ref2.length; _i < _l2; _i++) {
|
||||
for (_i = 0, _len2 = _ref2.length; _i < _len2; _i++) {
|
||||
rule = _ref2[_i];
|
||||
if (rule.shortFlag === arg || rule.longFlag === arg) {
|
||||
value = rule.hasArgument ? args[i += 1] : true;
|
||||
|
@ -38,13 +38,13 @@
|
|||
return options;
|
||||
};
|
||||
OptionParser.prototype.help = function() {
|
||||
var _i, _l, _ref, _result, i, letPart, lines, rule, spaces;
|
||||
var _i, _len, _ref, _result, i, letPart, lines, rule, spaces;
|
||||
lines = ['Available options:'];
|
||||
if (this.banner) {
|
||||
lines.unshift("" + (this.banner) + "\n");
|
||||
}
|
||||
_ref = this.rules;
|
||||
for (_i = 0, _l = _ref.length; _i < _l; _i++) {
|
||||
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
||||
rule = _ref[_i];
|
||||
spaces = 15 - rule.longFlag.length;
|
||||
spaces = spaces > 0 ? (function() {
|
||||
|
@ -66,9 +66,9 @@
|
|||
MULTI_FLAG = /^-(\w{2,})/;
|
||||
OPTIONAL = /\[(\w+(\*?))\]/;
|
||||
buildRules = function(rules) {
|
||||
var _i, _l, _ref, _result, tuple;
|
||||
var _i, _len, _ref, _result, tuple;
|
||||
_result = []; _ref = rules;
|
||||
for (_i = 0, _l = _ref.length; _i < _l; _i++) {
|
||||
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
||||
tuple = _ref[_i];
|
||||
_result.push((function() {
|
||||
if (tuple.length < 3) {
|
||||
|
@ -94,15 +94,15 @@
|
|||
};
|
||||
};
|
||||
normalizeArguments = function(args) {
|
||||
var _i, _i2, _l, _l2, _ref, _ref2, arg, l, match, result;
|
||||
var _i, _i2, _len, _len2, _ref, _ref2, arg, l, match, result;
|
||||
args = args.slice(0);
|
||||
result = [];
|
||||
_ref = args;
|
||||
for (_i = 0, _l = _ref.length; _i < _l; _i++) {
|
||||
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
||||
arg = _ref[_i];
|
||||
if (match = arg.match(MULTI_FLAG)) {
|
||||
_ref2 = match[1].split('');
|
||||
for (_i2 = 0, _l2 = _ref2.length; _i2 < _l2; _i2++) {
|
||||
for (_i2 = 0, _len2 = _ref2.length; _i2 < _len2; _i2++) {
|
||||
l = _ref2[_i2];
|
||||
result.push('-' + l);
|
||||
}
|
||||
|
|
120
lib/rewriter.js
120
lib/rewriter.js
|
@ -1,5 +1,5 @@
|
|||
(function() {
|
||||
var BALANCED_PAIRS, EXPRESSION_CLOSE, EXPRESSION_END, EXPRESSION_START, IMPLICIT_BLOCK, IMPLICIT_CALL, IMPLICIT_END, IMPLICIT_FUNC, INVERSES, LINEBREAKS, Rewriter, SINGLE_CLOSERS, SINGLE_LINERS, _i, _i2, _i3, _l, _l2, _l3, _ref, _ref2, _ref3, _ref4, _ref5, _result, _result2, helpers, include, pair;
|
||||
var BALANCED_PAIRS, EXPRESSION_CLOSE, EXPRESSION_END, EXPRESSION_START, IMPLICIT_BLOCK, IMPLICIT_CALL, IMPLICIT_END, IMPLICIT_FUNC, INVERSES, LINEBREAKS, Rewriter, SINGLE_CLOSERS, SINGLE_LINERS, _i, _len, _ref, _result, helpers, include, pair;
|
||||
var __hasProp = Object.prototype.hasOwnProperty;
|
||||
if (typeof process !== "undefined" && process !== null) {
|
||||
_ref = require('./helpers');
|
||||
|
@ -8,8 +8,8 @@
|
|||
this.exports = this;
|
||||
helpers = this.helpers;
|
||||
}
|
||||
_ref2 = helpers;
|
||||
include = _ref2.include;
|
||||
_ref = helpers;
|
||||
include = _ref.include;
|
||||
exports.Rewriter = (function() {
|
||||
Rewriter = function() {};
|
||||
Rewriter.prototype.rewrite = function(tokens) {
|
||||
|
@ -62,15 +62,15 @@
|
|||
};
|
||||
Rewriter.prototype.adjustComments = function() {
|
||||
return this.scanTokens(function(token, i) {
|
||||
var _ref3, _ref4, after, before, post, prev;
|
||||
var _ref2, after, before, post, prev;
|
||||
if (token[0] !== 'HERECOMMENT') {
|
||||
return 1;
|
||||
}
|
||||
_ref3 = [this.tokens[i - 2], this.tokens[i - 1], this.tokens[i + 1], this.tokens[i + 2]];
|
||||
before = _ref3[0];
|
||||
prev = _ref3[1];
|
||||
post = _ref3[2];
|
||||
after = _ref3[3];
|
||||
_ref2 = [this.tokens[i - 2], this.tokens[i - 1], this.tokens[i + 1], this.tokens[i + 2]];
|
||||
before = _ref2[0];
|
||||
prev = _ref2[1];
|
||||
post = _ref2[2];
|
||||
after = _ref2[3];
|
||||
if (after && after[0] === 'INDENT') {
|
||||
this.tokens.splice(i + 2, 1);
|
||||
if (before && before[0] === 'OUTDENT' && post && (prev[0] === post[0]) && (post[0] === 'TERMINATOR')) {
|
||||
|
@ -78,7 +78,7 @@
|
|||
} else {
|
||||
this.tokens.splice(i, 0, after);
|
||||
}
|
||||
} else if (prev && !('TERMINATOR' === (_ref4 = prev[0]) || 'INDENT' === _ref4 || 'OUTDENT' === _ref4)) {
|
||||
} else if (prev && !('TERMINATOR' === (_ref2 = prev[0]) || 'INDENT' === _ref2 || 'OUTDENT' === _ref2)) {
|
||||
if (post && post[0] === 'TERMINATOR' && after && after[0] === 'OUTDENT') {
|
||||
this.tokens.splice.apply(this.tokens, [i + 2, 0].concat(this.tokens.splice(i, 2)));
|
||||
if (this.tokens[i + 2][0] !== 'TERMINATOR') {
|
||||
|
@ -114,8 +114,8 @@
|
|||
var action, condition;
|
||||
if (token[0] === 'CALL_START') {
|
||||
condition = function(token, i) {
|
||||
var _ref3;
|
||||
return ((')' === (_ref3 = token[0]) || 'CALL_END' === _ref3)) || (token[0] === 'OUTDENT' && this.tokens[i - 1][0] === ')');
|
||||
var _ref2;
|
||||
return ((')' === (_ref2 = token[0]) || 'CALL_END' === _ref2)) || (token[0] === 'OUTDENT' && this.tokens[i - 1][0] === ')');
|
||||
};
|
||||
action = function(token, i) {
|
||||
var idx;
|
||||
|
@ -132,8 +132,8 @@
|
|||
var action, condition;
|
||||
if (token[0] === 'INDEX_START') {
|
||||
condition = function(token, i) {
|
||||
var _ref3;
|
||||
return (']' === (_ref3 = token[0]) || 'INDEX_END' === _ref3);
|
||||
var _ref2;
|
||||
return (']' === (_ref2 = token[0]) || 'INDEX_END' === _ref2);
|
||||
};
|
||||
action = function(token, i) {
|
||||
return (token[0] = 'INDEX_END');
|
||||
|
@ -162,15 +162,15 @@
|
|||
tok.generated = true;
|
||||
this.tokens.splice(idx, 0, tok);
|
||||
condition = function(token, i) {
|
||||
var _ref3, _ref4, _ref5, one, three, two;
|
||||
_ref3 = this.tokens.slice(i + 1, i + 4);
|
||||
one = _ref3[0];
|
||||
two = _ref3[1];
|
||||
three = _ref3[2];
|
||||
var _ref2, one, three, two;
|
||||
_ref2 = this.tokens.slice(i + 1, i + 4);
|
||||
one = _ref2[0];
|
||||
two = _ref2[1];
|
||||
three = _ref2[2];
|
||||
if ((this.tag(i + 1) === 'HERECOMMENT' || this.tag(i - 1) === 'HERECOMMENT')) {
|
||||
return false;
|
||||
}
|
||||
return ((('TERMINATOR' === (_ref4 = token[0]) || 'OUTDENT' === _ref4)) && !((two && two[0] === ':') || (one && one[0] === '@' && three && three[0] === ':'))) || (token[0] === ',' && one && (!('IDENTIFIER' === (_ref5 = one[0]) || 'STRING' === _ref5 || '@' === _ref5 || 'TERMINATOR' === _ref5 || 'OUTDENT' === _ref5)));
|
||||
return ((('TERMINATOR' === (_ref2 = token[0]) || 'OUTDENT' === _ref2)) && !((two && two[0] === ':') || (one && one[0] === '@' && three && three[0] === ':'))) || (token[0] === ',' && one && (!('IDENTIFIER' === (_ref2 = one[0]) || 'STRING' === _ref2 || '@' === _ref2 || 'TERMINATOR' === _ref2 || 'OUTDENT' === _ref2)));
|
||||
};
|
||||
action = function(token, i) {
|
||||
return this.tokens.splice(i, 0, ['}', '}', token[2]]);
|
||||
|
@ -185,7 +185,7 @@
|
|||
var classLine;
|
||||
classLine = false;
|
||||
return this.scanTokens(function(token, i) {
|
||||
var _ref3, action, callObject, condition, idx, next, prev, seenSingle;
|
||||
var _ref2, action, callObject, condition, idx, next, prev, seenSingle;
|
||||
if (token[0] === 'CLASS') {
|
||||
classLine = true;
|
||||
}
|
||||
|
@ -203,14 +203,14 @@
|
|||
if (prev && !prev.spaced && token[0] === '?') {
|
||||
token.call = true;
|
||||
}
|
||||
if (prev && (prev.spaced && (include(IMPLICIT_FUNC, prev[0]) || prev.call) && include(IMPLICIT_CALL, token[0]) && !(token[0] === 'UNARY' && (('IN' === (_ref3 = this.tag(i + 1)) || 'OF' === _ref3 || 'INSTANCEOF' === _ref3)))) || callObject) {
|
||||
if (prev && (prev.spaced && (include(IMPLICIT_FUNC, prev[0]) || prev.call) && include(IMPLICIT_CALL, token[0]) && !(token[0] === 'UNARY' && (('IN' === (_ref2 = this.tag(i + 1)) || 'OF' === _ref2 || 'INSTANCEOF' === _ref2)))) || callObject) {
|
||||
this.tokens.splice(i, 0, ['CALL_START', '(', token[2]]);
|
||||
condition = function(token, i) {
|
||||
var _ref3, post;
|
||||
var _ref2, post;
|
||||
if (!seenSingle && token.fromThen) {
|
||||
return true;
|
||||
}
|
||||
if (('IF' === (_ref3 = token[0]) || 'ELSE' === _ref3 || 'UNLESS' === _ref3 || '->' === _ref3 || '=>' === _ref3)) {
|
||||
if (('IF' === (_ref2 = token[0]) || 'ELSE' === _ref2 || 'UNLESS' === _ref2 || '->' === _ref2 || '=>' === _ref2)) {
|
||||
seenSingle = true;
|
||||
}
|
||||
post = this.tokens[i + 1];
|
||||
|
@ -231,7 +231,7 @@
|
|||
};
|
||||
Rewriter.prototype.addImplicitIndentation = function() {
|
||||
return this.scanTokens(function(token, i) {
|
||||
var _ref3, action, condition, indent, outdent, starter;
|
||||
var _ref2, action, condition, indent, outdent, starter;
|
||||
if (token[0] === 'ELSE' && this.tag(i - 1) !== 'OUTDENT') {
|
||||
this.tokens.splice.apply(this.tokens, [i, 0].concat(this.indentation(token)));
|
||||
return 2;
|
||||
|
@ -242,9 +242,9 @@
|
|||
}
|
||||
if (include(SINGLE_LINERS, token[0]) && this.tag(i + 1) !== 'INDENT' && !(token[0] === 'ELSE' && this.tag(i + 1) === 'IF')) {
|
||||
starter = token[0];
|
||||
_ref3 = this.indentation(token);
|
||||
indent = _ref3[0];
|
||||
outdent = _ref3[1];
|
||||
_ref2 = this.indentation(token);
|
||||
indent = _ref2[0];
|
||||
outdent = _ref2[1];
|
||||
if (starter === 'THEN') {
|
||||
indent.fromThen = true;
|
||||
}
|
||||
|
@ -269,12 +269,12 @@
|
|||
};
|
||||
Rewriter.prototype.tagPostfixConditionals = function() {
|
||||
return this.scanTokens(function(token, i) {
|
||||
var _ref3, action, condition, original;
|
||||
if (('IF' === (_ref3 = token[0]) || 'UNLESS' === _ref3)) {
|
||||
var _ref2, action, condition, original;
|
||||
if (('IF' === (_ref2 = token[0]) || 'UNLESS' === _ref2)) {
|
||||
original = token;
|
||||
condition = function(token, i) {
|
||||
var _ref3;
|
||||
return ('TERMINATOR' === (_ref3 = token[0]) || 'INDENT' === _ref3);
|
||||
var _ref2;
|
||||
return ('TERMINATOR' === (_ref2 = token[0]) || 'INDENT' === _ref2);
|
||||
};
|
||||
action = function(token, i) {
|
||||
if (token[0] !== 'INDENT') {
|
||||
|
@ -288,17 +288,17 @@
|
|||
});
|
||||
};
|
||||
Rewriter.prototype.ensureBalance = function(pairs) {
|
||||
var _ref3, _result, key, levels, line, open, openLine, unclosed, value;
|
||||
var _ref2, _result, key, levels, line, open, openLine, unclosed, value;
|
||||
levels = {};
|
||||
openLine = {};
|
||||
this.scanTokens(function(token, i) {
|
||||
var _i, _l, _ref3, _ref4, close, open, pair;
|
||||
_ref3 = pairs;
|
||||
for (_i = 0, _l = _ref3.length; _i < _l; _i++) {
|
||||
pair = _ref3[_i];
|
||||
_ref4 = pair;
|
||||
open = _ref4[0];
|
||||
close = _ref4[1];
|
||||
var _i, _len, _ref2, _ref3, close, open, pair;
|
||||
_ref2 = pairs;
|
||||
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
|
||||
pair = _ref2[_i];
|
||||
_ref3 = pair;
|
||||
open = _ref3[0];
|
||||
close = _ref3[1];
|
||||
levels[open] || (levels[open] = 0);
|
||||
if (token[0] === open) {
|
||||
if (levels[open] === 0) {
|
||||
|
@ -316,10 +316,10 @@
|
|||
return 1;
|
||||
});
|
||||
unclosed = (function() {
|
||||
_result = []; _ref3 = levels;
|
||||
for (key in _ref3) {
|
||||
if (!__hasProp.call(_ref3, key)) continue;
|
||||
value = _ref3[key];
|
||||
_result = []; _ref2 = levels;
|
||||
for (key in _ref2) {
|
||||
if (!__hasProp.call(_ref2, key)) continue;
|
||||
value = _ref2[key];
|
||||
if (value > 0) {
|
||||
_result.push(key);
|
||||
}
|
||||
|
@ -333,13 +333,13 @@
|
|||
}
|
||||
};
|
||||
Rewriter.prototype.rewriteClosingParens = function() {
|
||||
var _ref3, debt, key, stack, val;
|
||||
var _ref2, debt, key, stack, val;
|
||||
stack = [];
|
||||
debt = {};
|
||||
_ref3 = INVERSES;
|
||||
for (key in _ref3) {
|
||||
if (!__hasProp.call(_ref3, key)) continue;
|
||||
val = _ref3[key];
|
||||
_ref2 = INVERSES;
|
||||
for (key in _ref2) {
|
||||
if (!__hasProp.call(_ref2, key)) continue;
|
||||
val = _ref2[key];
|
||||
(debt[key] = 0);
|
||||
}
|
||||
return this.scanTokens(function(token, i) {
|
||||
|
@ -386,27 +386,27 @@
|
|||
})();
|
||||
BALANCED_PAIRS = [['(', ')'], ['[', ']'], ['{', '}'], ['INDENT', 'OUTDENT'], ['PARAM_START', 'PARAM_END'], ['CALL_START', 'CALL_END'], ['INDEX_START', 'INDEX_END']];
|
||||
INVERSES = {};
|
||||
_ref3 = BALANCED_PAIRS;
|
||||
for (_i = 0, _l = _ref3.length; _i < _l; _i++) {
|
||||
pair = _ref3[_i];
|
||||
_ref = BALANCED_PAIRS;
|
||||
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
||||
pair = _ref[_i];
|
||||
INVERSES[pair[0]] = pair[1];
|
||||
INVERSES[pair[1]] = pair[0];
|
||||
}
|
||||
EXPRESSION_START = (function() {
|
||||
_result = []; _ref4 = BALANCED_PAIRS;
|
||||
for (_i2 = 0, _l2 = _ref4.length; _i2 < _l2; _i2++) {
|
||||
pair = _ref4[_i2];
|
||||
_result = []; _ref = BALANCED_PAIRS;
|
||||
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
||||
pair = _ref[_i];
|
||||
_result.push(pair[0]);
|
||||
}
|
||||
return _result;
|
||||
})();
|
||||
EXPRESSION_END = (function() {
|
||||
_result2 = []; _ref5 = BALANCED_PAIRS;
|
||||
for (_i3 = 0, _l3 = _ref5.length; _i3 < _l3; _i3++) {
|
||||
pair = _ref5[_i3];
|
||||
_result2.push(pair[1]);
|
||||
_result = []; _ref = BALANCED_PAIRS;
|
||||
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
||||
pair = _ref[_i];
|
||||
_result.push(pair[1]);
|
||||
}
|
||||
return _result2;
|
||||
return _result;
|
||||
})();
|
||||
EXPRESSION_CLOSE = ['CATCH', 'WHEN', 'ELSE', 'FINALLY'].concat(EXPRESSION_END);
|
||||
IMPLICIT_FUNC = ['IDENTIFIER', 'SUPER', ')', 'CALL_END', ']', 'INDEX_END', '@', 'THIS'];
|
||||
|
|
33
lib/scope.js
33
lib/scope.js
|
@ -16,15 +16,29 @@
|
|||
this.expressions = _ref2[1];
|
||||
this.method = _ref2[2];
|
||||
this.variables = {};
|
||||
this.generated = {};
|
||||
if (this.parent) {
|
||||
extend(this.generated, this.parent.generated);
|
||||
this.garbage = this.parent.garbage;
|
||||
} else {
|
||||
this.garbage = [];
|
||||
Scope.root = this;
|
||||
}
|
||||
return this;
|
||||
};
|
||||
Scope.root = null;
|
||||
Scope.prototype.startLevel = function() {
|
||||
return this.garbage.push([]);
|
||||
};
|
||||
Scope.prototype.endLevel = function() {
|
||||
var _i, _len, _ref2, _result, name;
|
||||
_result = []; _ref2 = this.garbage.pop();
|
||||
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
|
||||
name = _ref2[_i];
|
||||
if (this.variables[name] === 'var') {
|
||||
_result.push(this.variables[name] = 'reuse');
|
||||
}
|
||||
}
|
||||
return _result;
|
||||
};
|
||||
Scope.prototype.find = function(name, options) {
|
||||
if (this.check(name, options)) {
|
||||
return true;
|
||||
|
@ -59,12 +73,15 @@
|
|||
return '_' + type + (index > 1 ? index : '');
|
||||
};
|
||||
Scope.prototype.freeVariable = function(type) {
|
||||
var temp;
|
||||
this.generated[type] || (this.generated[type] = 1);
|
||||
while (this.check(temp = this.temporary(type, this.generated[type]))) {
|
||||
this.generated[type]++;
|
||||
var index, temp;
|
||||
index = 0;
|
||||
while (this.check(temp = this.temporary(type, index)) && this.variables[temp] !== 'reuse') {
|
||||
index++;
|
||||
}
|
||||
this.variables[temp] = 'var';
|
||||
if (this.garbage.length) {
|
||||
this.garbage[this.garbage.length - 1].push(temp);
|
||||
}
|
||||
return temp;
|
||||
};
|
||||
Scope.prototype.assign = function(name, value) {
|
||||
|
@ -75,7 +92,7 @@
|
|||
};
|
||||
Scope.prototype.hasDeclarations = function(body) {
|
||||
return body === this.expressions && this.any(function(k, val) {
|
||||
return val === 'var';
|
||||
return val === 'var' || val === 'reuse';
|
||||
});
|
||||
};
|
||||
Scope.prototype.hasAssignments = function(body) {
|
||||
|
@ -90,7 +107,7 @@
|
|||
for (key in _ref2) {
|
||||
if (!__hasProp.call(_ref2, key)) continue;
|
||||
val = _ref2[key];
|
||||
if (val === 'var') {
|
||||
if (val === 'var' || val === 'reuse') {
|
||||
_result.push(key);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -50,7 +50,10 @@ exports.BaseNode = class BaseNode
|
|||
closure = @isStatement(o) and not @isPureStatement() and not top and
|
||||
not @options.asStatement and this not instanceof CommentNode and
|
||||
not @containsPureStatement()
|
||||
if closure then @compileClosure(@options) else @compileNode(@options)
|
||||
o.scope.startLevel() if not o.keepLevel
|
||||
code = if closure then @compileClosure(@options) else @compileNode(@options)
|
||||
o.scope.endLevel() if not o.keepLevel
|
||||
code
|
||||
|
||||
# Statements converted into expressions via closure-wrapping share a scope
|
||||
# object with their parent closure, to preserve the expected lexical scope.
|
||||
|
@ -497,7 +500,7 @@ exports.CallNode = class CallNode extends BaseNode
|
|||
arg.contains (n) -> mentionsArgs or= n instanceof LiteralNode and (n.value is 'arguments')
|
||||
utility 'extends'
|
||||
a = o.scope.freeVariable 'ctor'
|
||||
b = o.scope.freeVariable 'instance'
|
||||
b = o.scope.freeVariable 'ref'
|
||||
c = o.scope.freeVariable 'result'
|
||||
"""
|
||||
#{@first}(function() {
|
||||
|
@ -1011,7 +1014,7 @@ exports.SplatNode = class SplatNode extends BaseNode
|
|||
o.scope.find name
|
||||
end = ''
|
||||
if @trailings.length
|
||||
len = o.scope.freeVariable 'ref'
|
||||
len = o.scope.freeVariable 'len'
|
||||
o.scope.assign len, "arguments.length"
|
||||
variadic = o.scope.freeVariable 'result'
|
||||
o.scope.assign variadic, len + ' >= ' + @arglength
|
||||
|
@ -1227,7 +1230,7 @@ exports.InNode = class InNode extends BaseNode
|
|||
|
||||
compileLoopTest: (o) ->
|
||||
[@arr1, @arr2] = @array.compileReference o, precompile: yes
|
||||
[i, l] = [o.scope.freeVariable('i'), o.scope.freeVariable('l')]
|
||||
[i, l] = [o.scope.freeVariable('i'), o.scope.freeVariable('len')]
|
||||
prefix = if @obj1 isnt @obj2 then @obj1 + '; ' else ''
|
||||
"(function(){ #{prefix}for (var #{i}=0, #{l}=#{@arr1}.length; #{i}<#{l}; #{i}++) { if (#{@arr2}[#{i}] === #{@obj2}) return true; } return false; }).call(this)"
|
||||
|
||||
|
@ -1401,11 +1404,11 @@ exports.ForNode = class ForNode extends BaseNode
|
|||
svar = scope.freeVariable 'ref'
|
||||
sourcePart = "#{svar} = #{ @source.compile(o) };"
|
||||
if @pattern
|
||||
namePart = new AssignNode(@name, literal("#{svar}[#{ivar}]")).compile(merge o, {indent: @idt(1), top: true}) + '\n'
|
||||
namePart = new AssignNode(@name, literal("#{svar}[#{ivar}]")).compile(merge o, {indent: @idt(1), top: true, keepLevel: yes}) + '\n'
|
||||
else
|
||||
namePart = "#{name} = #{svar}[#{ivar}]" if name
|
||||
unless @object
|
||||
lvar = scope.freeVariable 'l'
|
||||
lvar = scope.freeVariable 'len'
|
||||
stepPart = if @step then "#{ivar} += #{ @step.compile(o) }" else "#{ivar}++"
|
||||
forPart = "#{ivar} = 0, #{lvar} = #{svar}.length; #{ivar} < #{lvar}; #{stepPart}"
|
||||
sourcePart = (if rvar then "#{rvar} = []; " else '') + sourcePart
|
||||
|
|
|
@ -26,12 +26,21 @@ exports.Scope = class Scope
|
|||
constructor: (parent, expressions, method) ->
|
||||
[@parent, @expressions, @method] = [parent, expressions, method]
|
||||
@variables = {}
|
||||
@generated = {}
|
||||
if @parent
|
||||
extend @generated, @parent.generated
|
||||
@garbage = @parent.garbage
|
||||
else
|
||||
@garbage = []
|
||||
Scope.root = this
|
||||
|
||||
# Create a new garbage level
|
||||
startLevel: ->
|
||||
@garbage.push []
|
||||
|
||||
# Return to the previous garbage level and erase referenced temporary
|
||||
# variables in current level from scope.
|
||||
endLevel: ->
|
||||
(@variables[name] = 'reuse') for name in @garbage.pop() when @variables[name] is 'var'
|
||||
|
||||
# Look up a variable name in lexical scope, and declare it if it does not
|
||||
# already exist.
|
||||
find: (name, options) ->
|
||||
|
@ -64,9 +73,10 @@ exports.Scope = class Scope
|
|||
# If we need to store an intermediate result, find an available name for a
|
||||
# compiler-generated variable. `_var`, `_var2`, and so on...
|
||||
freeVariable: (type) ->
|
||||
@generated[type] or= 1
|
||||
@generated[type]++ while @check temp = @temporary type, @generated[type]
|
||||
index = 0
|
||||
index++ while @check(temp = @temporary type, index) and @variables[temp] isnt 'reuse'
|
||||
@variables[temp] = 'var'
|
||||
@garbage[@garbage.length - 1].push temp if @garbage.length
|
||||
temp
|
||||
|
||||
# Ensure that an assignment is made at the top of this scope
|
||||
|
@ -77,7 +87,7 @@ exports.Scope = class Scope
|
|||
# Does this scope reference any variables that need to be declared in the
|
||||
# given function body?
|
||||
hasDeclarations: (body) ->
|
||||
body is @expressions and @any (k, val) -> val is 'var'
|
||||
body is @expressions and @any (k, val) -> val is 'var' or val is 'reuse'
|
||||
|
||||
# Does this scope reference any assignments that need to be declared at the
|
||||
# top of the given function body?
|
||||
|
@ -86,7 +96,7 @@ exports.Scope = class Scope
|
|||
|
||||
# Return the list of variables first declared in this scope.
|
||||
declaredVariables: ->
|
||||
(key for key, val of @variables when val is 'var').sort()
|
||||
(key for key, val of @variables when val is 'var' or val is 'reuse').sort()
|
||||
|
||||
# Return the list of assignments that are supposed to be made at the top
|
||||
# of this scope.
|
||||
|
|
Loading…
Reference in New Issue