Compare commits

...

5 Commits
0.1.5 ... 0.1.6

Author SHA1 Message Date
Jeremy Ashkenas
8fe6fa1cd7 CoffeeScript 0.1.6 -- bugfixes 2009-12-27 12:49:11 -08:00
Jeremy Ashkenas
835db4b279 fixing paths for running
coffee compiles CoffeeScript source files into JavaScript.

Usage:
  coffee path/to/script.coffee
    -i, --interactive                run a CoffeeScript REPL (requires Narwhal)
    -r, --run                        compile and run a script (requires Narwhal)
    -o, --output [DIR]               set the directory for compiled JavaScript
    -w, --watch                      watch scripts for changes, and recompile
    -p, --print                      print the compiled JavaScript to stdout
    -l, --lint                       pipe the compiled JavaScript through JSLint
    -e, --eval                       compile a cli scriptlet or read from stdin
    -t, --tokens                     print the tokens that the lexer produces
    -v, --verbose                    print at every step of code generation
    -n, --no-wrap                    raw output, no safety wrapper or vars
        --install-bundle             install the CoffeeScript TextMate bundle
        --version                    display CoffeeScript version
    -h, --help                       display this help message outside of the coffee-script directory
2009-12-27 12:43:05 -08:00
Jeremy Ashkenas
f89c864911 more underscore examples 2009-12-27 11:01:19 -08:00
Jeremy Ashkenas
542726911a more underscore and bugfix edits to code generation 2009-12-26 22:24:21 -08:00
Jeremy Ashkenas
575dc7d12e more underscore, and removing custom_assign and return from conditional compilation 2009-12-26 21:55:56 -08:00
16 changed files with 232 additions and 258 deletions

View File

@@ -1,7 +1,7 @@
Gem::Specification.new do |s|
s.name = 'coffee-script'
s.version = '0.1.5' # Keep version in sync with coffee-script.rb
s.date = '2009-12-26'
s.version = '0.1.6' # Keep version in sync with coffee-script.rb
s.date = '2009-12-27'
s.homepage = "http://jashkenas.github.com/coffee-script/"
s.summary = "The CoffeeScript Compiler"

View File

