shapesecurity / shift-parser-js

ECMAScript parser that produces a Shift format AST
http://shift-ast.org/parser.html
Apache License 2.0
249 stars 28 forks source link

Fails to parse sequence expression without parens in for-in RHS #347

Closed lydell closed 7 years ago

lydell commented 7 years ago

test.js:

const { parseModule } = require("shift-parser");

const input = "for (a in b, c);";
console.log(parseModule(input));
$ node test.js 
/home/lydell/test/node_modules/shift-parser/dist/parser.js:184
      throw this.createUnexpected(this.lookahead);
      ^

Error: [1:12]: Unexpected token ","
    at new JsError (/home/lydell/test/node_modules/shift-parser/dist/tokenizer.js:165:81)
    at GenericParser.createError (/home/lydell/test/node_modules/shift-parser/dist/tokenizer.js:294:14)
    at GenericParser.createUnexpected (/home/lydell/test/node_modules/shift-parser/dist/tokenizer.js:275:23)
    at GenericParser.expect (/home/lydell/test/node_modules/shift-parser/dist/parser.js:184:18)
    at GenericParser.getIteratorStatementEpilogue (/home/lydell/test/node_modules/shift-parser/dist/parser.js:830:12)
    at GenericParser.parseForStatement (/home/lydell/test/node_modules/shift-parser/dist/parser.js:799:98)
    at GenericParser.parseStatementHelper (/home/lydell/test/node_modules/shift-parser/dist/parser.js:604:23)
    at GenericParser.isolateCoverGrammar (/home/lydell/test/node_modules/shift-parser/dist/parser.js:1089:23)
    at GenericParser.parseStatement (/home/lydell/test/node_modules/shift-parser/dist/parser.js:578:23)
    at GenericParser.parseStatementListItem (/home/lydell/test/node_modules/shift-parser/dist/parser.js:570:25)
michaelficarra commented 7 years ago

Confirmed. for-of only allows AssignmentExpression, but for-in allows sequences. See IterationStatement.

bakkot commented 7 years ago

Huh. I explicitly disallowed this. Guess I misread the grammar.