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

Skip to content

Commit c884564

Browse files
fixes jashkenas#1385: property access on parenthesized number literals
1 parent 19520d8 commit c884564

3 files changed

Lines changed: 7 additions & 3 deletions

File tree

lib/nodes.js

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

src/nodes.coffee

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ exports.Value = class Value extends Base
402402
@base.front = @front
403403
props = @properties
404404
code = @base.compile o, if props.length then LEVEL_ACCESS else null
405-
code = "(#{code})" if props[0] instanceof Access and @isSimpleNumber()
405+
code = "#{code}." if (@base instanceof Parens or props.length) and SIMPLENUM.test code
406406
code += prop.compile o for prop in props
407407
code
408408

test/numbers.coffee

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,15 @@ value = 0.0 + -.25 - -.75 + 0.0
3232
ok value is 0.5
3333

3434
#764: Numbers should be indexable
35+
eq Number::toString, 4['toString']
3536
eq Number::toString, 4.2['toString']
3637
eq Number::toString, .42['toString']
38+
eq Number::toString, (4)['toString']
3739

40+
eq Number::toString, 4.toString
3841
eq Number::toString, 4.2.toString
3942
eq Number::toString, .42.toString
43+
eq Number::toString, (4).toString
4044

4145
test '#1168: leading floating point suppresses newline', ->
4246
eq 1, do ->

0 commit comments

Comments
 (0)