mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-02-18 11:31:20 -05:00
merging all narwhal integration into a single file, so we can merge the node branch without breaking narwhal compatibility
This commit is contained in:
3
Rakefile
3
Rakefile
@@ -19,8 +19,7 @@ namespace :build do
|
|||||||
|
|
||||||
desc "Compile the Narwhal interface for --interactive and --run"
|
desc "Compile the Narwhal interface for --interactive and --run"
|
||||||
task :narwhal do
|
task :narwhal do
|
||||||
sh "bin/coffee lib/coffee_script/narwhal/*.coffee -o lib/coffee_script/narwhal/lib/coffee-script"
|
sh "bin/coffee lib/coffee_script/narwhal/*.coffee -o lib/coffee_script/narwhal"
|
||||||
sh "mv lib/coffee_script/narwhal/lib/coffee-script/coffee-script.js lib/coffee_script/narwhal/lib/coffee-script.js"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
desc "Compile and install the Ultraviolet syntax highlighter"
|
desc "Compile and install the Ultraviolet syntax highlighter"
|
||||||
|
|||||||
@@ -1,62 +1,74 @@
|
|||||||
# This (javascript) file is generated from lib/coffee_script/narwhal/coffee-script.coffee
|
# The Narwhal-compatibility wrapper for CoffeeScript.
|
||||||
|
|
||||||
# Executes the `coffee` Ruby program to convert from CoffeeScript
|
|
||||||
# to Javascript. Eventually this will hopefully happen entirely within JS.
|
|
||||||
|
|
||||||
# Require external dependencies.
|
# 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().join('bin', 'coffee')
|
||||||
|
|
||||||
# Our general-purpose error handler.
|
# Our general-purpose error handler.
|
||||||
checkForErrors: (coffeeProcess) ->
|
checkForErrors: (coffeeProcess) ->
|
||||||
return true if coffeeProcess.wait() is 0
|
return true if coffeeProcess.wait() is 0
|
||||||
system.stderr.print(coffeeProcess.stderr.read())
|
system.stderr.print coffeeProcess.stderr.read()
|
||||||
throw new Error("CoffeeScript compile error")
|
throw new Error "CoffeeScript compile error"
|
||||||
|
|
||||||
# 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: (args) ->
|
exports.run: (args) ->
|
||||||
if args.length
|
if args.length
|
||||||
for path, i in args
|
for path, i in args
|
||||||
exports.evalCS(File.read(path))
|
exports.evalCS File.read path
|
||||||
delete args[i]
|
delete args[i]
|
||||||
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(), ['--globals'])
|
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
|
||||||
|
|
||||||
# Compile a given CoffeeScript file into JavaScript.
|
# Compile a given CoffeeScript file into JavaScript.
|
||||||
exports.compileFile: (path) ->
|
exports.compileFile: (path) ->
|
||||||
coffee: OS.popen([coffeePath, "--print", "--no-wrap", path])
|
coffee: OS.popen [coffeePath, "--print", "--no-wrap", path]
|
||||||
checkForErrors(coffee)
|
checkForErrors coffee
|
||||||
coffee.stdout.read()
|
coffee.stdout.read()
|
||||||
|
|
||||||
# Compile a string of CoffeeScript into JavaScript.
|
# Compile a string of CoffeeScript into JavaScript.
|
||||||
exports.compile: (source, flags) ->
|
exports.compile: (source, flags) ->
|
||||||
coffee: OS.popen([coffeePath, "--eval", "--no-wrap"].concat(flags or []))
|
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, flags) ->
|
exports.evalCS: (source, flags) ->
|
||||||
eval(exports.compile(source, flags))
|
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) ->
|
||||||
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}"
|
||||||
if system.engine is "rhino"
|
if system.engine is "rhino"
|
||||||
Packages.org.mozilla.javascript.Context.getCurrentContext().compileFunction(global, factoryText, path, 0, null)
|
Packages.org.mozilla.javascript.Context.getCurrentContext().compileFunction(global, factoryText, path, 0, null)
|
||||||
else
|
else
|
||||||
# eval requires parentheses, but parentheses break compileFunction.
|
# eval requires parentheses, but parentheses break compileFunction.
|
||||||
eval("(" + factoryText + ")")
|
eval "(" + factoryText + ")"
|
||||||
|
|
||||||
|
# The Narwhal loader for '.coffee' files.
|
||||||
|
factories: {}
|
||||||
|
loader: {}
|
||||||
|
|
||||||
|
# Reload the coffee-script environment from source.
|
||||||
|
loader.reload: (topId, path) ->
|
||||||
|
factories[topId]: ->
|
||||||
|
exports.makeNarwhalFactory path
|
||||||
|
|
||||||
|
# Ensure that the coffee-script environment is loaded.
|
||||||
|
loader.load: (topId, path) ->
|
||||||
|
factories[topId] ||= this.reload topId, path
|
||||||
|
|
||||||
|
require.loader.loaders.unshift [".coffee", loader]
|
||||||
|
|||||||
@@ -1,14 +1,12 @@
|
|||||||
(function(){
|
(function(){
|
||||||
var File, OS, Readline, checkForErrors, coffeePath;
|
var File, OS, Readline, checkForErrors, coffeePath, factories, loader;
|
||||||
// This (javascript) file is generated from lib/coffee_script/narwhal/coffee-script.coffee
|
// The Narwhal-compatibility wrapper for CoffeeScript.
|
||||||
// Executes the `coffee` Ruby program to convert from CoffeeScript
|
|
||||||
// to Javascript. Eventually this will hopefully happen entirely within JS.
|
|
||||||
// Require external dependencies.
|
// 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().join('bin', 'coffee');
|
||||||
// Our general-purpose error handler.
|
// Our general-purpose error handler.
|
||||||
checkForErrors = function checkForErrors(coffeeProcess) {
|
checkForErrors = function checkForErrors(coffeeProcess) {
|
||||||
if (coffeeProcess.wait() === 0) {
|
if (coffeeProcess.wait() === 0) {
|
||||||
@@ -77,4 +75,20 @@
|
|||||||
return eval("(" + factoryText + ")");
|
return eval("(" + factoryText + ")");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
// The Narwhal loader for '.coffee' files.
|
||||||
|
factories = {
|
||||||
|
};
|
||||||
|
loader = {
|
||||||
|
};
|
||||||
|
// Reload the coffee-script environment from source.
|
||||||
|
loader.reload = function reload(topId, path) {
|
||||||
|
return factories[topId] = function() {
|
||||||
|
return exports.makeNarwhalFactory(path);
|
||||||
|
};
|
||||||
|
};
|
||||||
|
// Ensure that the coffee-script environment is loaded.
|
||||||
|
loader.load = function load(topId, path) {
|
||||||
|
return factories[topId] = factories[topId] || this.reload(topId, path);
|
||||||
|
};
|
||||||
|
require.loader.loaders.unshift([".coffee", loader]);
|
||||||
})();
|
})();
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
(function(){
|
|
||||||
var coffeescript, factories, loader;
|
|
||||||
// This (javascript) file is generated from lib/coffee_script/narwhal/loader.coffee
|
|
||||||
coffeescript = null;
|
|
||||||
factories = {
|
|
||||||
};
|
|
||||||
loader = {
|
|
||||||
// Reload the coffee-script environment from source.
|
|
||||||
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 load(topId, path) {
|
|
||||||
return factories[topId] = factories[topId] || this.reload(topId, path);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
require.loader.loaders.unshift([".coffee", loader]);
|
|
||||||
})();
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
# This (javascript) file is generated from lib/coffee_script/narwhal/loader.coffee
|
|
||||||
|
|
||||||
coffeescript: null
|
|
||||||
factories: {}
|
|
||||||
|
|
||||||
loader: {
|
|
||||||
|
|
||||||
# Reload the coffee-script environment from source.
|
|
||||||
reload: (topId, path) ->
|
|
||||||
coffeescript ||= require('coffee-script')
|
|
||||||
factories[topId]: -> coffeescript.makeNarwhalFactory(path)
|
|
||||||
|
|
||||||
# Ensure that the coffee-script environment is loaded.
|
|
||||||
load: (topId, path) ->
|
|
||||||
factories[topId] ||= this.reload(topId, path)
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
require.loader.loaders.unshift([".coffee", loader])
|
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "coffee-script",
|
"name": "coffee-script",
|
||||||
"lib": "lib/coffee_script/narwhal/lib",
|
"lib": "lib/coffee_script/narwhal",
|
||||||
"preload": ["coffee-script/loader"],
|
"preload": ["narwhal"],
|
||||||
"description": "Unfancy JavaScript",
|
"description": "Unfancy JavaScript",
|
||||||
"keywords": ["javascript", "language"],
|
"keywords": ["javascript", "language"],
|
||||||
"author": "Jeremy Ashkenas",
|
"author": "Jeremy Ashkenas",
|
||||||
|
|||||||
Reference in New Issue
Block a user