mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-02-18 11:31:20 -05:00
separating out the --no-wrap and the --globals arguments, which shouldn't be jammed together
This commit is contained in:
@@ -139,6 +139,7 @@ Usage:
|
|||||||
begin
|
begin
|
||||||
options = {}
|
options = {}
|
||||||
options[:no_wrap] = true if @options[:no_wrap]
|
options[:no_wrap] = true if @options[:no_wrap]
|
||||||
|
options[:globals] = true if @options[:globals]
|
||||||
CoffeeScript.compile(script, options)
|
CoffeeScript.compile(script, options)
|
||||||
rescue CoffeeScript::ParseError, SyntaxError => e
|
rescue CoffeeScript::ParseError, SyntaxError => e
|
||||||
STDERR.puts "#{source}: #{e.message}"
|
STDERR.puts "#{source}: #{e.message}"
|
||||||
@@ -193,9 +194,12 @@ Usage:
|
|||||||
opts.on('-v', '--verbose', 'print at every step of code generation') do |v|
|
opts.on('-v', '--verbose', 'print at every step of code generation') do |v|
|
||||||
ENV['VERBOSE'] = 'true'
|
ENV['VERBOSE'] = 'true'
|
||||||
end
|
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
|
@options[:no_wrap] = true
|
||||||
end
|
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|
|
opts.on_tail('--install-bundle', 'install the CoffeeScript TextMate bundle') do |i|
|
||||||
install_bundle
|
install_bundle
|
||||||
exit
|
exit
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ exports.run: args =>
|
|||||||
while true
|
while true
|
||||||
try
|
try
|
||||||
system.stdout.write('coffee> ').flush()
|
system.stdout.write('coffee> ').flush()
|
||||||
result: exports.evalCS(Readline.readline())
|
result: exports.evalCS(Readline.readline(), ['--globals'])
|
||||||
print(result) if result isnt undefined
|
print(result) if result isnt undefined
|
||||||
catch e
|
catch e
|
||||||
print(e)
|
print(e)
|
||||||
@@ -41,15 +41,15 @@ exports.compileFile: path =>
|
|||||||
coffee.stdout.read()
|
coffee.stdout.read()
|
||||||
|
|
||||||
# Compile a string of CoffeeScript into JavaScript.
|
# Compile a string of CoffeeScript into JavaScript.
|
||||||
exports.compile: source =>
|
exports.compile: source, flags =>
|
||||||
coffee: OS.popen([coffeePath, "--eval", "--no-wrap"])
|
coffee: OS.popen([coffeePath, "--eval", "--no-wrap"].concat(flags or []))
|
||||||
coffee.stdin.write(source).flush().close()
|
coffee.stdin.write(source).flush().close()
|
||||||
checkForErrors(coffee)
|
checkForErrors(coffee)
|
||||||
coffee.stdout.read()
|
coffee.stdout.read()
|
||||||
|
|
||||||
# Evaluating a string of CoffeeScript first compiles it externally.
|
# Evaluating a string of CoffeeScript first compiles it externally.
|
||||||
exports.evalCS: source =>
|
exports.evalCS: source, flags =>
|
||||||
eval(exports.compile(source))
|
eval(exports.compile(source, flags))
|
||||||
|
|
||||||
# Make a factory for the CoffeeScript environment.
|
# Make a factory for the CoffeeScript environment.
|
||||||
exports.makeNarwhalFactory: path =>
|
exports.makeNarwhalFactory: path =>
|
||||||
|
|||||||
@@ -20,25 +20,24 @@
|
|||||||
// Run a simple REPL, round-tripping to the CoffeeScript compiler for every
|
// Run a simple REPL, round-tripping to the CoffeeScript compiler for every
|
||||||
// command.
|
// command.
|
||||||
exports.run = function run(args) {
|
exports.run = function run(args) {
|
||||||
var __a, __b, __c, i, path, result;
|
var __a, __b, i, result;
|
||||||
if (args.length) {
|
if (args.length) {
|
||||||
__a = args;
|
__a = args;
|
||||||
__b = [];
|
__b = function(path, i) {
|
||||||
for (i in __a) {
|
exports.evalCS(File.read(path));
|
||||||
if (__a.hasOwnProperty(i)) {
|
delete args[i];
|
||||||
path = __a[i];
|
};
|
||||||
exports.evalCS(File.read(path));
|
if (__a instanceof Array) {
|
||||||
__c = delete args[i];
|
for (i=0; i<__a.length; i++) __b(__a[i], i);
|
||||||
__b.push(__c);
|
} else {
|
||||||
}
|
for (i in __a) { if (__a.hasOwnProperty(i)) __b(__a[i], i); }
|
||||||
}
|
}
|
||||||
__b;
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
while (true) {
|
while (true) {
|
||||||
try {
|
try {
|
||||||
system.stdout.write('coffee> ').flush();
|
system.stdout.write('coffee> ').flush();
|
||||||
result = exports.evalCS(Readline.readline());
|
result = exports.evalCS(Readline.readline(), ['--globals']);
|
||||||
if (result !== undefined) {
|
if (result !== undefined) {
|
||||||
print(result);
|
print(result);
|
||||||
}
|
}
|
||||||
@@ -46,6 +45,7 @@
|
|||||||
print(e);
|
print(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return null;
|
||||||
};
|
};
|
||||||
// Compile a given CoffeeScript file into JavaScript.
|
// Compile a given CoffeeScript file into JavaScript.
|
||||||
exports.compileFile = function compileFile(path) {
|
exports.compileFile = function compileFile(path) {
|
||||||
@@ -55,16 +55,16 @@
|
|||||||
return coffee.stdout.read();
|
return coffee.stdout.read();
|
||||||
};
|
};
|
||||||
// Compile a string of CoffeeScript into JavaScript.
|
// Compile a string of CoffeeScript into JavaScript.
|
||||||
exports.compile = function compile(source) {
|
exports.compile = function compile(source, flags) {
|
||||||
var coffee;
|
var coffee;
|
||||||
coffee = OS.popen([coffeePath, "--eval", "--no-wrap"]);
|
coffee = OS.popen([coffeePath, "--eval", "--no-wrap"].concat(flags || []));
|
||||||
coffee.stdin.write(source).flush().close();
|
coffee.stdin.write(source).flush().close();
|
||||||
checkForErrors(coffee);
|
checkForErrors(coffee);
|
||||||
return coffee.stdout.read();
|
return coffee.stdout.read();
|
||||||
};
|
};
|
||||||
// Evaluating a string of CoffeeScript first compiles it externally.
|
// Evaluating a string of CoffeeScript first compiles it externally.
|
||||||
exports.evalCS = function evalCS(source) {
|
exports.evalCS = function evalCS(source, flags) {
|
||||||
return eval(exports.compile(source));
|
return eval(exports.compile(source, flags));
|
||||||
};
|
};
|
||||||
// Make a factory for the CoffeeScript environment.
|
// Make a factory for the CoffeeScript environment.
|
||||||
exports.makeNarwhalFactory = function makeNarwhalFactory(path) {
|
exports.makeNarwhalFactory = function makeNarwhalFactory(path) {
|
||||||
|
|||||||
@@ -8,9 +8,9 @@
|
|||||||
// Reload the coffee-script environment from source.
|
// Reload the coffee-script environment from source.
|
||||||
reload: function reload(topId, path) {
|
reload: function reload(topId, path) {
|
||||||
coffeescript = coffeescript || require('coffee-script');
|
coffeescript = coffeescript || require('coffee-script');
|
||||||
return (factories[topId] = function() {
|
return factories[topId] = function() {
|
||||||
return coffeescript.makeNarwhalFactory(path);
|
return coffeescript.makeNarwhalFactory(path);
|
||||||
});
|
};
|
||||||
},
|
},
|
||||||
// Ensure that the coffee-script environment is loaded.
|
// Ensure that the coffee-script environment is loaded.
|
||||||
load: function load(topId, path) {
|
load: function load(topId, path) {
|
||||||
|
|||||||
@@ -127,7 +127,7 @@ module CoffeeScript
|
|||||||
indent = o[:no_wrap] ? '' : TAB
|
indent = o[:no_wrap] ? '' : TAB
|
||||||
@indent = indent
|
@indent = indent
|
||||||
o.merge!(:indent => indent, :scope => Scope.new(nil, self))
|
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, '')
|
code.gsub!(STRIP_TRAILING_WHITESPACE, '')
|
||||||
o[:no_wrap] ? code : "(function(){\n#{code}\n})();"
|
o[:no_wrap] ? code : "(function(){\n#{code}\n})();"
|
||||||
end
|
end
|
||||||
@@ -499,6 +499,7 @@ module CoffeeScript
|
|||||||
o[:top] = true
|
o[:top] = true
|
||||||
o[:indent] = idt(1)
|
o[:indent] = idt(1)
|
||||||
o.delete(:no_wrap)
|
o.delete(:no_wrap)
|
||||||
|
o.delete(:globals)
|
||||||
name = o.delete(:immediate_assign)
|
name = o.delete(:immediate_assign)
|
||||||
if @params.last.is_a?(ParamSplatNode)
|
if @params.last.is_a?(ParamSplatNode)
|
||||||
splat = @params.pop
|
splat = @params.pop
|
||||||
|
|||||||
Reference in New Issue
Block a user