mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-05-03 03:00:14 -04:00
Avoids unnecessary temporary in comprehensions with pure statements in them.
This commit is contained in:
@@ -1654,7 +1654,7 @@
|
||||
topLevel = del(o, 'top') && !this.returns;
|
||||
range = this.source instanceof Value && this.source.base instanceof Range && !this.source.properties.length;
|
||||
source = range ? this.source.base : this.source;
|
||||
codeInBody = this.body.contains(function(node) {
|
||||
codeInBody = !this.body.containsPureStatement() && this.body.contains(function(node) {
|
||||
return node instanceof Code;
|
||||
});
|
||||
scope = o.scope;
|
||||
@@ -1722,8 +1722,6 @@
|
||||
if (range) {
|
||||
body.unshift(new Literal("var " + name + " = " + ivar));
|
||||
}
|
||||
}
|
||||
if (codeInBody && !body.containsPureStatement()) {
|
||||
if (namePart) {
|
||||
body.unshift(new Literal("var " + namePart));
|
||||
}
|
||||
|
||||
@@ -1413,7 +1413,7 @@ exports.For = class For extends Base
|
||||
topLevel = del(o, 'top') and not @returns
|
||||
range = @source instanceof Value and @source.base instanceof Range and not @source.properties.length
|
||||
source = if range then @source.base else @source
|
||||
codeInBody = @body.contains (node) -> node instanceof Code
|
||||
codeInBody = not @body.containsPureStatement() and @body.contains (node) -> node instanceof Code
|
||||
scope = o.scope
|
||||
name = @name and @name.compile o
|
||||
index = @index and @index.compile o
|
||||
@@ -1452,7 +1452,6 @@ exports.For = class For extends Base
|
||||
body = Expressions.wrap([new If(@guard, body)])
|
||||
if codeInBody
|
||||
body.unshift new Literal "var #{name} = #{ivar}" if range
|
||||
if codeInBody and not body.containsPureStatement()
|
||||
body.unshift new Literal "var #{namePart}" if namePart
|
||||
body.unshift new Literal "var #{index} = #{ivar}" if index
|
||||
lastLine = body.expressions.pop()
|
||||
|
||||
Reference in New Issue
Block a user