shapesecurity / shift-java

Shift format ECMAScript AST tooling
http://shift-ast.org/
Apache License 2.0
71 stars 25 forks source link

Handling Optional Chaining operator #293

Open zmeggyesi opened 2 years ago

zmeggyesi commented 2 years ago

We've recently encountered an issue where the Shift parser doesn't seem to handle ECMA262's Conditional Chaining operator (AKA null-aware accessor, null-aware invocation, Jackson Operator, and other names). Both version 2.0.4 of the JS parser and the online demo parser fail with the same exception on the following snippet:

const adventurer = {
  name: 'Alice',
  cat: {
    name: 'Dinah'
  }
};

const dogName = adventurer.dog?.name;
console.log(dogName);

Source: MDN

Example exception from the Java library:

Exception in thread "main" com.shapesecurity.shift.es2018.parser.JsError: JavaScript error: Line 8 Column 31 (Index = 104), Unexpected token ".".
    at com.shapesecurity.shift.es2018.parser.Tokenizer.createError(Tokenizer.java:455)
    at com.shapesecurity.shift.es2018.parser.Tokenizer.createUnexpected(Tokenizer.java:439)
    at com.shapesecurity.shift.es2018.parser.GenericParser.parsePrimaryExpression(GenericParser.java:1989)
    at com.shapesecurity.shift.es2018.parser.GenericParser.parseLeftHandSideExpression(GenericParser.java:1666)
    at com.shapesecurity.shift.es2018.parser.GenericParser.parseUpdateExpression(GenericParser.java:1521)
    at com.shapesecurity.shift.es2018.parser.GenericParser.parseUnaryExpression(GenericParser.java:1493)
    at com.shapesecurity.shift.es2018.parser.GenericParser.parseExponentiationExpression(GenericParser.java:1464)
    at com.shapesecurity.shift.es2018.parser.GenericParser.parseBinaryExpression(GenericParser.java:1403)
    at com.shapesecurity.shift.es2018.parser.GenericParser.parseConditionalExpression(GenericParser.java:1376)
    at com.shapesecurity.shift.es2018.parser.GenericParser.parseAssignmentExpressionOrTarget(GenericParser.java:1233)
    at com.shapesecurity.shift.es2018.parser.GenericParser.isolateCoverGrammar(GenericParser.java:1178)
    at com.shapesecurity.shift.es2018.parser.GenericParser.parseAssignmentExpression(GenericParser.java:1220)
    at com.shapesecurity.shift.es2018.parser.GenericParser.isolateCoverGrammar(GenericParser.java:1178)
    at com.shapesecurity.shift.es2018.parser.GenericParser.parseConditionalExpression(GenericParser.java:1386)
    at com.shapesecurity.shift.es2018.parser.GenericParser.parseAssignmentExpressionOrTarget(GenericParser.java:1233)
    at com.shapesecurity.shift.es2018.parser.GenericParser.isolateCoverGrammar(GenericParser.java:1178)
    at com.shapesecurity.shift.es2018.parser.GenericParser.parseAssignmentExpression(GenericParser.java:1220)
    at com.shapesecurity.shift.es2018.parser.GenericParser.parseVariableDeclarator(GenericParser.java:314)
    at com.shapesecurity.shift.es2018.parser.GenericParser.parseVariableDeclaratorList(GenericParser.java:294)
    at com.shapesecurity.shift.es2018.parser.GenericParser.parseVariableDeclaration(GenericParser.java:285)
    at com.shapesecurity.shift.es2018.parser.GenericParser.parseVariableDeclarationStatement(GenericParser.java:274)
    at com.shapesecurity.shift.es2018.parser.GenericParser.parseStatementListItem(GenericParser.java:265)
    at com.shapesecurity.shift.es2018.parser.GenericParser.parseBody(GenericParser.java:191)
    at com.shapesecurity.shift.es2018.parser.GenericParser.parseTopLevel(GenericParser.java:157)
    at com.shapesecurity.shift.es2018.parser.GenericParser.parseScript(GenericParser.java:166)
    at com.shapesecurity.shift.es2018.parser.Parser.parseScript(Parser.java:17)
    at hu.skawa.App.main(App.java:12)

This got me thinking, though, that other new language features may not be supported either. Is a new version forthcoming that will support these - but at least this one, since this is the one causing my organization a headache as of now - features?

bakkot commented 2 years ago

Yeah, support for the latest features is not yet implemented, sorry. We do intend to support these but it may be a few months before we're able to get to it.