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);
|
__extends(LiteralNode, BaseNode);
|
||||||
LiteralNode.prototype['class'] = 'LiteralNode';
|
LiteralNode.prototype['class'] = 'LiteralNode';
|
||||||
|
LiteralNode.prototype.makeReturn = function() {
|
||||||
|
return this.isStatement() ? this : LiteralNode.__superClass__.makeReturn.call(this);
|
||||||
|
};
|
||||||
LiteralNode.prototype.isStatement = function() {
|
LiteralNode.prototype.isStatement = function() {
|
||||||
return this.value === 'break' || this.value === 'continue';
|
return this.value === 'break' || this.value === 'continue';
|
||||||
};
|
};
|
||||||
|
|
|
@ -238,6 +238,9 @@ exports.LiteralNode = class LiteralNode extends BaseNode
|
||||||
|
|
||||||
constructor: (@value) ->
|
constructor: (@value) ->
|
||||||
|
|
||||||
|
makeReturn: ->
|
||||||
|
if @isStatement() then this else super()
|
||||||
|
|
||||||
# Break and continue must be treated as pure statements -- they lose their
|
# Break and continue must be treated as pure statements -- they lose their
|
||||||
# meaning when wrapped in a closure.
|
# meaning when wrapped in a closure.
|
||||||
isStatement: ->
|
isStatement: ->
|
||||||
|
@ -258,10 +261,10 @@ exports.LiteralNode = class LiteralNode extends BaseNode
|
||||||
# make sense.
|
# make sense.
|
||||||
exports.ReturnNode = class ReturnNode extends BaseNode
|
exports.ReturnNode = class ReturnNode extends BaseNode
|
||||||
|
|
||||||
class: 'ReturnNode'
|
class: 'ReturnNode'
|
||||||
isStatement: -> yes
|
isStatement: -> yes
|
||||||
isPureStatement: -> yes
|
isPureStatement: -> yes
|
||||||
children: ['expression']
|
children: ['expression']
|
||||||
|
|
||||||
constructor: (@expression) ->
|
constructor: (@expression) ->
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue