mirror of
https://github.com/jashkenas/coffeescript.git
synced 2022-11-09 12:23:24 -05:00
rebuilding narwhal uncovered a bug with named functions
This commit is contained in:
parent
c3d0e50e8f
commit
38520bfece
4 changed files with 26 additions and 27 deletions
|
@ -21,8 +21,9 @@ checkForErrors: coffeeProcess =>
|
||||||
# command.
|
# command.
|
||||||
exports.run: args =>
|
exports.run: args =>
|
||||||
if args.length
|
if args.length
|
||||||
exports.evalCS(File.read(path)) for path in args
|
for path, i in args
|
||||||
delete args[i] for path, i in args
|
exports.evalCS(File.read(path))
|
||||||
|
delete args[i]
|
||||||
return true
|
return true
|
||||||
|
|
||||||
while true
|
while true
|
||||||
|
|
|
@ -1,14 +1,16 @@
|
||||||
(function(){
|
(function(){
|
||||||
var File, OS, Readline, checkForErrors, coffeePath;
|
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
|
// This (javascript) file is generated from lib/coffee_script/narwhal/coffee-script.coffee
|
||||||
// to Javascript. Eventually this will hopefully happen entirely within JS. Require external dependencies.
|
// 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');
|
OS = require('os');
|
||||||
File = require('file');
|
File = require('file');
|
||||||
Readline = require('readline');
|
Readline = require('readline');
|
||||||
// The path to the CoffeeScript Compiler.
|
// The path to the CoffeeScript Compiler.
|
||||||
coffeePath = File.path(module.path).dirname().dirname().dirname().dirname().dirname().join('bin', 'coffee');
|
coffeePath = File.path(module.path).dirname().dirname().dirname().dirname().dirname().join('bin', 'coffee');
|
||||||
// Our general-purpose error handler.
|
// Our general-purpose error handler.
|
||||||
checkForErrors = function(coffeeProcess) {
|
checkForErrors = function checkForErrors(coffeeProcess) {
|
||||||
if (coffeeProcess.wait() === 0) {
|
if (coffeeProcess.wait() === 0) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -17,24 +19,20 @@
|
||||||
};
|
};
|
||||||
// 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(args) {
|
exports.run = function run(args) {
|
||||||
var __a, __b, __c, __d, __e, __f, __g, __h, i, path, result;
|
var __a, __b, __c, i, path, result;
|
||||||
if (args.length) {
|
if (args.length) {
|
||||||
__a = args;
|
__a = args;
|
||||||
__d = [];
|
__b = [];
|
||||||
for (__b=0, __c=__a.length; __b<__c; __b++) {
|
for (i in __a) {
|
||||||
path = __a[__b];
|
if (__a.hasOwnProperty(i)) {
|
||||||
__d[__b] = exports.evalCS(File.read(path));
|
path = __a[i];
|
||||||
|
exports.evalCS(File.read(path));
|
||||||
|
__c = delete args[i];
|
||||||
|
__b.push(__c);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
__d;
|
__b;
|
||||||
__e = args;
|
|
||||||
__h = [];
|
|
||||||
for (__f=0, __g=__e.length; __f<__g; __f++) {
|
|
||||||
path = __e[__f];
|
|
||||||
i = __f;
|
|
||||||
__h[__f] = delete args[i];
|
|
||||||
}
|
|
||||||
__h;
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
while (true) {
|
while (true) {
|
||||||
|
@ -50,14 +48,14 @@
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
// Compile a given CoffeeScript file into JavaScript.
|
// Compile a given CoffeeScript file into JavaScript.
|
||||||
exports.compileFile = function(path) {
|
exports.compileFile = function compileFile(path) {
|
||||||
var coffee;
|
var coffee;
|
||||||
coffee = OS.popen([coffeePath, "--print", "--no-wrap", path]);
|
coffee = OS.popen([coffeePath, "--print", "--no-wrap", path]);
|
||||||
checkForErrors(coffee);
|
checkForErrors(coffee);
|
||||||
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(source) {
|
exports.compile = function compile(source) {
|
||||||
var coffee;
|
var coffee;
|
||||||
coffee = OS.popen([coffeePath, "--eval", "--no-wrap"]);
|
coffee = OS.popen([coffeePath, "--eval", "--no-wrap"]);
|
||||||
coffee.stdin.write(source).flush().close();
|
coffee.stdin.write(source).flush().close();
|
||||||
|
@ -65,11 +63,11 @@
|
||||||
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(source) {
|
exports.evalCS = function evalCS(source) {
|
||||||
return eval(exports.compile(source));
|
return eval(exports.compile(source));
|
||||||
};
|
};
|
||||||
// Make a factory for the CoffeeScript environment.
|
// Make a factory for the CoffeeScript environment.
|
||||||
exports.makeNarwhalFactory = function(path) {
|
exports.makeNarwhalFactory = function makeNarwhalFactory(path) {
|
||||||
var code, factoryText;
|
var code, factoryText;
|
||||||
code = exports.compileFile(path);
|
code = exports.compileFile(path);
|
||||||
factoryText = "function(require,exports,module,system,print){" + code + "/**/\n}";
|
factoryText = "function(require,exports,module,system,print){" + code + "/**/\n}";
|
||||||
|
|
|
@ -6,14 +6,14 @@
|
||||||
};
|
};
|
||||||
loader = {
|
loader = {
|
||||||
// Reload the coffee-script environment from source.
|
// Reload the coffee-script environment from source.
|
||||||
reload: function(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(topId, path) {
|
load: function load(topId, path) {
|
||||||
return factories[topId] = factories[topId] || this.reload(topId, path);
|
return factories[topId] = factories[topId] || this.reload(topId, path);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -417,7 +417,7 @@ module CoffeeScript
|
||||||
last = @variable.last.to_s.sub(LEADING_DOT, '')
|
last = @variable.last.to_s.sub(LEADING_DOT, '')
|
||||||
proto = name[PROTO_ASSIGN, 1]
|
proto = name[PROTO_ASSIGN, 1]
|
||||||
o = o.merge(:assign => @variable, :last_assign => last, :proto_assign => proto)
|
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
|
return write("#{name}: #{@value.compile(o)}") if @context == :object
|
||||||
o[:scope].find(name) unless @variable.properties?
|
o[:scope].find(name) unless @variable.properties?
|
||||||
return write(@value.compile(o)) if @value.custom_assign?
|
return write(@value.compile(o)) if @value.custom_assign?
|
||||||
|
|
Loading…
Add table
Reference in a new issue