Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Make reserved words safe in object literals

  • Loading branch information...
commit 6642c3c570b1d8fc42fb7c04cc6fd6aca93da8fd 1 parent 873bfe3
@wycats authored
Showing with 7 additions and 3 deletions.
  1. +2 −1  lib/grammar.y
  2. +1 −1  lib/lexer.l
  3. +4 −1 test/stringify-test.js
View
3  lib/grammar.y
@@ -72,6 +72,7 @@ Keyword
| BREAK
| CASE
| CATCH
+ | CLASS
| CONSTTOKEN
| CONTINUE
| DEBUGGER
@@ -133,7 +134,7 @@ Property
| IDENT ':' AssignmentExpr
{ yy.locComb(@$,@3);$$ = {key:yy.Node('Identifier', $1,yy.loc(@1)),value:$3,kind: "init"}; }
| Keyword ':' AssignmentExpr
- { yy.locComb(@$,@3);$$ = {key:yy.Node('Identifier', $1,yy.loc(@1)),value:$3,kind: "init"}; }
+ { yy.locComb(@$,@3);$$ = {key:yy.Node('Literal', String($1),yy.loc(@1)),value:$3,kind: "init"}; }
| STRING ':' AssignmentExpr
{ yy.locComb(@$,@3);$$ = {key:yy.Node('Literal', String($1),yy.loc(@1)),value:$3,kind: "init"}; }
| NUMBER ':' AssignmentExpr
View
2  lib/lexer.l
@@ -146,7 +146,7 @@ RCLASS "["({BSL}|[^\\\]])*"]"
"void" return 'VOIDTOKEN'
"while" return 'WHILE'
"with" return 'WITH'
-"class" return 'WITH'
+"class" return 'CLASS'
"const" return 'CONSTTOKEN'
<for>"const" { this.popState(); return 'CONSTTOKEN'; }
"enum" return 'ENUM'
View
5 test/stringify-test.js
@@ -313,7 +313,10 @@ function runUnitTests() {
" continue;\n" +
" }\n" +
" console.log(foo);\n" +
- "}\n")]
+ "}\n")],
+
+ // safe reserved property name
+ ['({class: "foo"});\n', '({"class": "foo"});\n']
];
for (var i = 0; i < tests.length; i++) {
Please sign in to comment.
Something went wrong with that request. Please try again.