1
0
Fork 0
mirror of https://github.com/jashkenas/coffeescript.git synced 2022-11-09 12:23:24 -05:00

separating out the --no-wrap and the --globals arguments, which shouldn't be jammed together

This commit is contained in:
Jeremy Ashkenas 2010-01-07 21:10:25 -05:00
parent 30dca132bd
commit d416c184db
5 changed files with 29 additions and 24 deletions

View file

@ -139,6 +139,7 @@ Usage:
begin
options = {}
options[:no_wrap] = true if @options[:no_wrap]
options[:globals] = true if @options[:globals]
CoffeeScript.compile(script, options)
rescue CoffeeScript::ParseError, SyntaxError => e
STDERR.puts "#{source}: #{e.message}"
@ -193,9 +194,12 @@ Usage:
opts.on('-v', '--verbose', 'print at every step of code generation') do |v|
ENV['VERBOSE'] = 'true'
end
opts.on('-n', '--no-wrap', 'raw output, no safety wrapper or vars') do |n|
opts.on('-n', '--no-wrap', 'raw output, no function safety wrapper') do |n|
@options[:no_wrap] = true
end
opts.on('-g', '--globals', 'attach all top-level variable as globals') do |n|
@options[:globals] = true
end
opts.on_tail('--install-bundle', 'install the CoffeeScript TextMate bundle') do |i|
install_bundle
exit

View file

@ -29,7 +29,7 @@ exports.run: args =>
while true
try
system.stdout.write('coffee> ').flush()
result: exports.evalCS(Readline.readline())
result: exports.evalCS(Readline.readline(), ['--globals'])
print(result) if result isnt undefined
catch e
print(e)
@ -41,15 +41,15 @@ exports.compileFile: path =>
coffee.stdout.read()
# Compile a string of CoffeeScript into JavaScript.
exports.compile: source =>
coffee: OS.popen([coffeePath, "--eval", "--no-wrap"])
exports.compile: source, flags =>
coffee: OS.popen([coffeePath, "--eval", "--no-wrap"].concat(flags or []))
coffee.stdin.write(source).flush().close()
checkForErrors(coffee)
coffee.stdout.read()
# Evaluating a string of CoffeeScript first compiles it externally.
exports.evalCS: source =>
eval(exports.compile(source))
exports.evalCS: source, flags =>
eval(exports.compile(source, flags))
# Make a factory for the CoffeeScript environment.
exports.makeNarwhalFactory: path =>

View file

@ -20,25 +20,24 @@
// Run a simple REPL, round-tripping to the CoffeeScript compiler for every
// command.
exports.run = function run(args) {
var __a, __b, __c, i, path, result;
var __a, __b, i, result;
if (args.length) {
__a = args;
__b = [];
for (i in __a) {
if (__a.hasOwnProperty(i)) {
path = __a[i];
exports.evalCS(File.read(path));
__c = delete args[i];
__b.push(__c);
}
__b = function(path, i) {
exports.evalCS(File.read(path));
delete args[i];
};
if (__a instanceof Array) {
for (i=0; i<__a.length; i++) __b(__a[i], i);
} else {
for (i in __a) { if (__a.hasOwnProperty(i)) __b(__a[i], i); }
}
__b;
return true;
}
while (true) {
try {
system.stdout.write('coffee> ').flush();
result = exports.evalCS(Readline.readline());
result = exports.evalCS(Readline.readline(), ['--globals']);
if (result !== undefined) {
print(result);
}
@ -46,6 +45,7 @@
print(e);
}
}
return null;
};
// Compile a given CoffeeScript file into JavaScript.
exports.compileFile = function compileFile(path) {
@ -55,16 +55,16 @@
return coffee.stdout.read();
};
// Compile a string of CoffeeScript into JavaScript.
exports.compile = function compile(source) {
exports.compile = function compile(source, flags) {
var coffee;
coffee = OS.popen([coffeePath, "--eval", "--no-wrap"]);
coffee = OS.popen([coffeePath, "--eval", "--no-wrap"].concat(flags || []));
coffee.stdin.write(source).flush().close();
checkForErrors(coffee);
return coffee.stdout.read();
};
// Evaluating a string of CoffeeScript first compiles it externally.
exports.evalCS = function evalCS(source) {
return eval(exports.compile(source));
exports.evalCS = function evalCS(source, flags) {
return eval(exports.compile(source, flags));
};
// Make a factory for the CoffeeScript environment.
exports.makeNarwhalFactory = function makeNarwhalFactory(path) {

View file

@ -8,9 +8,9 @@
// Reload the coffee-script environment from source.
reload: function reload(topId, path) {
coffeescript = coffeescript || require('coffee-script');
return (factories[topId] = function() {
return factories[topId] = function() {
return coffeescript.makeNarwhalFactory(path);
});
};
},
// Ensure that the coffee-script environment is loaded.
load: function load(topId, path) {

View file

@ -127,7 +127,7 @@ module CoffeeScript
indent = o[:no_wrap] ? '' : TAB
@indent = indent
o.merge!(:indent => indent, :scope => Scope.new(nil, self))
code = o[:no_wrap] ? compile_node(o) : compile_with_declarations(o)
code = o[:globals] ? compile_node(o) : compile_with_declarations(o)
code.gsub!(STRIP_TRAILING_WHITESPACE, '')
o[:no_wrap] ? code : "(function(){\n#{code}\n})();"
end
@ -499,6 +499,7 @@ module CoffeeScript
o[:top] = true
o[:indent] = idt(1)
o.delete(:no_wrap)
o.delete(:globals)
name = o.delete(:immediate_assign)
if @params.last.is_a?(ParamSplatNode)
splat = @params.pop