|
4 | 4 | # the syntax tree into a string of JavaScript code, call `compile()` on the root.
|
5 | 5 |
|
6 | 6 | {Scope} = require './scope'
|
7 |
| -{RESERVED} = require './lexer' |
| 7 | +{RESERVED, STRICT_PROSCRIBED} = require './lexer' |
8 | 8 |
|
9 | 9 | # Import the helpers we plan to use.
|
10 | 10 | {compact, flatten, extend, merge, del, starts, ends, last} = require './helpers'
|
@@ -329,7 +329,7 @@ exports.Literal = class Literal extends Base
|
329 | 329 | if o.level >= LEVEL_ACCESS then '(void 0)' else 'void 0'
|
330 | 330 | else if @value is 'this'
|
331 | 331 | if o.scope.method?.bound then o.scope.method.context else @value
|
332 |
| - else if @value.reserved and "#{@value}" not in ['eval', 'arguments'] |
| 332 | + else if @value.reserved |
333 | 333 | "\"#{@value}\""
|
334 | 334 | else
|
335 | 335 | @value
|
@@ -861,6 +861,8 @@ exports.Class = class Class extends Base
|
861 | 861 | tail instanceof Access and tail.name.value
|
862 | 862 | else
|
863 | 863 | @variable.base.value
|
| 864 | + if decl in STRICT_PROSCRIBED |
| 865 | + throw SyntaxError 'variable name may not be eval or arguments' |
864 | 866 | decl and= IDENTIFIER.test(decl) and decl
|
865 | 867 |
|
866 | 868 | # For all `this`-references and bound functions in the class definition,
|
@@ -1042,7 +1044,7 @@ exports.Assign = class Assign extends Base
|
1042 | 1044 | acc = IDENTIFIER.test idx.unwrap().value or 0
|
1043 | 1045 | value = new Value value
|
1044 | 1046 | value.properties.push new (if acc then Access else Index) idx
|
1045 |
| - if obj.unwrap().value in ['arguments','eval'].concat RESERVED |
| 1047 | + if obj.unwrap().value in RESERVED |
1046 | 1048 | throw new SyntaxError "assignment to a reserved word: #{obj.compile o} = #{value.compile o}"
|
1047 | 1049 | return new Assign(obj, value, null, param: @param).compile o, LEVEL_TOP
|
1048 | 1050 | vvar = value.compile o, LEVEL_LIST
|
@@ -1087,7 +1089,7 @@ exports.Assign = class Assign extends Base
|
1087 | 1089 | else
|
1088 | 1090 | acc = isObject and IDENTIFIER.test idx.unwrap().value or 0
|
1089 | 1091 | val = new Value new Literal(vvar), [new (if acc then Access else Index) idx]
|
1090 |
| - if name? and name in ['arguments','eval'].concat RESERVED |
| 1092 | + if name? and name in RESERVED |
1091 | 1093 | throw new SyntaxError "assignment to a reserved word: #{obj.compile o} = #{val.compile o}"
|
1092 | 1094 | assigns.push new Assign(obj, val, null, param: @param, subpattern: yes).compile o, LEVEL_LIST
|
1093 | 1095 | assigns.push vvar unless top or @subpattern
|
@@ -1210,6 +1212,8 @@ exports.Code = class Code extends Base
|
1210 | 1212 | # as well as be a splat, gathering up a group of parameters into an array.
|
1211 | 1213 | exports.Param = class Param extends Base
|
1212 | 1214 | constructor: (@name, @value, @splat) ->
|
| 1215 | + if @name.unwrapAll().value in STRICT_PROSCRIBED |
| 1216 | + throw SyntaxError 'parameter name eval or arguments is not allowed' |
1213 | 1217 |
|
1214 | 1218 | children: ['name', 'value']
|
1215 | 1219 |
|
@@ -1545,6 +1549,8 @@ exports.Try = class Try extends Base
|
1545 | 1549 | tryPart = @attempt.compile o, LEVEL_TOP
|
1546 | 1550 |
|
1547 | 1551 | catchPart = if @recovery
|
| 1552 | + if @error.value in STRICT_PROSCRIBED |
| 1553 | + throw SyntaxError "catch variable may not be eval or arguments" |
1548 | 1554 | o.scope.add @error.value, 'param' unless o.scope.check @error.value
|
1549 | 1555 | " catch#{errorPart}{\n#{ @recovery.compile o, LEVEL_TOP }\n#{@tab}}"
|
1550 | 1556 | else unless @ensure or @recovery
|
|
0 commit comments