mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-04-11 03:00:13 -04:00
Allowing temporary variables to be reused.
This commit is contained in:
@@ -1,16 +1,16 @@
|
|||||||
(function() {
|
(function() {
|
||||||
var BANNER, CoffeeScript, EventEmitter, SWITCHES, _cache, _cache2, _cache3, 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, _cache, compileOptions, compileScript, compileScripts, compileStdio, exec, fs, helpers, lint, optionParser, optparse, opts, parseOptions, path, printTokens, sources, spawn, usage, version, watch, writeJs;
|
||||||
fs = require('fs');
|
fs = require('fs');
|
||||||
path = require('path');
|
path = require('path');
|
||||||
optparse = require('./optparse');
|
optparse = require('./optparse');
|
||||||
CoffeeScript = require('./coffee-script');
|
CoffeeScript = require('./coffee-script');
|
||||||
_cache = require('./helpers');
|
_cache = require('./helpers');
|
||||||
helpers = _cache.helpers;
|
helpers = _cache.helpers;
|
||||||
_cache2 = require('child_process');
|
_cache = require('child_process');
|
||||||
spawn = _cache2.spawn;
|
spawn = _cache.spawn;
|
||||||
exec = _cache2.exec;
|
exec = _cache.exec;
|
||||||
_cache3 = require('events');
|
_cache = require('events');
|
||||||
EventEmitter = _cache3.EventEmitter;
|
EventEmitter = _cache.EventEmitter;
|
||||||
helpers.extend(CoffeeScript, new EventEmitter());
|
helpers.extend(CoffeeScript, new EventEmitter());
|
||||||
global.CoffeeScript = CoffeeScript;
|
global.CoffeeScript = CoffeeScript;
|
||||||
BANNER = 'coffee compiles CoffeeScript source files into JavaScript.\n\nUsage:\n coffee path/to/script.coffee';
|
BANNER = 'coffee compiles CoffeeScript source files into JavaScript.\n\nUsage:\n coffee path/to/script.coffee';
|
||||||
@@ -53,12 +53,12 @@
|
|||||||
return compileScripts();
|
return compileScripts();
|
||||||
};
|
};
|
||||||
compileScripts = function() {
|
compileScripts = function() {
|
||||||
var _cache4, _cache5, _index, _result;
|
var _cache2, _cache3, _index, _result;
|
||||||
_result = []; _cache4 = sources;
|
_result = []; _cache2 = sources;
|
||||||
for (_index = 0, _cache5 = _cache4.length; _index < _cache5; _index++) {
|
for (_index = 0, _cache3 = _cache2.length; _index < _cache3; _index++) {
|
||||||
(function() {
|
(function() {
|
||||||
var base, compile;
|
var base, compile;
|
||||||
var source = _cache4[_index];
|
var source = _cache2[_index];
|
||||||
return _result.push((function() {
|
return _result.push((function() {
|
||||||
base = source;
|
base = source;
|
||||||
compile = function(source, topLevel) {
|
compile = function(source, topLevel) {
|
||||||
@@ -69,10 +69,10 @@
|
|||||||
return fs.stat(source, function(err, stats) {
|
return fs.stat(source, function(err, stats) {
|
||||||
if (stats.isDirectory()) {
|
if (stats.isDirectory()) {
|
||||||
return fs.readdir(source, function(err, files) {
|
return fs.readdir(source, function(err, files) {
|
||||||
var _cache6, _cache7, _index2, _result2, file;
|
var _cache4, _cache5, _index2, _result2, file;
|
||||||
_result2 = []; _cache6 = files;
|
_result2 = []; _cache4 = files;
|
||||||
for (_index2 = 0, _cache7 = _cache6.length; _index2 < _cache7; _index2++) {
|
for (_index2 = 0, _cache5 = _cache4.length; _index2 < _cache5; _index2++) {
|
||||||
file = _cache6[_index2];
|
file = _cache4[_index2];
|
||||||
_result2.push(compile(path.join(source, file)));
|
_result2.push(compile(path.join(source, file)));
|
||||||
}
|
}
|
||||||
return _result2;
|
return _result2;
|
||||||
@@ -95,13 +95,13 @@
|
|||||||
return _result;
|
return _result;
|
||||||
};
|
};
|
||||||
compileScript = function(file, input, base) {
|
compileScript = function(file, input, base) {
|
||||||
var _cache4, _cache5, _index, o, options, req, t, task;
|
var _cache2, _cache3, _index, o, options, req, t, task;
|
||||||
o = opts;
|
o = opts;
|
||||||
options = compileOptions(file);
|
options = compileOptions(file);
|
||||||
if (o.require) {
|
if (o.require) {
|
||||||
_cache4 = o.require;
|
_cache2 = o.require;
|
||||||
for (_index = 0, _cache5 = _cache4.length; _index < _cache5; _index++) {
|
for (_index = 0, _cache3 = _cache2.length; _index < _cache3; _index++) {
|
||||||
req = _cache4[_index];
|
req = _cache2[_index];
|
||||||
require(helpers.starts(req, '.') ? fs.realpathSync(req) : req);
|
require(helpers.starts(req, '.') ? fs.realpathSync(req) : req);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -204,15 +204,15 @@
|
|||||||
return jsl.stdin.end();
|
return jsl.stdin.end();
|
||||||
};
|
};
|
||||||
printTokens = function(tokens) {
|
printTokens = function(tokens) {
|
||||||
var _cache4, _cache5, _cache6, _index, _result, strings, tag, token, value;
|
var _cache2, _cache3, _cache4, _index, _result, strings, tag, token, value;
|
||||||
strings = (function() {
|
strings = (function() {
|
||||||
_result = []; _cache4 = tokens;
|
_result = []; _cache2 = tokens;
|
||||||
for (_index = 0, _cache5 = _cache4.length; _index < _cache5; _index++) {
|
for (_index = 0, _cache3 = _cache2.length; _index < _cache3; _index++) {
|
||||||
token = _cache4[_index];
|
token = _cache2[_index];
|
||||||
_result.push((function() {
|
_result.push((function() {
|
||||||
_cache6 = [token[0], token[1].toString().replace(/\n/, '\\n')];
|
_cache4 = [token[0], token[1].toString().replace(/\n/, '\\n')];
|
||||||
tag = _cache6[0];
|
tag = _cache4[0];
|
||||||
value = _cache6[1];
|
value = _cache4[1];
|
||||||
return "[" + (tag) + " " + (value) + "]";
|
return "[" + (tag) + " " + (value) + "]";
|
||||||
})());
|
})());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,7 +51,7 @@
|
|||||||
return num;
|
return num;
|
||||||
});
|
});
|
||||||
helpers.merge = (merge = function(options, overrides) {
|
helpers.merge = (merge = function(options, overrides) {
|
||||||
var _cache, _cache2, fresh, key, val;
|
var _cache, fresh, key, val;
|
||||||
fresh = {};
|
fresh = {};
|
||||||
_cache = options;
|
_cache = options;
|
||||||
for (key in _cache) {
|
for (key in _cache) {
|
||||||
@@ -59,9 +59,9 @@
|
|||||||
(fresh[key] = val);
|
(fresh[key] = val);
|
||||||
}
|
}
|
||||||
if (overrides) {
|
if (overrides) {
|
||||||
_cache2 = overrides;
|
_cache = overrides;
|
||||||
for (key in _cache2) {
|
for (key in _cache) {
|
||||||
val = _cache2[key];
|
val = _cache[key];
|
||||||
(fresh[key] = val);
|
(fresh[key] = val);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
68
lib/lexer.js
68
lib/lexer.js
@@ -1,21 +1,21 @@
|
|||||||
(function() {
|
(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, _cache, _cache2, _cache3, 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, _cache, compact, count, helpers, include, starts;
|
||||||
var __slice = Array.prototype.slice;
|
var __slice = Array.prototype.slice;
|
||||||
if (typeof process !== "undefined" && process !== null) {
|
if (typeof process !== "undefined" && process !== null) {
|
||||||
_cache = require('./rewriter');
|
_cache = require('./rewriter');
|
||||||
Rewriter = _cache.Rewriter;
|
Rewriter = _cache.Rewriter;
|
||||||
_cache2 = require('./helpers');
|
_cache = require('./helpers');
|
||||||
helpers = _cache2.helpers;
|
helpers = _cache.helpers;
|
||||||
} else {
|
} else {
|
||||||
this.exports = this;
|
this.exports = this;
|
||||||
Rewriter = this.Rewriter;
|
Rewriter = this.Rewriter;
|
||||||
helpers = this.helpers;
|
helpers = this.helpers;
|
||||||
}
|
}
|
||||||
_cache3 = helpers;
|
_cache = helpers;
|
||||||
include = _cache3.include;
|
include = _cache.include;
|
||||||
count = _cache3.count;
|
count = _cache.count;
|
||||||
starts = _cache3.starts;
|
starts = _cache.starts;
|
||||||
compact = _cache3.compact;
|
compact = _cache.compact;
|
||||||
exports.Lexer = (function() {
|
exports.Lexer = (function() {
|
||||||
Lexer = function() {};
|
Lexer = function() {};
|
||||||
Lexer.prototype.tokenize = function(code, options) {
|
Lexer.prototype.tokenize = function(code, options) {
|
||||||
@@ -192,11 +192,11 @@
|
|||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
Lexer.prototype.regexToken = function() {
|
Lexer.prototype.regexToken = function() {
|
||||||
var _cache4, end, first, flags, regex, str;
|
var _cache2, end, first, flags, regex, str;
|
||||||
if (!(first = this.chunk.match(REGEX_START))) {
|
if (!(first = this.chunk.match(REGEX_START))) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (first[1] === ' ' && !('CALL_START' === (_cache4 = this.tag()) || '=' === _cache4)) {
|
if (first[1] === ' ' && !('CALL_START' === (_cache2 = this.tag()) || '=' === _cache2)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (include(NOT_REGEX, this.tag())) {
|
if (include(NOT_REGEX, this.tag())) {
|
||||||
@@ -320,7 +320,7 @@
|
|||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
Lexer.prototype.literalToken = function() {
|
Lexer.prototype.literalToken = function() {
|
||||||
var _cache4, match, prev, space, spaced, tag, value;
|
var _cache2, match, prev, space, spaced, tag, value;
|
||||||
match = this.chunk.match(OPERATOR);
|
match = this.chunk.match(OPERATOR);
|
||||||
value = match && match[1];
|
value = match && match[1];
|
||||||
space = match && match[2];
|
space = match && match[2];
|
||||||
@@ -335,7 +335,7 @@
|
|||||||
if (include(JS_FORBIDDEN, this.value())) {
|
if (include(JS_FORBIDDEN, this.value())) {
|
||||||
this.assignmentError();
|
this.assignmentError();
|
||||||
}
|
}
|
||||||
if (('or' === (_cache4 = this.value()) || 'and' === _cache4)) {
|
if (('or' === (_cache2 = this.value()) || 'and' === _cache2)) {
|
||||||
this.tokens.splice(this.tokens.length - 1, 1, ['COMPOUND_ASSIGN', CONVERSIONS[this.value()] + '=', prev[2]]);
|
this.tokens.splice(this.tokens.length - 1, 1, ['COMPOUND_ASSIGN', CONVERSIONS[this.value()] + '=', prev[2]]);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -395,14 +395,14 @@
|
|||||||
return accessor ? 'accessor' : false;
|
return accessor ? 'accessor' : false;
|
||||||
};
|
};
|
||||||
Lexer.prototype.sanitizeHeredoc = function(doc, options) {
|
Lexer.prototype.sanitizeHeredoc = function(doc, options) {
|
||||||
var _cache4, attempt, indent, match;
|
var _cache2, attempt, indent, match;
|
||||||
indent = options.indent;
|
indent = options.indent;
|
||||||
if (options.herecomment && !include(doc, '\n')) {
|
if (options.herecomment && !include(doc, '\n')) {
|
||||||
return doc;
|
return doc;
|
||||||
}
|
}
|
||||||
if (!(options.herecomment)) {
|
if (!(options.herecomment)) {
|
||||||
while ((match = HEREDOC_INDENT.exec(doc)) !== null) {
|
while ((match = HEREDOC_INDENT.exec(doc)) !== null) {
|
||||||
attempt = (typeof (_cache4 = match[2]) !== "undefined" && _cache4 !== null) ? match[2] : match[3];
|
attempt = (typeof (_cache2 = match[2]) !== "undefined" && _cache2 !== null) ? match[2] : match[3];
|
||||||
if (!(typeof indent !== "undefined" && indent !== null) || attempt.length < indent.length) {
|
if (!(typeof indent !== "undefined" && indent !== null) || attempt.length < indent.length) {
|
||||||
indent = attempt;
|
indent = attempt;
|
||||||
}
|
}
|
||||||
@@ -451,7 +451,7 @@
|
|||||||
throw new Error("SyntaxError: Reserved word \"" + (this.value()) + "\" on line " + (this.line + 1) + " can't be assigned");
|
throw new Error("SyntaxError: Reserved word \"" + (this.value()) + "\" on line " + (this.line + 1) + " can't be assigned");
|
||||||
};
|
};
|
||||||
Lexer.prototype.balancedString = function(str, delimited, options) {
|
Lexer.prototype.balancedString = function(str, delimited, options) {
|
||||||
var _cache4, _cache5, _cache6, _index, close, i, levels, open, pair, slash;
|
var _cache2, _cache3, _cache4, _index, close, i, levels, open, pair, slash;
|
||||||
options || (options = {});
|
options || (options = {});
|
||||||
slash = delimited[0][0] === '/';
|
slash = delimited[0][0] === '/';
|
||||||
levels = [];
|
levels = [];
|
||||||
@@ -460,12 +460,12 @@
|
|||||||
if (levels.length && starts(str, '\\', i)) {
|
if (levels.length && starts(str, '\\', i)) {
|
||||||
i += 1;
|
i += 1;
|
||||||
} else {
|
} else {
|
||||||
_cache4 = delimited;
|
_cache2 = delimited;
|
||||||
for (_index = 0, _cache5 = _cache4.length; _index < _cache5; _index++) {
|
for (_index = 0, _cache3 = _cache2.length; _index < _cache3; _index++) {
|
||||||
pair = _cache4[_index];
|
pair = _cache2[_index];
|
||||||
_cache6 = pair;
|
_cache4 = pair;
|
||||||
open = _cache6[0];
|
open = _cache4[0];
|
||||||
close = _cache6[1];
|
close = _cache4[1];
|
||||||
if (levels.length && starts(str, close, i) && levels[levels.length - 1] === pair) {
|
if (levels.length && starts(str, close, i) && levels[levels.length - 1] === pair) {
|
||||||
levels.pop();
|
levels.pop();
|
||||||
i += close.length - 1;
|
i += close.length - 1;
|
||||||
@@ -494,7 +494,7 @@
|
|||||||
return !i ? false : str.substring(0, i);
|
return !i ? false : str.substring(0, i);
|
||||||
};
|
};
|
||||||
Lexer.prototype.interpolateString = function(str, options) {
|
Lexer.prototype.interpolateString = function(str, options) {
|
||||||
var _cache4, _cache5, _cache6, _cache7, _cache8, _cache9, escaped, expr, i, idx, inner, interpolated, lexer, nested, pi, quote, tag, tok, token, tokens, value;
|
var _cache2, _cache3, _cache4, escaped, expr, i, idx, inner, interpolated, lexer, nested, pi, quote, tag, tok, token, tokens, value;
|
||||||
options || (options = {});
|
options || (options = {});
|
||||||
if (str.length < 3 || !starts(str, '"')) {
|
if (str.length < 3 || !starts(str, '"')) {
|
||||||
return this.token('STRING', str);
|
return this.token('STRING', str);
|
||||||
@@ -502,9 +502,9 @@
|
|||||||
lexer = new Lexer();
|
lexer = new Lexer();
|
||||||
tokens = [];
|
tokens = [];
|
||||||
quote = str.substring(0, 1);
|
quote = str.substring(0, 1);
|
||||||
_cache4 = [1, 1];
|
_cache2 = [1, 1];
|
||||||
i = _cache4[0];
|
i = _cache2[0];
|
||||||
pi = _cache4[1];
|
pi = _cache2[1];
|
||||||
while (i < str.length - 1) {
|
while (i < str.length - 1) {
|
||||||
if (starts(str, '\\', i)) {
|
if (starts(str, '\\', i)) {
|
||||||
i += 1;
|
i += 1;
|
||||||
@@ -520,9 +520,9 @@
|
|||||||
nested = lexer.tokenize("(" + (inner) + ")", {
|
nested = lexer.tokenize("(" + (inner) + ")", {
|
||||||
line: this.line
|
line: this.line
|
||||||
});
|
});
|
||||||
_cache5 = nested;
|
_cache2 = nested;
|
||||||
for (idx = 0, _cache6 = _cache5.length; idx < _cache6; idx++) {
|
for (idx = 0, _cache3 = _cache2.length; idx < _cache3; idx++) {
|
||||||
tok = _cache5[idx];
|
tok = _cache2[idx];
|
||||||
if (tok[0] === 'CALL_END') {
|
if (tok[0] === 'CALL_END') {
|
||||||
(tok[0] = ')');
|
(tok[0] = ')');
|
||||||
}
|
}
|
||||||
@@ -547,12 +547,12 @@
|
|||||||
if (interpolated) {
|
if (interpolated) {
|
||||||
this.token('(', '(');
|
this.token('(', '(');
|
||||||
}
|
}
|
||||||
_cache7 = tokens;
|
_cache2 = tokens;
|
||||||
for (i = 0, _cache8 = _cache7.length; i < _cache8; i++) {
|
for (i = 0, _cache3 = _cache2.length; i < _cache3; i++) {
|
||||||
token = _cache7[i];
|
token = _cache2[i];
|
||||||
_cache9 = token;
|
_cache4 = token;
|
||||||
tag = _cache9[0];
|
tag = _cache4[0];
|
||||||
value = _cache9[1];
|
value = _cache4[1];
|
||||||
if (tag === 'TOKENS') {
|
if (tag === 'TOKENS') {
|
||||||
this.tokens = this.tokens.concat(value);
|
this.tokens = this.tokens.concat(value);
|
||||||
} else if (tag === 'STRING' && options.escapeQuotes) {
|
} else if (tag === 'STRING' && options.escapeQuotes) {
|
||||||
|
|||||||
151
lib/nodes.js
151
lib/nodes.js
@@ -31,7 +31,7 @@
|
|||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
BaseNode.prototype.compile = function(o) {
|
BaseNode.prototype.compile = function(o) {
|
||||||
var closure, top;
|
var closure, code, top;
|
||||||
this.options = merge(o || {});
|
this.options = merge(o || {});
|
||||||
this.tab = o.indent;
|
this.tab = o.indent;
|
||||||
if (!(this instanceof AccessorNode || this instanceof IndexNode)) {
|
if (!(this instanceof AccessorNode || this instanceof IndexNode)) {
|
||||||
@@ -39,7 +39,14 @@
|
|||||||
}
|
}
|
||||||
top = this.topSensitive() ? this.options.top : del(this.options, 'top');
|
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();
|
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) {
|
BaseNode.prototype.compileClosure = function(o) {
|
||||||
this.tab = o.indent;
|
this.tab = o.indent;
|
||||||
@@ -47,7 +54,7 @@
|
|||||||
return ClosureNode.wrap(this).compile(o);
|
return ClosureNode.wrap(this).compile(o);
|
||||||
};
|
};
|
||||||
BaseNode.prototype.compileReference = function(o, options) {
|
BaseNode.prototype.compileReference = function(o, options) {
|
||||||
var compiled, pair, reference, temp;
|
var compiled, pair, reference;
|
||||||
options || (options = {});
|
options || (options = {});
|
||||||
pair = (function() {
|
pair = (function() {
|
||||||
if (!(this.containsType(CallNode) || (this instanceof ValueNode && (!(this.base instanceof LiteralNode) || this.hasProperties())))) {
|
if (!(this.containsType(CallNode) || (this instanceof ValueNode && (!(this.base instanceof LiteralNode) || this.hasProperties())))) {
|
||||||
@@ -55,13 +62,13 @@
|
|||||||
} else if (this instanceof ValueNode && options.assignment) {
|
} else if (this instanceof ValueNode && options.assignment) {
|
||||||
return this.cacheIndexes(o);
|
return this.cacheIndexes(o);
|
||||||
} else {
|
} else {
|
||||||
reference = literal(temp = o.scope.freeVariable('cache'));
|
reference = literal(o.scope.freeVariable('cache'));
|
||||||
compiled = new AssignNode(reference, this);
|
compiled = new AssignNode(reference, this);
|
||||||
return [compiled, reference, temp];
|
return [compiled, reference];
|
||||||
}
|
}
|
||||||
}).call(this);
|
}).call(this);
|
||||||
if (options.precompile) {
|
if (options.precompile) {
|
||||||
return [pair[0].compile(o), pair[1].compile(o), pair[2]];
|
return [pair[0].compile(o), pair[1].compile(o)];
|
||||||
}
|
}
|
||||||
return pair;
|
return pair;
|
||||||
};
|
};
|
||||||
@@ -355,25 +362,25 @@
|
|||||||
return this.base instanceof LiteralNode && this.base.value.match(NUMBER);
|
return this.base instanceof LiteralNode && this.base.value.match(NUMBER);
|
||||||
};
|
};
|
||||||
ValueNode.prototype.cacheIndexes = function(o) {
|
ValueNode.prototype.cacheIndexes = function(o) {
|
||||||
var _cache2, _cache3, _cache4, _index, copy, i;
|
var _cache2, _cache3, _index, copy, i;
|
||||||
copy = new ValueNode(this.base, this.properties.slice(0));
|
copy = new ValueNode(this.base, this.properties.slice(0));
|
||||||
if (this.base instanceof CallNode) {
|
if (this.base instanceof CallNode) {
|
||||||
_cache2 = this.base.compileReference(o);
|
_cache2 = this.base.compileReference(o);
|
||||||
this.base = _cache2[0];
|
this.base = _cache2[0];
|
||||||
copy.base = _cache2[1];
|
copy.base = _cache2[1];
|
||||||
}
|
}
|
||||||
_cache3 = copy.properties;
|
_cache2 = copy.properties;
|
||||||
for (_index = 0, _cache4 = _cache3.length; _index < _cache4; _index++) {
|
for (_index = 0, _cache3 = _cache2.length; _index < _cache3; _index++) {
|
||||||
(function() {
|
(function() {
|
||||||
var _cache5, index, indexVar;
|
var _cache4, index, indexVar;
|
||||||
var i = _index;
|
var i = _index;
|
||||||
var prop = _cache3[_index];
|
var prop = _cache2[_index];
|
||||||
if (prop instanceof IndexNode && prop.contains(function(n) {
|
if (prop instanceof IndexNode && prop.contains(function(n) {
|
||||||
return n instanceof CallNode;
|
return n instanceof CallNode;
|
||||||
})) {
|
})) {
|
||||||
_cache5 = prop.index.compileReference(o);
|
_cache4 = prop.index.compileReference(o);
|
||||||
index = _cache5[0];
|
index = _cache4[0];
|
||||||
indexVar = _cache5[1];
|
indexVar = _cache4[1];
|
||||||
this.properties[i] = new IndexNode(index);
|
this.properties[i] = new IndexNode(index);
|
||||||
return (copy.properties[i] = new IndexNode(indexVar));
|
return (copy.properties[i] = new IndexNode(indexVar));
|
||||||
}
|
}
|
||||||
@@ -385,7 +392,7 @@
|
|||||||
return !o.top || this.properties.length ? ValueNode.__super__.compile.call(this, o) : this.base.compile(o);
|
return !o.top || this.properties.length ? ValueNode.__super__.compile.call(this, o) : this.base.compile(o);
|
||||||
};
|
};
|
||||||
ValueNode.prototype.compileNode = function(o) {
|
ValueNode.prototype.compileNode = function(o) {
|
||||||
var _cache2, _cache3, _cache4, _cache5, _cache6, _index, baseline, complete, copy, hasSoak, i, me, only, op, part, prop, props, temp;
|
var _cache2, _cache3, _index, baseline, complete, copy, hasSoak, i, me, only, op, part, prop, props, temp;
|
||||||
only = del(o, 'onlyFirst');
|
only = del(o, 'onlyFirst');
|
||||||
op = this.tags.operation;
|
op = this.tags.operation;
|
||||||
props = only ? this.properties.slice(0, this.properties.length - 1) : this.properties;
|
props = only ? this.properties.slice(0, this.properties.length - 1) : this.properties;
|
||||||
@@ -398,9 +405,9 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (hasSoak && this.containsType(CallNode)) {
|
if (hasSoak && this.containsType(CallNode)) {
|
||||||
_cache4 = this.cacheIndexes(o);
|
_cache2 = this.cacheIndexes(o);
|
||||||
me = _cache4[0];
|
me = _cache2[0];
|
||||||
copy = _cache4[1];
|
copy = _cache2[1];
|
||||||
}
|
}
|
||||||
if (this.parenthetical && !props.length) {
|
if (this.parenthetical && !props.length) {
|
||||||
this.base.parenthetical = true;
|
this.base.parenthetical = true;
|
||||||
@@ -410,9 +417,9 @@
|
|||||||
baseline = ("(" + (baseline) + ")");
|
baseline = ("(" + (baseline) + ")");
|
||||||
}
|
}
|
||||||
complete = (this.last = baseline);
|
complete = (this.last = baseline);
|
||||||
_cache5 = props;
|
_cache2 = props;
|
||||||
for (i = 0, _cache6 = _cache5.length; i < _cache6; i++) {
|
for (i = 0, _cache3 = _cache2.length; i < _cache3; i++) {
|
||||||
prop = _cache5[i];
|
prop = _cache2[i];
|
||||||
this.source = baseline;
|
this.source = baseline;
|
||||||
if (prop.soakNode) {
|
if (prop.soakNode) {
|
||||||
if (this.base.containsType(CallNode) && i === 0) {
|
if (this.base.containsType(CallNode) && i === 0) {
|
||||||
@@ -497,7 +504,7 @@
|
|||||||
})());
|
})());
|
||||||
};
|
};
|
||||||
CallNode.prototype.compileNode = function(o) {
|
CallNode.prototype.compileNode = function(o) {
|
||||||
var _cache2, _cache3, _cache4, _cache5, _cache6, _cache7, _index, _index2, _result, arg, args, code, first, meth, methodAccessor, op;
|
var _cache2, _cache3, _index, _result, arg, args, code, first, meth, methodAccessor, op;
|
||||||
if (!(o.chainRoot)) {
|
if (!(o.chainRoot)) {
|
||||||
o.chainRoot = this;
|
o.chainRoot = this;
|
||||||
}
|
}
|
||||||
@@ -511,29 +518,29 @@
|
|||||||
this.first = new ValueNode(first, [methodAccessor]).compile(o);
|
this.first = new ValueNode(first, [methodAccessor]).compile(o);
|
||||||
this.meth = new ValueNode(meth, [methodAccessor]).compile(o);
|
this.meth = new ValueNode(meth, [methodAccessor]).compile(o);
|
||||||
} else {
|
} else {
|
||||||
_cache3 = this.variable.compileReference(o, {
|
_cache2 = this.variable.compileReference(o, {
|
||||||
precompile: true
|
precompile: true
|
||||||
});
|
});
|
||||||
this.first = _cache3[0];
|
this.first = _cache2[0];
|
||||||
this.meth = _cache3[1];
|
this.meth = _cache2[1];
|
||||||
}
|
}
|
||||||
this.first = ("(typeof " + (this.first) + " === \"function\" ? ");
|
this.first = ("(typeof " + (this.first) + " === \"function\" ? ");
|
||||||
this.last = " : undefined)";
|
this.last = " : undefined)";
|
||||||
} else if (this.variable) {
|
} else if (this.variable) {
|
||||||
this.meth = this.variable.compile(o);
|
this.meth = this.variable.compile(o);
|
||||||
}
|
}
|
||||||
_cache4 = this.args;
|
_cache2 = this.args;
|
||||||
for (_index = 0, _cache5 = _cache4.length; _index < _cache5; _index++) {
|
for (_index = 0, _cache3 = _cache2.length; _index < _cache3; _index++) {
|
||||||
arg = _cache4[_index];
|
arg = _cache2[_index];
|
||||||
if (arg instanceof SplatNode) {
|
if (arg instanceof SplatNode) {
|
||||||
code = this.compileSplat(o);
|
code = this.compileSplat(o);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!code) {
|
if (!code) {
|
||||||
args = (function() {
|
args = (function() {
|
||||||
_result = []; _cache6 = this.args;
|
_result = []; _cache2 = this.args;
|
||||||
for (_index2 = 0, _cache7 = _cache6.length; _index2 < _cache7; _index2++) {
|
for (_index = 0, _cache3 = _cache2.length; _index < _cache3; _index++) {
|
||||||
arg = _cache6[_index2];
|
arg = _cache2[_index];
|
||||||
_result.push((function() {
|
_result.push((function() {
|
||||||
arg.parenthetical = true;
|
arg.parenthetical = true;
|
||||||
return arg.compile(o);
|
return arg.compile(o);
|
||||||
@@ -647,7 +654,7 @@
|
|||||||
RangeNode.prototype["class"] = 'RangeNode';
|
RangeNode.prototype["class"] = 'RangeNode';
|
||||||
RangeNode.prototype.children = ['from', 'to'];
|
RangeNode.prototype.children = ['from', 'to'];
|
||||||
RangeNode.prototype.compileVariables = function(o) {
|
RangeNode.prototype.compileVariables = function(o) {
|
||||||
var _cache2, _cache3, _cache4, parts;
|
var _cache2, parts;
|
||||||
o = merge(o, {
|
o = merge(o, {
|
||||||
top: true
|
top: true
|
||||||
});
|
});
|
||||||
@@ -656,14 +663,14 @@
|
|||||||
});
|
});
|
||||||
this.from = _cache2[0];
|
this.from = _cache2[0];
|
||||||
this.fromVar = _cache2[1];
|
this.fromVar = _cache2[1];
|
||||||
_cache3 = this.to.compileReference(o, {
|
_cache2 = this.to.compileReference(o, {
|
||||||
precompile: true
|
precompile: true
|
||||||
});
|
});
|
||||||
this.to = _cache3[0];
|
this.to = _cache2[0];
|
||||||
this.toVar = _cache3[1];
|
this.toVar = _cache2[1];
|
||||||
_cache4 = [this.fromVar.match(SIMPLENUM), this.toVar.match(SIMPLENUM)];
|
_cache2 = [this.fromVar.match(SIMPLENUM), this.toVar.match(SIMPLENUM)];
|
||||||
this.fromNum = _cache4[0];
|
this.fromNum = _cache2[0];
|
||||||
this.toNum = _cache4[1];
|
this.toNum = _cache2[1];
|
||||||
parts = [];
|
parts = [];
|
||||||
if (this.from !== this.fromVar) {
|
if (this.from !== this.fromVar) {
|
||||||
parts.push(this.from);
|
parts.push(this.from);
|
||||||
@@ -766,7 +773,7 @@
|
|||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
ObjectNode.prototype.compileNode = function(o) {
|
ObjectNode.prototype.compileNode = function(o) {
|
||||||
var _cache2, _cache3, _cache4, _cache5, _index, _result, _result2, i, indent, join, lastNoncom, nonComments, obj, prop, props, top;
|
var _cache2, _cache3, _index, _result, i, indent, join, lastNoncom, nonComments, obj, prop, props, top;
|
||||||
top = del(o, 'top');
|
top = del(o, 'top');
|
||||||
o.indent = this.idt(1);
|
o.indent = this.idt(1);
|
||||||
nonComments = (function() {
|
nonComments = (function() {
|
||||||
@@ -781,10 +788,10 @@
|
|||||||
}).call(this);
|
}).call(this);
|
||||||
lastNoncom = nonComments[nonComments.length - 1];
|
lastNoncom = nonComments[nonComments.length - 1];
|
||||||
props = (function() {
|
props = (function() {
|
||||||
_result2 = []; _cache4 = this.properties;
|
_result = []; _cache2 = this.properties;
|
||||||
for (i = 0, _cache5 = _cache4.length; i < _cache5; i++) {
|
for (i = 0, _cache3 = _cache2.length; i < _cache3; i++) {
|
||||||
prop = _cache4[i];
|
prop = _cache2[i];
|
||||||
_result2.push((function() {
|
_result.push((function() {
|
||||||
join = ",\n";
|
join = ",\n";
|
||||||
if ((prop === lastNoncom) || (prop instanceof CommentNode)) {
|
if ((prop === lastNoncom) || (prop instanceof CommentNode)) {
|
||||||
join = "\n";
|
join = "\n";
|
||||||
@@ -799,7 +806,7 @@
|
|||||||
return indent + prop.compile(o) + join;
|
return indent + prop.compile(o) + join;
|
||||||
}).call(this));
|
}).call(this));
|
||||||
}
|
}
|
||||||
return _result2;
|
return _result;
|
||||||
}).call(this);
|
}).call(this);
|
||||||
props = props.join('');
|
props = props.join('');
|
||||||
obj = '{' + (props ? '\n' + props + '\n' + this.idt() : '') + '}';
|
obj = '{' + (props ? '\n' + props + '\n' + this.idt() : '') + '}';
|
||||||
@@ -1067,7 +1074,7 @@
|
|||||||
CodeNode.prototype["class"] = 'CodeNode';
|
CodeNode.prototype["class"] = 'CodeNode';
|
||||||
CodeNode.prototype.children = ['params', 'body'];
|
CodeNode.prototype.children = ['params', 'body'];
|
||||||
CodeNode.prototype.compileNode = function(o) {
|
CodeNode.prototype.compileNode = function(o) {
|
||||||
var _cache2, _cache3, _cache4, _cache5, _cache6, _cache7, _cache8, _cache9, _index, _index2, _result, code, empty, func, i, param, params, sharedScope, splat, top, value;
|
var _cache2, _cache3, _cache4, _index, _result, code, empty, func, i, param, params, sharedScope, splat, top, value;
|
||||||
sharedScope = del(o, 'sharedScope');
|
sharedScope = del(o, 'sharedScope');
|
||||||
top = del(o, 'top');
|
top = del(o, 'top');
|
||||||
o.scope = sharedScope || new Scope(o.scope, this.body, this);
|
o.scope = sharedScope || new Scope(o.scope, this.body, this);
|
||||||
@@ -1091,9 +1098,9 @@
|
|||||||
if (param.attach) {
|
if (param.attach) {
|
||||||
_cache4 = param;
|
_cache4 = param;
|
||||||
value = _cache4.value;
|
value = _cache4.value;
|
||||||
_cache5 = [literal(o.scope.freeVariable('arg')), param.splat];
|
_cache4 = [literal(o.scope.freeVariable('arg')), param.splat];
|
||||||
param = _cache5[0];
|
param = _cache4[0];
|
||||||
param.splat = _cache5[1];
|
param.splat = _cache4[1];
|
||||||
this.body.unshift(new AssignNode(new ValueNode(literal('this'), [new AccessorNode(value)]), param));
|
this.body.unshift(new AssignNode(new ValueNode(literal('this'), [new AccessorNode(value)]), param));
|
||||||
}
|
}
|
||||||
if (param.splat) {
|
if (param.splat) {
|
||||||
@@ -1108,9 +1115,9 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
params = (function() {
|
params = (function() {
|
||||||
_result = []; _cache6 = params;
|
_result = []; _cache2 = params;
|
||||||
for (_index = 0, _cache7 = _cache6.length; _index < _cache7; _index++) {
|
for (_index = 0, _cache3 = _cache2.length; _index < _cache3; _index++) {
|
||||||
param = _cache6[_index];
|
param = _cache2[_index];
|
||||||
_result.push(param.compile(o));
|
_result.push(param.compile(o));
|
||||||
}
|
}
|
||||||
return _result;
|
return _result;
|
||||||
@@ -1118,9 +1125,9 @@
|
|||||||
if (!(empty)) {
|
if (!(empty)) {
|
||||||
this.body.makeReturn();
|
this.body.makeReturn();
|
||||||
}
|
}
|
||||||
_cache8 = params;
|
_cache2 = params;
|
||||||
for (_index2 = 0, _cache9 = _cache8.length; _index2 < _cache9; _index2++) {
|
for (_index = 0, _cache3 = _cache2.length; _index < _cache3; _index++) {
|
||||||
param = _cache8[_index2];
|
param = _cache2[_index];
|
||||||
(o.scope.parameter(param));
|
(o.scope.parameter(param));
|
||||||
}
|
}
|
||||||
code = this.body.expressions.length ? ("\n" + (this.body.compileWithDeclarations(o)) + "\n") : '';
|
code = this.body.expressions.length ? ("\n" + (this.body.compileWithDeclarations(o)) + "\n") : '';
|
||||||
@@ -1377,23 +1384,18 @@
|
|||||||
return [this.first.compile(o), this.operator, this.second.compile(o)].join(' ');
|
return [this.first.compile(o), this.operator, this.second.compile(o)].join(' ');
|
||||||
};
|
};
|
||||||
OpNode.prototype.compileChain = function(o) {
|
OpNode.prototype.compileChain = function(o) {
|
||||||
var _cache2, _cache3, first, js, second, shared, temp;
|
var _cache2, first, second, shared;
|
||||||
shared = this.first.unwrap().second;
|
shared = this.first.unwrap().second;
|
||||||
if (shared.containsType(CallNode)) {
|
if (shared.containsType(CallNode)) {
|
||||||
_cache2 = shared.compileReference(o);
|
_cache2 = shared.compileReference(o);
|
||||||
this.first.second = _cache2[0];
|
this.first.second = _cache2[0];
|
||||||
shared = _cache2[1];
|
shared = _cache2[1];
|
||||||
temp = _cache2[2];
|
|
||||||
}
|
}
|
||||||
_cache3 = [this.first.compile(o), this.second.compile(o), shared.compile(o)];
|
_cache2 = [this.first.compile(o), this.second.compile(o), shared.compile(o)];
|
||||||
first = _cache3[0];
|
first = _cache2[0];
|
||||||
second = _cache3[1];
|
second = _cache2[1];
|
||||||
shared = _cache3[2];
|
shared = _cache2[2];
|
||||||
js = ("(" + (first) + ") && (" + (shared) + " " + (this.operator) + " " + (second) + ")");
|
return "(" + (first) + ") && (" + (shared) + " " + (this.operator) + " " + (second) + ")";
|
||||||
if (temp) {
|
|
||||||
o.scope.reuse(temp);
|
|
||||||
}
|
|
||||||
return js;
|
|
||||||
};
|
};
|
||||||
OpNode.prototype.compileAssignment = function(o) {
|
OpNode.prototype.compileAssignment = function(o) {
|
||||||
var _cache2, first, firstVar, second;
|
var _cache2, first, firstVar, second;
|
||||||
@@ -1468,15 +1470,15 @@
|
|||||||
return "(" + (tests.join(' || ')) + ")";
|
return "(" + (tests.join(' || ')) + ")";
|
||||||
};
|
};
|
||||||
InNode.prototype.compileLoopTest = function(o) {
|
InNode.prototype.compileLoopTest = function(o) {
|
||||||
var _cache2, _cache3, i, l, prefix;
|
var _cache2, i, l, prefix;
|
||||||
_cache2 = this.array.compileReference(o, {
|
_cache2 = this.array.compileReference(o, {
|
||||||
precompile: true
|
precompile: true
|
||||||
});
|
});
|
||||||
this.arr1 = _cache2[0];
|
this.arr1 = _cache2[0];
|
||||||
this.arr2 = _cache2[1];
|
this.arr2 = _cache2[1];
|
||||||
_cache3 = [o.scope.freeVariable('index'), o.scope.freeVariable('cache')];
|
_cache2 = [o.scope.freeVariable('index'), o.scope.freeVariable('cache')];
|
||||||
i = _cache3[0];
|
i = _cache2[0];
|
||||||
l = _cache3[1];
|
l = _cache2[1];
|
||||||
prefix = this.obj1 !== this.obj2 ? this.obj1 + '; ' : '';
|
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)";
|
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)";
|
||||||
};
|
};
|
||||||
@@ -1691,7 +1693,8 @@
|
|||||||
if (this.pattern) {
|
if (this.pattern) {
|
||||||
namePart = new AssignNode(this.name, literal("" + (svar) + "[" + (ivar) + "]")).compile(merge(o, {
|
namePart = new AssignNode(this.name, literal("" + (svar) + "[" + (ivar) + "]")).compile(merge(o, {
|
||||||
indent: this.idt(1),
|
indent: this.idt(1),
|
||||||
top: true
|
top: true,
|
||||||
|
keepLevel: true
|
||||||
})) + '\n';
|
})) + '\n';
|
||||||
} else {
|
} else {
|
||||||
if (name) {
|
if (name) {
|
||||||
@@ -1771,7 +1774,7 @@
|
|||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
SwitchNode.prototype.compileNode = function(o) {
|
SwitchNode.prototype.compileNode = function(o) {
|
||||||
var _cache2, _cache3, _cache4, _cache5, _cache6, _index, _index2, block, code, condition, conditions, exprs, idt, pair;
|
var _cache2, _cache3, _cache4, _cache5, _index, _index2, block, code, condition, conditions, exprs, idt, pair;
|
||||||
idt = (o.indent = this.idt(1));
|
idt = (o.indent = this.idt(1));
|
||||||
o.top = true;
|
o.top = true;
|
||||||
code = ("" + (this.tab) + "switch (" + (this.subject.compile(o)) + ") {");
|
code = ("" + (this.tab) + "switch (" + (this.subject.compile(o)) + ") {");
|
||||||
@@ -1782,9 +1785,9 @@
|
|||||||
conditions = _cache4[0];
|
conditions = _cache4[0];
|
||||||
block = _cache4[1];
|
block = _cache4[1];
|
||||||
exprs = block.expressions;
|
exprs = block.expressions;
|
||||||
_cache5 = flatten([conditions]);
|
_cache4 = flatten([conditions]);
|
||||||
for (_index2 = 0, _cache6 = _cache5.length; _index2 < _cache6; _index2++) {
|
for (_index2 = 0, _cache5 = _cache4.length; _index2 < _cache5; _index2++) {
|
||||||
condition = _cache5[_index2];
|
condition = _cache4[_index2];
|
||||||
if (this.tags.subjectless) {
|
if (this.tags.subjectless) {
|
||||||
condition = new OpNode('!!', new ParentheticalNode(condition));
|
condition = new OpNode('!!', new ParentheticalNode(condition));
|
||||||
}
|
}
|
||||||
|
|||||||
120
lib/rewriter.js
120
lib/rewriter.js
@@ -1,5 +1,5 @@
|
|||||||
(function() {
|
(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, _cache, _cache2, _cache3, _cache4, _cache5, _cache6, _cache7, _cache8, _index, _index2, _index3, _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, _cache, _cache2, _index, _result, helpers, include, pair;
|
||||||
var __hasProp = Object.prototype.hasOwnProperty;
|
var __hasProp = Object.prototype.hasOwnProperty;
|
||||||
if (typeof process !== "undefined" && process !== null) {
|
if (typeof process !== "undefined" && process !== null) {
|
||||||
_cache = require('./helpers');
|
_cache = require('./helpers');
|
||||||
@@ -8,8 +8,8 @@
|
|||||||
this.exports = this;
|
this.exports = this;
|
||||||
helpers = this.helpers;
|
helpers = this.helpers;
|
||||||
}
|
}
|
||||||
_cache2 = helpers;
|
_cache = helpers;
|
||||||
include = _cache2.include;
|
include = _cache.include;
|
||||||
exports.Rewriter = (function() {
|
exports.Rewriter = (function() {
|
||||||
Rewriter = function() {};
|
Rewriter = function() {};
|
||||||
Rewriter.prototype.rewrite = function(tokens) {
|
Rewriter.prototype.rewrite = function(tokens) {
|
||||||
@@ -62,15 +62,15 @@
|
|||||||
};
|
};
|
||||||
Rewriter.prototype.adjustComments = function() {
|
Rewriter.prototype.adjustComments = function() {
|
||||||
return this.scanTokens(function(token, i) {
|
return this.scanTokens(function(token, i) {
|
||||||
var _cache3, _cache4, after, before, post, prev;
|
var _cache2, after, before, post, prev;
|
||||||
if (token[0] !== 'HERECOMMENT') {
|
if (token[0] !== 'HERECOMMENT') {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
_cache3 = [this.tokens[i - 2], this.tokens[i - 1], this.tokens[i + 1], this.tokens[i + 2]];
|
_cache2 = [this.tokens[i - 2], this.tokens[i - 1], this.tokens[i + 1], this.tokens[i + 2]];
|
||||||
before = _cache3[0];
|
before = _cache2[0];
|
||||||
prev = _cache3[1];
|
prev = _cache2[1];
|
||||||
post = _cache3[2];
|
post = _cache2[2];
|
||||||
after = _cache3[3];
|
after = _cache2[3];
|
||||||
if (after && after[0] === 'INDENT') {
|
if (after && after[0] === 'INDENT') {
|
||||||
this.tokens.splice(i + 2, 1);
|
this.tokens.splice(i + 2, 1);
|
||||||
if (before && before[0] === 'OUTDENT' && post && (prev[0] === post[0]) && (post[0] === 'TERMINATOR')) {
|
if (before && before[0] === 'OUTDENT' && post && (prev[0] === post[0]) && (post[0] === 'TERMINATOR')) {
|
||||||
@@ -78,7 +78,7 @@
|
|||||||
} else {
|
} else {
|
||||||
this.tokens.splice(i, 0, after);
|
this.tokens.splice(i, 0, after);
|
||||||
}
|
}
|
||||||
} else if (prev && !('TERMINATOR' === (_cache4 = prev[0]) || 'INDENT' === _cache4 || 'OUTDENT' === _cache4)) {
|
} else if (prev && !('TERMINATOR' === (_cache2 = prev[0]) || 'INDENT' === _cache2 || 'OUTDENT' === _cache2)) {
|
||||||
if (post && post[0] === 'TERMINATOR' && after && after[0] === 'OUTDENT') {
|
if (post && post[0] === 'TERMINATOR' && after && after[0] === 'OUTDENT') {
|
||||||
this.tokens.splice.apply(this.tokens, [i + 2, 0].concat(this.tokens.splice(i, 2)));
|
this.tokens.splice.apply(this.tokens, [i + 2, 0].concat(this.tokens.splice(i, 2)));
|
||||||
if (this.tokens[i + 2][0] !== 'TERMINATOR') {
|
if (this.tokens[i + 2][0] !== 'TERMINATOR') {
|
||||||
@@ -114,8 +114,8 @@
|
|||||||
var action, condition;
|
var action, condition;
|
||||||
if (token[0] === 'CALL_START') {
|
if (token[0] === 'CALL_START') {
|
||||||
condition = function(token, i) {
|
condition = function(token, i) {
|
||||||
var _cache3;
|
var _cache2;
|
||||||
return ((')' === (_cache3 = token[0]) || 'CALL_END' === _cache3)) || (token[0] === 'OUTDENT' && this.tokens[i - 1][0] === ')');
|
return ((')' === (_cache2 = token[0]) || 'CALL_END' === _cache2)) || (token[0] === 'OUTDENT' && this.tokens[i - 1][0] === ')');
|
||||||
};
|
};
|
||||||
action = function(token, i) {
|
action = function(token, i) {
|
||||||
var idx;
|
var idx;
|
||||||
@@ -132,8 +132,8 @@
|
|||||||
var action, condition;
|
var action, condition;
|
||||||
if (token[0] === 'INDEX_START') {
|
if (token[0] === 'INDEX_START') {
|
||||||
condition = function(token, i) {
|
condition = function(token, i) {
|
||||||
var _cache3;
|
var _cache2;
|
||||||
return (']' === (_cache3 = token[0]) || 'INDEX_END' === _cache3);
|
return (']' === (_cache2 = token[0]) || 'INDEX_END' === _cache2);
|
||||||
};
|
};
|
||||||
action = function(token, i) {
|
action = function(token, i) {
|
||||||
return (token[0] = 'INDEX_END');
|
return (token[0] = 'INDEX_END');
|
||||||
@@ -162,15 +162,15 @@
|
|||||||
tok.generated = true;
|
tok.generated = true;
|
||||||
this.tokens.splice(idx, 0, tok);
|
this.tokens.splice(idx, 0, tok);
|
||||||
condition = function(token, i) {
|
condition = function(token, i) {
|
||||||
var _cache3, _cache4, _cache5, one, three, two;
|
var _cache2, one, three, two;
|
||||||
_cache3 = this.tokens.slice(i + 1, i + 4);
|
_cache2 = this.tokens.slice(i + 1, i + 4);
|
||||||
one = _cache3[0];
|
one = _cache2[0];
|
||||||
two = _cache3[1];
|
two = _cache2[1];
|
||||||
three = _cache3[2];
|
three = _cache2[2];
|
||||||
if ((this.tag(i + 1) === 'HERECOMMENT' || this.tag(i - 1) === 'HERECOMMENT')) {
|
if ((this.tag(i + 1) === 'HERECOMMENT' || this.tag(i - 1) === 'HERECOMMENT')) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return ((('TERMINATOR' === (_cache4 = token[0]) || 'OUTDENT' === _cache4)) && !((two && two[0] === ':') || (one && one[0] === '@' && three && three[0] === ':'))) || (token[0] === ',' && one && (!('IDENTIFIER' === (_cache5 = one[0]) || 'STRING' === _cache5 || '@' === _cache5 || 'TERMINATOR' === _cache5 || 'OUTDENT' === _cache5)));
|
return ((('TERMINATOR' === (_cache2 = token[0]) || 'OUTDENT' === _cache2)) && !((two && two[0] === ':') || (one && one[0] === '@' && three && three[0] === ':'))) || (token[0] === ',' && one && (!('IDENTIFIER' === (_cache2 = one[0]) || 'STRING' === _cache2 || '@' === _cache2 || 'TERMINATOR' === _cache2 || 'OUTDENT' === _cache2)));
|
||||||
};
|
};
|
||||||
action = function(token, i) {
|
action = function(token, i) {
|
||||||
return this.tokens.splice(i, 0, ['}', '}', token[2]]);
|
return this.tokens.splice(i, 0, ['}', '}', token[2]]);
|
||||||
@@ -185,7 +185,7 @@
|
|||||||
var classLine;
|
var classLine;
|
||||||
classLine = false;
|
classLine = false;
|
||||||
return this.scanTokens(function(token, i) {
|
return this.scanTokens(function(token, i) {
|
||||||
var _cache3, action, callObject, condition, idx, next, prev, seenSingle;
|
var _cache2, action, callObject, condition, idx, next, prev, seenSingle;
|
||||||
if (token[0] === 'CLASS') {
|
if (token[0] === 'CLASS') {
|
||||||
classLine = true;
|
classLine = true;
|
||||||
}
|
}
|
||||||
@@ -203,14 +203,14 @@
|
|||||||
if (prev && !prev.spaced && token[0] === '?') {
|
if (prev && !prev.spaced && token[0] === '?') {
|
||||||
token.call = true;
|
token.call = true;
|
||||||
}
|
}
|
||||||
if (prev && (prev.spaced && (include(IMPLICIT_FUNC, prev[0]) || prev.call) && include(IMPLICIT_CALL, token[0]) && !(token[0] === 'UNARY' && (('IN' === (_cache3 = this.tag(i + 1)) || 'OF' === _cache3 || 'INSTANCEOF' === _cache3)))) || callObject) {
|
if (prev && (prev.spaced && (include(IMPLICIT_FUNC, prev[0]) || prev.call) && include(IMPLICIT_CALL, token[0]) && !(token[0] === 'UNARY' && (('IN' === (_cache2 = this.tag(i + 1)) || 'OF' === _cache2 || 'INSTANCEOF' === _cache2)))) || callObject) {
|
||||||
this.tokens.splice(i, 0, ['CALL_START', '(', token[2]]);
|
this.tokens.splice(i, 0, ['CALL_START', '(', token[2]]);
|
||||||
condition = function(token, i) {
|
condition = function(token, i) {
|
||||||
var _cache3;
|
var _cache2;
|
||||||
if (!seenSingle && token.fromThen) {
|
if (!seenSingle && token.fromThen) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (('IF' === (_cache3 = token[0]) || 'ELSE' === _cache3 || 'UNLESS' === _cache3 || '->' === _cache3 || '=>' === _cache3)) {
|
if (('IF' === (_cache2 = token[0]) || 'ELSE' === _cache2 || 'UNLESS' === _cache2 || '->' === _cache2 || '=>' === _cache2)) {
|
||||||
seenSingle = true;
|
seenSingle = true;
|
||||||
}
|
}
|
||||||
return (!token.generated && this.tokens[i - 1][0] !== ',' && include(IMPLICIT_END, token[0]) && !(token[0] === 'INDENT' && (include(IMPLICIT_BLOCK, this.tag(i - 1)) || this.tag(i - 2) === 'CLASS' || this.tag(i + 1) === '{'))) || token[0] === 'PROPERTY_ACCESS' && this.tag(i - 1) === 'OUTDENT';
|
return (!token.generated && this.tokens[i - 1][0] !== ',' && include(IMPLICIT_END, token[0]) && !(token[0] === 'INDENT' && (include(IMPLICIT_BLOCK, this.tag(i - 1)) || this.tag(i - 2) === 'CLASS' || this.tag(i + 1) === '{'))) || token[0] === 'PROPERTY_ACCESS' && this.tag(i - 1) === 'OUTDENT';
|
||||||
@@ -230,7 +230,7 @@
|
|||||||
};
|
};
|
||||||
Rewriter.prototype.addImplicitIndentation = function() {
|
Rewriter.prototype.addImplicitIndentation = function() {
|
||||||
return this.scanTokens(function(token, i) {
|
return this.scanTokens(function(token, i) {
|
||||||
var _cache3, action, condition, indent, outdent, starter;
|
var _cache2, action, condition, indent, outdent, starter;
|
||||||
if (token[0] === 'ELSE' && this.tag(i - 1) !== 'OUTDENT') {
|
if (token[0] === 'ELSE' && this.tag(i - 1) !== 'OUTDENT') {
|
||||||
this.tokens.splice.apply(this.tokens, [i, 0].concat(this.indentation(token)));
|
this.tokens.splice.apply(this.tokens, [i, 0].concat(this.indentation(token)));
|
||||||
return 2;
|
return 2;
|
||||||
@@ -241,9 +241,9 @@
|
|||||||
}
|
}
|
||||||
if (include(SINGLE_LINERS, token[0]) && this.tag(i + 1) !== 'INDENT' && !(token[0] === 'ELSE' && this.tag(i + 1) === 'IF')) {
|
if (include(SINGLE_LINERS, token[0]) && this.tag(i + 1) !== 'INDENT' && !(token[0] === 'ELSE' && this.tag(i + 1) === 'IF')) {
|
||||||
starter = token[0];
|
starter = token[0];
|
||||||
_cache3 = this.indentation(token);
|
_cache2 = this.indentation(token);
|
||||||
indent = _cache3[0];
|
indent = _cache2[0];
|
||||||
outdent = _cache3[1];
|
outdent = _cache2[1];
|
||||||
if (starter === 'THEN') {
|
if (starter === 'THEN') {
|
||||||
indent.fromThen = true;
|
indent.fromThen = true;
|
||||||
}
|
}
|
||||||
@@ -268,12 +268,12 @@
|
|||||||
};
|
};
|
||||||
Rewriter.prototype.tagPostfixConditionals = function() {
|
Rewriter.prototype.tagPostfixConditionals = function() {
|
||||||
return this.scanTokens(function(token, i) {
|
return this.scanTokens(function(token, i) {
|
||||||
var _cache3, action, condition, original;
|
var _cache2, action, condition, original;
|
||||||
if (('IF' === (_cache3 = token[0]) || 'UNLESS' === _cache3)) {
|
if (('IF' === (_cache2 = token[0]) || 'UNLESS' === _cache2)) {
|
||||||
original = token;
|
original = token;
|
||||||
condition = function(token, i) {
|
condition = function(token, i) {
|
||||||
var _cache3;
|
var _cache2;
|
||||||
return ('TERMINATOR' === (_cache3 = token[0]) || 'INDENT' === _cache3);
|
return ('TERMINATOR' === (_cache2 = token[0]) || 'INDENT' === _cache2);
|
||||||
};
|
};
|
||||||
action = function(token, i) {
|
action = function(token, i) {
|
||||||
if (token[0] !== 'INDENT') {
|
if (token[0] !== 'INDENT') {
|
||||||
@@ -287,17 +287,17 @@
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
Rewriter.prototype.ensureBalance = function(pairs) {
|
Rewriter.prototype.ensureBalance = function(pairs) {
|
||||||
var _cache3, _result, key, levels, line, open, openLine, unclosed, value;
|
var _cache2, _result, key, levels, line, open, openLine, unclosed, value;
|
||||||
levels = {};
|
levels = {};
|
||||||
openLine = {};
|
openLine = {};
|
||||||
this.scanTokens(function(token, i) {
|
this.scanTokens(function(token, i) {
|
||||||
var _cache3, _cache4, _cache5, _index, close, open, pair;
|
var _cache2, _cache3, _cache4, _index, close, open, pair;
|
||||||
_cache3 = pairs;
|
_cache2 = pairs;
|
||||||
for (_index = 0, _cache4 = _cache3.length; _index < _cache4; _index++) {
|
for (_index = 0, _cache3 = _cache2.length; _index < _cache3; _index++) {
|
||||||
pair = _cache3[_index];
|
pair = _cache2[_index];
|
||||||
_cache5 = pair;
|
_cache4 = pair;
|
||||||
open = _cache5[0];
|
open = _cache4[0];
|
||||||
close = _cache5[1];
|
close = _cache4[1];
|
||||||
levels[open] || (levels[open] = 0);
|
levels[open] || (levels[open] = 0);
|
||||||
if (token[0] === open) {
|
if (token[0] === open) {
|
||||||
if (levels[open] === 0) {
|
if (levels[open] === 0) {
|
||||||
@@ -315,10 +315,10 @@
|
|||||||
return 1;
|
return 1;
|
||||||
});
|
});
|
||||||
unclosed = (function() {
|
unclosed = (function() {
|
||||||
_result = []; _cache3 = levels;
|
_result = []; _cache2 = levels;
|
||||||
for (key in _cache3) {
|
for (key in _cache2) {
|
||||||
if (!__hasProp.call(_cache3, key)) continue;
|
if (!__hasProp.call(_cache2, key)) continue;
|
||||||
value = _cache3[key];
|
value = _cache2[key];
|
||||||
if (value > 0) {
|
if (value > 0) {
|
||||||
_result.push(key);
|
_result.push(key);
|
||||||
}
|
}
|
||||||
@@ -332,13 +332,13 @@
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
Rewriter.prototype.rewriteClosingParens = function() {
|
Rewriter.prototype.rewriteClosingParens = function() {
|
||||||
var _cache3, debt, key, stack, val;
|
var _cache2, debt, key, stack, val;
|
||||||
stack = [];
|
stack = [];
|
||||||
debt = {};
|
debt = {};
|
||||||
_cache3 = INVERSES;
|
_cache2 = INVERSES;
|
||||||
for (key in _cache3) {
|
for (key in _cache2) {
|
||||||
if (!__hasProp.call(_cache3, key)) continue;
|
if (!__hasProp.call(_cache2, key)) continue;
|
||||||
val = _cache3[key];
|
val = _cache2[key];
|
||||||
(debt[key] = 0);
|
(debt[key] = 0);
|
||||||
}
|
}
|
||||||
return this.scanTokens(function(token, i) {
|
return this.scanTokens(function(token, i) {
|
||||||
@@ -385,27 +385,27 @@
|
|||||||
})();
|
})();
|
||||||
BALANCED_PAIRS = [['(', ')'], ['[', ']'], ['{', '}'], ['INDENT', 'OUTDENT'], ['PARAM_START', 'PARAM_END'], ['CALL_START', 'CALL_END'], ['INDEX_START', 'INDEX_END']];
|
BALANCED_PAIRS = [['(', ')'], ['[', ']'], ['{', '}'], ['INDENT', 'OUTDENT'], ['PARAM_START', 'PARAM_END'], ['CALL_START', 'CALL_END'], ['INDEX_START', 'INDEX_END']];
|
||||||
INVERSES = {};
|
INVERSES = {};
|
||||||
_cache3 = BALANCED_PAIRS;
|
_cache = BALANCED_PAIRS;
|
||||||
for (_index = 0, _cache4 = _cache3.length; _index < _cache4; _index++) {
|
for (_index = 0, _cache2 = _cache.length; _index < _cache2; _index++) {
|
||||||
pair = _cache3[_index];
|
pair = _cache[_index];
|
||||||
INVERSES[pair[0]] = pair[1];
|
INVERSES[pair[0]] = pair[1];
|
||||||
INVERSES[pair[1]] = pair[0];
|
INVERSES[pair[1]] = pair[0];
|
||||||
}
|
}
|
||||||
EXPRESSION_START = (function() {
|
EXPRESSION_START = (function() {
|
||||||
_result = []; _cache5 = BALANCED_PAIRS;
|
_result = []; _cache = BALANCED_PAIRS;
|
||||||
for (_index2 = 0, _cache6 = _cache5.length; _index2 < _cache6; _index2++) {
|
for (_index = 0, _cache2 = _cache.length; _index < _cache2; _index++) {
|
||||||
pair = _cache5[_index2];
|
pair = _cache[_index];
|
||||||
_result.push(pair[0]);
|
_result.push(pair[0]);
|
||||||
}
|
}
|
||||||
return _result;
|
return _result;
|
||||||
})();
|
})();
|
||||||
EXPRESSION_END = (function() {
|
EXPRESSION_END = (function() {
|
||||||
_result2 = []; _cache7 = BALANCED_PAIRS;
|
_result = []; _cache = BALANCED_PAIRS;
|
||||||
for (_index3 = 0, _cache8 = _cache7.length; _index3 < _cache8; _index3++) {
|
for (_index = 0, _cache2 = _cache.length; _index < _cache2; _index++) {
|
||||||
pair = _cache7[_index3];
|
pair = _cache[_index];
|
||||||
_result2.push(pair[1]);
|
_result.push(pair[1]);
|
||||||
}
|
}
|
||||||
return _result2;
|
return _result;
|
||||||
})();
|
})();
|
||||||
EXPRESSION_CLOSE = ['CATCH', 'WHEN', 'ELSE', 'FINALLY'].concat(EXPRESSION_END);
|
EXPRESSION_CLOSE = ['CATCH', 'WHEN', 'ELSE', 'FINALLY'].concat(EXPRESSION_END);
|
||||||
IMPLICIT_FUNC = ['IDENTIFIER', 'SUPER', ')', 'CALL_END', ']', 'INDEX_END', '@', 'THIS'];
|
IMPLICIT_FUNC = ['IDENTIFIER', 'SUPER', ')', 'CALL_END', ']', 'INDEX_END', '@', 'THIS'];
|
||||||
|
|||||||
34
lib/scope.js
34
lib/scope.js
@@ -1,6 +1,6 @@
|
|||||||
(function() {
|
(function() {
|
||||||
var Scope;
|
var Scope;
|
||||||
var __slice = Array.prototype.slice, __hasProp = Object.prototype.hasOwnProperty;
|
var __hasProp = Object.prototype.hasOwnProperty;
|
||||||
if (!(typeof process !== "undefined" && process !== null)) {
|
if (!(typeof process !== "undefined" && process !== null)) {
|
||||||
this.exports = this;
|
this.exports = this;
|
||||||
}
|
}
|
||||||
@@ -12,12 +12,29 @@
|
|||||||
this.expressions = _cache[1];
|
this.expressions = _cache[1];
|
||||||
this.method = _cache[2];
|
this.method = _cache[2];
|
||||||
this.variables = {};
|
this.variables = {};
|
||||||
if (!this.parent) {
|
if (this.parent) {
|
||||||
|
this.garbage = this.parent.garbage;
|
||||||
|
} else {
|
||||||
|
this.garbage = [];
|
||||||
Scope.root = this;
|
Scope.root = this;
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
Scope.root = null;
|
Scope.root = null;
|
||||||
|
Scope.prototype.startLevel = function() {
|
||||||
|
return this.garbage.push([]);
|
||||||
|
};
|
||||||
|
Scope.prototype.endLevel = function() {
|
||||||
|
var _cache, _cache2, _index, _result, name;
|
||||||
|
_result = []; _cache = this.garbage.pop();
|
||||||
|
for (_index = 0, _cache2 = _cache.length; _index < _cache2; _index++) {
|
||||||
|
name = _cache[_index];
|
||||||
|
if (this.variables[name] === 'var') {
|
||||||
|
_result.push(this.variables[name] = 'reuse');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return _result;
|
||||||
|
};
|
||||||
Scope.prototype.find = function(name, options) {
|
Scope.prototype.find = function(name, options) {
|
||||||
if (this.check(name, options)) {
|
if (this.check(name, options)) {
|
||||||
return true;
|
return true;
|
||||||
@@ -25,16 +42,6 @@
|
|||||||
this.variables[name] = 'var';
|
this.variables[name] = 'var';
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
Scope.prototype.reuse = function() {
|
|
||||||
var _cache, _cache2, _index, _result, names, val;
|
|
||||||
names = __slice.call(arguments, 0);
|
|
||||||
_result = []; _cache = names;
|
|
||||||
for (_index = 0, _cache2 = _cache.length; _index < _cache2; _index++) {
|
|
||||||
val = _cache[_index];
|
|
||||||
_result.push(this.variables[val] = 'reuse');
|
|
||||||
}
|
|
||||||
return _result;
|
|
||||||
};
|
|
||||||
Scope.prototype.any = function(fn) {
|
Scope.prototype.any = function(fn) {
|
||||||
var _cache, k, v;
|
var _cache, k, v;
|
||||||
_cache = this.variables;
|
_cache = this.variables;
|
||||||
@@ -68,6 +75,9 @@
|
|||||||
index++;
|
index++;
|
||||||
}
|
}
|
||||||
this.variables[temp] = 'var';
|
this.variables[temp] = 'var';
|
||||||
|
if (this.garbage.length) {
|
||||||
|
this.garbage[this.garbage.length - 1].push(temp);
|
||||||
|
}
|
||||||
return temp;
|
return temp;
|
||||||
};
|
};
|
||||||
Scope.prototype.assign = function(name, value) {
|
Scope.prototype.assign = function(name, value) {
|
||||||
|
|||||||
@@ -50,7 +50,10 @@ exports.BaseNode = class BaseNode
|
|||||||
closure = @isStatement(o) and not @isPureStatement() and not top and
|
closure = @isStatement(o) and not @isPureStatement() and not top and
|
||||||
not @options.asStatement and this not instanceof CommentNode and
|
not @options.asStatement and this not instanceof CommentNode and
|
||||||
not @containsPureStatement()
|
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
|
# Statements converted into expressions via closure-wrapping share a scope
|
||||||
# object with their parent closure, to preserve the expected lexical scope.
|
# object with their parent closure, to preserve the expected lexical scope.
|
||||||
@@ -70,10 +73,10 @@ exports.BaseNode = class BaseNode
|
|||||||
else if this instanceof ValueNode and options.assignment
|
else if this instanceof ValueNode and options.assignment
|
||||||
this.cacheIndexes(o)
|
this.cacheIndexes(o)
|
||||||
else
|
else
|
||||||
reference = literal temp = o.scope.freeVariable 'cache'
|
reference = literal o.scope.freeVariable 'cache'
|
||||||
compiled = new AssignNode reference, this
|
compiled = new AssignNode reference, this
|
||||||
[compiled, reference, temp]
|
[compiled, reference]
|
||||||
return [pair[0].compile(o), pair[1].compile(o), pair[2]] if options.precompile
|
return [pair[0].compile(o), pair[1].compile(o)] if options.precompile
|
||||||
pair
|
pair
|
||||||
|
|
||||||
# Convenience method to grab the current indentation level, plus tabbing in.
|
# Convenience method to grab the current indentation level, plus tabbing in.
|
||||||
@@ -1176,11 +1179,9 @@ exports.OpNode = class OpNode extends BaseNode
|
|||||||
# true
|
# true
|
||||||
compileChain: (o) ->
|
compileChain: (o) ->
|
||||||
shared = @first.unwrap().second
|
shared = @first.unwrap().second
|
||||||
[@first.second, shared, temp] = shared.compileReference(o) if shared.containsType CallNode
|
[@first.second, shared] = shared.compileReference(o) if shared.containsType CallNode
|
||||||
[first, second, shared] = [@first.compile(o), @second.compile(o), shared.compile(o)]
|
[first, second, shared] = [@first.compile(o), @second.compile(o), shared.compile(o)]
|
||||||
js = "(#{first}) && (#{shared} #{@operator} #{second})"
|
"(#{first}) && (#{shared} #{@operator} #{second})"
|
||||||
o.scope.reuse temp if temp
|
|
||||||
js
|
|
||||||
|
|
||||||
# When compiling a conditional assignment, take care to ensure that the
|
# When compiling a conditional assignment, take care to ensure that the
|
||||||
# operands are only evaluated once, even though we have to reference them
|
# operands are only evaluated once, even though we have to reference them
|
||||||
@@ -1403,7 +1404,7 @@ exports.ForNode = class ForNode extends BaseNode
|
|||||||
svar = scope.freeVariable 'cache'
|
svar = scope.freeVariable 'cache'
|
||||||
sourcePart = "#{svar} = #{ @source.compile(o) };"
|
sourcePart = "#{svar} = #{ @source.compile(o) };"
|
||||||
if @pattern
|
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
|
else
|
||||||
namePart = "#{name} = #{svar}[#{ivar}]" if name
|
namePart = "#{name} = #{svar}[#{ivar}]" if name
|
||||||
unless @object
|
unless @object
|
||||||
|
|||||||
@@ -20,7 +20,20 @@ exports.Scope = class Scope
|
|||||||
constructor: (parent, expressions, method) ->
|
constructor: (parent, expressions, method) ->
|
||||||
[@parent, @expressions, @method] = [parent, expressions, method]
|
[@parent, @expressions, @method] = [parent, expressions, method]
|
||||||
@variables = {}
|
@variables = {}
|
||||||
Scope.root = this if not @parent
|
if @parent
|
||||||
|
@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
|
# Look up a variable name in lexical scope, and declare it if it does not
|
||||||
# already exist.
|
# already exist.
|
||||||
@@ -29,11 +42,6 @@ exports.Scope = class Scope
|
|||||||
@variables[name] = 'var'
|
@variables[name] = 'var'
|
||||||
false
|
false
|
||||||
|
|
||||||
# Erase a variable from scope. This is usually carried when we are done
|
|
||||||
# working with a list of temporary variables and we want to flag them for reuse.
|
|
||||||
reuse: (names...) ->
|
|
||||||
(@variables[val] = 'reuse') for val in names
|
|
||||||
|
|
||||||
# Test variables and return true the first time fn(v, k) returns true
|
# Test variables and return true the first time fn(v, k) returns true
|
||||||
any: (fn) ->
|
any: (fn) ->
|
||||||
for v, k of @variables when fn(v, k)
|
for v, k of @variables when fn(v, k)
|
||||||
@@ -62,6 +70,7 @@ exports.Scope = class Scope
|
|||||||
index = 0
|
index = 0
|
||||||
index++ while (@check temp = @temporary type, index) and @variables[temp] isnt 'reuse'
|
index++ while (@check temp = @temporary type, index) and @variables[temp] isnt 'reuse'
|
||||||
@variables[temp] = 'var'
|
@variables[temp] = 'var'
|
||||||
|
@garbage[@garbage.length - 1].push temp if @garbage.length
|
||||||
temp
|
temp
|
||||||
|
|
||||||
# Ensure that an assignment is made at the top of this scope
|
# Ensure that an assignment is made at the top of this scope
|
||||||
|
|||||||
Reference in New Issue
Block a user