@@ -470,6 +470,13 @@ coffee --print app/scripts/*.coffee > concatenation.js</pre>
<h2 id="change_log">Change Log</h2>
<p>
<b class="header" style="margin-top: 20px;">0.1.6</b>
Bugfix for running <tt>coffee --interactive</tt> and <tt>--run</tt>
from outside of the CoffeeScript directory. Bugfix for nested
function/if-statements.
</p>
<p>
<b class="header" style="margin-top: 20px;">0.1.5</b>
Array slice literals and array comprehensions can now both take Ruby-style

View File

@@ -4,8 +4,7 @@
change_numbers = function() {
var new_num;
num = 2;
new_num = 3;
return new_num;
return (new_num = 3);
};
new_num = change_numbers();
})();

View File

@@ -6,8 +6,7 @@
return alert(this.name + " moved " + meters + "m.");
};
Snake = function(name) {
this.name = name;
return this.name;
return (this.name = name);
};
Snake.__superClass__ = Animal.prototype;
Snake.prototype = new Animal();
@@ -17,8 +16,7 @@
return Snake.__superClass__.move.call(this, 5);
};
Horse = function(name) {
this.name = name;
return this.name;
return (this.name = name);
};
Horse.__superClass__ = Animal.prototype;
Horse.prototype = new Animal();

View File

@@ -93,77 +93,63 @@ _.reduceRight: obj, memo, iterator, context =>
if obj and _.isFunction(obj.filter) then return obj.filter(iterator, context).
results: []
_.each(obj, (value, index, list =>
iterator.call(context, value, index, list) and results.push(value).))
results.push(value) if iterator.call(context, value, index, list).))
results.
#
# # Return all the elements for which a truth test fails.
# _.reject = function(obj, iterator, context) {
# var results = [];
# _.each(obj, function(value, index, list) {
# !iterator.call(context, value, index, list) && results.push(value);
# });
# return results;
# };
#
# # Determine whether all of the elements match a truth test. Delegate to
# # JavaScript 1.6's every(), if it is present.
# _.all = function(obj, iterator, context) {
# iterator = iterator || _.identity;
# if (obj && _.isFunction(obj.every)) return obj.every(iterator, context);
# var result = true;
# _.each(obj, function(value, index, list) {
# if (!(result = result && iterator.call(context, value, index, list))) _.breakLoop();
# });
# return result;
# };
#
# # Determine if at least one element in the object matches a truth test. Use
# # JavaScript 1.6's some(), if it exists.
# _.any = function(obj, iterator, context) {
# iterator = iterator || _.identity;
# if (obj && _.isFunction(obj.some)) return obj.some(iterator, context);
# var result = false;
# _.each(obj, function(value, index, list) {
# if (result = iterator.call(context, value, index, list)) _.breakLoop();
# });
# return result;
# };
#
# # Determine if a given value is included in the array or object,
# # based on '==='.
# _.include = function(obj, target) {
# if (_.isArray(obj)) return _.indexOf(obj, target) != -1;
# var found = false;
# _.each(obj, function(value) {
# if (found = value === target) _.breakLoop();
# });
# return found;
# };
#
# # Invoke a method with arguments on every item in a collection.
# _.invoke = function(obj, method) {
# var args = _.rest(arguments, 2);
# return _.map(obj, function(value) {
# return (method ? value[method] : value).apply(value, args);
# });
# };
#
# # Convenience version of a common use case of map: fetching a property.
# _.pluck = function(obj, key) {
# return _.map(obj, function(value){ return value[key]; });
# };
#
# # Return the maximum item or (item-based computation).
# _.max = function(obj, iterator, context) {
# if (!iterator && _.isArray(obj)) return Math.max.apply(Math, obj);
# var result = {computed : -Infinity};
# _.each(obj, function(value, index, list) {
# var computed = iterator ? iterator.call(context, value, index, list) : value;
# computed >= result.computed && (result = {value : value, computed : computed});
# });
# return result.value;
# };
# Return all the elements for which a truth test fails.
_.reject: obj, iterator, context =>
results: []
_.each(obj, (value, index, list =>
results.push(value) if not iterator.call(context, value, index, list).))
results.
# Determine whether all of the elements match a truth test. Delegate to
# JavaScript 1.6's every(), if it is present.
_.all: obj, iterator, context =>
iterator ||= _.identity
return obj.every(iterator, context) if obj and _.isFunction(obj.every)
result: true
_.each(obj, (value, index, list =>
_.breakLoop() unless result: result and iterator.call(context, value, index, list).))
result.
# Determine if at least one element in the object matches a truth test. Use
# JavaScript 1.6's some(), if it exists.
_.any: obj, iterator, context =>
iterator ||= _.identity
return obj.some(iterator, context) if obj and _.isFunction(obj.some)
result: false
_.each(obj, (value, index, list =>
_.breakLoop() if (result: iterator.call(context, value, index, list)).))
result.
# Determine if a given value is included in the array or object,
# based on '==='.
_.include: obj, target =>
return _.indexOf(obj, target) isnt -1 if _.isArray(obj)
found: false
_.each(obj, (value =>
_.breakLoop() if (found: value is target).))
found.
# Invoke a method with arguments on every item in a collection.
_.invoke: obj, method =>
args: _.rest(arguments, 2)
_.map(obj, (value =>
(if method then value[method] else value.).apply(value, args).)).
# Convenience version of a common use case of map: fetching a property.
_.pluck: obj, key =>
_.map(obj, (value => value[key].)).
# Return the maximum item or (item-based computation).
_.max: obj, iterator, context =>
return Math.max.apply(Math, obj) if !iterator and _.isArray(obj)
result: {computed: -Infinity}
_.each(obj, (value, index, list =>
computed: if iterator then iterator.call(context, value, index, list) else value.
computed >= result.computed and (result: {value: value, computed: computed}).))
result.value.
#
# # Return the minimum element (or element-based computation).
# _.min = function(obj, iterator, context) {
@@ -320,18 +306,15 @@ _.reduceRight: obj, memo, iterator, context =>
# range[idx++] = i;
# }
# };
#
# /* ----------------------- Function Functions: -----------------------------*/
#
# # Create a function bound to a given object (assigning 'this', and arguments,
# # optionally). Binding with arguments is also known as 'curry'.
# _.bind = function(func, obj) {
# var args = _.rest(arguments, 2);
# return function() {
# return func.apply(obj || root, args.concat(_.toArray(arguments)));
# };
# };
#
# ----------------------- Function Functions: -----------------------------
# Create a function bound to a given object (assigning 'this', and arguments,
# optionally). Binding with arguments is also known as 'curry'.
_.bind: func, obj =>
args: _.rest(arguments, 2)
=> func.apply(obj or root, args.concat(_.toArray(arguments)))..
# # Bind all of an object's methods to that object. Useful for ensuring that
# # all callbacks defined on an object belong to it.
# _.bindAll = function(obj) {
@@ -347,36 +330,27 @@ _.reduceRight: obj, memo, iterator, context =>
# var args = _.rest(arguments, 2);
# return setTimeout(function(){ return func.apply(func, args); }, wait);
# };
#
# # Defers a function, scheduling it to run after the current call stack has
# # cleared.
# _.defer = function(func) {
# return _.delay.apply(_, [func, 1].concat(_.rest(arguments)));
# };
#
# # Returns the first function passed as an argument to the second,
# # allowing you to adjust arguments, run code before and after, and
# # conditionally execute the original function.
# _.wrap = function(func, wrapper) {
# return function() {
# var args = [func].concat(_.toArray(arguments));
# return wrapper.apply(wrapper, args);
# };
# };
#
# # Returns a function that is the composition of a list of functions, each
# # consuming the return value of the function that follows.
# _.compose = function() {
# var funcs = _.toArray(arguments);
# return function() {
# var args = _.toArray(arguments);
# for (var i=funcs.length-1; i >= 0; i--) {
# args = [funcs[i].apply(this, args)];
# }
# return args[0];
# };
# };
#
# Defers a function, scheduling it to run after the current call stack has
# cleared.
_.defer: func =>
_.delay.apply(_, [func, 1].concat(_.rest(arguments))).
# Returns the first function passed as an argument to the second,
# allowing you to adjust arguments, run code before and after, and
# conditionally execute the original function.
_.wrap: func, wrapper =>
=> wrapper.apply(wrapper, [func].concat(_.toArray(arguments)))..
# Returns a function that is the composition of a list of functions, each
# consuming the return value of the function that follows.
_.compose: =>
funcs: _.toArray(arguments)
=>
args: _.toArray(arguments)
args: [funcs[i]].apply(this, args) for i in [(funcs.length - 1)..0].
args[0]..
# /* ------------------------- Object Functions: ---------------------------- */
#
# # Retrieve the names of an object's properties.
@@ -408,81 +382,67 @@ _.reduceRight: obj, memo, iterator, context =>
# if (_.isArray(obj)) return obj.slice(0);
# return _.extend({}, obj);
# };
#
# # Perform a deep comparison to check if two objects are equal.
# _.isEqual = function(a, b) {
# # Check object identity.
# if (a === b) return true;
# # Different types?
# var atype = typeof(a), btype = typeof(b);
# if (atype != btype) return false;
# # Basic equality test (watch out for coercions).
# if (a == b) return true;
# # One is falsy and the other truthy.
# if ((!a && b) || (a && !b)) return false;
# # One of them implements an isEqual()?
# if (a.isEqual) return a.isEqual(b);
# # Check dates' integer values.
# if (_.isDate(a) && _.isDate(b)) return a.getTime() === b.getTime();
# # Both are NaN?
# if (_.isNaN(a) && _.isNaN(b)) return true;
# # Compare regular expressions.
# if (_.isRegExp(a) && _.isRegExp(b))
# return a.source === b.source &&
# a.global === b.global &&
# a.ignoreCase === b.ignoreCase &&
# a.multiline === b.multiline;
# # If a is not an object by this point, we can't handle it.
# if (atype !== 'object') return false;
# # Check for different array lengths before comparing contents.
# if (a.length && (a.length !== b.length)) return false;
# # Nothing else worked, deep compare the contents.
# var aKeys = _.keys(a), bKeys = _.keys(b);
# # Different object sizes?
# if (aKeys.length != bKeys.length) return false;
# # Recursive comparison of contents.
# for (var key in a) if (!_.isEqual(a[key], b[key])) return false;
# return true;
# };
#
# # Is a given array or object empty?
# _.isEmpty = function(obj) {
# return _.keys(obj).length == 0;
# };
#
# # Is a given value a DOM element?
# _.isElement = function(obj) {
# return !!(obj && obj.nodeType == 1);
# };
#
# # Is a given variable an arguments object?
# _.isArguments = function(obj) {
# return obj && _.isNumber(obj.length) && !_.isArray(obj) && !propertyIsEnumerable.call(obj, 'length');
# };
#
# # Is the given value NaN -- this one is interesting. NaN != NaN, and
# # isNaN(undefined) == true, so we make sure it's a number first.
# _.isNaN = function(obj) {
# return _.isNumber(obj) && isNaN(obj);
# };
#
# # Is a given value equal to null?
# _.isNull = function(obj) {
# return obj === null;
# };
#
# # Is a given variable undefined?
# _.isUndefined = function(obj) {
# return typeof obj == 'undefined';
# };
#
# # Invokes interceptor with the obj, and then returns obj.
# # The primary purpose of this method is to "tap into" a method chain, in order to perform operations on intermediate results within the chain.
# _.tap = function(obj, interceptor) {
# interceptor(obj);
# return obj;
# }
#
# Perform a deep comparison to check if two objects are equal.
_.isEqual: a, b =>
# Check object identity.
return true if a is b
# Different types?
atype: typeof(a); btype: typeof(b)
return false if atype isnt btype
# Basic equality test (watch out for coercions).
return true if `a == b`
# One is falsy and the other truthy.
return false if (!a and b) or (a and !b)
# One of them implements an isEqual()?
return a.isEqual(b) if a.isEqual
# Check dates' integer values.
return a.getTime() is b.getTime() if _.isDate(a) and _.isDate(b)
# Both are NaN?
return true if _.isNaN(a) and _.isNaN(b)
# Compare regular expressions.
if _.isRegExp(a) and _.isRegExp(b)
return a.source is b.source and \
a.global is b.global and \
a.ignoreCase is b.ignoreCase and \
a.multiline is b.multiline.
# If a is not an object by this point, we can't handle it.
return false if atype isnt 'object'
# Check for different array lengths before comparing contents.
return false if a.length and (a.length isnt b.length)
# Nothing else worked, deep compare the contents.
aKeys: _.keys(a); bKeys: _.keys(b)
# Different object sizes?
return false if aKeys.length isnt bKeys.length
# Recursive comparison of contents.
# for (var key in a) if (!_.isEqual(a[key], b[key])) return false;
return true.
# Is a given array or object empty?
_.isEmpty: obj => _.keys(obj).length is 0.
# Is a given value a DOM element?
_.isElement: obj => !!(obj and obj.nodeType is 1).
# Is a given variable an arguments object?
_.isArguments: obj => obj and _.isNumber(obj.length) and !_.isArray(obj) and !propertyIsEnumerable.call(obj, 'length').
# Is the given value NaN -- this one is interesting. NaN != NaN, and
# isNaN(undefined) == true, so we make sure it's a number first.
_.isNaN: obj => _.isNumber(obj) and isNaN(obj).
# Is a given value equal to null?
_.isNull: obj => obj is null.
# Is a given variable undefined?
_.isUndefined: obj => typeof obj is 'undefined'.
# Invokes interceptor with the obj, and then returns obj.
# The primary purpose of this method is to "tap into" a method chain, in order to perform operations on intermediate results within the chain.
_.tap: obj, interceptor =>
interceptor(obj)
obj.
# # Define the isArray, isDate, isFunction, isNumber, isRegExp, and isString
# # functions based on their toString identifiers.
# var types = ['Array', 'Date', 'Function', 'Number', 'RegExp', 'String'];
@@ -492,26 +452,21 @@ _.reduceRight: obj, memo, iterator, context =>
# _['is' + types[i]] = function(obj) { return toString.call(obj) == identifier; };
# })();
# }
#
# /* -------------------------- Utility Functions: -------------------------- */
#
# # Run Underscore.js in noConflict mode, returning the '_' variable to its
# # previous owner. Returns a reference to the Underscore object.
# _.noConflict = function() {
# root._ = previousUnderscore;
# return this;
# };
#
# # Keep the identity function around for default iterators.
# _.identity = function(value) {
# return value;
# };
#
# # Break out of the middle of an iteration.
# _.breakLoop = function() {
# throw breaker;
# };
#
# -------------------------- Utility Functions: --------------------------
# Run Underscore.js in noConflict mode, returning the '_' variable to its
# previous owner. Returns a reference to the Underscore object.
_.noConflict: =>
root._: previousUnderscore
this.
# Keep the identity function around for default iterators.
_.identity: value => value.
# Break out of the middle of an iteration.
_.breakLoop: => throw breaker.
# # Generate a unique integer id (unique within the entire client session).
# # Useful for temporary DOM ids.
# var idCounter = 0;
@@ -537,19 +492,19 @@ _.reduceRight: obj, memo, iterator, context =>
# + "');}return p.join('');");
# return data ? fn(data) : fn;
# };
#
# /*------------------------------- Aliases ----------------------------------*/
#
# _.forEach = _.each;
# _.foldl = _.inject = _.reduce;
# _.foldr = _.reduceRight;
# _.filter = _.select;
# _.every = _.all;
# _.some = _.any;
# _.head = _.first;
# _.tail = _.rest;
# _.methods = _.functions;
#
# ------------------------------- Aliases ----------------------------------
_.forEach: _.each
_.foldl: _.inject: _.reduce
_.foldr: _.reduceRight
_.filter: _.select
_.every: _.all
_.some: _.any
_.head: _.first
_.tail: _.rest
_.methods: _.functions
# /*------------------------ Setup the OOP Wrapper: --------------------------*/
#
# # Helper function to continue chaining intermediate results.

