Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions lib/coffee-script/grammar.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions lib/coffee-script/lexer.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 23 additions & 2 deletions lib/coffee-script/nodes.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

291 changes: 147 additions & 144 deletions lib/coffee-script/parser.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/coffee-script/rewriter.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion src/grammar.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ grammar =
# they can also serve as keys in object literals.
AlphaNumeric: [
o 'NUMBER', -> new NumberLiteral $1
o 'INFINITY', -> new InfinityLiteral $1
o 'String'
]

Expand All @@ -168,6 +167,8 @@ grammar =
o 'UNDEFINED', -> new UndefinedLiteral
o 'NULL', -> new NullLiteral
o 'BOOL', -> new BooleanLiteral $1
o 'INFINITY', -> new InfinityLiteral $1
o 'NAN', -> new NaNLiteral
]

# Assignment of a variable, property, or index to a value.
Expand Down
7 changes: 5 additions & 2 deletions src/lexer.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -777,7 +777,10 @@ JS_KEYWORDS = [
]

# CoffeeScript-only keywords.
COFFEE_KEYWORDS = ['undefined', 'then', 'unless', 'until', 'loop', 'of', 'by', 'when']
COFFEE_KEYWORDS = [
'undefined', 'Infinity', 'NaN'
'then', 'unless', 'until', 'loop', 'of', 'by', 'when'
]

COFFEE_ALIAS_MAP =
and : '&&'
Expand Down Expand Up @@ -939,7 +942,7 @@ BOOL = ['TRUE', 'FALSE']
# of a function invocation or indexing operation.
CALLABLE = ['IDENTIFIER', 'PROPERTY', ')', ']', '?', '@', 'THIS', 'SUPER']
INDEXABLE = CALLABLE.concat [
'NUMBER', 'INFINITY', 'STRING', 'STRING_END', 'REGEX', 'REGEX_END'
'NUMBER', 'INFINITY', 'NAN', 'STRING', 'STRING_END', 'REGEX', 'REGEX_END'
'BOOL', 'NULL', 'UNDEFINED', '}', '::'
]

Expand Down
8 changes: 8 additions & 0 deletions src/nodes.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,14 @@ exports.InfinityLiteral = class InfinityLiteral extends NumberLiteral
compileNode: ->
[@makeCode '2e308']

exports.NaNLiteral = class NaNLiteral extends NumberLiteral
constructor: ->
super 'NaN'

compileNode: (o) ->
code = [@makeCode '0/0']
if o.level >= LEVEL_OP then @wrapInBraces code else code
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I settled on using @makeCode instead of new Op since that allows NaN to be rendered as 0/0 instead of 0 / 0.


exports.StringLiteral = class StringLiteral extends Literal

exports.RegexLiteral = class RegexLiteral extends Literal
Expand Down
8 changes: 5 additions & 3 deletions src/rewriter.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -483,9 +483,11 @@ IMPLICIT_FUNC = ['IDENTIFIER', 'PROPERTY', 'SUPER', ')', 'CALL_END', ']', 'IN

# If preceded by an `IMPLICIT_FUNC`, indicates a function invocation.
IMPLICIT_CALL = [
'IDENTIFIER', 'PROPERTY', 'NUMBER', 'INFINITY', 'STRING', 'STRING_START', 'JS', 'REGEX', 'REGEX_START'
'NEW', 'PARAM_START', 'CLASS', 'IF', 'TRY', 'SWITCH', 'THIS', 'BOOL', 'NULL'
'UNDEFINED', 'UNARY', 'YIELD', 'UNARY_MATH', 'SUPER', 'THROW'
'IDENTIFIER', 'PROPERTY', 'NUMBER', 'INFINITY', 'NAN'
'STRING', 'STRING_START', 'REGEX', 'REGEX_START', 'JS'
'NEW', 'PARAM_START', 'CLASS', 'IF', 'TRY', 'SWITCH', 'THIS'
'UNDEFINED', 'NULL', 'BOOL'
'UNARY', 'YIELD', 'UNARY_MATH', 'SUPER', 'THROW'
'@', '->', '=>', '[', '(', '{', '--', '++'
]

Expand Down
3 changes: 3 additions & 0 deletions test/numbers.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,6 @@ test "Infinity", ->
eq Infinity, CoffeeScript.eval "0x#{Array(256 + 1).join('f')}"
eq Infinity, CoffeeScript.eval Array(500 + 1).join('9')
eq Infinity, 2e308

test "NaN", ->
ok isNaN 1/NaN
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test would have failed in the first version of this PR, where 1/NaN became Infinity.

2 changes: 1 addition & 1 deletion test/operators.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ test "chained operations should evaluate each value only once", ->

test "#891: incorrect inversion of chained comparisons", ->
ok (true unless 0 > 1 > 2)
ok (true unless (NaN = 0/0) < 0/0 < NaN)
ok (true unless (this.NaN = 0/0) < 0/0 < this.NaN)

test "#1234: Applying a splat to :: applies the splat to the wrong object", ->
nonce = {}
Expand Down