coffee-script 0.1.5 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'coffee-script'
3
- s.version = '0.1.5' # Keep version in sync with coffee-script.rb
4
- s.date = '2009-12-26'
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"
@@ -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) and results.push(value).))
96
+ results.push(value) if iterator.call(context, value, index, list).))
97
97
  results.
98
98
 
99
- #
100
- # # Return all the elements for which a truth test fails.
101
- # _.reject = function(obj, iterator, context) {
102
- # var results = [];
103
- # _.each(obj, function(value, index, list) {
104
- # !iterator.call(context, value, index, list) && results.push(value);
105
- # });
106
- # return results;
107
- # };
108
- #
109
- # # Determine whether all of the elements match a truth test. Delegate to
110
- # # JavaScript 1.6's every(), if it is present.
111
- # _.all = function(obj, iterator, context) {
112
- # iterator = iterator || _.identity;
113
- # if (obj && _.isFunction(obj.every)) return obj.every(iterator, context);
114
- # var result = true;
115
- # _.each(obj, function(value, index, list) {
116
- # if (!(result = result && iterator.call(context, value, index, list))) _.breakLoop();
117
- # });
118
- # return result;
119
- # };
120
- #
121
- # # Determine if at least one element in the object matches a truth test. Use
122
- # # JavaScript 1.6's some(), if it exists.
123
- # _.any = function(obj, iterator, context) {
124
- # iterator = iterator || _.identity;
125
- # if (obj && _.isFunction(obj.some)) return obj.some(iterator, context);
126
- # var result = false;
127
- # _.each(obj, function(value, index, list) {
128
- # if (result = iterator.call(context, value, index, list)) _.breakLoop();
129
- # });
130
- # return result;
131
- # };
132
- #
133
- # # Determine if a given value is included in the array or object,
134
- # # based on '==='.
135
- # _.include = function(obj, target) {
136
- # if (_.isArray(obj)) return _.indexOf(obj, target) != -1;
137
- # var found = false;
138
- # _.each(obj, function(value) {
139
- # if (found = value === target) _.breakLoop();
140
- # });
141
- # return found;
142
- # };
143
- #
144
- # # Invoke a method with arguments on every item in a collection.
145
- # _.invoke = function(obj, method) {
146
- # var args = _.rest(arguments, 2);
147
- # return _.map(obj, function(value) {
148
- # return (method ? value[method] : value).apply(value, args);
149
- # });
150
- # };
151
- #
152
- # # Convenience version of a common use case of map: fetching a property.
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
- # /* ----------------------- Function Functions: -----------------------------*/
325
- #
326
- # # Create a function bound to a given object (assigning 'this', and arguments,
327
- # # optionally). Binding with arguments is also known as 'curry'.
328
- # _.bind = function(func, obj) {
329
- # var args = _.rest(arguments, 2);
330
- # return function() {
331
- # return func.apply(obj || root, args.concat(_.toArray(arguments)));
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
- # # Defers a function, scheduling it to run after the current call stack has
352
- # # cleared.
353
- # _.defer = function(func) {
354
- # return _.delay.apply(_, [func, 1].concat(_.rest(arguments)));
355
- # };
356
- #
357
- # # Returns the first function passed as an argument to the second,
358
- # # allowing you to adjust arguments, run code before and after, and
359
- # # conditionally execute the original function.
360
- # _.wrap = function(func, wrapper) {
361
- # return function() {
362
- # var args = [func].concat(_.toArray(arguments));
363
- # return wrapper.apply(wrapper, args);
364
- # };
365
- # };
366
- #
367
- # # Returns a function that is the composition of a list of functions, each
368
- # # consuming the return value of the function that follows.
369
- # _.compose = function() {
370
- # var funcs = _.toArray(arguments);
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
- # # Perform a deep comparison to check if two objects are equal.
413
- # _.isEqual = function(a, b) {
414
- # # Check object identity.
415
- # if (a === b) return true;
416
- # # Different types?
417
- # var atype = typeof(a), btype = typeof(b);
418
- # if (atype != btype) return false;
419
- # # Basic equality test (watch out for coercions).
420
- # if (a == b) return true;
421
- # # One is falsy and the other truthy.
422
- # if ((!a && b) || (a && !b)) return false;
423
- # # One of them implements an isEqual()?
424
- # if (a.isEqual) return a.isEqual(b);
425
- # # Check dates' integer values.
426
- # if (_.isDate(a) && _.isDate(b)) return a.getTime() === b.getTime();
427
- # # Both are NaN?
428
- # if (_.isNaN(a) && _.isNaN(b)) return true;
429
- # # Compare regular expressions.
430
- # if (_.isRegExp(a) && _.isRegExp(b))
431
- # return a.source === b.source &&
432
- # a.global === b.global &&
433
- # a.ignoreCase === b.ignoreCase &&
434
- # a.multiline === b.multiline;
435
- # # If a is not an object by this point, we can't handle it.
436
- # if (atype !== 'object') return false;
437
- # # Check for different array lengths before comparing contents.
438
- # if (a.length && (a.length !== b.length)) return false;
439
- # # Nothing else worked, deep compare the contents.
440
- # var aKeys = _.keys(a), bKeys = _.keys(b);
441
- # # Different object sizes?
442
- # if (aKeys.length != bKeys.length) return false;
443
- # # Recursive comparison of contents.
444
- # for (var key in a) if (!_.isEqual(a[key], b[key])) return false;
445
- # return true;
446
- # };
447
- #
448
- # # Is a given array or object empty?
449
- # _.isEmpty = function(obj) {
450
- # return _.keys(obj).length == 0;
451
- # };
452
- #
453
- # # Is a given value a DOM element?
454
- # _.isElement = function(obj) {
455
- # return !!(obj && obj.nodeType == 1);
456
- # };
457
- #
458
- # # Is a given variable an arguments object?
459
- # _.isArguments = function(obj) {
460
- # return obj && _.isNumber(obj.length) && !_.isArray(obj) && !propertyIsEnumerable.call(obj, 'length');
461
- # };
462
- #
463
- # # Is the given value NaN -- this one is interesting. NaN != NaN, and
464
- # # isNaN(undefined) == true, so we make sure it's a number first.
465
- # _.isNaN = function(obj) {
466
- # return _.isNumber(obj) && isNaN(obj);
467
- # };
468
- #
469
- # # Is a given value equal to null?
470
- # _.isNull = function(obj) {
471
- # return obj === null;
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
- # /* -------------------------- Utility Functions: -------------------------- */
497
- #
498
- # # Run Underscore.js in noConflict mode, returning the '_' variable to its
499
- # # previous owner. Returns a reference to the Underscore object.
500
- # _.noConflict = function() {
501
- # root._ = previousUnderscore;
502
- # return this;
503
- # };
504
- #
505
- # # Keep the identity function around for default iterators.
506
- # _.identity = function(value) {
507
- # return value;
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
- # /*------------------------------- Aliases ----------------------------------*/
542
- #
543
- # _.forEach = _.each;
544
- # _.foldl = _.inject = _.reduce;
545
- # _.foldr = _.reduceRight;
546
- # _.filter = _.select;
547
- # _.every = _.all;
548
- # _.some = _.any;
549
- # _.head = _.first;
550
- # _.tail = _.rest;
551
- # _.methods = _.functions;
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.5' # Keep in sync with the gemspec.
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 lib/coffee_script/narwhal/js/launcher.js"
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 lib/coffee_script/narwhal/js/launcher.js #{sources}"
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
- return require(File.absolute(args[0])) if args.length
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){" + code + "/**/\n}"
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
- return require(File.absolute(args[0]));
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){" + code + "/**/\n}";
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 {
@@ -1,3 +1,3 @@
1
1
  (function(){
2
- require("coffee-script").run(system.args);
2
+ require("./coffee-script").run(system.args);
3
3
  })();
@@ -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.
@@ -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
- write("#{name} = #{@value.compile(o)}#{postfix}")
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(o)}) {\n#{Expressions.wrap(@body).compile(o)}\n#{indent}}"
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.5
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-26 00:00:00 -08:00
12
+ date: 2009-12-27 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies: []
15
15