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