View File

@@ -373,8 +373,7 @@ num <span class="Keyword">=</span> <span class="Number">1</span>;
<span class="FunctionName">change_numbers</span> = <span class="Storage">function</span>() {
<span class="Storage">var</span> new_num;
num <span class="Keyword">=</span> <span class="Number">2</span>;
new_num <span class="Keyword">=</span> <span class="Number">3</span>;
<span class="Keyword">return</span> new_num;
<span class="Keyword">return</span> (new_num <span class="Keyword">=</span> <span class="Number">3</span>);
};
new_num <span class="Keyword">=</span> change_numbers();
</pre><button onclick='javascript: var change_numbers, new_num, num;
@@ -382,8 +381,7 @@ num = 1;
change_numbers = function() {
var new_num;
num = 2;
new_num = 3;
return new_num;
return (new_num = 3);
};
new_num = change_numbers();
;alert(new_num);'>run: new_num</button><br class='clear' /></div>
@@ -680,8 +678,7 @@ tom.move()
<span class="Keyword">return</span> <span class="LibraryFunction">alert</span>(<span class="Variable">this</span>.<span class="LibraryConstant">name</span> <span class="Keyword">+</span> <span class="String"><span class="String">&quot;</span> moved <span class="String">&quot;</span></span> <span class="Keyword">+</span> meters <span class="Keyword">+</span> <span class="String"><span class="String">&quot;</span>m.<span class="String">&quot;</span></span>);
};
<span class="FunctionName">Snake</span> = <span class="Storage">function</span>(<span class="FunctionArgument">name</span>) {
<span class="Variable">this</span>.<span class="LibraryConstant">name</span> <span class="Keyword">=</span> name;
<span class="Keyword">return</span> <span class="Variable">this</span>.<span class="LibraryConstant">name</span>;
<span class="Keyword">return</span> (<span class="Variable">this</span>.<span class="LibraryConstant">name</span> <span class="Keyword">=</span> name);
};
Snake.__superClass__ <span class="Keyword">=</span> Animal.<span class="LibraryConstant">prototype</span>;
<span class="LibraryClassType">Snake</span>.<span class="LibraryConstant">prototype</span> = <span class="Keyword">new</span> <span class="TypeName">Animal</span>();
@@ -691,8 +688,7 @@ Snake.__superClass__ <span class="Keyword">=</span> Animal.<span class="LibraryC
<span class="Keyword">return</span> Snake.__superClass__.move.<span class="LibraryFunction">call</span>(<span class="Variable">this</span>, <span class="Number">5</span>);
};
<span class="FunctionName">Horse</span> = <span class="Storage">function</span>(<span class="FunctionArgument">name</span>) {
<span class="Variable">this</span>.<span class="LibraryConstant">name</span> <span class="Keyword">=</span> name;
<span class="Keyword">return</span> <span class="Variable">this</span>.<span class="LibraryConstant">name</span>;
<span class="Keyword">return</span> (<span class="Variable">this</span>.<span class="LibraryConstant">name</span> <span class="Keyword">=</span> name);
};
Horse.__superClass__ <span class="Keyword">=</span> Animal.<span class="LibraryConstant">prototype</span>;
<span class="LibraryClassType">Horse</span>.<span class="LibraryConstant">prototype</span> = <span class="Keyword">new</span> <span class="TypeName">Animal</span>();
@@ -712,8 +708,7 @@ Animal.prototype.move = function(meters) {
return alert(this.name + " moved " + meters + "m.");
};
Snake = function(name) {
this.name = name;
return this.name;
return (this.name = name);
};
Snake.__superClass__ = Animal.prototype;
Snake.prototype = new Animal();
@@ -723,8 +718,7 @@ Snake.prototype.move = function() {
return Snake.__superClass__.move.call(this, 5);
};
Horse = function(name) {
this.name = name;
return this.name;
return (this.name = name);
};
Horse.__superClass__ = Animal.prototype;
Horse.prototype = new Animal();
@@ -889,6 +883,13 @@ world...";
<h2 id="change_log">Change Log</h2>
<p>
<b class="header" style="margin-top: 20px;">0.1.6</b>
Bugfix for running <tt>coffee --interactive</tt> and <tt>--run</tt>
from outside of the CoffeeScript directory. Bugfix for nested
function/if-statements.
</p>
<p>
<b class="header" style="margin-top: 20px;">0.1.5</b>
Array slice literals and array comprehensions can now both take Ruby-style

