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

UnicodeEscapeSequence > 1114111 causes an error when earlyErrors is false #328

Closed lydell closed 7 years ago

lydell commented 7 years ago

http://www.ecma-international.org/ecma-262/7.0/index.html#sec-string-literals-static-semantics-early-errors

$ cat test.js
require('shift-parser').default('"\\u{110000}"', {earlyErrors: false})
$ node test.js 
/home/lydell/bugs/shift-unicode/node_modules/shift-parser/dist/tokenizer.js:685
            throw this.createILLEGAL();
            ^

Error: [1:4]: Unexpected "{"
    at new JsError (/home/lydell/bugs/shift-unicode/node_modules/shift-parser/dist/tokenizer.js:163:81)
    at GenericParser.createError (/home/lydell/bugs/shift-unicode/node_modules/shift-parser/dist/tokenizer.js:285:14)
    at GenericParser.createILLEGAL (/home/lydell/bugs/shift-unicode/node_modules/shift-parser/dist/tokenizer.js:253:53)
    at GenericParser.scanUnicode (/home/lydell/bugs/shift-unicode/node_modules/shift-parser/dist/tokenizer.js:685:24)
    at GenericParser.scanStringEscape (/home/lydell/bugs/shift-unicode/node_modules/shift-parser/dist/tokenizer.js:1225:43)
    at GenericParser.scanStringLiteral (/home/lydell/bugs/shift-unicode/node_modules/shift-parser/dist/tokenizer.js:1305:40)
    at GenericParser.advance (/home/lydell/bugs/shift-unicode/node_modules/shift-parser/dist/tokenizer.js:1465:23)
    at GenericParser.parseScript (/home/lydell/bugs/shift-unicode/node_modules/shift-parser/dist/parser.js:241:29)
    at Object.parse (/home/lydell/bugs/shift-unicode/node_modules/shift-parser/dist/index.js:115:43)
    at Object.<anonymous> (/home/lydell/bugs/shift-unicode/test.js:1:94)
michaelficarra commented 7 years ago

This is a consequence of our AST format. In our tests, we call them "early grammar errors". Unfortunately, we cannot delay these early errors because our AST cannot represent the program with the error. It's a drawback of having such a restrictive AST. Closing as wontfix.

lydell commented 7 years ago

Damn, you guys have thought about everything! 👍