fixing infinite recursion when compiling if statements containing pure_statements

This commit is contained in:
Jeremy Ashkenas
2010-03-20 10:36:06 -04:00
parent a2778bf06d
commit 566321d67a
2 changed files with 7 additions and 4 deletions

View File

@@ -69,7 +69,9 @@
del(this.options, 'operation'); del(this.options, 'operation');
} }
top = this.top_sensitive() ? this.options.top : del(this.options, 'top'); top = this.top_sensitive() ? this.options.top : del(this.options, 'top');
closure = this.is_statement() && !this.is_pure_statement() && !top && !this.options.returns && !(this instanceof CommentNode); closure = this.is_statement() && !this.is_pure_statement() && !top && !this.options.returns && !(this instanceof CommentNode) && !(this.contains(function(n) {
return n.is_pure_statement();
}));
return closure ? this.compile_closure(this.options) : this.compile_node(this.options); return closure ? this.compile_closure(this.options) : this.compile_node(this.options);
}; };
// Statements converted into expressions via closure-wrapping share a scope // Statements converted into expressions via closure-wrapping share a scope

View File

@@ -56,7 +56,8 @@ exports.BaseNode: class BaseNode
del @options, 'operation' unless this instanceof ValueNode del @options, 'operation' unless this instanceof ValueNode
top: if @top_sensitive() then @options.top else del @options, 'top' top: if @top_sensitive() then @options.top else del @options, 'top'
closure: @is_statement() and not @is_pure_statement() and not top and closure: @is_statement() and not @is_pure_statement() and not top and
not @options.returns and not (this instanceof CommentNode) not @options.returns and not (this instanceof CommentNode) and
not (@contains (n) -> n.is_pure_statement())
if closure then @compile_closure(@options) else @compile_node(@options) if closure then @compile_closure(@options) else @compile_node(@options)
# Statements converted into expressions via closure-wrapping share a scope # Statements converted into expressions via closure-wrapping share a scope
@@ -549,7 +550,7 @@ exports.ArrayNode: class ArrayNode extends BaseNode
constructor: (objects) -> constructor: (objects) ->
@children: @objects: objects or [] @children: @objects: objects or []
@compile_splat_literal: SplatNode.compile_mixed_array <- @, @objects @compile_splat_literal: SplatNode.compile_mixed_array <- @, @objects
compile_node: (o) -> compile_node: (o) ->
o.indent: @idt(1) o.indent: @idt(1)
objects: [] objects: []
@@ -800,7 +801,7 @@ exports.SplatNode: class SplatNode extends BaseNode
compile_value: (o, name, index) -> compile_value: (o, name, index) ->
"Array.prototype.slice.call($name, $index)" "Array.prototype.slice.call($name, $index)"
# Utility function that converts arbitrary number of elements, mixed with # Utility function that converts arbitrary number of elements, mixed with
# splats, to a proper array # splats, to a proper array
SplatNode.compile_mixed_array: (list, o) -> SplatNode.compile_mixed_array: (list, o) ->
args: [] args: []