View File

@@ -9,7 +9,7 @@ require "coffee_script/parse_error"
# Namespace for all CoffeeScript internal classes.
module CoffeeScript
VERSION = '0.1.5' # Keep in sync with the gemspec.
VERSION = '0.1.6' # Keep in sync with the gemspec.
# Compile a script (String or IO) to JavaScript.
def self.compile(script, options={})

View File

@@ -19,6 +19,9 @@ Usage:
# Seconds to pause between checks for changed source files.
WATCH_INTERVAL = 0.5
# Path to the Narwhal Launcher:
LAUNCHER = File.expand_path(File.dirname(__FILE__)) + '/narwhal/js/launcher.js'
# Run the CommandLine off the contents of ARGV.
def initialize
@mtimes = {}
@@ -104,7 +107,7 @@ Usage:
# Use Narwhal to run an interactive CoffeeScript session.
def launch_repl
exec "narwhal lib/coffee_script/narwhal/js/launcher.js"
exec "narwhal #{LAUNCHER}"
rescue Errno::ENOENT
puts "Error: Narwhal must be installed to use the interactive REPL."
exit(1)
@@ -113,7 +116,7 @@ Usage:
# Use Narwhal to compile and execute CoffeeScripts.
def run_scripts
sources = @sources.join(' ')
exec "narwhal lib/coffee_script/narwhal/js/launcher.js #{sources}"
exec "narwhal #{LAUNCHER} #{sources}"
rescue Errno::ENOENT
puts "Error: Narwhal must be installed in order to execute CoffeeScripts."
exit(1)

