mirror of
https://github.com/jashkenas/coffeescript.git
synced 2022-11-09 12:23:24 -05:00
Merge branch 'master' of github.com:jashkenas/coffee-script
This commit is contained in:
commit
84dcd6fe2f
23 changed files with 81 additions and 85 deletions
2
Rakefile
2
Rakefile
|
@ -17,7 +17,7 @@ EOS
|
|||
desc "Build the documentation page"
|
||||
task :doc do
|
||||
source = 'documentation/index.html.erb'
|
||||
child = fork { exec "bin/coffee --no-wrap -cw -o documentation/js documentation/coffee/*.coffee" }
|
||||
child = fork { exec "bin/coffee -bcw -o documentation/js documentation/coffee/*.coffee" }
|
||||
at_exit { Process.kill("INT", child) }
|
||||
Signal.trap("INT") { exit }
|
||||
loop do
|
||||
|
|
|
@ -265,7 +265,7 @@ sudo npm install coffee-script</pre>
|
|||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>--no-wrap</code></td>
|
||||
<td><code>-b, --bare</code></td>
|
||||
<td>
|
||||
Compile the JavaScript without the top-level function safety wrapper.
|
||||
(Used for CoffeeScript as a Node.js module.)
|
||||
|
@ -1309,7 +1309,7 @@ coffee --print app/scripts/*.coffee > concatenation.js</pre>
|
|||
source = $('#repl_source').val()
|
||||
window.compiled_js = ''
|
||||
try
|
||||
window.compiled_js = CoffeeScript.compile source, wrap: false
|
||||
window.compiled_js = CoffeeScript.compile source, bare: on
|
||||
$('#repl_results').text window.compiled_js
|
||||
$('#error').hide()
|
||||
catch error
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -347,7 +347,7 @@ sudo npm install coffee-script</pre>
|
|||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>--no-wrap</code></td>
|
||||
<td><code>-b, --bare</code></td>
|
||||
<td>
|
||||
Compile the JavaScript without the top-level function safety wrapper.
|
||||
(Used for CoffeeScript as a Node.js module.)
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
return eval(CoffeeScript.compile(code, options));
|
||||
};
|
||||
CoffeeScript.run = function(code, options) {
|
||||
((options != null) ? (options.wrap = false) : undefined);
|
||||
((options != null) ? (options.bare = true) : undefined);
|
||||
return Function(CoffeeScript.compile(code, options))();
|
||||
};
|
||||
if (!(typeof window !== "undefined" && window !== null)) {
|
||||
|
|
|
@ -37,7 +37,7 @@
|
|||
if (!exists) {
|
||||
throw new Error("Cakefile not found in " + (process.cwd()));
|
||||
}
|
||||
args = process.argv.slice(2, process.argv.length);
|
||||
args = process.argv.slice(2);
|
||||
CoffeeScript.run(fs.readFileSync('Cakefile').toString(), {
|
||||
fileName: 'Cakefile'
|
||||
});
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
helpers.extend(CoffeeScript, new EventEmitter);
|
||||
global.CoffeeScript = CoffeeScript;
|
||||
BANNER = 'coffee compiles CoffeeScript source files into JavaScript.\n\nUsage:\n coffee path/to/script.coffee';
|
||||
SWITCHES = [['-c', '--compile', 'compile to JavaScript and save as .js files'], ['-i', '--interactive', 'run an interactive CoffeeScript REPL'], ['-o', '--output [DIR]', 'set the directory for compiled JavaScript'], ['-w', '--watch', 'watch scripts for changes, and recompile'], ['-p', '--print', 'print the compiled JavaScript to stdout'], ['-l', '--lint', 'pipe the compiled JavaScript through JSLint'], ['-s', '--stdio', 'listen for and compile scripts over stdio'], ['-e', '--eval', 'compile a string from the command line'], ['-r', '--require [FILE*]', 'require a library before executing your script'], ['--no-wrap', 'compile without the top-level function wrapper'], ['-t', '--tokens', 'print the tokens that the lexer produces'], ['-n', '--nodes', 'print the parse tree that Jison produces'], ['-v', '--version', 'display CoffeeScript version'], ['-h', '--help', 'display this help message']];
|
||||
SWITCHES = [['-c', '--compile', 'compile to JavaScript and save as .js files'], ['-i', '--interactive', 'run an interactive CoffeeScript REPL'], ['-o', '--output [DIR]', 'set the directory for compiled JavaScript'], ['-w', '--watch', 'watch scripts for changes, and recompile'], ['-p', '--print', 'print the compiled JavaScript to stdout'], ['-l', '--lint', 'pipe the compiled JavaScript through JSLint'], ['-s', '--stdio', 'listen for and compile scripts over stdio'], ['-e', '--eval', 'compile a string from the command line'], ['-r', '--require [FILE*]', 'require a library before executing your script'], ['-b', '--bare', 'compile without the top-level function wrapper'], ['-t', '--tokens', 'print the tokens that the lexer produces'], ['-n', '--nodes', 'print the parse tree that Jison produces'], ['-v', '--version', 'display CoffeeScript version'], ['-h', '--help', 'display this help message']];
|
||||
opts = {};
|
||||
sources = [];
|
||||
optionParser = null;
|
||||
|
@ -38,12 +38,11 @@
|
|||
separator = sources.indexOf('--');
|
||||
flags = [];
|
||||
if (separator >= 0) {
|
||||
flags = sources.slice((separator + 1), sources.length);
|
||||
sources = sources.slice(0, separator);
|
||||
flags = sources.splice(separator + 1);
|
||||
sources.pop();
|
||||
}
|
||||
if (opts.run) {
|
||||
flags = sources.slice(1, sources.length + 1).concat(flags);
|
||||
sources = [sources[0]];
|
||||
flags = sources.splice(1).concat(flags);
|
||||
}
|
||||
process.ARGV = (process.argv = flags);
|
||||
return compileScripts();
|
||||
|
@ -204,19 +203,17 @@
|
|||
parseOptions = function() {
|
||||
var o;
|
||||
optionParser = new optparse.OptionParser(SWITCHES, BANNER);
|
||||
o = (opts = optionParser.parse(process.argv.slice(2, process.argv.length)));
|
||||
o = (opts = optionParser.parse(process.argv.slice(2)));
|
||||
o.compile || (o.compile = !!o.output);
|
||||
o.run = !(o.compile || o.print || o.lint);
|
||||
o.print = !!(o.print || (o.eval || o.stdio && o.compile));
|
||||
return (sources = o.arguments);
|
||||
};
|
||||
compileOptions = function(fileName) {
|
||||
var o;
|
||||
o = {
|
||||
fileName: fileName
|
||||
return {
|
||||
fileName: fileName,
|
||||
bare: opts.bare
|
||||
};
|
||||
o.wrap = !opts['no-wrap'];
|
||||
return o;
|
||||
};
|
||||
usage = function() {
|
||||
puts(optionParser.help());
|
||||
|
|
|
@ -245,7 +245,7 @@
|
|||
prev = last(this.tokens, 1);
|
||||
size = indent.length - 1 - indent.lastIndexOf('\n');
|
||||
nextCharacter = NEXT_CHARACTER.exec(this.chunk)[1];
|
||||
noNewlines = (('.' === nextCharacter || ',' === nextCharacter) && !NEXT_ELLIPSIS.test(this.chunk)) || this.unfinished();
|
||||
noNewlines = ((nextCharacter === '.' || nextCharacter === ',') && !NEXT_ELLIPSIS.test(this.chunk)) || this.unfinished();
|
||||
if (size - this.indebt === this.indent) {
|
||||
if (noNewlines) {
|
||||
return this.suppressNewlines();
|
||||
|
@ -335,7 +335,7 @@
|
|||
if (!prev[1].reserved && include(JS_FORBIDDEN, prev[1])) {
|
||||
this.assignmentError();
|
||||
}
|
||||
if (('||' === (_ref2 = prev[1]) || '&&' === _ref2)) {
|
||||
if (((_ref2 = prev[1]) === '||' || _ref2 === '&&')) {
|
||||
prev[0] = 'COMPOUND_ASSIGN';
|
||||
prev[1] += '=';
|
||||
return true;
|
||||
|
@ -575,7 +575,7 @@
|
|||
return quote + quote;
|
||||
}
|
||||
body = body.replace(/\\([\s\S])/g, function(match, contents) {
|
||||
return ('\n' === contents || quote === contents) ? contents : match;
|
||||
return (contents === '\n' || contents === quote) ? contents : match;
|
||||
});
|
||||
body = body.replace(RegExp("" + quote, "g"), '\\$&');
|
||||
return quote + this.escapeLines(body, heredoc) + quote;
|
||||
|
|
28
lib/nodes.js
28
lib/nodes.js
|
@ -1,10 +1,9 @@
|
|||
(function() {
|
||||
var Accessor, ArrayLiteral, Assign, Base, Call, Class, Closure, Code, Comment, Existence, Expressions, Extends, For, IDENTIFIER, IS_STRING, If, In, Index, Literal, NO, NUMBER, ObjectLiteral, Op, Param, Parens, Push, Range, Return, SIMPLENUM, Scope, Slice, Splat, Switch, TAB, THIS, TRAILING_WHITESPACE, Throw, Try, UTILITIES, Value, While, YES, _ref, compact, del, ends, flatten, include, last, merge, starts, utility;
|
||||
var __extends = function(child, parent) {
|
||||
var ctor = function() {};
|
||||
function ctor() { this.constructor = child; }
|
||||
ctor.prototype = parent.prototype;
|
||||
child.prototype = new ctor();
|
||||
child.prototype.constructor = child;
|
||||
child.prototype = new ctor;
|
||||
if (typeof parent.extended === "function") parent.extended(child);
|
||||
child.__super__ = parent.prototype;
|
||||
};
|
||||
|
@ -206,16 +205,15 @@
|
|||
_result.push(this.compileExpression(node, merge(o)));
|
||||
}
|
||||
return _result;
|
||||
}).call(this).join("\n");
|
||||
}).call(this).join('\n');
|
||||
};
|
||||
Expressions.prototype.compileRoot = function(o) {
|
||||
var code, wrap;
|
||||
wrap = (o.wrap != null) ? o.wrap : true;
|
||||
o.indent = (this.tab = wrap ? TAB : '');
|
||||
var code;
|
||||
o.indent = (this.tab = o.bare ? '' : TAB);
|
||||
o.scope = new Scope(null, this, null);
|
||||
code = this.compileWithDeclarations(o);
|
||||
code = code.replace(TRAILING_WHITESPACE, '');
|
||||
return wrap ? ("(function() {\n" + code + "\n}).call(this);\n") : code;
|
||||
return o.bare ? code : ("(function() {\n" + code + "\n}).call(this);\n");
|
||||
};
|
||||
Expressions.prototype.compileWithDeclarations = function(o) {
|
||||
var code;
|
||||
|
@ -260,7 +258,7 @@
|
|||
};
|
||||
Literal.prototype.isStatement = function() {
|
||||
var _ref2;
|
||||
return ('break' === (_ref2 = this.value) || 'continue' === _ref2 || 'debugger' === _ref2);
|
||||
return ((_ref2 = this.value) === 'break' || _ref2 === 'continue' || _ref2 === 'debugger');
|
||||
};
|
||||
Literal.prototype.isPureStatement = Literal.prototype.isStatement;
|
||||
Literal.prototype.isComplex = NO;
|
||||
|
@ -1139,8 +1137,8 @@
|
|||
o.top = true;
|
||||
o.indent = this.idt(1);
|
||||
empty = this.body.expressions.length === 0;
|
||||
del(o, 'wrap');
|
||||
del(o, 'globals');
|
||||
delete o.bare;
|
||||
delete o.globals;
|
||||
splat = undefined;
|
||||
params = [];
|
||||
for (i = 0, _len = (_ref2 = this.params).length; i < _len; i++) {
|
||||
|
@ -1399,14 +1397,14 @@
|
|||
};
|
||||
Op.prototype.isMutator = function() {
|
||||
var _ref2;
|
||||
return ends(this.operator, '=') && !('===' === (_ref2 = this.operator) || '!==' === _ref2);
|
||||
return ends(this.operator, '=') && !((_ref2 = this.operator) === '===' || _ref2 === '!==');
|
||||
};
|
||||
Op.prototype.isChainable = function() {
|
||||
return include(this.CHAINABLE, this.operator);
|
||||
};
|
||||
Op.prototype.invert = function() {
|
||||
var _ref2;
|
||||
if (('===' === (_ref2 = this.operator) || '!==' === _ref2)) {
|
||||
if (((_ref2 = this.operator) === '===' || _ref2 === '!==')) {
|
||||
this.operator = this.INVERSIONS[this.operator];
|
||||
return this;
|
||||
} else return this.second ? new Parens(this).invert() : Op.__super__.invert.call(this);
|
||||
|
@ -1498,7 +1496,7 @@
|
|||
_result = [];
|
||||
for (i = 0, _len = (_ref2 = this.array.base.objects).length; i < _len; i++) {
|
||||
item = _ref2[i];
|
||||
_result.push("" + (item.compile(o)) + " === " + (i ? this.obj2 : this.obj1));
|
||||
_result.push("" + (i ? this.obj2 : this.obj1) + " === " + (item.compile(o)));
|
||||
}
|
||||
return _result;
|
||||
}).call(this);
|
||||
|
@ -1939,7 +1937,7 @@
|
|||
}
|
||||
};
|
||||
UTILITIES = {
|
||||
"extends": 'function(child, parent) {\n var ctor = function() {};\n ctor.prototype = parent.prototype;\n child.prototype = new ctor();\n child.prototype.constructor = child;\n if (typeof parent.extended === "function") parent.extended(child);\n child.__super__ = parent.prototype;\n}',
|
||||
"extends": 'function(child, parent) {\n function ctor() { this.constructor = child; }\n ctor.prototype = parent.prototype;\n child.prototype = new ctor;\n if (typeof parent.extended === "function") parent.extended(child);\n child.__super__ = parent.prototype;\n}',
|
||||
bind: 'function(func, context) {\n return function() { return func.apply(context, arguments); };\n}',
|
||||
hasProp: 'Object.prototype.hasOwnProperty',
|
||||
slice: 'Array.prototype.slice'
|
||||
|
|
|
@ -32,7 +32,7 @@
|
|||
throw new Error("unrecognized option: " + arg);
|
||||
}
|
||||
if (!isOption) {
|
||||
options.arguments = args.slice(i, args.length);
|
||||
options.arguments = args.slice(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
var val;
|
||||
try {
|
||||
val = CoffeeScript.eval(buffer.toString(), {
|
||||
wrap: false,
|
||||
bare: true,
|
||||
globals: true,
|
||||
fileName: 'repl'
|
||||
});
|
||||
|
|
|
@ -66,7 +66,7 @@
|
|||
} else {
|
||||
tokens.splice(i, 0, after);
|
||||
}
|
||||
} else if (prev && !('TERMINATOR' === (_ref = prev[0]) || 'INDENT' === _ref || 'OUTDENT' === _ref)) {
|
||||
} else if (prev && !((_ref = prev[0]) === 'TERMINATOR' || _ref === 'INDENT' || _ref === 'OUTDENT')) {
|
||||
if (((post != null) ? post[0] : undefined) === 'TERMINATOR' && ((after != null) ? after[0] : undefined) === 'OUTDENT') {
|
||||
tokens.splice.apply(tokens, [i + 2, 0].concat(tokens.splice(i, 2)));
|
||||
if (tokens[i + 2][0] !== 'TERMINATOR') {
|
||||
|
@ -103,7 +103,7 @@
|
|||
var action, condition;
|
||||
condition = function(token, i) {
|
||||
var _ref;
|
||||
return (')' === (_ref = token[0]) || 'CALL_END' === _ref) || token[0] === 'OUTDENT' && this.tag(i - 1) === ')';
|
||||
return ((_ref = token[0]) === ')' || _ref === 'CALL_END') || token[0] === 'OUTDENT' && this.tag(i - 1) === ')';
|
||||
};
|
||||
action = function(token, i) {
|
||||
return (this.tokens[token[0] === 'OUTDENT' ? i - 1 : i][0] = 'CALL_END');
|
||||
|
@ -119,7 +119,7 @@
|
|||
var action, condition;
|
||||
condition = function(token, i) {
|
||||
var _ref;
|
||||
return (']' === (_ref = token[0]) || 'INDEX_END' === _ref);
|
||||
return ((_ref = token[0]) === ']' || _ref === 'INDEX_END');
|
||||
};
|
||||
action = function(token, i) {
|
||||
return (token[0] = 'INDEX_END');
|
||||
|
@ -136,12 +136,12 @@
|
|||
stack = [];
|
||||
condition = function(token, i) {
|
||||
var _ref, _ref2, one, tag, three, two;
|
||||
if ((this.tag(i + 1) === 'HERECOMMENT' || this.tag(i - 1) === 'HERECOMMENT')) {
|
||||
if (('HERECOMMENT' === this.tag(i + 1) || 'HERECOMMENT' === this.tag(i - 1))) {
|
||||
return false;
|
||||
}
|
||||
_ref = this.tokens.slice(i + 1, i + 4), one = _ref[0], two = _ref[1], three = _ref[2];
|
||||
tag = token[0];
|
||||
return ('TERMINATOR' === tag || 'OUTDENT' === tag) && !(((two != null) ? two[0] : undefined) === ':' || ((one != null) ? one[0] : undefined) === '@' && ((three != null) ? three[0] : undefined) === ':') || tag === ',' && !('IDENTIFIER' === (_ref2 = ((one != null) ? one[0] : undefined)) || 'NUMBER' === _ref2 || 'STRING' === _ref2 || '@' === _ref2 || 'TERMINATOR' === _ref2 || 'OUTDENT' === _ref2);
|
||||
return (tag === 'TERMINATOR' || tag === 'OUTDENT') && !(((two != null) ? two[0] : undefined) === ':' || ((one != null) ? one[0] : undefined) === '@' && ((three != null) ? three[0] : undefined) === ':') || tag === ',' && !((_ref2 = ((one != null) ? one[0] : undefined)) === 'IDENTIFIER' || _ref2 === 'NUMBER' || _ref2 === 'STRING' || _ref2 === '@' || _ref2 === 'TERMINATOR' || _ref2 === 'OUTDENT');
|
||||
};
|
||||
action = function(token, i) {
|
||||
return this.tokens.splice(i, 0, ['}', '}', token[2]]);
|
||||
|
@ -205,7 +205,7 @@
|
|||
return true;
|
||||
}
|
||||
tag = token[0];
|
||||
if (('IF' === tag || 'ELSE' === tag || 'UNLESS' === tag || '->' === tag || '=>' === tag)) {
|
||||
if ((tag === 'IF' || tag === 'ELSE' || tag === 'UNLESS' || tag === '->' || tag === '=>')) {
|
||||
seenSingle = true;
|
||||
}
|
||||
if (tag === 'PROPERTY_ACCESS' && this.tag(i - 1) === 'OUTDENT') {
|
||||
|
@ -227,7 +227,7 @@
|
|||
tokens.splice.apply(tokens, [i, 0].concat(this.indentation(token)));
|
||||
return 2;
|
||||
}
|
||||
if (tag === 'CATCH' && ('TERMINATOR' === (_ref = this.tag(i + 2)) || 'FINALLY' === _ref)) {
|
||||
if (tag === 'CATCH' && ((_ref = this.tag(i + 2)) === 'TERMINATOR' || _ref === 'FINALLY')) {
|
||||
tokens.splice.apply(tokens, [i + 2, 0].concat(this.indentation(token)));
|
||||
return 4;
|
||||
}
|
||||
|
@ -240,7 +240,7 @@
|
|||
indent.generated = (outdent.generated = true);
|
||||
tokens.splice(i + 1, 0, indent);
|
||||
condition = function(token, i) {
|
||||
return token[1] !== ';' && include(SINGLE_CLOSERS, token[0]) && !(token[0] === 'ELSE' && !('IF' === starter || 'THEN' === starter));
|
||||
return token[1] !== ';' && include(SINGLE_CLOSERS, token[0]) && !(token[0] === 'ELSE' && !(starter === 'IF' || starter === 'THEN'));
|
||||
};
|
||||
action = function(token, i) {
|
||||
return this.tokens.splice(this.tag(i - 1) === ',' ? i - 1 : i, 0, outdent);
|
||||
|
@ -258,11 +258,11 @@
|
|||
var condition;
|
||||
condition = function(token, i) {
|
||||
var _ref;
|
||||
return ('TERMINATOR' === (_ref = token[0]) || 'INDENT' === _ref);
|
||||
return ((_ref = token[0]) === 'TERMINATOR' || _ref === 'INDENT');
|
||||
};
|
||||
return this.scanTokens(function(token, i) {
|
||||
var _ref, original;
|
||||
if (!('IF' === (_ref = token[0]) || 'UNLESS' === _ref)) {
|
||||
if (!((_ref = token[0]) === 'IF' || _ref === 'UNLESS')) {
|
||||
return 1;
|
||||
}
|
||||
original = token;
|
||||
|
|
|
@ -89,7 +89,7 @@
|
|||
};
|
||||
Scope.prototype.hasDeclarations = function(body) {
|
||||
return body === this.expressions && this.any(function(k, val) {
|
||||
return ('var' === val || 'reuse' === val);
|
||||
return (val === 'var' || val === 'reuse');
|
||||
});
|
||||
};
|
||||
Scope.prototype.hasAssignments = function(body) {
|
||||
|
@ -104,7 +104,7 @@
|
|||
for (key in _ref2 = this.variables) {
|
||||
if (!__hasProp.call(_ref2, key)) continue;
|
||||
val = _ref2[key];
|
||||
if (('var' === val || 'reuse' === val)) {
|
||||
if ((val === 'var' || val === 'reuse')) {
|
||||
_result.push(key);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@ CoffeeScript.eval = (code, options) ->
|
|||
|
||||
# Running code does not provide access to this scope.
|
||||
CoffeeScript.run = (code, options) ->
|
||||
options?.wrap = no
|
||||
options?.bare = on
|
||||
Function(CoffeeScript.compile code, options)()
|
||||
|
||||
# If we're not in a browser environment, we're finished with the public API.
|
||||
|
|
|
@ -46,7 +46,7 @@ helpers.extend global,
|
|||
exports.run = ->
|
||||
path.exists 'Cakefile', (exists) ->
|
||||
throw new Error("Cakefile not found in #{process.cwd()}") unless exists
|
||||
args = process.argv[2...process.argv.length]
|
||||
args = process.argv.slice 2
|
||||
CoffeeScript.run fs.readFileSync('Cakefile').toString(), fileName: 'Cakefile'
|
||||
oparse = new optparse.OptionParser switches
|
||||
return printTasks() unless args.length
|
||||
|
|
|
@ -36,7 +36,7 @@ SWITCHES = [
|
|||
['-s', '--stdio', 'listen for and compile scripts over stdio']
|
||||
['-e', '--eval', 'compile a string from the command line']
|
||||
['-r', '--require [FILE*]', 'require a library before executing your script']
|
||||
[ '--no-wrap', 'compile without the top-level function wrapper']
|
||||
['-b', '--bare', 'compile without the top-level function wrapper']
|
||||
['-t', '--tokens', 'print the tokens that the lexer produces']
|
||||
['-n', '--nodes', 'print the parse tree that Jison produces']
|
||||
['-v', '--version', 'display CoffeeScript version']
|
||||
|
@ -62,11 +62,10 @@ exports.run = ->
|
|||
separator = sources.indexOf '--'
|
||||
flags = []
|
||||
if separator >= 0
|
||||
flags = sources[(separator + 1)...sources.length]
|
||||
sources = sources[0...separator]
|
||||
flags = sources.splice separator + 1
|
||||
sources.pop()
|
||||
if opts.run
|
||||
flags = sources[1..sources.length].concat flags
|
||||
sources = [sources[0]]
|
||||
flags = sources.splice(1).concat flags
|
||||
process.ARGV = process.argv = flags
|
||||
compileScripts()
|
||||
|
||||
|
@ -176,17 +175,14 @@ printTokens = (tokens) ->
|
|||
# `process.argv` that are specified in `SWITCHES`.
|
||||
parseOptions = ->
|
||||
optionParser = new optparse.OptionParser SWITCHES, BANNER
|
||||
o = opts = optionParser.parse(process.argv[2...process.argv.length])
|
||||
o = opts = optionParser.parse process.argv.slice 2
|
||||
o.compile or= !!o.output
|
||||
o.run = not (o.compile or o.print or o.lint)
|
||||
o.print = !! (o.print or (o.eval or o.stdio and o.compile))
|
||||
sources = o.arguments
|
||||
|
||||
# The compile-time options to pass to the CoffeeScript compiler.
|
||||
compileOptions = (fileName) ->
|
||||
o = {fileName}
|
||||
o.wrap = !opts['no-wrap']
|
||||
o
|
||||
compileOptions = (fileName) -> {fileName, bare: opts.bare}
|
||||
|
||||
# Print the `--help` usage message and exit.
|
||||
usage = ->
|
||||
|
|
|
@ -549,7 +549,7 @@ grammar =
|
|||
if $2 is '!in'
|
||||
new Op '!', new In $1, $3
|
||||
else
|
||||
new Op '!', new Parens new Op $2[1..], $1, $3
|
||||
new Op '!', new Parens new Op $2.slice(1), $1, $3
|
||||
else
|
||||
if $2 is 'in' then new In $1, $3 else new Op $2, $1, $3
|
||||
]
|
||||
|
|
|
@ -47,7 +47,7 @@ exports.Lexer = class Lexer
|
|||
# At every position, run through this list of attempted matches,
|
||||
# short-circuiting if any of them succeed. Their order determines precedence:
|
||||
# `@literalToken` is the fallback catch-all.
|
||||
while (@chunk = code[@i..])
|
||||
while @chunk = code.slice @i
|
||||
@identifierToken() or
|
||||
@commentToken() or
|
||||
@whitespaceToken() or
|
||||
|
@ -445,9 +445,9 @@ exports.Lexer = class Lexer
|
|||
i += 1
|
||||
continue
|
||||
unless letter is '#' and str.charAt(i+1) is '{' and
|
||||
(expr = @balancedString str[i+1..], [['{', '}']])
|
||||
(expr = @balancedString str.slice(i+1), [['{', '}']])
|
||||
continue
|
||||
tokens.push ['TO_BE_STRING', str[pi...i]] if pi < i
|
||||
tokens.push ['TO_BE_STRING', str.slice(pi, i)] if pi < i
|
||||
inner = expr.slice(1, -1).replace(LEADING_SPACES, '').replace(TRAILING_SPACES, '')
|
||||
if inner.length
|
||||
nested = new Lexer().tokenize inner, line: @line, rewrite: off
|
||||
|
@ -458,7 +458,7 @@ exports.Lexer = class Lexer
|
|||
tokens.push ['TOKENS', nested]
|
||||
i += expr.length
|
||||
pi = i + 1
|
||||
tokens.push ['TO_BE_STRING', str[pi..]] if i > pi < str.length
|
||||
tokens.push ['TO_BE_STRING', str.slice pi] if i > pi < str.length
|
||||
return tokens if regex
|
||||
return @token 'STRING', '""' unless tokens.length
|
||||
tokens.unshift ['', ''] unless tokens[0][0] is 'TO_BE_STRING'
|
||||
|
|
|
@ -193,19 +193,18 @@ exports.Expressions = class Expressions extends Base
|
|||
if o.scope then super(o) else @compileRoot(o)
|
||||
|
||||
compileNode: (o) ->
|
||||
(@compileExpression(node, merge(o)) for node in @expressions).join("\n")
|
||||
(@compileExpression node, merge o for node in @expressions).join '\n'
|
||||
|
||||
# If we happen to be the top-level **Expressions**, wrap everything in
|
||||
# a safety closure, unless requested not to.
|
||||
# It would be better not to generate them in the first place, but for now,
|
||||
# clean up obvious double-parentheses.
|
||||
compileRoot: (o) ->
|
||||
wrap = if o.wrap? then o.wrap else true
|
||||
o.indent = @tab = if wrap then TAB else ''
|
||||
o.scope = new Scope(null, this, null)
|
||||
code = @compileWithDeclarations(o)
|
||||
code = code.replace(TRAILING_WHITESPACE, '')
|
||||
if wrap then "(function() {\n#{code}\n}).call(this);\n" else code
|
||||
o.indent = @tab = if o.bare then '' else TAB
|
||||
o.scope = new Scope null, this, null
|
||||
code = @compileWithDeclarations o
|
||||
code = code.replace TRAILING_WHITESPACE, ''
|
||||
if o.bare then code else "(function() {\n#{code}\n}).call(this);\n"
|
||||
|
||||
# Compile the expressions body for the contents of a function, with
|
||||
# declarations of all inner variables pushed up to the top.
|
||||
|
@ -981,8 +980,8 @@ exports.Code = class Code extends Base
|
|||
o.top = true
|
||||
o.indent = @idt(1)
|
||||
empty = @body.expressions.length is 0
|
||||
del o, 'wrap'
|
||||
del o, 'globals'
|
||||
delete o.bare
|
||||
delete o.globals
|
||||
splat = undefined
|
||||
params = []
|
||||
for param, i in @params
|
||||
|
@ -1276,7 +1275,7 @@ exports.In = class In extends Base
|
|||
|
||||
compileOrTest: (o) ->
|
||||
tests = for item, i in @array.base.objects
|
||||
"#{item.compile(o)} === #{if i then @obj2 else @obj1}"
|
||||
"#{if i then @obj2 else @obj1} === #{item.compile(o)}"
|
||||
"(#{tests.join(' || ')})"
|
||||
|
||||
compileLoopTest: (o) ->
|
||||
|
@ -1647,10 +1646,9 @@ UTILITIES =
|
|||
# [goog.inherits](http://closure-library.googlecode.com/svn/docs/closureGoogBase.js.source.html#line1206).
|
||||
extends: '''
|
||||
function(child, parent) {
|
||||
var ctor = function() {};
|
||||
function ctor() { this.constructor = child; }
|
||||
ctor.prototype = parent.prototype;
|
||||
child.prototype = new ctor();
|
||||
child.prototype.constructor = child;
|
||||
child.prototype = new ctor;
|
||||
if (typeof parent.extended === "function") parent.extended(child);
|
||||
child.__super__ = parent.prototype;
|
||||
}
|
||||
|
|
|
@ -36,7 +36,7 @@ exports.OptionParser = class OptionParser
|
|||
break
|
||||
throw new Error "unrecognized option: #{arg}" if isOption and not matchedRule
|
||||
if not isOption
|
||||
options.arguments = args[i...args.length]
|
||||
options.arguments = args.slice i
|
||||
break
|
||||
options
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@ helpers.extend global, quit: -> process.exit(0)
|
|||
# of exiting.
|
||||
run = (buffer) ->
|
||||
try
|
||||
val = CoffeeScript.eval buffer.toString(), wrap: false, globals: true, fileName: 'repl'
|
||||
val = CoffeeScript.eval buffer.toString(), bare: on, globals: on, fileName: 'repl'
|
||||
puts inspect val if val isnt undefined
|
||||
catch err
|
||||
puts err.stack or err.toString()
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
# Ensure that carriage returns don't break compilation on Windows.
|
||||
eq CoffeeScript.compile('one\r\ntwo', wrap: off), 'one;\ntwo;'
|
||||
eq CoffeeScript.compile('one\r\ntwo', bare: on), 'one;\ntwo;'
|
||||
|
||||
# `globals: on` removes `var`s
|
||||
eq CoffeeScript.compile('x = y', wrap: off, globals: on), 'x = y;'
|
||||
eq CoffeeScript.compile('x = y', bare: on, globals: on), 'x = y;'
|
||||
|
||||
ok 'passed' is CoffeeScript.eval '"passed"', wrap: off, fileName: 'test'
|
||||
ok 'passed' is CoffeeScript.eval '"passed"', bare: on, fileName: 'test'
|
||||
|
||||
#750
|
||||
try ok not CoffeeScript.nodes 'f(->'
|
||||
|
|
|
@ -145,3 +145,10 @@ ok new Number not instanceof String
|
|||
|
||||
#737: `in` should have higher precedence than logical operators
|
||||
eq 1, 1 in [1] and 1
|
||||
|
||||
#768: `in` should preserve evaluation order
|
||||
share = 0
|
||||
a = -> share++ if share is 0
|
||||
b = -> share++ if share is 1
|
||||
c = -> share++ if share is 2
|
||||
ok a() not in [b(),c()] and share is 3
|
||||
|
|
Loading…
Add table
Reference in a new issue