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
55 changes: 38 additions & 17 deletions lib/coffee-script/lexer.js

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

60 changes: 33 additions & 27 deletions lib/coffee-script/nodes.js

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

40 changes: 29 additions & 11 deletions src/lexer.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -411,14 +411,20 @@ exports.Lexer = class Lexer
value = @chunk.charAt 0
tag = value
[..., prev] = @tokens
if value is '=' and prev
if prev.variable and prev[1] in JS_FORBIDDEN
prev = prev.origin if prev.origin
@error "reserved word '#{prev[1]}' can't be assigned", prev[2]
if prev[1] in ['||', '&&']

if prev and value in ['=', COMPOUND_ASSIGN...]
skipToken = false
if value is '=' and prev[1] in ['||', '&&'] and not prev.spaced
prev[0] = 'COMPOUND_ASSIGN'
prev[1] += '='
return value.length
prev = @tokens[@tokens.length - 2]
skipToken = true
if prev and prev.variable
origin = prev.origin ? prev
message = isUnassignable prev[1], origin[1]
@error message, origin[2] if message
return value.length if skipToken

if value is ';'
@seenFor = no
tag = 'TERMINATOR'
Expand Down Expand Up @@ -744,6 +750,21 @@ exports.Lexer = class Lexer
{first_line, first_column, last_column: first_column + (options.length ? 1) - 1}
throwSyntaxError message, location

# Helper functions
# ----------------

isUnassignable = (name, displayName = name) -> switch
when name in [JS_KEYWORDS..., COFFEE_KEYWORDS...]
"keyword '#{displayName}' can't be assigned"
when name in STRICT_PROSCRIBED
"'#{displayName}' can't be assigned"
when name in RESERVED
"reserved word '#{displayName}' can't be assigned"
else
false

exports.isUnassignable = isUnassignable

# Constants
# ---------

Expand Down Expand Up @@ -782,15 +803,12 @@ RESERVED = [
'protected', 'public', 'static'
]

STRICT_PROSCRIBED = ['arguments', 'eval', 'yield*']
STRICT_PROSCRIBED = ['arguments', 'eval']
Copy link
Collaborator

Choose a reason for hiding this comment

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

This should include yield, shouldn't it?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

But yield is a CoffeeScript keyword?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Oh sure, if it's in that list then it shouldn't need to be in this list.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

(It’s in JS_KEYWORDS (“keywords that CoffeeScript shares in common with JavaScript”).)


# The superset of both JavaScript keywords and reserved words, none of which may
# be used as identifiers or properties.
JS_FORBIDDEN = JS_KEYWORDS.concat(RESERVED).concat(STRICT_PROSCRIBED)

exports.RESERVED = RESERVED.concat(JS_KEYWORDS).concat(COFFEE_KEYWORDS).concat(STRICT_PROSCRIBED)
exports.STRICT_PROSCRIBED = STRICT_PROSCRIBED
exports.JS_FORBIDDEN = JS_FORBIDDEN
exports.JS_FORBIDDEN = JS_KEYWORDS.concat(RESERVED).concat(STRICT_PROSCRIBED)

# The character code of the nasty Microsoft madness otherwise known as the BOM.
BOM = 65279
Expand Down
Loading