View File

@@ -21,7 +21,9 @@ checkForErrors: coffeeProcess =>
# command.
exports.run: args =>
args.shift()
return require(File.absolute(args[0])) if args.length
if args.length
exports.evalCS(File.read(path)) for path in args.
return true.
while true
try
@@ -51,7 +53,7 @@ exports.evalCS: source =>
# Make a factory for the CoffeeScript environment.
exports.makeNarwhalFactory: path =>
code: exports.compileFile(path)
factoryText: "function(require,exports,module,system,print){" + code + "/**/\n}"
factoryText: "function(require,exports,module,system,print){ 1 + 1 /**/\n}"
if system.engine is "rhino"
Packages.org.mozilla.javascript.Context.getCurrentContext().compileFunction(global, factoryText, path, 0, null)
else

View File

@@ -18,10 +18,17 @@
// Run a simple REPL, round-tripping to the CoffeeScript compiler for every
// command.
exports.run = function(args) {
var result;
var __a, __b, __c, __d, path, result;
args.shift();
if (args.length) {
return require(File.absolute(args[0]));
__a = args;
__d = [];
for (__b=0, __c=__a.length; __b<__c; __b++) {
path = __a[__b];
__d[__b] = exports.evalCS(File.read(path));
}
__d;
return true;
}
while (true) {
try {
@@ -58,7 +65,7 @@
exports.makeNarwhalFactory = function(path) {
var code, factoryText;
code = exports.compileFile(path);
factoryText = "function(require,exports,module,system,print){" + code + "/**/\n}";
factoryText = "function(require,exports,module,system,print){ 1 + 1 /**/\n}";
if (system.engine === "rhino") {
return Packages.org.mozilla.javascript.Context.getCurrentContext().compileFunction(global, factoryText, path, 0, null);
} else {

View File

@@ -1,3 +1,3 @@
(function(){
require("coffee-script").run(system.args);
require("./coffee-script").run(system.args);
})();

View File

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

View File

@@ -1 +1 @@
require("coffee-script").run(system.args)
require("./coffee-script").run(system.args)

View File

@@ -7,7 +7,7 @@ loader: {
# Reload the coffee-script environment from source.
reload: topId, path =>
coffeescript ||= require('coffee-script')
coffeescript ||= require('./coffee-script')
factories[topId]: coffeescript.makeNarwhalFactory(path).
# Ensure that the coffee-script environment is loaded.

View File

@@ -95,6 +95,7 @@ module CoffeeScript
if node.statement? || node.custom_return?
"#{o[:indent]}#{node.compile(o)}#{node.line_ending}"
else
o.delete(:return)
"#{o[:indent]}return #{node.compile(o)}#{node.line_ending}"
end
elsif o[:assign]
@@ -377,12 +378,11 @@ module CoffeeScript
last = @variable.last.to_s
proto = name[PROTO_ASSIGN, 1]
o = o.merge(:assign => @variable, :last_assign => last, :proto_assign => proto)
postfix = o[:return] ? ";\n#{o[:indent]}return #{name}" : ''
return write("#{name}: #{@value.compile(o)}") if @context == :object
return write("#{name} = #{@value.compile(o)}#{postfix}") if @variable.properties? && !@value.custom_assign?
o[:scope].find(name) unless @variable.properties?
return write(@value.compile(o)) if @value.custom_assign?
write("#{name} = #{@value.compile(o)}#{postfix}")
val = "#{name} = #{@value.compile(o)}"
write(o[:return] && !@value.custom_return? ? "return (#{val})" : val)
end
end
@@ -728,8 +728,11 @@ module CoffeeScript
# force sub-else bodies into statement form.
def compile_statement(o)
indent = o[:indent]
cond_o = o.dup
cond_o.delete(:assign)
cond_o.delete(:return)
o[:indent] += TAB
if_part = "if (#{@condition.compile(o)}) {\n#{Expressions.wrap(@body).compile(o)}\n#{indent}}"
if_part = "if (#{@condition.compile(cond_o)}) {\n#{Expressions.wrap(@body).compile(o)}\n#{indent}}"
return if_part unless @else_body
else_part = chain? ?
" else #{@else_body.compile(o.merge(:indent => indent))}" :

View File

@@ -5,5 +5,5 @@
"description": "Unfancy JavaScript",
"keywords": ["javascript", "language"],
"author": "Jeremy Ashkenas",
"version": "0.1.5"
"version": "0.1.6"
}