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:
Jeremy Ashkenas
2010-08-10 22:16:51 -04:00
parent 87fd05afb0
commit c2ec40e6ce
4 changed files with 14 additions and 7 deletions

View File

@@ -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