Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 604e39b

Browse files
committed
Merge pull request jashkenas#1605 from geraldalewis/1513_obj_front_ops
jashkenas#1513 Top level bare obj literals with unary and exist ops
2 parents 7e4d619 + f3253f4 commit 604e39b

3 files changed

Lines changed: 16 additions & 8 deletions

File tree

lib/coffee-script/nodes.js

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/nodes.coffee

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1324,11 +1324,14 @@ exports.Op = class Op extends Base
13241324
unfoldSoak: (o) ->
13251325
@operator in ['++', '--', 'delete'] and unfoldSoak o, this, 'first'
13261326

1327-
compileNode: (o) ->
1327+
compileNode: (o) ->
1328+
isChain = @isChainable() and @first.isChainable()
1329+
# In chains, there's no need to wrap bare obj literals in parens,
1330+
# as the chained expression is wrapped.
1331+
@first.front = @front unless isChain
13281332
return @compileUnary o if @isUnary()
1329-
return @compileChain o if @isChainable() and @first.isChainable()
1333+
return @compileChain o if isChain
13301334
return @compileExistence o if @operator is '?'
1331-
@first.front = @front
13321335
code = @first.compile(o, LEVEL_OP) + ' ' + @operator + ' ' +
13331336
@second.compile(o, LEVEL_OP)
13341337
if o.level <= LEVEL_OP then code else "(#{code})"
@@ -1469,6 +1472,7 @@ exports.Existence = class Existence extends Base
14691472
invert: NEGATE
14701473

14711474
compileNode: (o) ->
1475+
@expression.front = @front
14721476
code = @expression.compile o, LEVEL_OP
14731477
if IDENTIFIER.test(code) and not o.scope.check code
14741478
[cmp, cnj] = if @negated then ['===', '||'] else ['!==', '&&']

test/objects.coffee

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,3 +233,7 @@ test "#1322: implicit call against implicit object with block comments", ->
233233
x: 2
234234
### y ###
235235
y: 3
236+
237+
test "#1513: Top level bare objs need to be wrapped in parens for unary and existence ops", ->
238+
doesNotThrow -> CoffeeScript.run "{}?", bare: true
239+
doesNotThrow -> CoffeeScript.run "{}.a++", bare: true

0 commit comments

Comments
 (0)