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

'in' in braced arrow bodies in ForStatement inits fails to parse #349

Closed lydell closed 7 years ago

lydell commented 7 years ago

test.js:

const { parseModule } = require("shift-parser");
const { default: codeGen } = require("shift-codegen");

const input = "for (() => {(this in a)};;);";

const ast = parseModule(input);
const generated = codeGen(ast);

console.log(generated);

parseModule(generated);

console.log("done");
$ node test.js
for(()=>{this in a};;);
/home/lydell/test/node_modules/shift-parser/dist/parser.js:213
        throw this.createUnexpected(this.lookahead);
        ^

Error: [2:8]: Unexpected token "in"
    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:269:23)
    at GenericParser.consumeSemicolon (/home/lydell/test/node_modules/shift-parser/dist/parser.js:213:20)
    at GenericParser.parseStatementHelper (/home/lydell/test/node_modules/shift-parser/dist/parser.js:636:20)
    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)
    at GenericParser.parseBody (/home/lydell/test/node_modules/shift-parser/dist/parser.js:306:61)
    at GenericParser.parseFunctionBody (/home/lydell/test/node_modules/shift-parser/dist/parser.js:281:44)

Originally reported in shapesecurity/shift-codegen-js#54

lydell commented 7 years ago

Oops, looks like me and @michaelficarra submitted issues at the same time. Duplicate of #348.