765: -b/--bare <- --no-wrap

This commit is contained in:
satyr
2010-10-14 04:09:56 +09:00
parent 6e89ad3401
commit 88cc1ee35d
13 changed files with 32 additions and 39 deletions

View File

@@ -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)) {

View File

@@ -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;
@@ -210,12 +210,10 @@
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());

View File

@@ -205,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;
@@ -1138,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++) {

View File

@@ -13,7 +13,7 @@
var val;
try {
val = CoffeeScript.eval(buffer.toString(), {
wrap: false,
bare: true,
globals: true,
fileName: 'repl'
});