tweaking compiled tempvar names to satisfaction.
This commit is contained in:
parent
5d82dddfb1
commit
f7fce3cd68
|
@ -19,10 +19,10 @@
|
|||
return xhr.send(null);
|
||||
};
|
||||
processScripts = function() {
|
||||
var _cache, _cache2, _index, script;
|
||||
_cache = document.getElementsByTagName('script');
|
||||
for (_index = 0, _cache2 = _cache.length; _index < _cache2; _index++) {
|
||||
script = _cache[_index];
|
||||
var _i, _l, _ref, script;
|
||||
_ref = document.getElementsByTagName('script');
|
||||
for (_i = 0, _l = _ref.length; _i < _l; _i++) {
|
||||
script = _ref[_i];
|
||||
if (script.type === 'text/coffeescript') {
|
||||
if (script.src) {
|
||||
grindRemote(script.src);
|
||||
|
|
24
lib/cake.js
24
lib/cake.js
|
@ -11,11 +11,11 @@
|
|||
oparse = null;
|
||||
helpers.extend(global, {
|
||||
task: function(name, description, action) {
|
||||
var _cache;
|
||||
var _ref;
|
||||
if (!(action)) {
|
||||
_cache = [description, action];
|
||||
action = _cache[0];
|
||||
description = _cache[1];
|
||||
_ref = [description, action];
|
||||
action = _ref[0];
|
||||
description = _ref[1];
|
||||
}
|
||||
return (tasks[name] = {
|
||||
name: name,
|
||||
|
@ -35,7 +35,7 @@
|
|||
});
|
||||
exports.run = function() {
|
||||
return path.exists('Cakefile', function(exists) {
|
||||
var _cache, _cache2, _index, _result, arg, args;
|
||||
var _i, _l, _ref, _result, arg, args;
|
||||
if (!(exists)) {
|
||||
throw new Error("Cakefile not found in " + (process.cwd()));
|
||||
}
|
||||
|
@ -48,20 +48,20 @@
|
|||
return printTasks();
|
||||
}
|
||||
options = oparse.parse(args);
|
||||
_result = []; _cache = options.arguments;
|
||||
for (_index = 0, _cache2 = _cache.length; _index < _cache2; _index++) {
|
||||
arg = _cache[_index];
|
||||
_result = []; _ref = options.arguments;
|
||||
for (_i = 0, _l = _ref.length; _i < _l; _i++) {
|
||||
arg = _ref[_i];
|
||||
_result.push(invoke(arg));
|
||||
}
|
||||
return _result;
|
||||
});
|
||||
};
|
||||
printTasks = function() {
|
||||
var _cache, _result, desc, i, name, spaces, task;
|
||||
var _ref, _result, desc, i, name, spaces, task;
|
||||
puts('');
|
||||
_cache = tasks;
|
||||
for (name in _cache) {
|
||||
task = _cache[name];
|
||||
_ref = tasks;
|
||||
for (name in _ref) {
|
||||
task = _ref[name];
|
||||
spaces = 20 - name.length;
|
||||
spaces = spaces > 0 ? (function() {
|
||||
_result = [];
|
||||
|
|
|
@ -1,16 +1,16 @@
|
|||
(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, _ref, _ref2, _ref3, 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');
|
||||
_cache = require('./helpers');
|
||||
helpers = _cache.helpers;
|
||||
_cache2 = require('child_process');
|
||||
spawn = _cache2.spawn;
|
||||
exec = _cache2.exec;
|
||||
_cache3 = require('events');
|
||||
EventEmitter = _cache3.EventEmitter;
|
||||
_ref = require('./helpers');
|
||||
helpers = _ref.helpers;
|
||||
_ref2 = require('child_process');
|
||||
spawn = _ref2.spawn;
|
||||
exec = _ref2.exec;
|
||||
_ref3 = require('events');
|
||||
EventEmitter = _ref3.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 _cache4, _cache5, _index, _result;
|
||||
_result = []; _cache4 = sources;
|
||||
for (_index = 0, _cache5 = _cache4.length; _index < _cache5; _index++) {
|
||||
var _i, _l, _ref4, _result;
|
||||
_result = []; _ref4 = sources;
|
||||
for (_i = 0, _l = _ref4.length; _i < _l; _i++) {
|
||||
(function() {
|
||||
var base, compile;
|
||||
var source = _cache4[_index];
|
||||
var source = _ref4[_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 _cache6, _cache7, _index2, _result2, file;
|
||||
_result2 = []; _cache6 = files;
|
||||
for (_index2 = 0, _cache7 = _cache6.length; _index2 < _cache7; _index2++) {
|
||||
file = _cache6[_index2];
|
||||
var _i2, _l2, _ref5, _result2, file;
|
||||
_result2 = []; _ref5 = files;
|
||||
for (_i2 = 0, _l2 = _ref5.length; _i2 < _l2; _i2++) {
|
||||
file = _ref5[_i2];
|
||||
_result2.push(compile(path.join(source, file)));
|
||||
}
|
||||
return _result2;
|
||||
|
@ -95,13 +95,13 @@
|
|||
return _result;
|
||||
};
|
||||
compileScript = function(file, input, base) {
|
||||
var _cache4, _cache5, _index, o, options, req, t, task;
|
||||
var _i, _l, _ref4, o, options, req, t, task;
|
||||
o = opts;
|
||||
options = compileOptions(file);
|
||||
if (o.require) {
|
||||
_cache4 = o.require;
|
||||
for (_index = 0, _cache5 = _cache4.length; _index < _cache5; _index++) {
|
||||
req = _cache4[_index];
|
||||
_ref4 = o.require;
|
||||
for (_i = 0, _l = _ref4.length; _i < _l; _i++) {
|
||||
req = _ref4[_i];
|
||||
require(helpers.starts(req, '.') ? fs.realpathSync(req) : req);
|
||||
}
|
||||
}
|
||||
|
@ -204,15 +204,15 @@
|
|||
return jsl.stdin.end();
|
||||
};
|
||||
printTokens = function(tokens) {
|
||||
var _cache4, _cache5, _cache6, _index, _result, strings, tag, token, value;
|
||||
var _i, _l, _ref4, _ref5, _result, strings, tag, token, value;
|
||||
strings = (function() {
|
||||
_result = []; _cache4 = tokens;
|
||||
for (_index = 0, _cache5 = _cache4.length; _index < _cache5; _index++) {
|
||||
token = _cache4[_index];
|
||||
_result = []; _ref4 = tokens;
|
||||
for (_i = 0, _l = _ref4.length; _i < _l; _i++) {
|
||||
token = _ref4[_i];
|
||||
_result.push((function() {
|
||||
_cache6 = [token[0], token[1].toString().replace(/\n/, '\\n')];
|
||||
tag = _cache6[0];
|
||||
value = _cache6[1];
|
||||
_ref5 = [token[0], token[1].toString().replace(/\n/, '\\n')];
|
||||
tag = _ref5[0];
|
||||
value = _ref5[1];
|
||||
return "[" + (tag) + " " + (value) + "]";
|
||||
})());
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
(function() {
|
||||
var Parser, _cache, _cache2, _cache3, _cache4, _cache5, _index, _index2, _result, alt, alternatives, grammar, name, o, operators, token, tokens, unwrap;
|
||||
var Parser, _i, _i2, _l, _l2, _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*\}/;
|
||||
|
@ -612,18 +612,18 @@
|
|||
};
|
||||
operators = [["right", '?', 'NEW'], ["left", 'CALL_START', 'CALL_END'], ["nonassoc", '++', '--'], ["right", 'UNARY'], ["left", 'MATH'], ["left", '+', '-'], ["left", 'SHIFT'], ["left", 'COMPARE'], ["left", 'INSTANCEOF'], ["left", '==', '!='], ["left", 'LOGIC'], ["right", 'COMPOUND_ASSIGN'], ["left", '.'], ["nonassoc", 'INDENT', 'OUTDENT'], ["right", 'WHEN', 'LEADING_WHEN', 'IN', 'OF', 'BY', 'THROW'], ["right", 'IF', 'UNLESS', 'ELSE', 'FOR', 'WHILE', 'UNTIL', 'LOOP', 'SUPER', 'CLASS', 'EXTENDS'], ["right", '=', ':', 'RETURN'], ["right", '->', '=>', 'UNLESS', 'POST_IF', 'POST_UNLESS']];
|
||||
tokens = [];
|
||||
_cache = grammar;
|
||||
for (name in _cache) {
|
||||
if (!__hasProp.call(_cache, name)) continue;
|
||||
alternatives = _cache[name];
|
||||
_ref = grammar;
|
||||
for (name in _ref) {
|
||||
if (!__hasProp.call(_ref, name)) continue;
|
||||
alternatives = _ref[name];
|
||||
grammar[name] = (function() {
|
||||
_result = []; _cache2 = alternatives;
|
||||
for (_index = 0, _cache3 = _cache2.length; _index < _cache3; _index++) {
|
||||
alt = _cache2[_index];
|
||||
_result = []; _ref2 = alternatives;
|
||||
for (_i = 0, _l = _ref2.length; _i < _l; _i++) {
|
||||
alt = _ref2[_i];
|
||||
_result.push((function() {
|
||||
_cache4 = alt[0].split(' ');
|
||||
for (_index2 = 0, _cache5 = _cache4.length; _index2 < _cache5; _index2++) {
|
||||
token = _cache4[_index2];
|
||||
_ref3 = alt[0].split(' ');
|
||||
for (_i2 = 0, _l2 = _ref3.length; _i2 < _l2; _i2++) {
|
||||
token = _ref3[_i2];
|
||||
if (!(grammar[token])) {
|
||||
tokens.push(token);
|
||||
}
|
||||
|
|
|
@ -5,13 +5,13 @@
|
|||
}
|
||||
helpers = (exports.helpers = {});
|
||||
helpers.indexOf = (indexOf = function(array, item, from) {
|
||||
var _cache, _cache2, index, other;
|
||||
var _l, _ref, index, other;
|
||||
if (array.indexOf) {
|
||||
return array.indexOf(item, from);
|
||||
}
|
||||
_cache = array;
|
||||
for (index = 0, _cache2 = _cache.length; index < _cache2; index++) {
|
||||
other = _cache[index];
|
||||
_ref = array;
|
||||
for (index = 0, _l = _ref.length; index < _l; index++) {
|
||||
other = _ref[index];
|
||||
if (other === item && (!from || (from <= index))) {
|
||||
return index;
|
||||
}
|
||||
|
@ -30,10 +30,10 @@
|
|||
return string.substring(start, start + literal.length) === literal;
|
||||
});
|
||||
helpers.compact = (compact = function(array) {
|
||||
var _cache, _cache2, _index, _result, item;
|
||||
_result = []; _cache = array;
|
||||
for (_index = 0, _cache2 = _cache.length; _index < _cache2; _index++) {
|
||||
item = _cache[_index];
|
||||
var _i, _l, _ref, _result, item;
|
||||
_result = []; _ref = array;
|
||||
for (_i = 0, _l = _ref.length; _i < _l; _i++) {
|
||||
item = _ref[_i];
|
||||
if (item) {
|
||||
_result.push(item);
|
||||
}
|
||||
|
@ -51,37 +51,37 @@
|
|||
return num;
|
||||
});
|
||||
helpers.merge = (merge = function(options, overrides) {
|
||||
var _cache, _cache2, fresh, key, val;
|
||||
var _ref, _ref2, fresh, key, val;
|
||||
fresh = {};
|
||||
_cache = options;
|
||||
for (key in _cache) {
|
||||
val = _cache[key];
|
||||
_ref = options;
|
||||
for (key in _ref) {
|
||||
val = _ref[key];
|
||||
(fresh[key] = val);
|
||||
}
|
||||
if (overrides) {
|
||||
_cache2 = overrides;
|
||||
for (key in _cache2) {
|
||||
val = _cache2[key];
|
||||
_ref2 = overrides;
|
||||
for (key in _ref2) {
|
||||
val = _ref2[key];
|
||||
(fresh[key] = val);
|
||||
}
|
||||
}
|
||||
return fresh;
|
||||
});
|
||||
helpers.extend = (extend = function(object, properties) {
|
||||
var _cache, _result, key, val;
|
||||
_result = []; _cache = properties;
|
||||
for (key in _cache) {
|
||||
val = _cache[key];
|
||||
var _ref, _result, key, val;
|
||||
_result = []; _ref = properties;
|
||||
for (key in _ref) {
|
||||
val = _ref[key];
|
||||
_result.push(object[key] = val);
|
||||
}
|
||||
return _result;
|
||||
});
|
||||
helpers.flatten = (flatten = function(array) {
|
||||
var _cache, _cache2, _index, item, memo;
|
||||
var _i, _l, _ref, item, memo;
|
||||
memo = [];
|
||||
_cache = array;
|
||||
for (_index = 0, _cache2 = _cache.length; _index < _cache2; _index++) {
|
||||
item = _cache[_index];
|
||||
_ref = array;
|
||||
for (_i = 0, _l = _ref.length; _i < _l; _i++) {
|
||||
item = _ref[_i];
|
||||
if (item instanceof Array) {
|
||||
memo = memo.concat(item);
|
||||
} else {
|
||||
|
|
10
lib/index.js
10
lib/index.js
|
@ -1,10 +1,10 @@
|
|||
(function() {
|
||||
var _cache, key, val;
|
||||
var _ref, key, val;
|
||||
var __hasProp = Object.prototype.hasOwnProperty;
|
||||
_cache = require('./coffee-script');
|
||||
for (key in _cache) {
|
||||
if (!__hasProp.call(_cache, key)) continue;
|
||||
val = _cache[key];
|
||||
_ref = require('./coffee-script');
|
||||
for (key in _ref) {
|
||||
if (!__hasProp.call(_ref, key)) continue;
|
||||
val = _ref[key];
|
||||
(exports[key] = val);
|
||||
}
|
||||
})();
|
||||
|
|
72
lib/lexer.js
72
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, _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, _ref, _ref2, _ref3, compact, count, helpers, include, starts;
|
||||
var __slice = Array.prototype.slice;
|
||||
if (typeof process !== "undefined" && process !== null) {
|
||||
_cache = require('./rewriter');
|
||||
Rewriter = _cache.Rewriter;
|
||||
_cache2 = require('./helpers');
|
||||
helpers = _cache2.helpers;
|
||||
_ref = require('./rewriter');
|
||||
Rewriter = _ref.Rewriter;
|
||||
_ref2 = require('./helpers');
|
||||
helpers = _ref2.helpers;
|
||||
} else {
|
||||
this.exports = this;
|
||||
Rewriter = this.Rewriter;
|
||||
helpers = this.helpers;
|
||||
}
|
||||
_cache3 = helpers;
|
||||
include = _cache3.include;
|
||||
count = _cache3.count;
|
||||
starts = _cache3.starts;
|
||||
compact = _cache3.compact;
|
||||
_ref3 = helpers;
|
||||
include = _ref3.include;
|
||||
count = _ref3.count;
|
||||
starts = _ref3.starts;
|
||||
compact = _ref3.compact;
|
||||
exports.Lexer = (function() {
|
||||
Lexer = function() {};
|
||||
Lexer.prototype.tokenize = function(code, options) {
|
||||
|
@ -192,11 +192,11 @@
|
|||
return true;
|
||||
};
|
||||
Lexer.prototype.regexToken = function() {
|
||||
var _cache4, end, first, flags, regex, str;
|
||||
var _ref4, end, first, flags, regex, str;
|
||||
if (!(first = this.chunk.match(REGEX_START))) {
|
||||
return false;
|
||||
}
|
||||
if (first[1] === ' ' && !('CALL_START' === (_cache4 = this.tag()) || '=' === _cache4)) {
|
||||
if (first[1] === ' ' && !('CALL_START' === (_ref4 = this.tag()) || '=' === _ref4)) {
|
||||
return false;
|
||||
}
|
||||
if (include(NOT_REGEX, this.tag())) {
|
||||
|
@ -320,7 +320,7 @@
|
|||
return true;
|
||||
};
|
||||
Lexer.prototype.literalToken = function() {
|
||||
var _cache4, match, prev, space, spaced, tag, value;
|
||||
var _ref4, 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' === (_cache4 = this.value()) || 'and' === _cache4)) {
|
||||
if (('or' === (_ref4 = this.value()) || 'and' === _ref4)) {
|
||||
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 _cache4, attempt, indent, match;
|
||||
var _ref4, 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 (_cache4 = match[2]) !== "undefined" && _cache4 !== null) ? match[2] : match[3];
|
||||
attempt = (typeof (_ref4 = match[2]) !== "undefined" && _ref4 !== 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 _cache4, _cache5, _cache6, _index, close, i, levels, open, pair, slash;
|
||||
var _i, _l, _ref4, _ref5, 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 {
|
||||
_cache4 = delimited;
|
||||
for (_index = 0, _cache5 = _cache4.length; _index < _cache5; _index++) {
|
||||
pair = _cache4[_index];
|
||||
_cache6 = pair;
|
||||
open = _cache6[0];
|
||||
close = _cache6[1];
|
||||
_ref4 = delimited;
|
||||
for (_i = 0, _l = _ref4.length; _i < _l; _i++) {
|
||||
pair = _ref4[_i];
|
||||
_ref5 = pair;
|
||||
open = _ref5[0];
|
||||
close = _ref5[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 _cache4, _cache5, _cache6, _cache7, _cache8, _cache9, escaped, expr, i, idx, inner, interpolated, lexer, nested, pi, quote, tag, tok, token, tokens, value;
|
||||
var _l, _l2, _ref4, _ref5, _ref6, _ref7, 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);
|
||||
_cache4 = [1, 1];
|
||||
i = _cache4[0];
|
||||
pi = _cache4[1];
|
||||
_ref4 = [1, 1];
|
||||
i = _ref4[0];
|
||||
pi = _ref4[1];
|
||||
while (i < str.length - 1) {
|
||||
if (starts(str, '\\', i)) {
|
||||
i += 1;
|
||||
|
@ -520,9 +520,9 @@
|
|||
nested = lexer.tokenize("(" + (inner) + ")", {
|
||||
line: this.line
|
||||
});
|
||||
_cache5 = nested;
|
||||
for (idx = 0, _cache6 = _cache5.length; idx < _cache6; idx++) {
|
||||
tok = _cache5[idx];
|
||||
_ref5 = nested;
|
||||
for (idx = 0, _l = _ref5.length; idx < _l; idx++) {
|
||||
tok = _ref5[idx];
|
||||
if (tok[0] === 'CALL_END') {
|
||||
(tok[0] = ')');
|
||||
}
|
||||
|
@ -547,12 +547,12 @@
|
|||
if (interpolated) {
|
||||
this.token('(', '(');
|
||||
}
|
||||
_cache7 = tokens;
|
||||
for (i = 0, _cache8 = _cache7.length; i < _cache8; i++) {
|
||||
token = _cache7[i];
|
||||
_cache9 = token;
|
||||
tag = _cache9[0];
|
||||
value = _cache9[1];
|
||||
_ref6 = tokens;
|
||||
for (i = 0, _l2 = _ref6.length; i < _l2; i++) {
|
||||
token = _ref6[i];
|
||||
_ref7 = token;
|
||||
tag = _ref7[0];
|
||||
value = _ref7[1];
|
||||
if (tag === 'TOKENS') {
|
||||
this.tokens = this.tokens.concat(value);
|
||||
} else if (tag === 'STRING' && options.escapeQuotes) {
|
||||
|
|
422
lib/nodes.js
422
lib/nodes.js
|
@ -1,5 +1,5 @@
|
|||
(function() {
|
||||
var AccessorNode, ArrayNode, AssignNode, BaseNode, CallNode, ClassNode, ClosureNode, CodeNode, CommentNode, ExistenceNode, Expressions, ExtendsNode, ForNode, IDENTIFIER, IS_STRING, IfNode, InNode, IndexNode, LiteralNode, NUMBER, ObjectNode, OpNode, ParamNode, ParentheticalNode, PushNode, RangeNode, ReturnNode, SIMPLENUM, Scope, SliceNode, SplatNode, SwitchNode, TAB, TRAILING_WHITESPACE, ThrowNode, TryNode, UTILITIES, ValueNode, WhileNode, _cache, compact, del, ends, flatten, helpers, include, indexOf, literal, merge, starts, utility;
|
||||
var AccessorNode, ArrayNode, AssignNode, BaseNode, CallNode, ClassNode, ClosureNode, CodeNode, CommentNode, ExistenceNode, Expressions, ExtendsNode, ForNode, IDENTIFIER, IS_STRING, IfNode, InNode, IndexNode, LiteralNode, NUMBER, ObjectNode, OpNode, ParamNode, ParentheticalNode, PushNode, RangeNode, ReturnNode, SIMPLENUM, Scope, SliceNode, SplatNode, SwitchNode, TAB, TRAILING_WHITESPACE, ThrowNode, TryNode, UTILITIES, ValueNode, WhileNode, _ref, compact, del, ends, flatten, helpers, include, indexOf, literal, merge, starts, utility;
|
||||
var __extends = function(child, parent) {
|
||||
var ctor = function(){};
|
||||
ctor.prototype = parent.prototype;
|
||||
|
@ -16,15 +16,15 @@
|
|||
helpers = this.helpers;
|
||||
Scope = this.Scope;
|
||||
}
|
||||
_cache = helpers;
|
||||
compact = _cache.compact;
|
||||
flatten = _cache.flatten;
|
||||
merge = _cache.merge;
|
||||
del = _cache.del;
|
||||
include = _cache.include;
|
||||
indexOf = _cache.indexOf;
|
||||
starts = _cache.starts;
|
||||
ends = _cache.ends;
|
||||
_ref = helpers;
|
||||
compact = _ref.compact;
|
||||
flatten = _ref.flatten;
|
||||
merge = _ref.merge;
|
||||
del = _ref.del;
|
||||
include = _ref.include;
|
||||
indexOf = _ref.indexOf;
|
||||
starts = _ref.starts;
|
||||
ends = _ref.ends;
|
||||
exports.BaseNode = (function() {
|
||||
BaseNode = function() {
|
||||
this.tags = {};
|
||||
|
@ -55,7 +55,7 @@
|
|||
} else if (this instanceof ValueNode && options.assignment) {
|
||||
return this.cacheIndexes(o);
|
||||
} else {
|
||||
reference = literal(o.scope.freeVariable('cache'));
|
||||
reference = literal(o.scope.freeVariable('ref'));
|
||||
compiled = new AssignNode(reference, this);
|
||||
return [compiled, reference];
|
||||
}
|
||||
|
@ -102,12 +102,12 @@
|
|||
return this.traverseChildren(true, block);
|
||||
};
|
||||
BaseNode.prototype.toString = function(idt, override) {
|
||||
var _cache2, _cache3, _index, _result, child, children;
|
||||
var _i, _l, _ref2, _result, child, children;
|
||||
idt || (idt = '');
|
||||
children = (function() {
|
||||
_result = []; _cache2 = this.collectChildren();
|
||||
for (_index = 0, _cache3 = _cache2.length; _index < _cache3; _index++) {
|
||||
child = _cache2[_index];
|
||||
_result = []; _ref2 = this.collectChildren();
|
||||
for (_i = 0, _l = _ref2.length; _i < _l; _i++) {
|
||||
child = _ref2[_i];
|
||||
_result.push(child.toString(idt + TAB));
|
||||
}
|
||||
return _result;
|
||||
|
@ -115,17 +115,17 @@
|
|||
return '\n' + idt + (override || this["class"]) + children;
|
||||
};
|
||||
BaseNode.prototype.eachChild = function(func) {
|
||||
var _cache2, _cache3, _cache4, _cache5, _index, _index2, _result, attr, child;
|
||||
var _i, _i2, _l, _l2, _ref2, _ref3, _result, attr, child;
|
||||
if (!(this.children)) {
|
||||
return null;
|
||||
}
|
||||
_result = []; _cache2 = this.children;
|
||||
for (_index = 0, _cache3 = _cache2.length; _index < _cache3; _index++) {
|
||||
attr = _cache2[_index];
|
||||
_result = []; _ref2 = this.children;
|
||||
for (_i = 0, _l = _ref2.length; _i < _l; _i++) {
|
||||
attr = _ref2[_i];
|
||||
if (this[attr]) {
|
||||
_cache4 = flatten([this[attr]]);
|
||||
for (_index2 = 0, _cache5 = _cache4.length; _index2 < _cache5; _index2++) {
|
||||
child = _cache4[_index2];
|
||||
_ref3 = flatten([this[attr]]);
|
||||
for (_i2 = 0, _l2 = _ref3.length; _i2 < _l2; _i2++) {
|
||||
child = _ref3[_i2];
|
||||
if (func(child) === false) {
|
||||
return null;
|
||||
}
|
||||
|
@ -210,11 +210,11 @@
|
|||
return o.scope ? Expressions.__super__.compile.call(this, o) : this.compileRoot(o);
|
||||
};
|
||||
Expressions.prototype.compileNode = function(o) {
|
||||
var _cache2, _cache3, _index, _result, node;
|
||||
var _i, _l, _ref2, _result, node;
|
||||
return (function() {
|
||||
_result = []; _cache2 = this.expressions;
|
||||
for (_index = 0, _cache3 = _cache2.length; _index < _cache3; _index++) {
|
||||
node = _cache2[_index];
|
||||
_result = []; _ref2 = this.expressions;
|
||||
for (_i = 0, _l = _ref2.length; _i < _l; _i++) {
|
||||
node = _ref2[_i];
|
||||
_result.push(this.compileExpression(node, merge(o)));
|
||||
}
|
||||
return _result;
|
||||
|
@ -355,25 +355,25 @@
|
|||
return this.base instanceof LiteralNode && this.base.value.match(NUMBER);
|
||||
};
|
||||
ValueNode.prototype.cacheIndexes = function(o) {
|
||||
var _cache2, _cache3, _cache4, _index, copy, i;
|
||||
var _i, _l, _ref2, _ref3, copy, i;
|
||||
copy = new ValueNode(this.base, this.properties.slice(0));
|
||||
if (this.base instanceof CallNode) {
|
||||
_cache2 = this.base.compileReference(o);
|
||||
this.base = _cache2[0];
|
||||
copy.base = _cache2[1];
|
||||
_ref2 = this.base.compileReference(o);
|
||||
this.base = _ref2[0];
|
||||
copy.base = _ref2[1];
|
||||
}
|
||||
_cache3 = copy.properties;
|
||||
for (_index = 0, _cache4 = _cache3.length; _index < _cache4; _index++) {
|
||||
_ref3 = copy.properties;
|
||||
for (_i = 0, _l = _ref3.length; _i < _l; _i++) {
|
||||
(function() {
|
||||
var _cache5, index, indexVar;
|
||||
var i = _index;
|
||||
var prop = _cache3[_index];
|
||||
var _ref4, index, indexVar;
|
||||
var i = _i;
|
||||
var prop = _ref3[_i];
|
||||
if (prop instanceof IndexNode && prop.contains(function(n) {
|
||||
return n instanceof CallNode;
|
||||
})) {
|
||||
_cache5 = prop.index.compileReference(o);
|
||||
index = _cache5[0];
|
||||
indexVar = _cache5[1];
|
||||
_ref4 = prop.index.compileReference(o);
|
||||
index = _ref4[0];
|
||||
indexVar = _ref4[1];
|
||||
this.properties[i] = new IndexNode(index);
|
||||
return (copy.properties[i] = new IndexNode(indexVar));
|
||||
}
|
||||
|
@ -385,22 +385,22 @@
|
|||
return !o.top || this.properties.length ? ValueNode.__super__.compile.call(this, o) : this.base.compile(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 _i, _l, _l2, _ref2, _ref3, _ref4, 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);
|
||||
_cache2 = props;
|
||||
for (_index = 0, _cache3 = _cache2.length; _index < _cache3; _index++) {
|
||||
prop = _cache2[_index];
|
||||
_ref2 = props;
|
||||
for (_i = 0, _l = _ref2.length; _i < _l; _i++) {
|
||||
prop = _ref2[_i];
|
||||
if (prop.soakNode) {
|
||||
hasSoak = true;
|
||||
}
|
||||
}
|
||||
if (hasSoak && this.containsType(CallNode)) {
|
||||
_cache4 = this.cacheIndexes(o);
|
||||
me = _cache4[0];
|
||||
copy = _cache4[1];
|
||||
_ref3 = this.cacheIndexes(o);
|
||||
me = _ref3[0];
|
||||
copy = _ref3[1];
|
||||
}
|
||||
if (this.parenthetical && !props.length) {
|
||||
this.base.parenthetical = true;
|
||||
|
@ -410,13 +410,13 @@
|
|||
baseline = ("(" + (baseline) + ")");
|
||||
}
|
||||
complete = (this.last = baseline);
|
||||
_cache5 = props;
|
||||
for (i = 0, _cache6 = _cache5.length; i < _cache6; i++) {
|
||||
prop = _cache5[i];
|
||||
_ref4 = props;
|
||||
for (i = 0, _l2 = _ref4.length; i < _l2; i++) {
|
||||
prop = _ref4[i];
|
||||
this.source = baseline;
|
||||
if (prop.soakNode) {
|
||||
if (this.base.containsType(CallNode) && i === 0) {
|
||||
temp = o.scope.freeVariable('cache');
|
||||
temp = o.scope.freeVariable('ref');
|
||||
complete = ("(" + (baseline = temp) + " = (" + (complete) + "))");
|
||||
}
|
||||
complete = i === 0 ? ("(typeof " + (complete) + " === \"undefined\" || " + (baseline) + " === null) ? undefined : ") : ("" + (complete) + " == null ? undefined : ");
|
||||
|
@ -497,7 +497,7 @@
|
|||
})());
|
||||
};
|
||||
CallNode.prototype.compileNode = function(o) {
|
||||
var _cache2, _cache3, _cache4, _cache5, _cache6, _cache7, _index, _index2, _result, arg, args, code, first, meth, methodAccessor, op;
|
||||
var _i, _i2, _l, _l2, _ref2, _ref3, _ref4, _ref5, _result, arg, args, code, first, meth, methodAccessor, op;
|
||||
if (!(o.chainRoot)) {
|
||||
o.chainRoot = this;
|
||||
}
|
||||
|
@ -505,35 +505,35 @@
|
|||
if (this.exist) {
|
||||
if (this.variable instanceof ValueNode && this.variable.properties[this.variable.properties.length - 1] instanceof AccessorNode) {
|
||||
methodAccessor = this.variable.properties.pop();
|
||||
_cache2 = this.variable.compileReference(o);
|
||||
first = _cache2[0];
|
||||
meth = _cache2[1];
|
||||
_ref2 = this.variable.compileReference(o);
|
||||
first = _ref2[0];
|
||||
meth = _ref2[1];
|
||||
this.first = new ValueNode(first, [methodAccessor]).compile(o);
|
||||
this.meth = new ValueNode(meth, [methodAccessor]).compile(o);
|
||||
} else {
|
||||
_cache3 = this.variable.compileReference(o, {
|
||||
_ref3 = this.variable.compileReference(o, {
|
||||
precompile: true
|
||||
});
|
||||
this.first = _cache3[0];
|
||||
this.meth = _cache3[1];
|
||||
this.first = _ref3[0];
|
||||
this.meth = _ref3[1];
|
||||
}
|
||||
this.first = ("(typeof " + (this.first) + " === \"function\" ? ");
|
||||
this.last = " : undefined)";
|
||||
} else if (this.variable) {
|
||||
this.meth = this.variable.compile(o);
|
||||
}
|
||||
_cache4 = this.args;
|
||||
for (_index = 0, _cache5 = _cache4.length; _index < _cache5; _index++) {
|
||||
arg = _cache4[_index];
|
||||
_ref4 = this.args;
|
||||
for (_i = 0, _l = _ref4.length; _i < _l; _i++) {
|
||||
arg = _ref4[_i];
|
||||
if (arg instanceof SplatNode) {
|
||||
code = this.compileSplat(o);
|
||||
}
|
||||
}
|
||||
if (!code) {
|
||||
args = (function() {
|
||||
_result = []; _cache6 = this.args;
|
||||
for (_index2 = 0, _cache7 = _cache6.length; _index2 < _cache7; _index2++) {
|
||||
arg = _cache6[_index2];
|
||||
_result = []; _ref5 = this.args;
|
||||
for (_i2 = 0, _l2 = _ref5.length; _i2 < _l2; _i2++) {
|
||||
arg = _ref5[_i2];
|
||||
_result.push((function() {
|
||||
arg.parenthetical = true;
|
||||
return arg.compile(o);
|
||||
|
@ -549,29 +549,29 @@
|
|||
return "" + (this.superReference(o)) + ".call(this" + (args.length ? ', ' : '') + (args) + ")";
|
||||
};
|
||||
CallNode.prototype.compileSplat = function(o) {
|
||||
var _cache2, _cache3, _index, a, b, c, mentionsArgs, meth, obj, temp;
|
||||
var _i, _l, _ref2, a, b, c, mentionsArgs, meth, obj, temp;
|
||||
meth = this.meth || this.superReference(o);
|
||||
obj = this.variable && this.variable.source || 'this';
|
||||
if (obj.match(/\(/)) {
|
||||
temp = o.scope.freeVariable('cache');
|
||||
temp = o.scope.freeVariable('ref');
|
||||
obj = temp;
|
||||
meth = ("(" + (temp) + " = " + (this.variable.source) + ")" + (this.variable.last));
|
||||
}
|
||||
if (this.isNew) {
|
||||
mentionsArgs = false;
|
||||
_cache2 = this.args;
|
||||
for (_index = 0, _cache3 = _cache2.length; _index < _cache3; _index++) {
|
||||
_ref2 = this.args;
|
||||
for (_i = 0, _l = _ref2.length; _i < _l; _i++) {
|
||||
(function() {
|
||||
var arg = _cache2[_index];
|
||||
var arg = _ref2[_i];
|
||||
return arg.contains(function(n) {
|
||||
return mentionsArgs || (mentionsArgs = (n instanceof LiteralNode && (n.value === 'arguments')));
|
||||
});
|
||||
})();
|
||||
}
|
||||
utility('extends');
|
||||
a = o.scope.freeVariable('klass');
|
||||
b = o.scope.freeVariable('cache');
|
||||
c = o.scope.freeVariable('cache');
|
||||
a = o.scope.freeVariable('ctor');
|
||||
b = o.scope.freeVariable('instance');
|
||||
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 {
|
||||
return "" + (this.first) + (this.prefix()) + (meth) + ".apply(" + (obj) + ", " + (this.compileSplatArguments(o)) + ")" + (this.last);
|
||||
|
@ -647,23 +647,23 @@
|
|||
RangeNode.prototype["class"] = 'RangeNode';
|
||||
RangeNode.prototype.children = ['from', 'to'];
|
||||
RangeNode.prototype.compileVariables = function(o) {
|
||||
var _cache2, _cache3, _cache4, parts;
|
||||
var _ref2, _ref3, _ref4, parts;
|
||||
o = merge(o, {
|
||||
top: true
|
||||
});
|
||||
_cache2 = this.from.compileReference(o, {
|
||||
_ref2 = this.from.compileReference(o, {
|
||||
precompile: true
|
||||
});
|
||||
this.from = _cache2[0];
|
||||
this.fromVar = _cache2[1];
|
||||
_cache3 = this.to.compileReference(o, {
|
||||
this.from = _ref2[0];
|
||||
this.fromVar = _ref2[1];
|
||||
_ref3 = this.to.compileReference(o, {
|
||||
precompile: true
|
||||
});
|
||||
this.to = _cache3[0];
|
||||
this.toVar = _cache3[1];
|
||||
_cache4 = [this.fromVar.match(SIMPLENUM), this.toVar.match(SIMPLENUM)];
|
||||
this.fromNum = _cache4[0];
|
||||
this.toNum = _cache4[1];
|
||||
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];
|
||||
parts = [];
|
||||
if (this.from !== this.fromVar) {
|
||||
parts.push(this.from);
|
||||
|
@ -691,17 +691,17 @@
|
|||
return "" + (vars) + "; " + (compare) + "; " + (incr);
|
||||
};
|
||||
RangeNode.prototype.compileSimple = function(o) {
|
||||
var _cache2, from, idx, step, to;
|
||||
_cache2 = [parseInt(this.fromNum, 10), parseInt(this.toNum, 10)];
|
||||
from = _cache2[0];
|
||||
to = _cache2[1];
|
||||
var _ref2, from, idx, step, to;
|
||||
_ref2 = [parseInt(this.fromNum, 10), parseInt(this.toNum, 10)];
|
||||
from = _ref2[0];
|
||||
to = _ref2[1];
|
||||
idx = del(o, 'index');
|
||||
step = del(o, 'step');
|
||||
step && (step = ("" + (idx) + " += " + (step.compile(o))));
|
||||
return from <= to ? ("" + (idx) + " = " + (from) + "; " + (idx) + " <" + (this.equals) + " " + (to) + "; " + (step || ("" + (idx) + "++"))) : ("" + (idx) + " = " + (from) + "; " + (idx) + " >" + (this.equals) + " " + (to) + "; " + (step || ("" + (idx) + "--")));
|
||||
};
|
||||
RangeNode.prototype.compileArray = function(o) {
|
||||
var _index, _result, body, clause, i, idt, post, pre, range, result, vars;
|
||||
var _i, _result, body, clause, i, idt, post, pre, range, result, vars;
|
||||
idt = this.idt(1);
|
||||
vars = this.compileVariables(merge(o, {
|
||||
indent: idt
|
||||
|
@ -709,7 +709,7 @@
|
|||
if (this.fromNum && this.toNum && (Math.abs(+this.fromNum - +this.toNum) <= 20)) {
|
||||
range = (function() {
|
||||
_result = [];
|
||||
for (var _index = +this.fromNum; +this.fromNum <= +this.toNum ? _index <= +this.toNum : _index >= +this.toNum; +this.fromNum <= +this.toNum ? _index += 1 : _index -= 1){ _result.push(_index); }
|
||||
for (var _i = +this.fromNum; +this.fromNum <= +this.toNum ? _i <= +this.toNum : _i >= +this.toNum; +this.fromNum <= +this.toNum ? _i += 1 : _i -= 1){ _result.push(_i); }
|
||||
return _result;
|
||||
}).call(this);
|
||||
if (this.exclusive) {
|
||||
|
@ -717,7 +717,7 @@
|
|||
}
|
||||
return ("[" + (range.join(', ')) + "]");
|
||||
}
|
||||
i = o.scope.freeVariable('index');
|
||||
i = o.scope.freeVariable('i');
|
||||
result = o.scope.freeVariable('result');
|
||||
pre = ("\n" + (idt) + (result) + " = []; " + (vars));
|
||||
if (this.fromNum && this.toNum) {
|
||||
|
@ -766,13 +766,13 @@
|
|||
return true;
|
||||
};
|
||||
ObjectNode.prototype.compileNode = function(o) {
|
||||
var _cache2, _cache3, _cache4, _cache5, _index, _result, _result2, i, indent, join, lastNoncom, nonComments, obj, prop, props, top;
|
||||
var _i, _l, _l2, _ref2, _ref3, _result, _result2, i, indent, join, lastNoncom, nonComments, obj, prop, props, top;
|
||||
top = del(o, 'top');
|
||||
o.indent = this.idt(1);
|
||||
nonComments = (function() {
|
||||
_result = []; _cache2 = this.properties;
|
||||
for (_index = 0, _cache3 = _cache2.length; _index < _cache3; _index++) {
|
||||
prop = _cache2[_index];
|
||||
_result = []; _ref2 = this.properties;
|
||||
for (_i = 0, _l = _ref2.length; _i < _l; _i++) {
|
||||
prop = _ref2[_i];
|
||||
if (!(prop instanceof CommentNode)) {
|
||||
_result.push(prop);
|
||||
}
|
||||
|
@ -781,9 +781,9 @@
|
|||
}).call(this);
|
||||
lastNoncom = nonComments[nonComments.length - 1];
|
||||
props = (function() {
|
||||
_result2 = []; _cache4 = this.properties;
|
||||
for (i = 0, _cache5 = _cache4.length; i < _cache5; i++) {
|
||||
prop = _cache4[i];
|
||||
_result2 = []; _ref3 = this.properties;
|
||||
for (i = 0, _l2 = _ref3.length; i < _l2; i++) {
|
||||
prop = _ref3[i];
|
||||
_result2.push((function() {
|
||||
join = ",\n";
|
||||
if ((prop === lastNoncom) || (prop instanceof CommentNode)) {
|
||||
|
@ -821,12 +821,12 @@
|
|||
ArrayNode.prototype["class"] = 'ArrayNode';
|
||||
ArrayNode.prototype.children = ['objects'];
|
||||
ArrayNode.prototype.compileNode = function(o) {
|
||||
var _cache2, _cache3, code, i, obj, objects;
|
||||
var _l, _ref2, code, i, obj, objects;
|
||||
o.indent = this.idt(1);
|
||||
objects = [];
|
||||
_cache2 = this.objects;
|
||||
for (i = 0, _cache3 = _cache2.length; i < _cache3; i++) {
|
||||
obj = _cache2[i];
|
||||
_ref2 = this.objects;
|
||||
for (i = 0, _l = _ref2.length; i < _l; i++) {
|
||||
obj = _ref2[i];
|
||||
code = obj.compile(o);
|
||||
if (obj instanceof SplatNode) {
|
||||
return this.compileSplatLiteral(o);
|
||||
|
@ -864,9 +864,9 @@
|
|||
return this;
|
||||
};
|
||||
ClassNode.prototype.compileNode = function(o) {
|
||||
var _cache2, _cache3, _cache4, _index, access, applied, className, constScope, construct, constructor, extension, func, me, pname, prop, props, pvar, returns, val;
|
||||
var _i, _l, _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('klass'));
|
||||
this.variable = literal(o.scope.freeVariable('ctor'));
|
||||
}
|
||||
extension = this.parent && new ExtendsNode(this.variable, this.parent);
|
||||
props = new Expressions();
|
||||
|
@ -880,12 +880,12 @@
|
|||
} else {
|
||||
constructor = new CodeNode();
|
||||
}
|
||||
_cache2 = this.properties;
|
||||
for (_index = 0, _cache3 = _cache2.length; _index < _cache3; _index++) {
|
||||
prop = _cache2[_index];
|
||||
_cache4 = [prop.variable, prop.value];
|
||||
pvar = _cache4[0];
|
||||
func = _cache4[1];
|
||||
_ref2 = this.properties;
|
||||
for (_i = 0, _l = _ref2.length; _i < _l; _i++) {
|
||||
prop = _ref2[_i];
|
||||
_ref3 = [prop.variable, prop.value];
|
||||
pvar = _ref3[0];
|
||||
func = _ref3[1];
|
||||
if (pvar && pvar.base.value === 'constructor' && func instanceof CodeNode) {
|
||||
if (func.bound) {
|
||||
throw new Error("cannot define a constructor as a bound function.");
|
||||
|
@ -903,7 +903,7 @@
|
|||
} else {
|
||||
func.bound = false;
|
||||
constScope || (constScope = new Scope(o.scope, constructor.body, constructor));
|
||||
me || (me = constScope.freeVariable('self'));
|
||||
me || (me = constScope.freeVariable('this'));
|
||||
pname = pvar.compile(o);
|
||||
if (constructor.body.empty()) {
|
||||
constructor.body.push(new ReturnNode(literal('this')));
|
||||
|
@ -996,22 +996,22 @@
|
|||
return top || this.parenthetical ? val : ("(" + (val) + ")");
|
||||
};
|
||||
AssignNode.prototype.compilePatternMatch = function(o) {
|
||||
var _cache2, _cache3, _cache4, accessClass, assigns, code, i, idx, isString, obj, oindex, olength, splat, val, valVar, value;
|
||||
valVar = o.scope.freeVariable('cache');
|
||||
var _l, _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)) + ";")];
|
||||
o.top = true;
|
||||
o.asStatement = true;
|
||||
splat = false;
|
||||
_cache2 = this.variable.base.objects;
|
||||
for (i = 0, _cache3 = _cache2.length; i < _cache3; i++) {
|
||||
obj = _cache2[i];
|
||||
_ref2 = this.variable.base.objects;
|
||||
for (i = 0, _l = _ref2.length; i < _l; i++) {
|
||||
obj = _ref2[i];
|
||||
idx = i;
|
||||
if (this.variable.isObject()) {
|
||||
if (obj instanceof AssignNode) {
|
||||
_cache4 = [obj.value, obj.variable.base];
|
||||
obj = _cache4[0];
|
||||
idx = _cache4[1];
|
||||
_ref3 = [obj.value, obj.variable.base];
|
||||
obj = _ref3[0];
|
||||
idx = _ref3[1];
|
||||
} else {
|
||||
idx = obj;
|
||||
}
|
||||
|
@ -1067,7 +1067,7 @@
|
|||
CodeNode.prototype["class"] = 'CodeNode';
|
||||
CodeNode.prototype.children = ['params', 'body'];
|
||||
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 _i, _i2, _l, _l2, _l3, _ref2, _ref3, _ref4, _ref5, _ref6, _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);
|
||||
|
@ -1078,9 +1078,9 @@
|
|||
del(o, 'globals');
|
||||
splat = undefined;
|
||||
params = [];
|
||||
_cache2 = this.params;
|
||||
for (i = 0, _cache3 = _cache2.length; i < _cache3; i++) {
|
||||
param = _cache2[i];
|
||||
_ref2 = this.params;
|
||||
for (i = 0, _l = _ref2.length; i < _l; i++) {
|
||||
param = _ref2[i];
|
||||
if (splat) {
|
||||
if (param.attach) {
|
||||
param.assign = new AssignNode(new ValueNode(literal('this'), [new AccessorNode(param.value)]));
|
||||
|
@ -1089,11 +1089,11 @@
|
|||
splat.trailings.push(param);
|
||||
} else {
|
||||
if (param.attach) {
|
||||
_cache4 = param;
|
||||
value = _cache4.value;
|
||||
_cache5 = [literal(o.scope.freeVariable('arg')), param.splat];
|
||||
param = _cache5[0];
|
||||
param.splat = _cache5[1];
|
||||
_ref3 = param;
|
||||
value = _ref3.value;
|
||||
_ref4 = [literal(o.scope.freeVariable('arg')), param.splat];
|
||||
param = _ref4[0];
|
||||
param.splat = _ref4[1];
|
||||
this.body.unshift(new AssignNode(new ValueNode(literal('this'), [new AccessorNode(value)]), param));
|
||||
}
|
||||
if (param.splat) {
|
||||
|
@ -1108,9 +1108,9 @@
|
|||
}
|
||||
}
|
||||
params = (function() {
|
||||
_result = []; _cache6 = params;
|
||||
for (_index = 0, _cache7 = _cache6.length; _index < _cache7; _index++) {
|
||||
param = _cache6[_index];
|
||||
_result = []; _ref5 = params;
|
||||
for (_i = 0, _l2 = _ref5.length; _i < _l2; _i++) {
|
||||
param = _ref5[_i];
|
||||
_result.push(param.compile(o));
|
||||
}
|
||||
return _result;
|
||||
|
@ -1118,9 +1118,9 @@
|
|||
if (!(empty)) {
|
||||
this.body.makeReturn();
|
||||
}
|
||||
_cache8 = params;
|
||||
for (_index2 = 0, _cache9 = _cache8.length; _index2 < _cache9; _index2++) {
|
||||
param = _cache8[_index2];
|
||||
_ref6 = params;
|
||||
for (_i2 = 0, _l3 = _ref6.length; _i2 < _l3; _i2++) {
|
||||
param = _ref6[_i2];
|
||||
(o.scope.parameter(param));
|
||||
}
|
||||
code = this.body.expressions.length ? ("\n" + (this.body.compileWithDeclarations(o)) + "\n") : '';
|
||||
|
@ -1139,12 +1139,12 @@
|
|||
}
|
||||
};
|
||||
CodeNode.prototype.toString = function(idt) {
|
||||
var _cache2, _cache3, _index, _result, child, children;
|
||||
var _i, _l, _ref2, _result, child, children;
|
||||
idt || (idt = '');
|
||||
children = (function() {
|
||||
_result = []; _cache2 = this.collectChildren();
|
||||
for (_index = 0, _cache3 = _cache2.length; _index < _cache3; _index++) {
|
||||
child = _cache2[_index];
|
||||
_result = []; _ref2 = this.collectChildren();
|
||||
for (_i = 0, _l = _ref2.length; _i < _l; _i++) {
|
||||
child = _ref2[_i];
|
||||
_result.push(child.toString(idt + TAB));
|
||||
}
|
||||
return _result;
|
||||
|
@ -1186,23 +1186,23 @@
|
|||
SplatNode.prototype["class"] = 'SplatNode';
|
||||
SplatNode.prototype.children = ['name'];
|
||||
SplatNode.prototype.compileNode = function(o) {
|
||||
var _cache2;
|
||||
return (typeof (_cache2 = this.index) !== "undefined" && _cache2 !== null) ? this.compileParam(o) : this.name.compile(o);
|
||||
var _ref2;
|
||||
return (typeof (_ref2 = this.index) !== "undefined" && _ref2 !== null) ? this.compileParam(o) : this.name.compile(o);
|
||||
};
|
||||
SplatNode.prototype.compileParam = function(o) {
|
||||
var _cache2, _cache3, assign, end, idx, len, name, pos, trailing, variadic;
|
||||
var _l, _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('cache');
|
||||
len = o.scope.freeVariable('ref');
|
||||
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;
|
||||
_cache2 = this.trailings;
|
||||
for (idx = 0, _cache3 = _cache2.length; idx < _cache3; idx++) {
|
||||
trailing = _cache2[idx];
|
||||
_ref2 = this.trailings;
|
||||
for (idx = 0, _l = _ref2.length; idx < _l; idx++) {
|
||||
trailing = _ref2[idx];
|
||||
if (trailing.attach) {
|
||||
assign = trailing.assign;
|
||||
trailing = literal(o.scope.freeVariable('arg'));
|
||||
|
@ -1220,11 +1220,11 @@
|
|||
return "" + (utility('slice')) + ".call(" + (name) + ", " + (index) + (trail) + ")";
|
||||
};
|
||||
SplatNode.compileSplattedArray = function(list, o) {
|
||||
var _cache2, _cache3, arg, args, code, i, last, prev;
|
||||
var _l, _ref2, arg, args, code, i, last, prev;
|
||||
args = [];
|
||||
_cache2 = list;
|
||||
for (i = 0, _cache3 = _cache2.length; i < _cache3; i++) {
|
||||
arg = _cache2[i];
|
||||
_ref2 = list;
|
||||
for (i = 0, _l = _ref2.length; i < _l; i++) {
|
||||
arg = _ref2[i];
|
||||
code = arg.compile(o);
|
||||
prev = args[(last = args.length - 1)];
|
||||
if (!(arg instanceof SplatNode)) {
|
||||
|
@ -1339,12 +1339,12 @@
|
|||
return !this.second;
|
||||
};
|
||||
OpNode.prototype.isInvertible = function() {
|
||||
var _cache2;
|
||||
return (('===' === (_cache2 = this.operator) || '!==' === _cache2)) && !(this.first instanceof OpNode) && !(this.second instanceof OpNode);
|
||||
var _ref2;
|
||||
return (('===' === (_ref2 = this.operator) || '!==' === _ref2)) && !(this.first instanceof OpNode) && !(this.second instanceof OpNode);
|
||||
};
|
||||
OpNode.prototype.isMutator = function() {
|
||||
var _cache2;
|
||||
return ends(this.operator, '=') && !(('===' === (_cache2 = this.operator) || '!==' === _cache2));
|
||||
var _ref2;
|
||||
return ends(this.operator, '=') && !(('===' === (_ref2 = this.operator) || '!==' === _ref2));
|
||||
};
|
||||
OpNode.prototype.isChainable = function() {
|
||||
return include(this.CHAINABLE, this.operator);
|
||||
|
@ -1377,27 +1377,27 @@
|
|||
return [this.first.compile(o), this.operator, this.second.compile(o)].join(' ');
|
||||
};
|
||||
OpNode.prototype.compileChain = function(o) {
|
||||
var _cache2, _cache3, first, second, shared;
|
||||
var _ref2, _ref3, first, second, shared;
|
||||
shared = this.first.unwrap().second;
|
||||
if (shared.containsType(CallNode)) {
|
||||
_cache2 = shared.compileReference(o);
|
||||
this.first.second = _cache2[0];
|
||||
shared = _cache2[1];
|
||||
_ref2 = shared.compileReference(o);
|
||||
this.first.second = _ref2[0];
|
||||
shared = _ref2[1];
|
||||
}
|
||||
_cache3 = [this.first.compile(o), this.second.compile(o), shared.compile(o)];
|
||||
first = _cache3[0];
|
||||
second = _cache3[1];
|
||||
shared = _cache3[2];
|
||||
_ref3 = [this.first.compile(o), this.second.compile(o), shared.compile(o)];
|
||||
first = _ref3[0];
|
||||
second = _ref3[1];
|
||||
shared = _ref3[2];
|
||||
return "(" + (first) + ") && (" + (shared) + " " + (this.operator) + " " + (second) + ")";
|
||||
};
|
||||
OpNode.prototype.compileAssignment = function(o) {
|
||||
var _cache2, first, firstVar, second;
|
||||
_cache2 = this.first.compileReference(o, {
|
||||
var _ref2, first, firstVar, second;
|
||||
_ref2 = this.first.compileReference(o, {
|
||||
precompile: true,
|
||||
assignment: true
|
||||
});
|
||||
first = _cache2[0];
|
||||
firstVar = _cache2[1];
|
||||
first = _ref2[0];
|
||||
firstVar = _ref2[1];
|
||||
second = this.second.compile(o);
|
||||
if (this.second instanceof OpNode) {
|
||||
second = ("(" + (second) + ")");
|
||||
|
@ -1411,10 +1411,10 @@
|
|||
return "" + (first) + " " + (this.operator.substr(0, 2)) + " (" + (firstVar) + " = " + (second) + ")";
|
||||
};
|
||||
OpNode.prototype.compileExistence = function(o) {
|
||||
var _cache2, ref, test;
|
||||
_cache2 = ExistenceNode.compileTest(o, this.first);
|
||||
test = _cache2[0];
|
||||
ref = _cache2[1];
|
||||
var _ref2, ref, test;
|
||||
_ref2 = ExistenceNode.compileTest(o, this.first);
|
||||
test = _ref2[0];
|
||||
ref = _ref2[1];
|
||||
return "" + (test) + " ? " + (ref) + " : " + (this.second.compile(o));
|
||||
};
|
||||
OpNode.prototype.compileUnary = function(o) {
|
||||
|
@ -1442,20 +1442,20 @@
|
|||
return this.array instanceof ValueNode && this.array.isArray();
|
||||
};
|
||||
InNode.prototype.compileNode = function(o) {
|
||||
var _cache2;
|
||||
_cache2 = this.object.compileReference(o, {
|
||||
var _ref2;
|
||||
_ref2 = this.object.compileReference(o, {
|
||||
precompile: true
|
||||
});
|
||||
this.obj1 = _cache2[0];
|
||||
this.obj2 = _cache2[1];
|
||||
this.obj1 = _ref2[0];
|
||||
this.obj2 = _ref2[1];
|
||||
return this.isArray() ? this.compileOrTest(o) : this.compileLoopTest(o);
|
||||
};
|
||||
InNode.prototype.compileOrTest = function(o) {
|
||||
var _cache2, _cache3, _result, i, item, tests;
|
||||
var _l, _ref2, _result, i, item, tests;
|
||||
tests = (function() {
|
||||
_result = []; _cache2 = this.array.base.objects;
|
||||
for (i = 0, _cache3 = _cache2.length; i < _cache3; i++) {
|
||||
item = _cache2[i];
|
||||
_result = []; _ref2 = this.array.base.objects;
|
||||
for (i = 0, _l = _ref2.length; i < _l; i++) {
|
||||
item = _ref2[i];
|
||||
_result.push("" + (item.compile(o)) + " === " + (i ? this.obj2 : this.obj1));
|
||||
}
|
||||
return _result;
|
||||
|
@ -1463,15 +1463,15 @@
|
|||
return "(" + (tests.join(' || ')) + ")";
|
||||
};
|
||||
InNode.prototype.compileLoopTest = function(o) {
|
||||
var _cache2, _cache3, i, l, prefix;
|
||||
_cache2 = this.array.compileReference(o, {
|
||||
var _ref2, _ref3, i, l, prefix;
|
||||
_ref2 = this.array.compileReference(o, {
|
||||
precompile: true
|
||||
});
|
||||
this.arr1 = _cache2[0];
|
||||
this.arr2 = _cache2[1];
|
||||
_cache3 = [o.scope.freeVariable('index'), o.scope.freeVariable('cache')];
|
||||
i = _cache3[0];
|
||||
l = _cache3[1];
|
||||
this.arr1 = _ref2[0];
|
||||
this.arr2 = _ref2[1];
|
||||
_ref3 = [o.scope.freeVariable('i'), o.scope.freeVariable('l')];
|
||||
i = _ref3[0];
|
||||
l = _ref3[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)";
|
||||
};
|
||||
|
@ -1548,12 +1548,12 @@
|
|||
return this.parenthetical ? test.substring(1, test.length - 1) : test;
|
||||
};
|
||||
ExistenceNode.compileTest = function(o, variable) {
|
||||
var _cache2, first, second;
|
||||
_cache2 = variable.compileReference(o, {
|
||||
var _ref2, first, second;
|
||||
_ref2 = variable.compileReference(o, {
|
||||
precompile: true
|
||||
});
|
||||
first = _cache2[0];
|
||||
second = _cache2[1];
|
||||
first = _ref2[0];
|
||||
second = _ref2[1];
|
||||
return [("(typeof " + (first) + " !== \"undefined\" && " + (second) + " !== null)"), second];
|
||||
};
|
||||
return ExistenceNode;
|
||||
|
@ -1593,7 +1593,7 @@
|
|||
})();
|
||||
exports.ForNode = (function() {
|
||||
ForNode = function(_arg, source, _arg2, _arg3) {
|
||||
var _cache2;
|
||||
var _ref2;
|
||||
this.index = _arg3;
|
||||
this.name = _arg2;
|
||||
this.body = _arg;
|
||||
|
@ -1605,9 +1605,9 @@
|
|||
this.raw = !!source.raw;
|
||||
this.object = !!source.object;
|
||||
if (this.object) {
|
||||
_cache2 = [this.index, this.name];
|
||||
this.name = _cache2[0];
|
||||
this.index = _cache2[1];
|
||||
_ref2 = [this.index, this.name];
|
||||
this.name = _ref2[0];
|
||||
this.index = _ref2[1];
|
||||
}
|
||||
this.pattern = this.name instanceof ValueNode;
|
||||
if (this.index instanceof ValueNode) {
|
||||
|
@ -1647,7 +1647,7 @@
|
|||
return n instanceof CodeNode;
|
||||
});
|
||||
scope = o.scope;
|
||||
name = (this.name && this.name.compile(o)) || scope.freeVariable('index');
|
||||
name = (this.name && this.name.compile(o)) || scope.freeVariable('i');
|
||||
index = this.index && this.index.compile(o);
|
||||
if (name && !this.pattern && (range || !codeInBody)) {
|
||||
scope.find(name, {
|
||||
|
@ -1664,11 +1664,11 @@
|
|||
}
|
||||
ivar = (function() {
|
||||
if (codeInBody) {
|
||||
return scope.freeVariable('index');
|
||||
return scope.freeVariable('i');
|
||||
} else if (range) {
|
||||
return name;
|
||||
} else {
|
||||
return index || scope.freeVariable('index');
|
||||
return index || scope.freeVariable('i');
|
||||
}
|
||||
})();
|
||||
varPart = '';
|
||||
|
@ -1681,7 +1681,7 @@
|
|||
step: this.step
|
||||
}));
|
||||
} else {
|
||||
svar = scope.freeVariable('cache');
|
||||
svar = scope.freeVariable('ref');
|
||||
sourcePart = ("" + (svar) + " = " + (this.source.compile(o)) + ";");
|
||||
if (this.pattern) {
|
||||
namePart = new AssignNode(this.name, literal("" + (svar) + "[" + (ivar) + "]")).compile(merge(o, {
|
||||
|
@ -1694,7 +1694,7 @@
|
|||
}
|
||||
}
|
||||
if (!(this.object)) {
|
||||
lvar = scope.freeVariable('cache');
|
||||
lvar = scope.freeVariable('l');
|
||||
stepPart = this.step ? ("" + (ivar) + " += " + (this.step.compile(o))) : ("" + (ivar) + "++");
|
||||
forPart = ("" + (ivar) + " = 0, " + (lvar) + " = " + (svar) + ".length; " + (ivar) + " < " + (lvar) + "; " + (stepPart));
|
||||
}
|
||||
|
@ -1754,10 +1754,10 @@
|
|||
return true;
|
||||
};
|
||||
SwitchNode.prototype.makeReturn = function() {
|
||||
var _cache2, _cache3, _index, pair;
|
||||
_cache2 = this.cases;
|
||||
for (_index = 0, _cache3 = _cache2.length; _index < _cache3; _index++) {
|
||||
pair = _cache2[_index];
|
||||
var _i, _l, _ref2, pair;
|
||||
_ref2 = this.cases;
|
||||
for (_i = 0, _l = _ref2.length; _i < _l; _i++) {
|
||||
pair = _ref2[_i];
|
||||
pair[1].makeReturn();
|
||||
}
|
||||
if (this.otherwise) {
|
||||
|
@ -1766,20 +1766,20 @@
|
|||
return this;
|
||||
};
|
||||
SwitchNode.prototype.compileNode = function(o) {
|
||||
var _cache2, _cache3, _cache4, _cache5, _cache6, _index, _index2, block, code, condition, conditions, exprs, idt, pair;
|
||||
var _i, _i2, _l, _l2, _ref2, _ref3, _ref4, block, code, condition, conditions, exprs, idt, pair;
|
||||
idt = (o.indent = this.idt(1));
|
||||
o.top = true;
|
||||
code = ("" + (this.tab) + "switch (" + (this.subject.compile(o)) + ") {");
|
||||
_cache2 = this.cases;
|
||||
for (_index = 0, _cache3 = _cache2.length; _index < _cache3; _index++) {
|
||||
pair = _cache2[_index];
|
||||
_cache4 = pair;
|
||||
conditions = _cache4[0];
|
||||
block = _cache4[1];
|
||||
_ref2 = this.cases;
|
||||
for (_i = 0, _l = _ref2.length; _i < _l; _i++) {
|
||||
pair = _ref2[_i];
|
||||
_ref3 = pair;
|
||||
conditions = _ref3[0];
|
||||
block = _ref3[1];
|
||||
exprs = block.expressions;
|
||||
_cache5 = flatten([conditions]);
|
||||
for (_index2 = 0, _cache6 = _cache5.length; _index2 < _cache6; _index2++) {
|
||||
condition = _cache5[_index2];
|
||||
_ref4 = flatten([conditions]);
|
||||
for (_i2 = 0, _l2 = _ref4.length; _i2 < _l2; _i2++) {
|
||||
condition = _ref4[_i2];
|
||||
if (this.tags.subjectless) {
|
||||
condition = new OpNode('!!', new ParentheticalNode(condition));
|
||||
}
|
||||
|
@ -1844,15 +1844,15 @@
|
|||
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 _cache2, _cache3, _index, _result, cond, conditions;
|
||||
var _i, _l, _ref2, _result, cond, conditions;
|
||||
conditions = flatten([this.condition]);
|
||||
if (conditions.length === 1) {
|
||||
conditions[0].parenthetical = true;
|
||||
}
|
||||
return (function() {
|
||||
_result = []; _cache2 = conditions;
|
||||
for (_index = 0, _cache3 = _cache2.length; _index < _cache3; _index++) {
|
||||
cond = _cache2[_index];
|
||||
_result = []; _ref2 = conditions;
|
||||
for (_i = 0, _l = _ref2.length; _i < _l; _i++) {
|
||||
cond = _ref2[_i];
|
||||
_result.push(cond.compile(o));
|
||||
}
|
||||
return _result;
|
||||
|
|
|
@ -7,19 +7,19 @@
|
|||
return this;
|
||||
};
|
||||
OptionParser.prototype.parse = function(args) {
|
||||
var _cache, _cache2, _cache3, _cache4, _index, arg, i, isOption, matchedRule, options, rule, value;
|
||||
var _i, _l, _l2, _ref, _ref2, arg, i, isOption, matchedRule, options, rule, value;
|
||||
options = {
|
||||
arguments: []
|
||||
};
|
||||
args = normalizeArguments(args);
|
||||
_cache = args;
|
||||
for (i = 0, _cache2 = _cache.length; i < _cache2; i++) {
|
||||
arg = _cache[i];
|
||||
_ref = args;
|
||||
for (i = 0, _l = _ref.length; i < _l; i++) {
|
||||
arg = _ref[i];
|
||||
isOption = !!(arg.match(LONG_FLAG) || arg.match(SHORT_FLAG));
|
||||
matchedRule = false;
|
||||
_cache3 = this.rules;
|
||||
for (_index = 0, _cache4 = _cache3.length; _index < _cache4; _index++) {
|
||||
rule = _cache3[_index];
|
||||
_ref2 = this.rules;
|
||||
for (_i = 0, _l2 = _ref2.length; _i < _l2; _i++) {
|
||||
rule = _ref2[_i];
|
||||
if (rule.shortFlag === arg || rule.longFlag === arg) {
|
||||
value = rule.hasArgument ? args[i += 1] : true;
|
||||
options[rule.name] = rule.isList ? (options[rule.name] || []).concat(value) : value;
|
||||
|
@ -38,14 +38,14 @@
|
|||
return options;
|
||||
};
|
||||
OptionParser.prototype.help = function() {
|
||||
var _cache, _cache2, _index, _result, i, letPart, lines, rule, spaces;
|
||||
var _i, _l, _ref, _result, i, letPart, lines, rule, spaces;
|
||||
lines = ['Available options:'];
|
||||
if (this.banner) {
|
||||
lines.unshift("" + (this.banner) + "\n");
|
||||
}
|
||||
_cache = this.rules;
|
||||
for (_index = 0, _cache2 = _cache.length; _index < _cache2; _index++) {
|
||||
rule = _cache[_index];
|
||||
_ref = this.rules;
|
||||
for (_i = 0, _l = _ref.length; _i < _l; _i++) {
|
||||
rule = _ref[_i];
|
||||
spaces = 15 - rule.longFlag.length;
|
||||
spaces = spaces > 0 ? (function() {
|
||||
_result = [];
|
||||
|
@ -66,10 +66,10 @@
|
|||
MULTI_FLAG = /^-(\w{2,})/;
|
||||
OPTIONAL = /\[(\w+(\*?))\]/;
|
||||
buildRules = function(rules) {
|
||||
var _cache, _cache2, _index, _result, tuple;
|
||||
_result = []; _cache = rules;
|
||||
for (_index = 0, _cache2 = _cache.length; _index < _cache2; _index++) {
|
||||
tuple = _cache[_index];
|
||||
var _i, _l, _ref, _result, tuple;
|
||||
_result = []; _ref = rules;
|
||||
for (_i = 0, _l = _ref.length; _i < _l; _i++) {
|
||||
tuple = _ref[_i];
|
||||
_result.push((function() {
|
||||
if (tuple.length < 3) {
|
||||
tuple.unshift(null);
|
||||
|
@ -94,16 +94,16 @@
|
|||
};
|
||||
};
|
||||
normalizeArguments = function(args) {
|
||||
var _cache, _cache2, _cache3, _cache4, _index, _index2, arg, l, match, result;
|
||||
var _i, _i2, _l, _l2, _ref, _ref2, arg, l, match, result;
|
||||
args = args.slice(0);
|
||||
result = [];
|
||||
_cache = args;
|
||||
for (_index = 0, _cache2 = _cache.length; _index < _cache2; _index++) {
|
||||
arg = _cache[_index];
|
||||
_ref = args;
|
||||
for (_i = 0, _l = _ref.length; _i < _l; _i++) {
|
||||
arg = _ref[_i];
|
||||
if (match = arg.match(MULTI_FLAG)) {
|
||||
_cache3 = match[1].split('');
|
||||
for (_index2 = 0, _cache4 = _cache3.length; _index2 < _cache4; _index2++) {
|
||||
l = _cache3[_index2];
|
||||
_ref2 = match[1].split('');
|
||||
for (_i2 = 0, _l2 = _ref2.length; _i2 < _l2; _i2++) {
|
||||
l = _ref2[_i2];
|
||||
result.push('-' + l);
|
||||
}
|
||||
} else {
|
||||
|
|
120
lib/rewriter.js
120
lib/rewriter.js
|
@ -1,15 +1,15 @@
|
|||
(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, _i, _i2, _i3, _l, _l2, _l3, _ref, _ref2, _ref3, _ref4, _ref5, _result, _result2, helpers, include, pair;
|
||||
var __hasProp = Object.prototype.hasOwnProperty;
|
||||
if (typeof process !== "undefined" && process !== null) {
|
||||
_cache = require('./helpers');
|
||||
helpers = _cache.helpers;
|
||||
_ref = require('./helpers');
|
||||
helpers = _ref.helpers;
|
||||
} else {
|
||||
this.exports = this;
|
||||
helpers = this.helpers;
|
||||
}
|
||||
_cache2 = helpers;
|
||||
include = _cache2.include;
|
||||
_ref2 = helpers;
|
||||
include = _ref2.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 _cache3, _cache4, after, before, post, prev;
|
||||
var _ref3, _ref4, after, before, post, prev;
|
||||
if (token[0] !== 'HERECOMMENT') {
|
||||
return 1;
|
||||
}
|
||||
_cache3 = [this.tokens[i - 2], this.tokens[i - 1], this.tokens[i + 1], this.tokens[i + 2]];
|
||||
before = _cache3[0];
|
||||
prev = _cache3[1];
|
||||
post = _cache3[2];
|
||||
after = _cache3[3];
|
||||
_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];
|
||||
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' === (_cache4 = prev[0]) || 'INDENT' === _cache4 || 'OUTDENT' === _cache4)) {
|
||||
} else if (prev && !('TERMINATOR' === (_ref4 = prev[0]) || 'INDENT' === _ref4 || 'OUTDENT' === _ref4)) {
|
||||
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 _cache3;
|
||||
return ((')' === (_cache3 = token[0]) || 'CALL_END' === _cache3)) || (token[0] === 'OUTDENT' && this.tokens[i - 1][0] === ')');
|
||||
var _ref3;
|
||||
return ((')' === (_ref3 = token[0]) || 'CALL_END' === _ref3)) || (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 _cache3;
|
||||
return (']' === (_cache3 = token[0]) || 'INDEX_END' === _cache3);
|
||||
var _ref3;
|
||||
return (']' === (_ref3 = token[0]) || 'INDEX_END' === _ref3);
|
||||
};
|
||||
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 _cache3, _cache4, _cache5, one, three, two;
|
||||
_cache3 = this.tokens.slice(i + 1, i + 4);
|
||||
one = _cache3[0];
|
||||
two = _cache3[1];
|
||||
three = _cache3[2];
|
||||
var _ref3, _ref4, _ref5, one, three, two;
|
||||
_ref3 = this.tokens.slice(i + 1, i + 4);
|
||||
one = _ref3[0];
|
||||
two = _ref3[1];
|
||||
three = _ref3[2];
|
||||
if ((this.tag(i + 1) === 'HERECOMMENT' || this.tag(i - 1) === 'HERECOMMENT')) {
|
||||
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' === (_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)));
|
||||
};
|
||||
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 _cache3, action, callObject, condition, idx, next, prev, seenSingle;
|
||||
var _ref3, 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' === (_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' === (_ref3 = this.tag(i + 1)) || 'OF' === _ref3 || 'INSTANCEOF' === _ref3)))) || callObject) {
|
||||
this.tokens.splice(i, 0, ['CALL_START', '(', token[2]]);
|
||||
condition = function(token, i) {
|
||||
var _cache3, post;
|
||||
var _ref3, post;
|
||||
if (!seenSingle && token.fromThen) {
|
||||
return true;
|
||||
}
|
||||
if (('IF' === (_cache3 = token[0]) || 'ELSE' === _cache3 || 'UNLESS' === _cache3 || '->' === _cache3 || '=>' === _cache3)) {
|
||||
if (('IF' === (_ref3 = token[0]) || 'ELSE' === _ref3 || 'UNLESS' === _ref3 || '->' === _ref3 || '=>' === _ref3)) {
|
||||
seenSingle = true;
|
||||
}
|
||||
post = this.tokens[i + 1];
|
||||
|
@ -231,7 +231,7 @@
|
|||
};
|
||||
Rewriter.prototype.addImplicitIndentation = function() {
|
||||
return this.scanTokens(function(token, i) {
|
||||
var _cache3, action, condition, indent, outdent, starter;
|
||||
var _ref3, 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];
|
||||
_cache3 = this.indentation(token);
|
||||
indent = _cache3[0];
|
||||
outdent = _cache3[1];
|
||||
_ref3 = this.indentation(token);
|
||||
indent = _ref3[0];
|
||||
outdent = _ref3[1];
|
||||
if (starter === 'THEN') {
|
||||
indent.fromThen = true;
|
||||
}
|
||||
|
@ -269,12 +269,12 @@
|
|||
};
|
||||
Rewriter.prototype.tagPostfixConditionals = function() {
|
||||
return this.scanTokens(function(token, i) {
|
||||
var _cache3, action, condition, original;
|
||||
if (('IF' === (_cache3 = token[0]) || 'UNLESS' === _cache3)) {
|
||||
var _ref3, action, condition, original;
|
||||
if (('IF' === (_ref3 = token[0]) || 'UNLESS' === _ref3)) {
|
||||
original = token;
|
||||
condition = function(token, i) {
|
||||
var _cache3;
|
||||
return ('TERMINATOR' === (_cache3 = token[0]) || 'INDENT' === _cache3);
|
||||
var _ref3;
|
||||
return ('TERMINATOR' === (_ref3 = token[0]) || 'INDENT' === _ref3);
|
||||
};
|
||||
action = function(token, i) {
|
||||
if (token[0] !== 'INDENT') {
|
||||
|
@ -288,17 +288,17 @@
|
|||
});
|
||||
};
|
||||
Rewriter.prototype.ensureBalance = function(pairs) {
|
||||
var _cache3, _result, key, levels, line, open, openLine, unclosed, value;
|
||||
var _ref3, _result, key, levels, line, open, openLine, unclosed, value;
|
||||
levels = {};
|
||||
openLine = {};
|
||||
this.scanTokens(function(token, i) {
|
||||
var _cache3, _cache4, _cache5, _index, close, open, pair;
|
||||
_cache3 = pairs;
|
||||
for (_index = 0, _cache4 = _cache3.length; _index < _cache4; _index++) {
|
||||
pair = _cache3[_index];
|
||||
_cache5 = pair;
|
||||
open = _cache5[0];
|
||||
close = _cache5[1];
|
||||
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];
|
||||
levels[open] || (levels[open] = 0);
|
||||
if (token[0] === open) {
|
||||
if (levels[open] === 0) {
|
||||
|
@ -316,10 +316,10 @@
|
|||
return 1;
|
||||
});
|
||||
unclosed = (function() {
|
||||
_result = []; _cache3 = levels;
|
||||
for (key in _cache3) {
|
||||
if (!__hasProp.call(_cache3, key)) continue;
|
||||
value = _cache3[key];
|
||||
_result = []; _ref3 = levels;
|
||||
for (key in _ref3) {
|
||||
if (!__hasProp.call(_ref3, key)) continue;
|
||||
value = _ref3[key];
|
||||
if (value > 0) {
|
||||
_result.push(key);
|
||||
}
|
||||
|
@ -333,13 +333,13 @@
|
|||
}
|
||||
};
|
||||
Rewriter.prototype.rewriteClosingParens = function() {
|
||||
var _cache3, debt, key, stack, val;
|
||||
var _ref3, debt, key, stack, val;
|
||||
stack = [];
|
||||
debt = {};
|
||||
_cache3 = INVERSES;
|
||||
for (key in _cache3) {
|
||||
if (!__hasProp.call(_cache3, key)) continue;
|
||||
val = _cache3[key];
|
||||
_ref3 = INVERSES;
|
||||
for (key in _ref3) {
|
||||
if (!__hasProp.call(_ref3, key)) continue;
|
||||
val = _ref3[key];
|
||||
(debt[key] = 0);
|
||||
}
|
||||
return this.scanTokens(function(token, i) {
|
||||
|
@ -386,24 +386,24 @@
|
|||
})();
|
||||
BALANCED_PAIRS = [['(', ')'], ['[', ']'], ['{', '}'], ['INDENT', 'OUTDENT'], ['PARAM_START', 'PARAM_END'], ['CALL_START', 'CALL_END'], ['INDEX_START', 'INDEX_END']];
|
||||
INVERSES = {};
|
||||
_cache3 = BALANCED_PAIRS;
|
||||
for (_index = 0, _cache4 = _cache3.length; _index < _cache4; _index++) {
|
||||
pair = _cache3[_index];
|
||||
_ref3 = BALANCED_PAIRS;
|
||||
for (_i = 0, _l = _ref3.length; _i < _l; _i++) {
|
||||
pair = _ref3[_i];
|
||||
INVERSES[pair[0]] = pair[1];
|
||||
INVERSES[pair[1]] = pair[0];
|
||||
}
|
||||
EXPRESSION_START = (function() {
|
||||
_result = []; _cache5 = BALANCED_PAIRS;
|
||||
for (_index2 = 0, _cache6 = _cache5.length; _index2 < _cache6; _index2++) {
|
||||
pair = _cache5[_index2];
|
||||
_result = []; _ref4 = BALANCED_PAIRS;
|
||||
for (_i2 = 0, _l2 = _ref4.length; _i2 < _l2; _i2++) {
|
||||
pair = _ref4[_i2];
|
||||
_result.push(pair[0]);
|
||||
}
|
||||
return _result;
|
||||
})();
|
||||
EXPRESSION_END = (function() {
|
||||
_result2 = []; _cache7 = BALANCED_PAIRS;
|
||||
for (_index3 = 0, _cache8 = _cache7.length; _index3 < _cache8; _index3++) {
|
||||
pair = _cache7[_index3];
|
||||
_result2 = []; _ref5 = BALANCED_PAIRS;
|
||||
for (_i3 = 0, _l3 = _ref5.length; _i3 < _l3; _i3++) {
|
||||
pair = _ref5[_i3];
|
||||
_result2.push(pair[1]);
|
||||
}
|
||||
return _result2;
|
||||
|
|
64
lib/scope.js
64
lib/scope.js
|
@ -1,25 +1,24 @@
|
|||
(function() {
|
||||
var Scope;
|
||||
var Scope, _ref, extend, helpers;
|
||||
var __hasProp = Object.prototype.hasOwnProperty;
|
||||
if (!(typeof process !== "undefined" && process !== null)) {
|
||||
if (typeof process !== "undefined" && process !== null) {
|
||||
helpers = require('./helpers').helpers;
|
||||
} else {
|
||||
this.exports = this;
|
||||
}
|
||||
_ref = helpers;
|
||||
extend = _ref.extend;
|
||||
exports.Scope = (function() {
|
||||
Scope = function(parent, expressions, method) {
|
||||
var _cache, _cache2, k, val;
|
||||
_cache = [parent, expressions, method];
|
||||
this.parent = _cache[0];
|
||||
this.expressions = _cache[1];
|
||||
this.method = _cache[2];
|
||||
var _ref2;
|
||||
_ref2 = [parent, expressions, method];
|
||||
this.parent = _ref2[0];
|
||||
this.expressions = _ref2[1];
|
||||
this.method = _ref2[2];
|
||||
this.variables = {};
|
||||
this.tempVars = {};
|
||||
this.generated = {};
|
||||
if (this.parent) {
|
||||
_cache2 = this.parent.tempVars;
|
||||
for (k in _cache2) {
|
||||
if (!__hasProp.call(_cache2, k)) continue;
|
||||
val = _cache2[k];
|
||||
(this.tempVars[k] = val);
|
||||
}
|
||||
extend(this.generated, this.parent.generated);
|
||||
} else {
|
||||
Scope.root = this;
|
||||
}
|
||||
|
@ -34,11 +33,11 @@
|
|||
return false;
|
||||
};
|
||||
Scope.prototype.any = function(fn) {
|
||||
var _cache, k, v;
|
||||
_cache = this.variables;
|
||||
for (v in _cache) {
|
||||
if (!__hasProp.call(_cache, v)) continue;
|
||||
k = _cache[v];
|
||||
var _ref2, k, v;
|
||||
_ref2 = this.variables;
|
||||
for (v in _ref2) {
|
||||
if (!__hasProp.call(_ref2, v)) continue;
|
||||
k = _ref2[v];
|
||||
if (fn(v, k)) {
|
||||
return true;
|
||||
}
|
||||
|
@ -57,12 +56,13 @@
|
|||
return !!(this.parent && this.parent.check(name));
|
||||
};
|
||||
Scope.prototype.temporary = function(type, index) {
|
||||
return '_' + type + ((index) > 1 ? index : '');
|
||||
return '_' + type + (index > 1 ? index : '');
|
||||
};
|
||||
Scope.prototype.freeVariable = function(type) {
|
||||
var temp;
|
||||
while (this.check(temp = this.temporary(type, this.tempVars[type] || (this.tempVars[type] = 1)))) {
|
||||
this.tempVars[type]++;
|
||||
this.generated[type] || (this.generated[type] = 1);
|
||||
while (this.check(temp = this.temporary(type, this.generated[type]))) {
|
||||
this.generated[type]++;
|
||||
}
|
||||
this.variables[temp] = 'var';
|
||||
return temp;
|
||||
|
@ -84,12 +84,12 @@
|
|||
});
|
||||
};
|
||||
Scope.prototype.declaredVariables = function() {
|
||||
var _cache, _result, key, val;
|
||||
var _ref2, _result, key, val;
|
||||
return (function() {
|
||||
_result = []; _cache = this.variables;
|
||||
for (key in _cache) {
|
||||
if (!__hasProp.call(_cache, key)) continue;
|
||||
val = _cache[key];
|
||||
_result = []; _ref2 = this.variables;
|
||||
for (key in _ref2) {
|
||||
if (!__hasProp.call(_ref2, key)) continue;
|
||||
val = _ref2[key];
|
||||
if (val === 'var') {
|
||||
_result.push(key);
|
||||
}
|
||||
|
@ -98,11 +98,11 @@
|
|||
}).call(this).sort();
|
||||
};
|
||||
Scope.prototype.assignedVariables = function() {
|
||||
var _cache, _result, key, val;
|
||||
_result = []; _cache = this.variables;
|
||||
for (key in _cache) {
|
||||
if (!__hasProp.call(_cache, key)) continue;
|
||||
val = _cache[key];
|
||||
var _ref2, _result, key, val;
|
||||
_result = []; _ref2 = this.variables;
|
||||
for (key in _ref2) {
|
||||
if (!__hasProp.call(_ref2, key)) continue;
|
||||
val = _ref2[key];
|
||||
if (val.assigned) {
|
||||
_result.push("" + (key) + " = " + (val.value));
|
||||
}
|
||||
|
|
|
@ -70,7 +70,7 @@ exports.BaseNode = class BaseNode
|
|||
else if this instanceof ValueNode and options.assignment
|
||||
this.cacheIndexes(o)
|
||||
else
|
||||
reference = literal o.scope.freeVariable 'cache'
|
||||
reference = literal o.scope.freeVariable 'ref'
|
||||
compiled = new AssignNode reference, this
|
||||
[compiled, reference]
|
||||
return [pair[0].compile(o), pair[1].compile(o)] if options.precompile
|
||||
|
@ -374,7 +374,7 @@ exports.ValueNode = class ValueNode extends BaseNode
|
|||
@source = baseline
|
||||
if prop.soakNode
|
||||
if @base.containsType(CallNode) and i is 0
|
||||
temp = o.scope.freeVariable 'cache'
|
||||
temp = o.scope.freeVariable 'ref'
|
||||
complete = "(#{ baseline = temp } = (#{complete}))"
|
||||
complete = if i is 0
|
||||
"(typeof #{complete} === \"undefined\" || #{baseline} === null) ? undefined : "
|
||||
|
@ -488,7 +488,7 @@ exports.CallNode = class CallNode extends BaseNode
|
|||
meth = @meth or @superReference(o)
|
||||
obj = @variable and @variable.source or 'this'
|
||||
if obj.match(/\(/)
|
||||
temp = o.scope.freeVariable 'cache'
|
||||
temp = o.scope.freeVariable 'ref'
|
||||
obj = temp
|
||||
meth = "(#{temp} = #{ @variable.source })#{ @variable.last }"
|
||||
if @isNew
|
||||
|
@ -496,9 +496,9 @@ exports.CallNode = class CallNode extends BaseNode
|
|||
for arg in @args
|
||||
arg.contains (n) -> mentionsArgs or= n instanceof LiteralNode and (n.value is 'arguments')
|
||||
utility 'extends'
|
||||
a = o.scope.freeVariable 'klass'
|
||||
b = o.scope.freeVariable 'cache'
|
||||
c = o.scope.freeVariable 'cache'
|
||||
a = o.scope.freeVariable 'ctor'
|
||||
b = o.scope.freeVariable 'instance'
|
||||
c = o.scope.freeVariable 'result'
|
||||
"""
|
||||
#{@first}(function() {
|
||||
#{@idt(1)}var ctor = function(){};
|
||||
|
@ -624,7 +624,7 @@ exports.RangeNode = class RangeNode extends BaseNode
|
|||
range = [+@fromNum..+@toNum]
|
||||
range.pop() if @exclusive
|
||||
return "[#{ range.join(', ') }]"
|
||||
i = o.scope.freeVariable 'index'
|
||||
i = o.scope.freeVariable 'i'
|
||||
result = o.scope.freeVariable 'result'
|
||||
pre = "\n#{idt}#{result} = []; #{vars}"
|
||||
if @fromNum and @toNum
|
||||
|
@ -743,7 +743,7 @@ exports.ClassNode = class ClassNode extends BaseNode
|
|||
# equivalent syntax tree and compile that, in pieces. You can see the
|
||||
# constructor, property assignments, and inheritance getting built out below.
|
||||
compileNode: (o) ->
|
||||
@variable = literal o.scope.freeVariable 'klass' if @variable is '__temp__'
|
||||
@variable = literal o.scope.freeVariable 'ctor' if @variable is '__temp__'
|
||||
extension = @parent and new ExtendsNode(@variable, @parent)
|
||||
props = new Expressions
|
||||
o.top = true
|
||||
|
@ -775,7 +775,7 @@ exports.ClassNode = class ClassNode extends BaseNode
|
|||
else
|
||||
func.bound = false
|
||||
constScope or= new Scope(o.scope, constructor.body, constructor)
|
||||
me or= constScope.freeVariable 'self'
|
||||
me or= constScope.freeVariable 'this'
|
||||
pname = pvar.compile(o)
|
||||
constructor.body.push new ReturnNode literal 'this' if constructor.body.empty()
|
||||
constructor.body.unshift literal "this.#{pname} = function(){ return #{className}.prototype.#{pname}.apply(#{me}, arguments); }"
|
||||
|
@ -851,7 +851,7 @@ exports.AssignNode = class AssignNode extends BaseNode
|
|||
# See the [ECMAScript Harmony Wiki](http://wiki.ecmascript.org/doku.php?id=harmony:destructuring)
|
||||
# for details.
|
||||
compilePatternMatch: (o) ->
|
||||
valVar = o.scope.freeVariable 'cache'
|
||||
valVar = o.scope.freeVariable 'ref'
|
||||
value = if @value.isStatement(o) then ClosureNode.wrap(@value) else @value
|
||||
assigns = ["#{@tab}#{valVar} = #{ value.compile(o) };"]
|
||||
o.top = true
|
||||
|
@ -1011,7 +1011,7 @@ exports.SplatNode = class SplatNode extends BaseNode
|
|||
o.scope.find name
|
||||
end = ''
|
||||
if @trailings.length
|
||||
len = o.scope.freeVariable 'cache'
|
||||
len = o.scope.freeVariable 'ref'
|
||||
o.scope.assign len, "arguments.length"
|
||||
variadic = o.scope.freeVariable 'result'
|
||||
o.scope.assign variadic, len + ' >= ' + @arglength
|
||||
|
@ -1227,7 +1227,7 @@ exports.InNode = class InNode extends BaseNode
|
|||
|
||||
compileLoopTest: (o) ->
|
||||
[@arr1, @arr2] = @array.compileReference o, precompile: yes
|
||||
[i, l] = [o.scope.freeVariable('index'), o.scope.freeVariable('cache')]
|
||||
[i, l] = [o.scope.freeVariable('i'), o.scope.freeVariable('l')]
|
||||
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)"
|
||||
|
||||
|
@ -1385,12 +1385,12 @@ exports.ForNode = class ForNode extends BaseNode
|
|||
source = if range then @source.base else @source
|
||||
codeInBody = @body.contains (n) -> n instanceof CodeNode
|
||||
scope = o.scope
|
||||
name = (@name and @name.compile(o)) or scope.freeVariable 'index'
|
||||
name = (@name and @name.compile(o)) or scope.freeVariable 'i'
|
||||
index = @index and @index.compile o
|
||||
scope.find(name, immediate: yes) if name and not @pattern and (range or not codeInBody)
|
||||
scope.find(index, immediate: yes) if index
|
||||
rvar = scope.freeVariable 'result' unless topLevel
|
||||
ivar = if codeInBody then scope.freeVariable 'index' else if range then name else index or scope.freeVariable 'index'
|
||||
ivar = if codeInBody then scope.freeVariable 'i' else if range then name else index or scope.freeVariable 'i'
|
||||
varPart = ''
|
||||
guardPart = ''
|
||||
body = Expressions.wrap([@body])
|
||||
|
@ -1398,14 +1398,14 @@ exports.ForNode = class ForNode extends BaseNode
|
|||
sourcePart = source.compileVariables(o)
|
||||
forPart = source.compile merge o, index: ivar, step: @step
|
||||
else
|
||||
svar = scope.freeVariable 'cache'
|
||||
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'
|
||||
else
|
||||
namePart = "#{name} = #{svar}[#{ivar}]" if name
|
||||
unless @object
|
||||
lvar = scope.freeVariable 'cache'
|
||||
lvar = scope.freeVariable 'l'
|
||||
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
|
||||
|
|
|
@ -6,7 +6,13 @@
|
|||
# with the outside.
|
||||
|
||||
# Set up exported variables for both **Node.js** and the browser.
|
||||
this.exports = this unless process?
|
||||
if process?
|
||||
helpers = require('./helpers').helpers
|
||||
else
|
||||
this.exports = this
|
||||
|
||||
# Import the helpers we plan to use.
|
||||
{extend} = helpers
|
||||
|
||||
exports.Scope = class Scope
|
||||
|
||||
|
@ -20,9 +26,9 @@ exports.Scope = class Scope
|
|||
constructor: (parent, expressions, method) ->
|
||||
[@parent, @expressions, @method] = [parent, expressions, method]
|
||||
@variables = {}
|
||||
@tempVars = {}
|
||||
@generated = {}
|
||||
if @parent
|
||||
(@tempVars[k] = val) for k, val of @parent.tempVars
|
||||
extend @generated, @parent.generated
|
||||
else
|
||||
Scope.root = this
|
||||
|
||||
|
@ -53,12 +59,13 @@ exports.Scope = class Scope
|
|||
|
||||
# Generate a temporary variable name at the given index.
|
||||
temporary: (type, index) ->
|
||||
'_' + type + (if (index) > 1 then index else '')
|
||||
'_' + type + if index > 1 then index else ''
|
||||
|
||||
# If we need to store an intermediate result, find an available name for a
|
||||
# compiler-generated variable. `_var`, `_var2`, and so on...
|
||||
freeVariable: (type) ->
|
||||
@tempVars[type]++ while @check temp = @temporary type, @tempVars[type] or= 1
|
||||
@generated[type] or= 1
|
||||
@generated[type]++ while @check temp = @temporary type, @generated[type]
|
||||
@variables[temp] = 'var'
|
||||
temp
|
||||
|
||||
|
@ -90,6 +97,6 @@ exports.Scope = class Scope
|
|||
compiledDeclarations: ->
|
||||
@declaredVariables().join ', '
|
||||
|
||||
# Compile the JavaScript for all of the variable assignments in this scope.
|
||||
# Compile the JavaScript forall of the variable assignments in this scope.
|
||||
compiledAssignments: ->
|
||||
@assignedVariables().join ', '
|
||||
|
|
Loading…
Reference in New Issue