mirror of
https://github.com/jashkenas/coffeescript.git
synced 2022-11-09 12:23:24 -05:00
better output when trying to force a pure statment to become a return
This commit is contained in:
parent
b18d7fb550
commit
d1b17df38c
2 changed files with 9 additions and 3 deletions
|
@ -261,6 +261,9 @@
|
|||
};
|
||||
__extends(LiteralNode, BaseNode);
|
||||
LiteralNode.prototype['class'] = 'LiteralNode';
|
||||
LiteralNode.prototype.makeReturn = function() {
|
||||
return this.isStatement() ? this : LiteralNode.__superClass__.makeReturn.call(this);
|
||||
};
|
||||
LiteralNode.prototype.isStatement = function() {
|
||||
return this.value === 'break' || this.value === 'continue';
|
||||
};
|
||||
|
|
|
@ -238,6 +238,9 @@ exports.LiteralNode = class LiteralNode extends BaseNode
|
|||
|
||||
constructor: (@value) ->
|
||||
|
||||
makeReturn: ->
|
||||
if @isStatement() then this else super()
|
||||
|
||||
# Break and continue must be treated as pure statements -- they lose their
|
||||
# meaning when wrapped in a closure.
|
||||
isStatement: ->
|
||||
|
@ -258,10 +261,10 @@ exports.LiteralNode = class LiteralNode extends BaseNode
|
|||
# make sense.
|
||||
exports.ReturnNode = class ReturnNode extends BaseNode
|
||||
|
||||
class: 'ReturnNode'
|
||||
isStatement: -> yes
|
||||
class: 'ReturnNode'
|
||||
isStatement: -> yes
|
||||
isPureStatement: -> yes
|
||||
children: ['expression']
|
||||
children: ['expression']
|
||||
|
||||
constructor: (@expression) ->
|
||||
|
||||
|
|
Loading…
Reference in a new issue