rspivak / slimit

SlimIt - a JavaScript minifier/parser in Python
MIT License
550 stars 94 forks source link

keywords incorrectly disallowed as object property names #90

Open jason-s opened 7 years ago

jason-s commented 7 years ago

This works just fine in Javascript:

> keywordobj = {for: 3, if: 7, while: 99, in: 66, function: 33}
Object {for: 3, if: 7, while: 99, in: 66, function: 33}
> keywordobj.for
3
> keywordobj.while
99

but the use of keywords causes slimit to puke:

from slimit import ast
from slimit.parser import Parser
from slimit.visitors import nodevisitor

parser = Parser()
tree = parser.parse("x={a: 3, b: 7, c: 99, d: 66, e: 33}")
print "x read"
tree = parser.parse("y={for: 3, if: 7, while: 99, in: 66, function: 33}")
print "y read"

which reports x read and then

SyntaxError: Unexpected token (FOR, 'for') at 1:3 between LexToken(LBRACE,'{',1,2) and LexToken(COLON,':',1,6)
metatoaster commented 7 years ago

This is related to #59