eslint-parser: ES2020 features (#11815)
* chore: update espree test on nullish coalescing * feat: add optional chaining support * fix: adapt to estree AST shape * chore: update lockfile * add estree optional-chaining test fixtures * address review comments * chore: simplify smoke test * export * support Co-authored-by: Brian Ng <bng412@gmail.com>
This commit is contained in:
@@ -388,8 +388,6 @@ export default (superClass: Class<Parser>): Class<Parser> =>
|
||||
delete node.arguments;
|
||||
// $FlowIgnore - callee isn't optional in the type definition
|
||||
delete node.callee;
|
||||
} else if (node.type === "CallExpression") {
|
||||
(node: N.Node).optional = false;
|
||||
}
|
||||
|
||||
return node;
|
||||
@@ -431,10 +429,38 @@ export default (superClass: Class<Parser>): Class<Parser> =>
|
||||
return node;
|
||||
}
|
||||
|
||||
parseSubscript(...args) {
|
||||
const node = super.parseSubscript(...args);
|
||||
parseSubscript(
|
||||
base: N.Expression,
|
||||
startPos: number,
|
||||
startLoc: Position,
|
||||
noCalls: ?boolean,
|
||||
state: N.ParseSubscriptState,
|
||||
) {
|
||||
const node = super.parseSubscript(
|
||||
base,
|
||||
startPos,
|
||||
startLoc,
|
||||
noCalls,
|
||||
state,
|
||||
);
|
||||
|
||||
if (node.type === "MemberExpression") {
|
||||
if (state.optionalChainMember) {
|
||||
// https://github.com/estree/estree/blob/master/es2020.md#chainexpression
|
||||
if (
|
||||
node.type === "OptionalMemberExpression" ||
|
||||
node.type === "OptionalCallExpression"
|
||||
) {
|
||||
node.type = node.type.substring(8); // strip Optional prefix
|
||||
}
|
||||
if (state.stop) {
|
||||
const chain = this.startNodeAtNode(node);
|
||||
chain.expression = node;
|
||||
return this.finishNode(chain, "ChainExpression");
|
||||
}
|
||||
} else if (
|
||||
node.type === "MemberExpression" ||
|
||||
node.type === "CallExpression"
|
||||
) {
|
||||
node.optional = false;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user