mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-02-18 11:31:20 -05:00
tweaking existential compilation.
This commit is contained in:
@@ -288,8 +288,6 @@ exports.ReturnNode = class ReturnNode extends BaseNode
|
||||
# or vanilla.
|
||||
exports.ValueNode = class ValueNode extends BaseNode
|
||||
|
||||
SOAK: " == undefined ? undefined : "
|
||||
|
||||
class: 'ValueNode'
|
||||
children: ['base', 'properties']
|
||||
|
||||
@@ -331,13 +329,6 @@ exports.ValueNode = class ValueNode extends BaseNode
|
||||
isNumber: ->
|
||||
@base instanceof LiteralNode and @base.value.match NUMBER
|
||||
|
||||
# Works out if the value is the start of a chain.
|
||||
isStart: (o) ->
|
||||
return true if this is o.chainRoot and @properties[0] instanceof AccessorNode
|
||||
node = o.chainRoot.base or o.chainRoot.variable
|
||||
while node instanceof CallNode then node = node.variable
|
||||
node is this
|
||||
|
||||
# If the value node has indexes containing function calls, and the value node
|
||||
# needs to be used twice, in compound assignment ... then we need to cache
|
||||
# the value of the indexes.
|
||||
@@ -373,8 +364,11 @@ exports.ValueNode = class ValueNode extends BaseNode
|
||||
if @base instanceof CallNode or @base.contains((n) -> n instanceof CallNode) and i is 0
|
||||
temp = o.scope.freeVariable()
|
||||
complete = "(#{ baseline = temp } = (#{complete}))"
|
||||
complete = "typeof #{complete} === \"undefined\" || #{baseline}" if i is 0 and @isStart(o)
|
||||
complete += @SOAK + (baseline += prop.compile(o))
|
||||
complete = if i is 0
|
||||
"(typeof #{complete} === \"undefined\" || #{baseline} === null) ? undefined : "
|
||||
else
|
||||
"#{complete} == undefined ? undefined : "
|
||||
complete += (baseline += prop.compile(o))
|
||||
else
|
||||
part = prop.compile(o)
|
||||
baseline += part
|
||||
|
||||
Reference in New Issue
Block a user