mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-02-18 19:34:27 -05:00
Fixes Issue #542. Ensure that top-level objects are parenthesized. It's not valid code, but we might as well not SyntaxError out.
This commit is contained in:
@@ -623,10 +623,13 @@ exports.ObjectNode = class ObjectNode extends BaseNode
|
||||
class: 'ObjectNode'
|
||||
children: ['properties']
|
||||
|
||||
topSensitive: -> true
|
||||
|
||||
constructor: (props) ->
|
||||
@objects = @properties = props or []
|
||||
|
||||
compileNode: (o) ->
|
||||
top = del o, 'top'
|
||||
o.indent = @idt 1
|
||||
nonComments = prop for prop in @properties when not (prop instanceof CommentNode)
|
||||
lastNoncom = nonComments[nonComments.length - 1]
|
||||
@@ -638,8 +641,8 @@ exports.ObjectNode = class ObjectNode extends BaseNode
|
||||
prop = new AssignNode prop, prop, 'object' unless prop instanceof AssignNode or prop instanceof CommentNode
|
||||
indent + prop.compile(o) + join
|
||||
props = props.join('')
|
||||
inner = if props then '\n' + props + '\n' + @idt() else ''
|
||||
'{' + inner + '}'
|
||||
obj = '{' + (if props then '\n' + props + '\n' + @idt() else '') + '}'
|
||||
if top then "(#{obj})" else obj
|
||||
|
||||
#### ArrayNode
|
||||
|
||||
|
||||
Reference in New Issue
Block a user