From 38520bfeced51a7b4005dfe09ee241770229a1e5 Mon Sep 17 00:00:00 2001 From: Jeremy Ashkenas Date: Fri, 1 Jan 2010 22:00:34 -0500 Subject: [PATCH] rebuilding narwhal uncovered a bug with named functions --- .../narwhal/coffee-script.coffee | 5 ++- .../narwhal/lib/coffee-script.js | 42 +++++++++---------- .../narwhal/lib/coffee-script/loader.js | 4 +- lib/coffee_script/nodes.rb | 2 +- 4 files changed, 26 insertions(+), 27 deletions(-) diff --git a/lib/coffee_script/narwhal/coffee-script.coffee b/lib/coffee_script/narwhal/coffee-script.coffee index 289e58b4..d687c42b 100644 --- a/lib/coffee_script/narwhal/coffee-script.coffee +++ b/lib/coffee_script/narwhal/coffee-script.coffee @@ -21,8 +21,9 @@ checkForErrors: coffeeProcess => # command. exports.run: args => if args.length - exports.evalCS(File.read(path)) for path in args - delete args[i] for path, i in args + for path, i in args + exports.evalCS(File.read(path)) + delete args[i] return true while true diff --git a/lib/coffee_script/narwhal/lib/coffee-script.js b/lib/coffee_script/narwhal/lib/coffee-script.js index 12ec02b1..99a2c40c 100644 --- a/lib/coffee_script/narwhal/lib/coffee-script.js +++ b/lib/coffee_script/narwhal/lib/coffee-script.js @@ -1,14 +1,16 @@ (function(){ var File, OS, Readline, checkForErrors, coffeePath; - // This (javascript) file is generated from lib/coffee_script/narwhal/coffee-script.coffee Executes the `coffee` Ruby program to convert from CoffeeScript - // to Javascript. Eventually this will hopefully happen entirely within JS. Require external dependencies. + // This (javascript) file is generated from lib/coffee_script/narwhal/coffee-script.coffee + // Executes the `coffee` Ruby program to convert from CoffeeScript + // to Javascript. Eventually this will hopefully happen entirely within JS. + // Require external dependencies. OS = require('os'); File = require('file'); Readline = require('readline'); // The path to the CoffeeScript Compiler. coffeePath = File.path(module.path).dirname().dirname().dirname().dirname().dirname().join('bin', 'coffee'); // Our general-purpose error handler. - checkForErrors = function(coffeeProcess) { + checkForErrors = function checkForErrors(coffeeProcess) { if (coffeeProcess.wait() === 0) { return true; } @@ -17,24 +19,20 @@ }; // Run a simple REPL, round-tripping to the CoffeeScript compiler for every // command. - exports.run = function(args) { - var __a, __b, __c, __d, __e, __f, __g, __h, i, path, result; + exports.run = function run(args) { + var __a, __b, __c, i, path, result; if (args.length) { __a = args; - __d = []; - for (__b=0, __c=__a.length; __b<__c; __b++) { - path = __a[__b]; - __d[__b] = exports.evalCS(File.read(path)); + __b = []; + for (i in __a) { + if (__a.hasOwnProperty(i)) { + path = __a[i]; + exports.evalCS(File.read(path)); + __c = delete args[i]; + __b.push(__c); + } } - __d; - __e = args; - __h = []; - for (__f=0, __g=__e.length; __f<__g; __f++) { - path = __e[__f]; - i = __f; - __h[__f] = delete args[i]; - } - __h; + __b; return true; } while (true) { @@ -50,14 +48,14 @@ } }; // Compile a given CoffeeScript file into JavaScript. - exports.compileFile = function(path) { + exports.compileFile = function compileFile(path) { var coffee; coffee = OS.popen([coffeePath, "--print", "--no-wrap", path]); checkForErrors(coffee); return coffee.stdout.read(); }; // Compile a string of CoffeeScript into JavaScript. - exports.compile = function(source) { + exports.compile = function compile(source) { var coffee; coffee = OS.popen([coffeePath, "--eval", "--no-wrap"]); coffee.stdin.write(source).flush().close(); @@ -65,11 +63,11 @@ return coffee.stdout.read(); }; // Evaluating a string of CoffeeScript first compiles it externally. - exports.evalCS = function(source) { + exports.evalCS = function evalCS(source) { return eval(exports.compile(source)); }; // Make a factory for the CoffeeScript environment. - exports.makeNarwhalFactory = function(path) { + exports.makeNarwhalFactory = function makeNarwhalFactory(path) { var code, factoryText; code = exports.compileFile(path); factoryText = "function(require,exports,module,system,print){" + code + "/**/\n}"; diff --git a/lib/coffee_script/narwhal/lib/coffee-script/loader.js b/lib/coffee_script/narwhal/lib/coffee-script/loader.js index b6680332..24b7ef27 100644 --- a/lib/coffee_script/narwhal/lib/coffee-script/loader.js +++ b/lib/coffee_script/narwhal/lib/coffee-script/loader.js @@ -6,14 +6,14 @@ }; loader = { // Reload the coffee-script environment from source. - reload: function(topId, path) { + reload: function reload(topId, path) { coffeescript = coffeescript || require('coffee-script'); return (factories[topId] = function() { return coffeescript.makeNarwhalFactory(path); }); }, // Ensure that the coffee-script environment is loaded. - load: function(topId, path) { + load: function load(topId, path) { return factories[topId] = factories[topId] || this.reload(topId, path); } }; diff --git a/lib/coffee_script/nodes.rb b/lib/coffee_script/nodes.rb index 00591410..2ea0a336 100644 --- a/lib/coffee_script/nodes.rb +++ b/lib/coffee_script/nodes.rb @@ -417,7 +417,7 @@ module CoffeeScript last = @variable.last.to_s.sub(LEADING_DOT, '') proto = name[PROTO_ASSIGN, 1] o = o.merge(:assign => @variable, :last_assign => last, :proto_assign => proto) - o[:immediate_assign] = last if @value.is_a?(CodeNode) + o[:immediate_assign] = last if @value.is_a?(CodeNode) && last.match(Lexer::IDENTIFIER) return write("#{name}: #{@value.compile(o)}") if @context == :object o[:scope].find(name) unless @variable.properties? return write(@value.compile(o)) if @value.custom_assign?