Skip to content

Handling Optional Chaining operator #293

@zmeggyesi

Description

@zmeggyesi

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions