coffee-script 0.1.5 → 0.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/coffee-script.gemspec +2 -2
- data/examples/underscore.coffee +174 -219
- data/lib/coffee-script.rb +1 -1
- data/lib/coffee_script/command_line.rb +5 -2
- data/lib/coffee_script/narwhal/coffee-script.coffee +4 -2
- data/lib/coffee_script/narwhal/js/coffee-script.js +10 -3
- data/lib/coffee_script/narwhal/js/launcher.js +1 -1
- data/lib/coffee_script/narwhal/js/loader.js +2 -3
- data/lib/coffee_script/narwhal/launcher.coffee +1 -1
- data/lib/coffee_script/narwhal/loader.coffee +1 -1
- data/lib/coffee_script/nodes.rb +7 -4
- metadata +2 -2
data/coffee-script.gemspec
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'coffee-script'
|
3
|
-
s.version = '0.1.
|
4
|
-
s.date = '2009-12-
|
3
|
+
s.version = '0.1.6' # Keep version in sync with coffee-script.rb
|
4
|
+
s.date = '2009-12-27'
|
5
5
|
|
6
6
|
s.homepage = "http://jashkenas.github.com/coffee-script/"
|
7
7
|
s.summary = "The CoffeeScript Compiler"
|
data/examples/underscore.coffee
CHANGED
@@ -93,77 +93,63 @@ _.reduceRight: obj, memo, iterator, context =>
|
|
93
93
|
if obj and _.isFunction(obj.filter) then return obj.filter(iterator, context).
|
94
94
|
results: []
|
95
95
|
_.each(obj, (value, index, list =>
|
96
|
-
iterator.call(context, value, index, list)
|
96
|
+
results.push(value) if iterator.call(context, value, index, list).))
|
97
97
|
results.
|
98
98
|
|
99
|
-
#
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
#
|
107
|
-
#
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
#
|
117
|
-
#
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
#
|
127
|
-
#
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
#
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
#
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
#
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
# _.pluck = function(obj, key) {
|
154
|
-
# return _.map(obj, function(value){ return value[key]; });
|
155
|
-
# };
|
156
|
-
#
|
157
|
-
# # Return the maximum item or (item-based computation).
|
158
|
-
# _.max = function(obj, iterator, context) {
|
159
|
-
# if (!iterator && _.isArray(obj)) return Math.max.apply(Math, obj);
|
160
|
-
# var result = {computed : -Infinity};
|
161
|
-
# _.each(obj, function(value, index, list) {
|
162
|
-
# var computed = iterator ? iterator.call(context, value, index, list) : value;
|
163
|
-
# computed >= result.computed && (result = {value : value, computed : computed});
|
164
|
-
# });
|
165
|
-
# return result.value;
|
166
|
-
# };
|
99
|
+
# Return all the elements for which a truth test fails.
|
100
|
+
_.reject: obj, iterator, context =>
|
101
|
+
results: []
|
102
|
+
_.each(obj, (value, index, list =>
|
103
|
+
results.push(value) if not iterator.call(context, value, index, list).))
|
104
|
+
results.
|
105
|
+
|
106
|
+
# Determine whether all of the elements match a truth test. Delegate to
|
107
|
+
# JavaScript 1.6's every(), if it is present.
|
108
|
+
_.all: obj, iterator, context =>
|
109
|
+
iterator ||= _.identity
|
110
|
+
return obj.every(iterator, context) if obj and _.isFunction(obj.every)
|
111
|
+
result: true
|
112
|
+
_.each(obj, (value, index, list =>
|
113
|
+
_.breakLoop() unless result: result and iterator.call(context, value, index, list).))
|
114
|
+
result.
|
115
|
+
|
116
|
+
# Determine if at least one element in the object matches a truth test. Use
|
117
|
+
# JavaScript 1.6's some(), if it exists.
|
118
|
+
_.any: obj, iterator, context =>
|
119
|
+
iterator ||= _.identity
|
120
|
+
return obj.some(iterator, context) if obj and _.isFunction(obj.some)
|
121
|
+
result: false
|
122
|
+
_.each(obj, (value, index, list =>
|
123
|
+
_.breakLoop() if (result: iterator.call(context, value, index, list)).))
|
124
|
+
result.
|
125
|
+
|
126
|
+
# Determine if a given value is included in the array or object,
|
127
|
+
# based on '==='.
|
128
|
+
_.include: obj, target =>
|
129
|
+
return _.indexOf(obj, target) isnt -1 if _.isArray(obj)
|
130
|
+
found: false
|
131
|
+
_.each(obj, (value =>
|
132
|
+
_.breakLoop() if (found: value is target).))
|
133
|
+
found.
|
134
|
+
|
135
|
+
# Invoke a method with arguments on every item in a collection.
|
136
|
+
_.invoke: obj, method =>
|
137
|
+
args: _.rest(arguments, 2)
|
138
|
+
_.map(obj, (value =>
|
139
|
+
(if method then value[method] else value.).apply(value, args).)).
|
140
|
+
|
141
|
+
# Convenience version of a common use case of map: fetching a property.
|
142
|
+
_.pluck: obj, key =>
|
143
|
+
_.map(obj, (value => value[key].)).
|
144
|
+
|
145
|
+
# Return the maximum item or (item-based computation).
|
146
|
+
_.max: obj, iterator, context =>
|
147
|
+
return Math.max.apply(Math, obj) if !iterator and _.isArray(obj)
|
148
|
+
result: {computed: -Infinity}
|
149
|
+
_.each(obj, (value, index, list =>
|
150
|
+
computed: if iterator then iterator.call(context, value, index, list) else value.
|
151
|
+
computed >= result.computed and (result: {value: value, computed: computed}).))
|
152
|
+
result.value.
|
167
153
|
#
|
168
154
|
# # Return the minimum element (or element-based computation).
|
169
155
|
# _.min = function(obj, iterator, context) {
|
@@ -320,18 +306,15 @@ _.reduceRight: obj, memo, iterator, context =>
|
|
320
306
|
# range[idx++] = i;
|
321
307
|
# }
|
322
308
|
# };
|
323
|
-
|
324
|
-
#
|
325
|
-
|
326
|
-
#
|
327
|
-
#
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
# };
|
333
|
-
# };
|
334
|
-
#
|
309
|
+
|
310
|
+
# ----------------------- Function Functions: -----------------------------
|
311
|
+
|
312
|
+
# Create a function bound to a given object (assigning 'this', and arguments,
|
313
|
+
# optionally). Binding with arguments is also known as 'curry'.
|
314
|
+
_.bind: func, obj =>
|
315
|
+
args: _.rest(arguments, 2)
|
316
|
+
=> func.apply(obj or root, args.concat(_.toArray(arguments)))..
|
317
|
+
|
335
318
|
# # Bind all of an object's methods to that object. Useful for ensuring that
|
336
319
|
# # all callbacks defined on an object belong to it.
|
337
320
|
# _.bindAll = function(obj) {
|
@@ -347,36 +330,27 @@ _.reduceRight: obj, memo, iterator, context =>
|
|
347
330
|
# var args = _.rest(arguments, 2);
|
348
331
|
# return setTimeout(function(){ return func.apply(func, args); }, wait);
|
349
332
|
# };
|
350
|
-
|
351
|
-
#
|
352
|
-
#
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
#
|
357
|
-
#
|
358
|
-
#
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
#
|
363
|
-
#
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
# return function() {
|
372
|
-
# var args = _.toArray(arguments);
|
373
|
-
# for (var i=funcs.length-1; i >= 0; i--) {
|
374
|
-
# args = [funcs[i].apply(this, args)];
|
375
|
-
# }
|
376
|
-
# return args[0];
|
377
|
-
# };
|
378
|
-
# };
|
379
|
-
#
|
333
|
+
|
334
|
+
# Defers a function, scheduling it to run after the current call stack has
|
335
|
+
# cleared.
|
336
|
+
_.defer: func =>
|
337
|
+
_.delay.apply(_, [func, 1].concat(_.rest(arguments))).
|
338
|
+
|
339
|
+
# Returns the first function passed as an argument to the second,
|
340
|
+
# allowing you to adjust arguments, run code before and after, and
|
341
|
+
# conditionally execute the original function.
|
342
|
+
_.wrap: func, wrapper =>
|
343
|
+
=> wrapper.apply(wrapper, [func].concat(_.toArray(arguments)))..
|
344
|
+
|
345
|
+
# Returns a function that is the composition of a list of functions, each
|
346
|
+
# consuming the return value of the function that follows.
|
347
|
+
_.compose: =>
|
348
|
+
funcs: _.toArray(arguments)
|
349
|
+
=>
|
350
|
+
args: _.toArray(arguments)
|
351
|
+
args: [funcs[i]].apply(this, args) for i in [(funcs.length - 1)..0].
|
352
|
+
args[0]..
|
353
|
+
|
380
354
|
# /* ------------------------- Object Functions: ---------------------------- */
|
381
355
|
#
|
382
356
|
# # Retrieve the names of an object's properties.
|
@@ -408,81 +382,67 @@ _.reduceRight: obj, memo, iterator, context =>
|
|
408
382
|
# if (_.isArray(obj)) return obj.slice(0);
|
409
383
|
# return _.extend({}, obj);
|
410
384
|
# };
|
411
|
-
|
412
|
-
#
|
413
|
-
|
414
|
-
#
|
415
|
-
|
416
|
-
#
|
417
|
-
|
418
|
-
|
419
|
-
#
|
420
|
-
|
421
|
-
#
|
422
|
-
|
423
|
-
#
|
424
|
-
|
425
|
-
#
|
426
|
-
|
427
|
-
#
|
428
|
-
|
429
|
-
#
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
#
|
436
|
-
|
437
|
-
#
|
438
|
-
|
439
|
-
#
|
440
|
-
|
441
|
-
#
|
442
|
-
|
443
|
-
#
|
444
|
-
#
|
445
|
-
|
446
|
-
|
447
|
-
#
|
448
|
-
|
449
|
-
|
450
|
-
#
|
451
|
-
|
452
|
-
|
453
|
-
#
|
454
|
-
|
455
|
-
|
456
|
-
#
|
457
|
-
#
|
458
|
-
|
459
|
-
|
460
|
-
#
|
461
|
-
|
462
|
-
|
463
|
-
#
|
464
|
-
|
465
|
-
|
466
|
-
#
|
467
|
-
#
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
# };
|
473
|
-
#
|
474
|
-
# # Is a given variable undefined?
|
475
|
-
# _.isUndefined = function(obj) {
|
476
|
-
# return typeof obj == 'undefined';
|
477
|
-
# };
|
478
|
-
#
|
479
|
-
# # Invokes interceptor with the obj, and then returns obj.
|
480
|
-
# # The primary purpose of this method is to "tap into" a method chain, in order to perform operations on intermediate results within the chain.
|
481
|
-
# _.tap = function(obj, interceptor) {
|
482
|
-
# interceptor(obj);
|
483
|
-
# return obj;
|
484
|
-
# }
|
485
|
-
#
|
385
|
+
|
386
|
+
# Perform a deep comparison to check if two objects are equal.
|
387
|
+
_.isEqual: a, b =>
|
388
|
+
# Check object identity.
|
389
|
+
return true if a is b
|
390
|
+
# Different types?
|
391
|
+
atype: typeof(a); btype: typeof(b)
|
392
|
+
return false if atype isnt btype
|
393
|
+
# Basic equality test (watch out for coercions).
|
394
|
+
return true if `a == b`
|
395
|
+
# One is falsy and the other truthy.
|
396
|
+
return false if (!a and b) or (a and !b)
|
397
|
+
# One of them implements an isEqual()?
|
398
|
+
return a.isEqual(b) if a.isEqual
|
399
|
+
# Check dates' integer values.
|
400
|
+
return a.getTime() is b.getTime() if _.isDate(a) and _.isDate(b)
|
401
|
+
# Both are NaN?
|
402
|
+
return true if _.isNaN(a) and _.isNaN(b)
|
403
|
+
# Compare regular expressions.
|
404
|
+
if _.isRegExp(a) and _.isRegExp(b)
|
405
|
+
return a.source is b.source and \
|
406
|
+
a.global is b.global and \
|
407
|
+
a.ignoreCase is b.ignoreCase and \
|
408
|
+
a.multiline is b.multiline.
|
409
|
+
# If a is not an object by this point, we can't handle it.
|
410
|
+
return false if atype isnt 'object'
|
411
|
+
# Check for different array lengths before comparing contents.
|
412
|
+
return false if a.length and (a.length isnt b.length)
|
413
|
+
# Nothing else worked, deep compare the contents.
|
414
|
+
aKeys: _.keys(a); bKeys: _.keys(b)
|
415
|
+
# Different object sizes?
|
416
|
+
return false if aKeys.length isnt bKeys.length
|
417
|
+
# Recursive comparison of contents.
|
418
|
+
# for (var key in a) if (!_.isEqual(a[key], b[key])) return false;
|
419
|
+
return true.
|
420
|
+
|
421
|
+
# Is a given array or object empty?
|
422
|
+
_.isEmpty: obj => _.keys(obj).length is 0.
|
423
|
+
|
424
|
+
# Is a given value a DOM element?
|
425
|
+
_.isElement: obj => !!(obj and obj.nodeType is 1).
|
426
|
+
|
427
|
+
# Is a given variable an arguments object?
|
428
|
+
_.isArguments: obj => obj and _.isNumber(obj.length) and !_.isArray(obj) and !propertyIsEnumerable.call(obj, 'length').
|
429
|
+
|
430
|
+
# Is the given value NaN -- this one is interesting. NaN != NaN, and
|
431
|
+
# isNaN(undefined) == true, so we make sure it's a number first.
|
432
|
+
_.isNaN: obj => _.isNumber(obj) and isNaN(obj).
|
433
|
+
|
434
|
+
# Is a given value equal to null?
|
435
|
+
_.isNull: obj => obj is null.
|
436
|
+
|
437
|
+
# Is a given variable undefined?
|
438
|
+
_.isUndefined: obj => typeof obj is 'undefined'.
|
439
|
+
|
440
|
+
# Invokes interceptor with the obj, and then returns obj.
|
441
|
+
# The primary purpose of this method is to "tap into" a method chain, in order to perform operations on intermediate results within the chain.
|
442
|
+
_.tap: obj, interceptor =>
|
443
|
+
interceptor(obj)
|
444
|
+
obj.
|
445
|
+
|
486
446
|
# # Define the isArray, isDate, isFunction, isNumber, isRegExp, and isString
|
487
447
|
# # functions based on their toString identifiers.
|
488
448
|
# var types = ['Array', 'Date', 'Function', 'Number', 'RegExp', 'String'];
|
@@ -492,26 +452,21 @@ _.reduceRight: obj, memo, iterator, context =>
|
|
492
452
|
# _['is' + types[i]] = function(obj) { return toString.call(obj) == identifier; };
|
493
453
|
# })();
|
494
454
|
# }
|
495
|
-
|
496
|
-
#
|
497
|
-
|
498
|
-
#
|
499
|
-
#
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
#
|
505
|
-
|
506
|
-
|
507
|
-
#
|
508
|
-
|
509
|
-
|
510
|
-
# # Break out of the middle of an iteration.
|
511
|
-
# _.breakLoop = function() {
|
512
|
-
# throw breaker;
|
513
|
-
# };
|
514
|
-
#
|
455
|
+
|
456
|
+
# -------------------------- Utility Functions: --------------------------
|
457
|
+
|
458
|
+
# Run Underscore.js in noConflict mode, returning the '_' variable to its
|
459
|
+
# previous owner. Returns a reference to the Underscore object.
|
460
|
+
_.noConflict: =>
|
461
|
+
root._: previousUnderscore
|
462
|
+
this.
|
463
|
+
|
464
|
+
# Keep the identity function around for default iterators.
|
465
|
+
_.identity: value => value.
|
466
|
+
|
467
|
+
# Break out of the middle of an iteration.
|
468
|
+
_.breakLoop: => throw breaker.
|
469
|
+
|
515
470
|
# # Generate a unique integer id (unique within the entire client session).
|
516
471
|
# # Useful for temporary DOM ids.
|
517
472
|
# var idCounter = 0;
|
@@ -537,19 +492,19 @@ _.reduceRight: obj, memo, iterator, context =>
|
|
537
492
|
# + "');}return p.join('');");
|
538
493
|
# return data ? fn(data) : fn;
|
539
494
|
# };
|
540
|
-
|
541
|
-
#
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
|
495
|
+
|
496
|
+
# ------------------------------- Aliases ----------------------------------
|
497
|
+
|
498
|
+
_.forEach: _.each
|
499
|
+
_.foldl: _.inject: _.reduce
|
500
|
+
_.foldr: _.reduceRight
|
501
|
+
_.filter: _.select
|
502
|
+
_.every: _.all
|
503
|
+
_.some: _.any
|
504
|
+
_.head: _.first
|
505
|
+
_.tail: _.rest
|
506
|
+
_.methods: _.functions
|
507
|
+
|
553
508
|
# /*------------------------ Setup the OOP Wrapper: --------------------------*/
|
554
509
|
#
|
555
510
|
# # Helper function to continue chaining intermediate results.
|
data/lib/coffee-script.rb
CHANGED
@@ -9,7 +9,7 @@ require "coffee_script/parse_error"
|
|
9
9
|
# Namespace for all CoffeeScript internal classes.
|
10
10
|
module CoffeeScript
|
11
11
|
|
12
|
-
VERSION = '0.1.
|
12
|
+
VERSION = '0.1.6' # Keep in sync with the gemspec.
|
13
13
|
|
14
14
|
# Compile a script (String or IO) to JavaScript.
|
15
15
|
def self.compile(script, options={})
|
@@ -19,6 +19,9 @@ Usage:
|
|
19
19
|
# Seconds to pause between checks for changed source files.
|
20
20
|
WATCH_INTERVAL = 0.5
|
21
21
|
|
22
|
+
# Path to the Narwhal Launcher:
|
23
|
+
LAUNCHER = File.expand_path(File.dirname(__FILE__)) + '/narwhal/js/launcher.js'
|
24
|
+
|
22
25
|
# Run the CommandLine off the contents of ARGV.
|
23
26
|
def initialize
|
24
27
|
@mtimes = {}
|
@@ -104,7 +107,7 @@ Usage:
|
|
104
107
|
|
105
108
|
# Use Narwhal to run an interactive CoffeeScript session.
|
106
109
|
def launch_repl
|
107
|
-
exec "narwhal
|
110
|
+
exec "narwhal #{LAUNCHER}"
|
108
111
|
rescue Errno::ENOENT
|
109
112
|
puts "Error: Narwhal must be installed to use the interactive REPL."
|
110
113
|
exit(1)
|
@@ -113,7 +116,7 @@ Usage:
|
|
113
116
|
# Use Narwhal to compile and execute CoffeeScripts.
|
114
117
|
def run_scripts
|
115
118
|
sources = @sources.join(' ')
|
116
|
-
exec "narwhal
|
119
|
+
exec "narwhal #{LAUNCHER} #{sources}"
|
117
120
|
rescue Errno::ENOENT
|
118
121
|
puts "Error: Narwhal must be installed in order to execute CoffeeScripts."
|
119
122
|
exit(1)
|
@@ -21,7 +21,9 @@ checkForErrors: coffeeProcess =>
|
|
21
21
|
# command.
|
22
22
|
exports.run: args =>
|
23
23
|
args.shift()
|
24
|
-
|
24
|
+
if args.length
|
25
|
+
exports.evalCS(File.read(path)) for path in args.
|
26
|
+
return true.
|
25
27
|
|
26
28
|
while true
|
27
29
|
try
|
@@ -51,7 +53,7 @@ exports.evalCS: source =>
|
|
51
53
|
# Make a factory for the CoffeeScript environment.
|
52
54
|
exports.makeNarwhalFactory: path =>
|
53
55
|
code: exports.compileFile(path)
|
54
|
-
factoryText: "function(require,exports,module,system,print){
|
56
|
+
factoryText: "function(require,exports,module,system,print){ 1 + 1 /**/\n}"
|
55
57
|
if system.engine is "rhino"
|
56
58
|
Packages.org.mozilla.javascript.Context.getCurrentContext().compileFunction(global, factoryText, path, 0, null)
|
57
59
|
else
|
@@ -18,10 +18,17 @@
|
|
18
18
|
// Run a simple REPL, round-tripping to the CoffeeScript compiler for every
|
19
19
|
// command.
|
20
20
|
exports.run = function(args) {
|
21
|
-
var result;
|
21
|
+
var __a, __b, __c, __d, path, result;
|
22
22
|
args.shift();
|
23
23
|
if (args.length) {
|
24
|
-
|
24
|
+
__a = args;
|
25
|
+
__d = [];
|
26
|
+
for (__b=0, __c=__a.length; __b<__c; __b++) {
|
27
|
+
path = __a[__b];
|
28
|
+
__d[__b] = exports.evalCS(File.read(path));
|
29
|
+
}
|
30
|
+
__d;
|
31
|
+
return true;
|
25
32
|
}
|
26
33
|
while (true) {
|
27
34
|
try {
|
@@ -58,7 +65,7 @@
|
|
58
65
|
exports.makeNarwhalFactory = function(path) {
|
59
66
|
var code, factoryText;
|
60
67
|
code = exports.compileFile(path);
|
61
|
-
factoryText = "function(require,exports,module,system,print){
|
68
|
+
factoryText = "function(require,exports,module,system,print){ 1 + 1 /**/\n}";
|
62
69
|
if (system.engine === "rhino") {
|
63
70
|
return Packages.org.mozilla.javascript.Context.getCurrentContext().compileFunction(global, factoryText, path, 0, null);
|
64
71
|
} else {
|
@@ -7,9 +7,8 @@
|
|
7
7
|
loader = {
|
8
8
|
// Reload the coffee-script environment from source.
|
9
9
|
reload: function(topId, path) {
|
10
|
-
coffeescript = coffeescript || require('coffee-script');
|
11
|
-
factories[topId] = coffeescript.makeNarwhalFactory(path);
|
12
|
-
return factories[topId];
|
10
|
+
coffeescript = coffeescript || require('./coffee-script');
|
11
|
+
return (factories[topId] = coffeescript.makeNarwhalFactory(path));
|
13
12
|
},
|
14
13
|
// Ensure that the coffee-script environment is loaded.
|
15
14
|
load: function(topId, path) {
|
@@ -1 +1 @@
|
|
1
|
-
require("coffee-script").run(system.args)
|
1
|
+
require("./coffee-script").run(system.args)
|
@@ -7,7 +7,7 @@ loader: {
|
|
7
7
|
|
8
8
|
# Reload the coffee-script environment from source.
|
9
9
|
reload: topId, path =>
|
10
|
-
coffeescript ||= require('coffee-script')
|
10
|
+
coffeescript ||= require('./coffee-script')
|
11
11
|
factories[topId]: coffeescript.makeNarwhalFactory(path).
|
12
12
|
|
13
13
|
# Ensure that the coffee-script environment is loaded.
|
data/lib/coffee_script/nodes.rb
CHANGED
@@ -95,6 +95,7 @@ module CoffeeScript
|
|
95
95
|
if node.statement? || node.custom_return?
|
96
96
|
"#{o[:indent]}#{node.compile(o)}#{node.line_ending}"
|
97
97
|
else
|
98
|
+
o.delete(:return)
|
98
99
|
"#{o[:indent]}return #{node.compile(o)}#{node.line_ending}"
|
99
100
|
end
|
100
101
|
elsif o[:assign]
|
@@ -377,12 +378,11 @@ module CoffeeScript
|
|
377
378
|
last = @variable.last.to_s
|
378
379
|
proto = name[PROTO_ASSIGN, 1]
|
379
380
|
o = o.merge(:assign => @variable, :last_assign => last, :proto_assign => proto)
|
380
|
-
postfix = o[:return] ? ";\n#{o[:indent]}return #{name}" : ''
|
381
381
|
return write("#{name}: #{@value.compile(o)}") if @context == :object
|
382
|
-
return write("#{name} = #{@value.compile(o)}#{postfix}") if @variable.properties? && !@value.custom_assign?
|
383
382
|
o[:scope].find(name) unless @variable.properties?
|
384
383
|
return write(@value.compile(o)) if @value.custom_assign?
|
385
|
-
|
384
|
+
val = "#{name} = #{@value.compile(o)}"
|
385
|
+
write(o[:return] && !@value.custom_return? ? "return (#{val})" : val)
|
386
386
|
end
|
387
387
|
end
|
388
388
|
|
@@ -728,8 +728,11 @@ module CoffeeScript
|
|
728
728
|
# force sub-else bodies into statement form.
|
729
729
|
def compile_statement(o)
|
730
730
|
indent = o[:indent]
|
731
|
+
cond_o = o.dup
|
732
|
+
cond_o.delete(:assign)
|
733
|
+
cond_o.delete(:return)
|
731
734
|
o[:indent] += TAB
|
732
|
-
if_part = "if (#{@condition.compile(
|
735
|
+
if_part = "if (#{@condition.compile(cond_o)}) {\n#{Expressions.wrap(@body).compile(o)}\n#{indent}}"
|
733
736
|
return if_part unless @else_body
|
734
737
|
else_part = chain? ?
|
735
738
|
" else #{@else_body.compile(o.merge(:indent => indent))}" :
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: coffee-script
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeremy Ashkenas
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-12-
|
12
|
+
date: 2009-12-27 00:00:00 -08:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|