diff --git a/package.json b/package.json index c130fec5ce1..fcd31a97678 100644 --- a/package.json +++ b/package.json @@ -79,7 +79,7 @@ "cspell": "^4.0.61", "cz-conventional-changelog": "^3.2.0", "downlevel-dts": "^0.4.0", - "eslint": "^7.2.0", + "eslint": "^7.5.0", "eslint-plugin-eslint-comments": "^3.1.2", "eslint-plugin-eslint-plugin": "^2.2.1", "eslint-plugin-import": "^2.20.2", diff --git a/packages/eslint-plugin-internal/src/rules/no-poorly-typed-ts-props.ts b/packages/eslint-plugin-internal/src/rules/no-poorly-typed-ts-props.ts index e112b8205b2..1fa447080ba 100644 --- a/packages/eslint-plugin-internal/src/rules/no-poorly-typed-ts-props.ts +++ b/packages/eslint-plugin-internal/src/rules/no-poorly-typed-ts-props.ts @@ -59,10 +59,8 @@ export default createRule({ const checker = program.getTypeChecker(); return { - ':matches(MemberExpression, OptionalMemberExpression)[computed = false]'( - node: - | TSESTree.MemberExpressionNonComputedName - | TSESTree.OptionalMemberExpressionNonComputedName, + 'MemberExpression[computed = false]'( + node: TSESTree.MemberExpressionNonComputedName, ): void { for (const banned of BANNED_PROPERTIES) { if (node.property.name !== banned.property) { diff --git a/packages/eslint-plugin-internal/tests/rules/no-poorly-typed-ts-props.test.ts b/packages/eslint-plugin-internal/tests/rules/no-poorly-typed-ts-props.test.ts index 63b1f8d5726..8fe109ee3d1 100644 --- a/packages/eslint-plugin-internal/tests/rules/no-poorly-typed-ts-props.test.ts +++ b/packages/eslint-plugin-internal/tests/rules/no-poorly-typed-ts-props.test.ts @@ -90,5 +90,37 @@ thing.getSymbol(); }, ], }, + { + code: ` +import ts from 'typescript'; +declare const thing: ts.Type; +thing?.symbol; + `.trimRight(), + errors: [ + { + messageId: 'doNotUseWithFixer', + data: { + type: 'Type', + property: 'symbol', + fixWith: 'getSymbol()', + }, + line: 4, + suggestions: [ + { + messageId: 'suggestedFix', + data: { + type: 'Type', + fixWith: 'getSymbol()', + }, + output: ` +import ts from 'typescript'; +declare const thing: ts.Type; +thing?.getSymbol(); + `.trimRight(), + }, + ], + }, + ], + }, ], }); diff --git a/packages/eslint-plugin/src/rules/consistent-type-assertions.ts b/packages/eslint-plugin/src/rules/consistent-type-assertions.ts index cc96778cbe0..adc88dc965a 100644 --- a/packages/eslint-plugin/src/rules/consistent-type-assertions.ts +++ b/packages/eslint-plugin/src/rules/consistent-type-assertions.ts @@ -139,7 +139,6 @@ export default util.createRule({ node.parent && (node.parent.type === AST_NODE_TYPES.NewExpression || node.parent.type === AST_NODE_TYPES.CallExpression || - node.parent.type === AST_NODE_TYPES.OptionalCallExpression || node.parent.type === AST_NODE_TYPES.ThrowStatement || node.parent.type === AST_NODE_TYPES.AssignmentPattern) ) { diff --git a/packages/eslint-plugin/src/rules/func-call-spacing.ts b/packages/eslint-plugin/src/rules/func-call-spacing.ts index 21a62af1950..08d72181eeb 100644 --- a/packages/eslint-plugin/src/rules/func-call-spacing.ts +++ b/packages/eslint-plugin/src/rules/func-call-spacing.ts @@ -77,12 +77,9 @@ export default util.createRule({ * @private */ function checkSpacing( - node: - | TSESTree.CallExpression - | TSESTree.OptionalCallExpression - | TSESTree.NewExpression, + node: TSESTree.CallExpression | TSESTree.NewExpression, ): void { - const isOptionalCall = util.isOptionalOptionalCallExpression(node); + const isOptionalCall = util.isOptionalCallExpression(node); const closingParenToken = sourceCode.getLastToken(node)!; const lastCalleeTokenWithoutPossibleParens = sourceCode.getLastToken( @@ -175,7 +172,6 @@ export default util.createRule({ return { CallExpression: checkSpacing, - OptionalCallExpression: checkSpacing, NewExpression: checkSpacing, }; }, diff --git a/packages/eslint-plugin/src/rules/no-array-constructor.ts b/packages/eslint-plugin/src/rules/no-array-constructor.ts index c9465e70799..f9d09439cbb 100644 --- a/packages/eslint-plugin/src/rules/no-array-constructor.ts +++ b/packages/eslint-plugin/src/rules/no-array-constructor.ts @@ -27,17 +27,14 @@ export default util.createRule({ * @param node node to evaluate */ function check( - node: - | TSESTree.CallExpression - | TSESTree.OptionalCallExpression - | TSESTree.NewExpression, + node: TSESTree.CallExpression | TSESTree.NewExpression, ): void { if ( node.arguments.length !== 1 && node.callee.type === AST_NODE_TYPES.Identifier && node.callee.name === 'Array' && !node.typeParameters && - !util.isOptionalOptionalCallExpression(node) + !util.isOptionalCallExpression(node) ) { context.report({ node, @@ -60,7 +57,6 @@ export default util.createRule({ return { CallExpression: check, - OptionalCallExpression: check, NewExpression: check, }; }, diff --git a/packages/eslint-plugin/src/rules/no-extra-non-null-assertion.ts b/packages/eslint-plugin/src/rules/no-extra-non-null-assertion.ts index 62b317e30cb..b0b4921dfaf 100644 --- a/packages/eslint-plugin/src/rules/no-extra-non-null-assertion.ts +++ b/packages/eslint-plugin/src/rules/no-extra-non-null-assertion.ts @@ -32,8 +32,8 @@ export default util.createRule({ return { 'TSNonNullExpression > TSNonNullExpression': checkExtraNonNullAssertion, - 'OptionalMemberExpression[optional = true] > TSNonNullExpression': checkExtraNonNullAssertion, - 'OptionalCallExpression[optional = true] > TSNonNullExpression.callee': checkExtraNonNullAssertion, + 'MemberExpression[optional = true] > TSNonNullExpression': checkExtraNonNullAssertion, + 'CallExpression[optional = true] > TSNonNullExpression.callee': checkExtraNonNullAssertion, }; }, }); diff --git a/packages/eslint-plugin/src/rules/no-inferrable-types.ts b/packages/eslint-plugin/src/rules/no-inferrable-types.ts index 2b84414dfcd..d6b6538a95d 100644 --- a/packages/eslint-plugin/src/rules/no-inferrable-types.ts +++ b/packages/eslint-plugin/src/rules/no-inferrable-types.ts @@ -53,9 +53,12 @@ export default util.createRule({ init: TSESTree.Expression, callName: string, ): boolean { + if (init.type === AST_NODE_TYPES.ChainExpression) { + return isFunctionCall(init.expression, callName); + } + return ( - (init.type === AST_NODE_TYPES.CallExpression || - init.type === AST_NODE_TYPES.OptionalCallExpression) && + init.type === AST_NODE_TYPES.CallExpression && init.callee.type === AST_NODE_TYPES.Identifier && init.callee.name === callName ); diff --git a/packages/eslint-plugin/src/rules/no-misused-promises.ts b/packages/eslint-plugin/src/rules/no-misused-promises.ts index bd74721c7a2..36ad6f676de 100644 --- a/packages/eslint-plugin/src/rules/no-misused-promises.ts +++ b/packages/eslint-plugin/src/rules/no-misused-promises.ts @@ -71,7 +71,6 @@ export default util.createRule({ const voidReturnChecks: TSESLint.RuleListener = { CallExpression: checkArguments, - OptionalCallExpression: checkArguments, NewExpression: checkArguments, }; @@ -94,10 +93,7 @@ export default util.createRule({ } function checkArguments( - node: - | TSESTree.CallExpression - | TSESTree.OptionalCallExpression - | TSESTree.NewExpression, + node: TSESTree.CallExpression | TSESTree.NewExpression, ): void { const tsNode = parserServices.esTreeNodeToTSNodeMap.get(node); const voidParams = voidFunctionParams(checker, tsNode); diff --git a/packages/eslint-plugin/src/rules/no-non-null-asserted-optional-chain.ts b/packages/eslint-plugin/src/rules/no-non-null-asserted-optional-chain.ts index fa14fa661b6..30eca97523e 100644 --- a/packages/eslint-plugin/src/rules/no-non-null-asserted-optional-chain.ts +++ b/packages/eslint-plugin/src/rules/no-non-null-asserted-optional-chain.ts @@ -3,15 +3,18 @@ import { TSESLint, AST_NODE_TYPES, } from '@typescript-eslint/experimental-utils'; -import { version } from 'typescript'; +import * as ts from 'typescript'; import * as semver from 'semver'; import * as util from '../util'; type MessageIds = 'noNonNullOptionalChain' | 'suggestRemovingNonNull'; -const is3dot9 = !semver.satisfies( - version, - '< 3.9.0 || < 3.9.1-rc || < 3.9.0-beta', +const is3dot9 = semver.satisfies( + ts.version, + `>= 3.9.0 || >= 3.9.1-rc || >= 3.9.0-beta`, + { + includePrerelease: true, + }, ); export default util.createRule<[], MessageIds>({ @@ -34,28 +37,62 @@ export default util.createRule<[], MessageIds>({ }, defaultOptions: [], create(context) { + const sourceCode = context.getSourceCode(); + + function isValidFor3dot9(node: TSESTree.ChainExpression): boolean { + if (!is3dot9) { + return false; + } + + // TS3.9 made a breaking change to how non-null works with optional chains. + // Pre-3.9, `x?.y!.z` means `(x?.y).z` - i.e. it essentially scrubbed the optionality from the chain + // Post-3.9, `x?.y!.z` means `x?.y!.z` - i.e. it just asserts that the property `y` is non-null, not the result of `x?.y`. + // This means that for > 3.9, x?.y!.z is valid! + // NOTE: these cases are still invalid: + // - x?.y.z! + // - (x?.y)!.z + + const parent = util.nullThrows( + node.parent, + util.NullThrowsReasons.MissingParent, + ); + const grandparent = util.nullThrows( + parent.parent, + util.NullThrowsReasons.MissingParent, + ); + + if ( + grandparent.type !== AST_NODE_TYPES.MemberExpression && + grandparent.type !== AST_NODE_TYPES.CallExpression + ) { + return false; + } + + const lastChildToken = util.nullThrows( + sourceCode.getLastToken(parent, util.isNotNonNullAssertionPunctuator), + util.NullThrowsReasons.MissingToken('last token', node.type), + ); + if (util.isClosingParenToken(lastChildToken)) { + return false; + } + + const tokenAfterNonNull = sourceCode.getTokenAfter(parent); + if ( + tokenAfterNonNull != null && + util.isClosingParenToken(tokenAfterNonNull) + ) { + return false; + } + + return true; + } + return { - 'TSNonNullExpression > :matches(OptionalMemberExpression, OptionalCallExpression)'( - node: - | TSESTree.OptionalCallExpression - | TSESTree.OptionalMemberExpression, + 'TSNonNullExpression > ChainExpression'( + node: TSESTree.ChainExpression, ): void { - if (is3dot9) { - // TS3.9 made a breaking change to how non-null works with optional chains. - // Pre-3.9, `x?.y!.z` means `(x?.y).z` - i.e. it essentially scrubbed the optionality from the chain - // Post-3.9, `x?.y!.z` means `x?.y!.z` - i.e. it just asserts that the property `y` is non-null, not the result of `x?.y`. - // This means that for > 3.9, x?.y!.z is valid! - // NOTE: these cases are still invalid: - // - x?.y.z! - // - (x?.y)!.z - const nnAssertionParent = node.parent?.parent; - if ( - nnAssertionParent?.type === - AST_NODE_TYPES.OptionalMemberExpression || - nnAssertionParent?.type === AST_NODE_TYPES.OptionalCallExpression - ) { - return; - } + if (isValidFor3dot9(node)) { + return; } // selector guarantees this assertion diff --git a/packages/eslint-plugin/src/rules/no-non-null-assertion.ts b/packages/eslint-plugin/src/rules/no-non-null-assertion.ts index 143b889b17c..4012693c755 100644 --- a/packages/eslint-plugin/src/rules/no-non-null-assertion.ts +++ b/packages/eslint-plugin/src/rules/no-non-null-assertion.ts @@ -59,60 +59,56 @@ export default util.createRule<[], MessageIds>({ }; } - if (node.parent) { - if ( - (node.parent.type === AST_NODE_TYPES.MemberExpression || - node.parent.type === AST_NODE_TYPES.OptionalMemberExpression) && - node.parent.object === node - ) { - if (!node.parent.optional) { - if (node.parent.computed) { - // it is x![y]?.z - suggest.push({ - messageId: 'suggestOptionalChain', - fix: convertTokenToOptional('?.'), - }); - } else { - // it is x!.y?.z - suggest.push({ - messageId: 'suggestOptionalChain', - fix: convertTokenToOptional('?'), - }); - } + if ( + node.parent?.type === AST_NODE_TYPES.MemberExpression && + node.parent.object === node + ) { + if (!node.parent.optional) { + if (node.parent.computed) { + // it is x![y]?.z + suggest.push({ + messageId: 'suggestOptionalChain', + fix: convertTokenToOptional('?.'), + }); } else { - if (node.parent.computed) { - // it is x!?.[y].z - suggest.push({ - messageId: 'suggestOptionalChain', - fix: removeToken(), - }); - } else { - // it is x!?.y.z - suggest.push({ - messageId: 'suggestOptionalChain', - fix: removeToken(), - }); - } + // it is x!.y?.z + suggest.push({ + messageId: 'suggestOptionalChain', + fix: convertTokenToOptional('?'), + }); } - } else if ( - (node.parent.type === AST_NODE_TYPES.CallExpression || - node.parent.type === AST_NODE_TYPES.OptionalCallExpression) && - node.parent.callee === node - ) { - if (!node.parent.optional) { - // it is x.y?.z!() + } else { + if (node.parent.computed) { + // it is x!?.[y].z suggest.push({ messageId: 'suggestOptionalChain', - fix: convertTokenToOptional('?.'), + fix: removeToken(), }); } else { - // it is x.y.z!?.() + // it is x!?.y.z suggest.push({ messageId: 'suggestOptionalChain', fix: removeToken(), }); } } + } else if ( + node.parent?.type === AST_NODE_TYPES.CallExpression && + node.parent.callee === node + ) { + if (!node.parent.optional) { + // it is x.y?.z!() + suggest.push({ + messageId: 'suggestOptionalChain', + fix: convertTokenToOptional('?.'), + }); + } else { + // it is x.y.z!?.() + suggest.push({ + messageId: 'suggestOptionalChain', + fix: removeToken(), + }); + } } context.report({ diff --git a/packages/eslint-plugin/src/rules/no-require-imports.ts b/packages/eslint-plugin/src/rules/no-require-imports.ts index 25f4f35c77b..91d81e0d8c5 100644 --- a/packages/eslint-plugin/src/rules/no-require-imports.ts +++ b/packages/eslint-plugin/src/rules/no-require-imports.ts @@ -18,7 +18,7 @@ export default util.createRule({ defaultOptions: [], create(context) { return { - ':matches(CallExpression, OptionalCallExpression) > Identifier[name="require"]'( + 'CallExpression > Identifier[name="require"]'( node: TSESTree.Identifier, ): void { context.report({ diff --git a/packages/eslint-plugin/src/rules/no-unnecessary-condition.ts b/packages/eslint-plugin/src/rules/no-unnecessary-condition.ts index 2528b8709fc..675bf613efb 100644 --- a/packages/eslint-plugin/src/rules/no-unnecessary-condition.ts +++ b/packages/eslint-plugin/src/rules/no-unnecessary-condition.ts @@ -20,7 +20,6 @@ import { isNullableType, nullThrows, NullThrowsReasons, - isMemberOrOptionalMemberExpression, isIdentifier, isTypeAnyType, isTypeUnknownType, @@ -440,18 +439,16 @@ export default createRule({ // ?.y // This access is considered "unnecessary" according to the types // ``` function optionChainContainsArrayIndex( - node: TSESTree.OptionalMemberExpression | TSESTree.OptionalCallExpression, + node: TSESTree.MemberExpression | TSESTree.CallExpression, ): boolean { const lhsNode = - node.type === AST_NODE_TYPES.OptionalCallExpression - ? node.callee - : node.object; + node.type === AST_NODE_TYPES.CallExpression ? node.callee : node.object; if (isArrayIndexExpression(lhsNode)) { return true; } if ( - lhsNode.type === AST_NODE_TYPES.OptionalMemberExpression || - lhsNode.type === AST_NODE_TYPES.OptionalCallExpression + lhsNode.type === AST_NODE_TYPES.MemberExpression || + lhsNode.type === AST_NODE_TYPES.CallExpression ) { return optionChainContainsArrayIndex(lhsNode); } @@ -494,7 +491,7 @@ export default createRule({ // foo?.bar; // ``` function isNullableOriginFromPrev( - node: TSESTree.MemberExpression | TSESTree.OptionalMemberExpression, + node: TSESTree.MemberExpression, ): boolean { const prevType = getNodeType(node.object); const property = node.property; @@ -518,9 +515,10 @@ export default createRule({ node: TSESTree.LeftHandSideExpression, ): boolean { const type = getNodeType(node); - const isOwnNullable = isMemberOrOptionalMemberExpression(node) - ? !isNullableOriginFromPrev(node) - : true; + const isOwnNullable = + node.type === AST_NODE_TYPES.MemberExpression + ? !isNullableOriginFromPrev(node) + : true; return ( isTypeAnyType(type) || isTypeUnknownType(type) || @@ -529,7 +527,7 @@ export default createRule({ } function checkOptionalChain( - node: TSESTree.OptionalMemberExpression | TSESTree.OptionalCallExpression, + node: TSESTree.MemberExpression | TSESTree.CallExpression, beforeOperator: TSESTree.Node, fix: '' | '.', ): void { @@ -547,9 +545,7 @@ export default createRule({ } const nodeToCheck = - node.type === AST_NODE_TYPES.OptionalCallExpression - ? node.callee - : node.object; + node.type === AST_NODE_TYPES.CallExpression ? node.callee : node.object; if (isOptionableExpression(nodeToCheck)) { return; @@ -575,14 +571,12 @@ export default createRule({ } function checkOptionalMemberExpression( - node: TSESTree.OptionalMemberExpression, + node: TSESTree.MemberExpression, ): void { checkOptionalChain(node, node.object, node.computed ? '' : '.'); } - function checkOptionalCallExpression( - node: TSESTree.OptionalCallExpression, - ): void { + function checkOptionalCallExpression(node: TSESTree.CallExpression): void { checkOptionalChain(node, node.callee, ''); } @@ -595,8 +589,8 @@ export default createRule({ IfStatement: (node): void => checkNode(node.test), LogicalExpression: checkLogicalExpressionForUnnecessaryConditionals, WhileStatement: checkIfLoopIsNecessaryConditional, - OptionalMemberExpression: checkOptionalMemberExpression, - OptionalCallExpression: checkOptionalCallExpression, + 'MemberExpression[optional = true]': checkOptionalMemberExpression, + 'CallExpression[optional = true]': checkOptionalCallExpression, }; }, }); diff --git a/packages/eslint-plugin/src/rules/no-unsafe-call.ts b/packages/eslint-plugin/src/rules/no-unsafe-call.ts index d3f6707e122..0535bfeab31 100644 --- a/packages/eslint-plugin/src/rules/no-unsafe-call.ts +++ b/packages/eslint-plugin/src/rules/no-unsafe-call.ts @@ -42,7 +42,7 @@ export default util.createRule<[], MessageIds>({ } return { - ':matches(CallExpression, OptionalCallExpression) > *.callee'( + 'CallExpression > *.callee'( node: TSESTree.CallExpression['callee'], ): void { checkCall(node, node, 'unsafeCall'); diff --git a/packages/eslint-plugin/src/rules/no-unsafe-member-access.ts b/packages/eslint-plugin/src/rules/no-unsafe-member-access.ts index c6280dea92c..e0bb605f0f1 100644 --- a/packages/eslint-plugin/src/rules/no-unsafe-member-access.ts +++ b/packages/eslint-plugin/src/rules/no-unsafe-member-access.ts @@ -35,15 +35,13 @@ export default util.createRule({ const stateCache = new Map(); - function checkMemberExpression( - node: TSESTree.MemberExpression | TSESTree.OptionalMemberExpression, - ): State { + function checkMemberExpression(node: TSESTree.MemberExpression): State { const cachedState = stateCache.get(node); if (cachedState) { return cachedState; } - if (util.isMemberOrOptionalMemberExpression(node.object)) { + if (node.object.type === AST_NODE_TYPES.MemberExpression) { const objectState = checkMemberExpression(node.object); if (objectState === State.Unsafe) { // if the object is unsafe, we know this will be unsafe as well @@ -73,8 +71,8 @@ export default util.createRule({ } return { - 'MemberExpression, OptionalMemberExpression': checkMemberExpression, - ':matches(MemberExpression, OptionalMemberExpression)[computed = true] > *.property'( + MemberExpression: checkMemberExpression, + 'MemberExpression[computed = true] > *.property'( node: TSESTree.Expression, ): void { if ( diff --git a/packages/eslint-plugin/src/rules/no-unused-expressions.ts b/packages/eslint-plugin/src/rules/no-unused-expressions.ts index 692b484f45d..bea69733006 100644 --- a/packages/eslint-plugin/src/rules/no-unused-expressions.ts +++ b/packages/eslint-plugin/src/rules/no-unused-expressions.ts @@ -43,7 +43,8 @@ export default util.createRule({ ); } return ( - node.type === AST_NODE_TYPES.OptionalCallExpression || + (node.type === AST_NODE_TYPES.ChainExpression && + node.expression.type === AST_NODE_TYPES.CallExpression) || node.type === AST_NODE_TYPES.ImportExpression ); } diff --git a/packages/eslint-plugin/src/rules/no-var-requires.ts b/packages/eslint-plugin/src/rules/no-var-requires.ts index af1d5f815fd..6b958d47ec2 100644 --- a/packages/eslint-plugin/src/rules/no-var-requires.ts +++ b/packages/eslint-plugin/src/rules/no-var-requires.ts @@ -25,18 +25,19 @@ export default util.createRule({ defaultOptions: [], create(context) { return { - 'CallExpression, OptionalCallExpression'( - node: TSESTree.CallExpression | TSESTree.OptionalCallExpression, - ): void { + CallExpression(node: TSESTree.CallExpression): void { + const parent = + node.parent?.type === AST_NODE_TYPES.ChainExpression + ? node.parent.parent + : node.parent; if ( node.callee.type === AST_NODE_TYPES.Identifier && node.callee.name === 'require' && - node.parent && - (node.parent.type === AST_NODE_TYPES.VariableDeclarator || - node.parent.type === AST_NODE_TYPES.CallExpression || - node.parent.type === AST_NODE_TYPES.OptionalCallExpression || - node.parent.type === AST_NODE_TYPES.TSAsExpression || - node.parent.type === AST_NODE_TYPES.MemberExpression) + parent && + (parent.type === AST_NODE_TYPES.VariableDeclarator || + parent.type === AST_NODE_TYPES.CallExpression || + parent.type === AST_NODE_TYPES.TSAsExpression || + parent.type === AST_NODE_TYPES.MemberExpression) ) { context.report({ node, diff --git a/packages/eslint-plugin/src/rules/prefer-for-of.ts b/packages/eslint-plugin/src/rules/prefer-for-of.ts index 49fbc236f5d..361ad5ec2cf 100644 --- a/packages/eslint-plugin/src/rules/prefer-for-of.ts +++ b/packages/eslint-plugin/src/rules/prefer-for-of.ts @@ -58,8 +58,7 @@ export default util.createRule({ node.type === AST_NODE_TYPES.BinaryExpression && node.operator === '<' && isMatchingIdentifier(node.left, name) && - (node.right.type === AST_NODE_TYPES.MemberExpression || - node.right.type === AST_NODE_TYPES.OptionalMemberExpression) && + node.right.type === AST_NODE_TYPES.MemberExpression && isMatchingIdentifier(node.right.property, 'length') ) { return node.right.object; @@ -172,8 +171,7 @@ export default util.createRule({ return ( !contains(body, id) || (node !== undefined && - (node.type === AST_NODE_TYPES.MemberExpression || - node.type === AST_NODE_TYPES.OptionalMemberExpression) && + node.type === AST_NODE_TYPES.MemberExpression && node.property === id && sourceCode.getText(node.object) === arrayText && !isAssignee(node)) diff --git a/packages/eslint-plugin/src/rules/prefer-includes.ts b/packages/eslint-plugin/src/rules/prefer-includes.ts index fb34951611b..f49b5385a0c 100644 --- a/packages/eslint-plugin/src/rules/prefer-includes.ts +++ b/packages/eslint-plugin/src/rules/prefer-includes.ts @@ -126,14 +126,18 @@ export default createRule({ } return { - "BinaryExpression > :matches(CallExpression, OptionalCallExpression).left > :matches(MemberExpression, OptionalMemberExpression).callee[property.name='indexOf'][computed=false]"( - node: TSESTree.MemberExpression | TSESTree.OptionalMemberExpression, - ): void { + [[ + // a.indexOf(b) !== 1 + "BinaryExpression > CallExpression.left > MemberExpression.callee[property.name='indexOf'][computed=false]", + // a?.indexOf(b) !== 1 + "BinaryExpression > ChainExpression.left > CallExpression > MemberExpression.callee[property.name='indexOf'][computed=false]", + ].join(', ')](node: TSESTree.MemberExpression): void { // Check if the comparison is equivalent to `includes()`. - const callNode = node.parent as - | TSESTree.CallExpression - | TSESTree.OptionalCallExpression; - const compareNode = callNode.parent as TSESTree.BinaryExpression; + const callNode = node.parent as TSESTree.CallExpression; + const compareNode = (callNode.parent?.type === + AST_NODE_TYPES.ChainExpression + ? callNode.parent.parent + : callNode.parent) as TSESTree.BinaryExpression; const negative = isNegativeCheck(compareNode); if (!negative && !isPositiveCheck(compareNode)) { return; @@ -184,12 +188,10 @@ export default createRule({ }, // /bar/.test(foo) - ':matches(CallExpression, OptionalCallExpression) > :matches(MemberExpression, OptionalMemberExpression).callee[property.name="test"][computed=false]'( - node: TSESTree.MemberExpression | TSESTree.OptionalMemberExpression, + 'CallExpression > MemberExpression.callee[property.name="test"][computed=false]'( + node: TSESTree.MemberExpression, ): void { - const callNode = node.parent as - | TSESTree.CallExpression - | TSESTree.OptionalCallExpression; + const callNode = node.parent as TSESTree.CallExpression; const text = callNode.arguments.length === 1 ? parseRegExp(node.object) : null; if (text == null) { @@ -218,9 +220,7 @@ export default createRule({ argNode.type !== AST_NODE_TYPES.TemplateLiteral && argNode.type !== AST_NODE_TYPES.Identifier && argNode.type !== AST_NODE_TYPES.MemberExpression && - argNode.type !== AST_NODE_TYPES.OptionalMemberExpression && - argNode.type !== AST_NODE_TYPES.CallExpression && - argNode.type !== AST_NODE_TYPES.OptionalCallExpression; + argNode.type !== AST_NODE_TYPES.CallExpression; yield fixer.removeRange([callNode.range[0], argNode.range[0]]); if (needsParen) { @@ -229,11 +229,7 @@ export default createRule({ } yield fixer.insertTextAfter( argNode, - `${ - callNode.type === AST_NODE_TYPES.OptionalCallExpression - ? '?.' - : '.' - }includes(${JSON.stringify(text)}`, + `${node.optional ? '?.' : '.'}includes(${JSON.stringify(text)}`, ); }, }); diff --git a/packages/eslint-plugin/src/rules/prefer-optional-chain.ts b/packages/eslint-plugin/src/rules/prefer-optional-chain.ts index 52067d2f9b7..c58e5d113d6 100644 --- a/packages/eslint-plugin/src/rules/prefer-optional-chain.ts +++ b/packages/eslint-plugin/src/rules/prefer-optional-chain.ts @@ -8,10 +8,9 @@ import * as util from '../util'; type ValidChainTarget = | TSESTree.BinaryExpression | TSESTree.CallExpression - | TSESTree.MemberExpression - | TSESTree.OptionalCallExpression - | TSESTree.OptionalMemberExpression + | TSESTree.ChainExpression | TSESTree.Identifier + | TSESTree.MemberExpression | TSESTree.ThisExpression; /* @@ -56,6 +55,7 @@ export default util.createRule({ [[ 'LogicalExpression[operator="&&"] > Identifier', 'LogicalExpression[operator="&&"] > MemberExpression', + 'LogicalExpression[operator="&&"] > ChainExpression > MemberExpression', 'LogicalExpression[operator="&&"] > BinaryExpression[operator="!=="]', 'LogicalExpression[operator="&&"] > BinaryExpression[operator="!="]', ].join(',')]( @@ -65,7 +65,10 @@ export default util.createRule({ | TSESTree.MemberExpression, ): void { // selector guarantees this cast - const initialExpression = initialIdentifierOrNotEqualsExpr.parent as TSESTree.LogicalExpression; + const initialExpression = (initialIdentifierOrNotEqualsExpr.parent + ?.type === AST_NODE_TYPES.ChainExpression + ? initialIdentifierOrNotEqualsExpr.parent.parent + : initialIdentifierOrNotEqualsExpr.parent) as TSESTree.LogicalExpression; if (initialExpression.left !== initialIdentifierOrNotEqualsExpr) { // the node(identifier or member expression) is not the deepest left node @@ -192,10 +195,7 @@ export default util.createRule({ ); } - if ( - node.type === AST_NODE_TYPES.CallExpression || - node.type === AST_NODE_TYPES.OptionalCallExpression - ) { + if (node.type === AST_NODE_TYPES.CallExpression) { const calleeText = getText( // isValidChainTarget ensures this is type safe node.callee as ValidChainTarget, @@ -233,27 +233,27 @@ export default util.createRule({ return 'this'; } + if (node.type === AST_NODE_TYPES.ChainExpression) { + return getText(node.expression); + } + return getMemberExpressionText(node); } /** * Gets a normalized representation of the given MemberExpression */ - function getMemberExpressionText( - node: TSESTree.MemberExpression | TSESTree.OptionalMemberExpression, - ): string { + function getMemberExpressionText(node: TSESTree.MemberExpression): string { let objectText: string; // cases should match the list in ALLOWED_MEMBER_OBJECT_TYPES switch (node.object.type) { case AST_NODE_TYPES.CallExpression: - case AST_NODE_TYPES.OptionalCallExpression: case AST_NODE_TYPES.Identifier: objectText = getText(node.object); break; case AST_NODE_TYPES.MemberExpression: - case AST_NODE_TYPES.OptionalMemberExpression: objectText = getMemberExpressionText(node.object); break; @@ -280,7 +280,6 @@ export default util.createRule({ break; case AST_NODE_TYPES.MemberExpression: - case AST_NODE_TYPES.OptionalMemberExpression: propertyText = getMemberExpressionText(node.property); break; @@ -316,15 +315,12 @@ const ALLOWED_MEMBER_OBJECT_TYPES: ReadonlySet = new Set([ AST_NODE_TYPES.CallExpression, AST_NODE_TYPES.Identifier, AST_NODE_TYPES.MemberExpression, - AST_NODE_TYPES.OptionalCallExpression, - AST_NODE_TYPES.OptionalMemberExpression, AST_NODE_TYPES.ThisExpression, ]); const ALLOWED_COMPUTED_PROP_TYPES: ReadonlySet = new Set([ AST_NODE_TYPES.Identifier, AST_NODE_TYPES.Literal, AST_NODE_TYPES.MemberExpression, - AST_NODE_TYPES.OptionalMemberExpression, AST_NODE_TYPES.TemplateLiteral, ]); const ALLOWED_NON_COMPUTED_PROP_TYPES: ReadonlySet = new Set([ @@ -335,10 +331,11 @@ function isValidChainTarget( node: TSESTree.Node, allowIdentifier: boolean, ): node is ValidChainTarget { - if ( - node.type === AST_NODE_TYPES.MemberExpression || - node.type === AST_NODE_TYPES.OptionalMemberExpression - ) { + if (node.type === AST_NODE_TYPES.ChainExpression) { + return isValidChainTarget(node.expression, allowIdentifier); + } + + if (node.type === AST_NODE_TYPES.MemberExpression) { const isObjectValid = ALLOWED_MEMBER_OBJECT_TYPES.has(node.object.type) && // make sure to validate the expression is of our expected structure @@ -346,8 +343,7 @@ function isValidChainTarget( const isPropertyValid = node.computed ? ALLOWED_COMPUTED_PROP_TYPES.has(node.property.type) && // make sure to validate the member expression is of our expected structure - (node.property.type === AST_NODE_TYPES.MemberExpression || - node.property.type === AST_NODE_TYPES.OptionalMemberExpression + (node.property.type === AST_NODE_TYPES.MemberExpression ? isValidChainTarget(node.property, allowIdentifier) : true) : ALLOWED_NON_COMPUTED_PROP_TYPES.has(node.property.type); @@ -355,10 +351,7 @@ function isValidChainTarget( return isObjectValid && isPropertyValid; } - if ( - node.type === AST_NODE_TYPES.CallExpression || - node.type === AST_NODE_TYPES.OptionalCallExpression - ) { + if (node.type === AST_NODE_TYPES.CallExpression) { return isValidChainTarget(node.callee, allowIdentifier); } diff --git a/packages/eslint-plugin/src/rules/prefer-reduce-type-parameter.ts b/packages/eslint-plugin/src/rules/prefer-reduce-type-parameter.ts index 7b63125e743..3b1af79ac6e 100644 --- a/packages/eslint-plugin/src/rules/prefer-reduce-type-parameter.ts +++ b/packages/eslint-plugin/src/rules/prefer-reduce-type-parameter.ts @@ -4,13 +4,12 @@ import { } from '@typescript-eslint/experimental-utils'; import * as util from '../util'; -type MemberExpressionWithCallExpressionParent = ( - | TSESTree.MemberExpression - | TSESTree.OptionalMemberExpression -) & { parent: TSESTree.CallExpression | TSESTree.OptionalCallExpression }; +type MemberExpressionWithCallExpressionParent = TSESTree.MemberExpression & { + parent: TSESTree.CallExpression; +}; const getMemberExpressionName = ( - member: TSESTree.MemberExpression | TSESTree.OptionalMemberExpression, + member: TSESTree.MemberExpression, ): string | null => { if (!member.computed) { return member.property.name; @@ -50,7 +49,7 @@ export default util.createRule({ const checker = service.program.getTypeChecker(); return { - ':matches(CallExpression, OptionalCallExpression) > :matches(MemberExpression, OptionalMemberExpression).callee'( + 'CallExpression > MemberExpression.callee'( callee: MemberExpressionWithCallExpressionParent, ): void { if (getMemberExpressionName(callee) !== 'reduce') { diff --git a/packages/eslint-plugin/src/rules/prefer-string-starts-ends-with.ts b/packages/eslint-plugin/src/rules/prefer-string-starts-ends-with.ts index 90b38f18e78..3126f616038 100644 --- a/packages/eslint-plugin/src/rules/prefer-string-starts-ends-with.ts +++ b/packages/eslint-plugin/src/rules/prefer-string-starts-ends-with.ts @@ -11,6 +11,8 @@ import { getStaticValue, getTypeName, isNotClosingParenToken, + nullThrows, + NullThrowsReasons, } from '../util'; const EQ_OPERATORS = /^[=!]=/; @@ -144,10 +146,7 @@ export default createRule({ node: TSESTree.Node, expectedObjectNode: TSESTree.Node, ): boolean { - if ( - node.type === AST_NODE_TYPES.MemberExpression || - node.type === AST_NODE_TYPES.OptionalMemberExpression - ) { + if (node.type === AST_NODE_TYPES.MemberExpression) { return ( getPropertyName(node, globalScope) === 'length' && isSameTokens(node.object, expectedObjectNode) @@ -216,7 +215,7 @@ export default createRule({ * @param node The member expression node to get. */ function getPropertyRange( - node: TSESTree.MemberExpression | TSESTree.OptionalMemberExpression, + node: TSESTree.MemberExpression, ): [number, number] { const dotOrOpenBracket = sourceCode.getTokenAfter( node.object, @@ -288,6 +287,25 @@ export default createRule({ return { isEndsWith, isStartsWith, text }; } + function getLeftNode(node: TSESTree.Expression): TSESTree.MemberExpression { + if (node.type === AST_NODE_TYPES.ChainExpression) { + return getLeftNode(node.expression); + } + + let leftNode; + if (node.type === AST_NODE_TYPES.CallExpression) { + leftNode = node.callee; + } else { + leftNode = node; + } + + if (leftNode.type !== AST_NODE_TYPES.MemberExpression) { + throw new Error(`Expected a MemberExpression, got ${leftNode.type}`); + } + + return leftNode; + } + /** * Fix code with using the right operand as the search string. * For example: `foo.slice(0, 3) === 'bar'` → `foo.startsWith('bar')` @@ -304,12 +322,7 @@ export default createRule({ isOptional: boolean, ): IterableIterator { // left is CallExpression or MemberExpression. - const leftNode = (node.left.type === AST_NODE_TYPES.CallExpression || - node.left.type === AST_NODE_TYPES.OptionalCallExpression - ? node.left.callee - : node.left) as - | TSESTree.MemberExpression - | TSESTree.OptionalMemberExpression; + const leftNode = getLeftNode(node.left); const propertyRange = getPropertyRange(leftNode); if (isNegative) { @@ -333,17 +346,12 @@ export default createRule({ function* fixWithArgument( fixer: TSESLint.RuleFixer, node: TSESTree.BinaryExpression, + callNode: TSESTree.CallExpression, + calleeNode: TSESTree.MemberExpression, kind: 'start' | 'end', negative: boolean, isOptional: boolean, ): IterableIterator { - const callNode = node.left as - | TSESTree.CallExpression - | TSESTree.OptionalCallExpression; - const calleeNode = callNode.callee as - | TSESTree.MemberExpression - | TSESTree.OptionalMemberExpression; - if (negative) { yield fixer.insertTextBefore(node, '!'); } @@ -354,27 +362,34 @@ export default createRule({ yield fixer.removeRange([callNode.range[1], node.range[1]]); } + function getParent(node: TSESTree.Node): TSESTree.Node { + return nullThrows( + node.parent?.type === AST_NODE_TYPES.ChainExpression + ? node.parent.parent + : node.parent, + NullThrowsReasons.MissingParent, + ); + } + return { // foo[0] === "a" // foo.charAt(0) === "a" // foo[foo.length - 1] === "a" // foo.charAt(foo.length - 1) === "a" [[ - 'BinaryExpression > :matches(MemberExpression, OptionalMemberExpression).left[computed=true]', - 'BinaryExpression > :matches(CallExpression, OptionalCallExpression).left > :matches(MemberExpression, OptionalMemberExpression).callee[property.name="charAt"][computed=false]', - ].join(', ')]( - node: TSESTree.MemberExpression | TSESTree.OptionalMemberExpression, - ): void { - let parentNode = node.parent!; + 'BinaryExpression > MemberExpression.left[computed=true]', + 'BinaryExpression > CallExpression.left > MemberExpression.callee[property.name="charAt"][computed=false]', + 'BinaryExpression > ChainExpression.left > MemberExpression[computed=true]', + 'BinaryExpression > ChainExpression.left > CallExpression > MemberExpression.callee[property.name="charAt"][computed=false]', + ].join(', ')](node: TSESTree.MemberExpression): void { + let parentNode = getParent(node); + let indexNode: TSESTree.Node | null = null; - if ( - parentNode.type === AST_NODE_TYPES.CallExpression || - parentNode.type === AST_NODE_TYPES.OptionalCallExpression - ) { + if (parentNode?.type === AST_NODE_TYPES.CallExpression) { if (parentNode.arguments.length === 1) { indexNode = parentNode.arguments[0]; } - parentNode = parentNode.parent!; + parentNode = getParent(parentNode); } else { indexNode = node.property; } @@ -414,18 +429,16 @@ export default createRule({ }, // foo.indexOf('bar') === 0 - 'BinaryExpression > :matches(CallExpression, OptionalCallExpression).left > :matches(MemberExpression, OptionalMemberExpression).callee[property.name="indexOf"][computed=false]'( - node: TSESTree.MemberExpression | TSESTree.OptionalMemberExpression, - ): void { - const callNode = node.parent as - | TSESTree.CallExpression - | TSESTree.OptionalCallExpression; - const parentNode = callNode.parent!; + [[ + 'BinaryExpression > CallExpression.left > MemberExpression.callee[property.name="indexOf"][computed=false]', + 'BinaryExpression > ChainExpression.left > CallExpression > MemberExpression.callee[property.name="indexOf"][computed=false]', + ].join(', ')](node: TSESTree.MemberExpression): void { + const callNode = getParent(node) as TSESTree.CallExpression; + const parentNode = getParent(callNode); if ( callNode.arguments.length !== 1 || !isEqualityComparison(parentNode) || - parentNode.left !== callNode || !isNumber(parentNode.right, 0) || !isStringType(node.object) ) { @@ -439,6 +452,8 @@ export default createRule({ return fixWithArgument( fixer, parentNode, + callNode, + node, 'start', parentNode.operator.startsWith('!'), node.optional, @@ -449,18 +464,16 @@ export default createRule({ // foo.lastIndexOf('bar') === foo.length - 3 // foo.lastIndexOf(bar) === foo.length - bar.length - 'BinaryExpression > :matches(CallExpression, OptionalCallExpression).left > :matches(MemberExpression, OptionalMemberExpression).callee[property.name="lastIndexOf"][computed=false]'( - node: TSESTree.MemberExpression | TSESTree.OptionalMemberExpression, - ): void { - const callNode = node.parent! as - | TSESTree.CallExpression - | TSESTree.OptionalCallExpression; - const parentNode = callNode.parent!; + [[ + 'BinaryExpression > CallExpression.left > MemberExpression.callee[property.name="lastIndexOf"][computed=false]', + 'BinaryExpression > ChainExpression.left > CallExpression > MemberExpression.callee[property.name="lastIndexOf"][computed=false]', + ].join(', ')](node: TSESTree.MemberExpression): void { + const callNode = getParent(node) as TSESTree.CallExpression; + const parentNode = getParent(callNode); if ( callNode.arguments.length !== 1 || !isEqualityComparison(parentNode) || - parentNode.left !== callNode || parentNode.right.type !== AST_NODE_TYPES.BinaryExpression || parentNode.right.operator !== '-' || !isLengthExpression(parentNode.right.left, node.object) || @@ -477,6 +490,8 @@ export default createRule({ return fixWithArgument( fixer, parentNode, + callNode, + node, 'end', parentNode.operator.startsWith('!'), node.optional, @@ -487,13 +502,13 @@ export default createRule({ // foo.match(/^bar/) === null // foo.match(/bar$/) === null - 'BinaryExpression > :matches(CallExpression, OptionalCallExpression).left > :matches(MemberExpression, OptionalMemberExpression).callee[property.name="match"][computed=false]'( - node: TSESTree.MemberExpression | TSESTree.OptionalMemberExpression, - ): void { - const callNode = node.parent as - | TSESTree.CallExpression - | TSESTree.OptionalCallExpression; - const parentNode = callNode.parent as TSESTree.BinaryExpression; + [[ + 'BinaryExpression > CallExpression.left > MemberExpression.callee[property.name="match"][computed=false]', + 'BinaryExpression > ChainExpression.left > CallExpression > MemberExpression.callee[property.name="match"][computed=false]', + ].join(', ')](node: TSESTree.MemberExpression): void { + const callNode = getParent(node) as TSESTree.CallExpression; + const parentNode = getParent(callNode) as TSESTree.BinaryExpression; + if ( !isEqualityComparison(parentNode) || !isNull(parentNode.right) || @@ -540,20 +555,15 @@ export default createRule({ // foo.substring(foo.length - 3) === 'bar' // foo.substring(foo.length - 3, foo.length) === 'bar' [[ - ':matches(CallExpression, OptionalCallExpression) > :matches(MemberExpression, OptionalMemberExpression).callee[property.name="slice"][computed=false]', - ':matches(CallExpression, OptionalCallExpression) > :matches(MemberExpression, OptionalMemberExpression).callee[property.name="substring"][computed=false]', - ].join(', ')]( - node: TSESTree.MemberExpression | TSESTree.OptionalMemberExpression, - ): void { - const callNode = node.parent! as - | TSESTree.CallExpression - | TSESTree.OptionalCallExpression; - const parentNode = callNode.parent!; - if ( - !isEqualityComparison(parentNode) || - parentNode.left !== callNode || - !isStringType(node.object) - ) { + 'BinaryExpression > CallExpression.left > MemberExpression.callee[property.name="slice"][computed=false]', + 'BinaryExpression > CallExpression.left > MemberExpression.callee[property.name="substring"][computed=false]', + 'BinaryExpression > ChainExpression.left > CallExpression > MemberExpression.callee[property.name="slice"][computed=false]', + 'BinaryExpression > ChainExpression.left > CallExpression > MemberExpression.callee[property.name="substring"][computed=false]', + ].join(', ')](node: TSESTree.MemberExpression): void { + const callNode = getParent(node) as TSESTree.CallExpression; + const parentNode = getParent(callNode); + + if (!isEqualityComparison(parentNode) || !isStringType(node.object)) { return; } @@ -621,12 +631,10 @@ export default createRule({ // /^bar/.test(foo) // /bar$/.test(foo) - ':matches(CallExpression, OptionalCallExpression) > :matches(MemberExpression, OptionalMemberExpression).callee[property.name="test"][computed=false]'( - node: TSESTree.MemberExpression | TSESTree.OptionalMemberExpression, + 'CallExpression > MemberExpression.callee[property.name="test"][computed=false]'( + node: TSESTree.MemberExpression, ): void { - const callNode = node.parent as - | TSESTree.CallExpression - | TSESTree.OptionalCallExpression; + const callNode = getParent(node) as TSESTree.CallExpression; const parsed = callNode.arguments.length === 1 ? parseRegExp(node.object) : null; if (parsed == null) { @@ -646,9 +654,7 @@ export default createRule({ argNode.type !== AST_NODE_TYPES.TemplateLiteral && argNode.type !== AST_NODE_TYPES.Identifier && argNode.type !== AST_NODE_TYPES.MemberExpression && - argNode.type !== AST_NODE_TYPES.OptionalMemberExpression && - argNode.type !== AST_NODE_TYPES.CallExpression && - argNode.type !== AST_NODE_TYPES.OptionalCallExpression; + argNode.type !== AST_NODE_TYPES.CallExpression; yield fixer.removeRange([callNode.range[0], argNode.range[0]]); if (needsParen) { @@ -657,11 +663,9 @@ export default createRule({ } yield fixer.insertTextAfter( argNode, - `${ - callNode.type === AST_NODE_TYPES.OptionalCallExpression - ? '?.' - : '.' - }${methodName}(${JSON.stringify(text)}`, + `${node.optional ? '?.' : '.'}${methodName}(${JSON.stringify( + text, + )}`, ); }, }); diff --git a/packages/eslint-plugin/src/rules/require-array-sort-compare.ts b/packages/eslint-plugin/src/rules/require-array-sort-compare.ts index d18f2bec14a..6e0c49f31a8 100644 --- a/packages/eslint-plugin/src/rules/require-array-sort-compare.ts +++ b/packages/eslint-plugin/src/rules/require-array-sort-compare.ts @@ -62,8 +62,8 @@ export default util.createRule({ } return { - ":matches(CallExpression, OptionalCallExpression)[arguments.length=0] > :matches(MemberExpression, OptionalMemberExpression)[property.name='sort'][computed=false]"( - callee: TSESTree.MemberExpression | TSESTree.OptionalMemberExpression, + "CallExpression[arguments.length=0] > MemberExpression[property.name='sort'][computed=false]"( + callee: TSESTree.MemberExpression, ): void { const tsNode = service.esTreeNodeToTSNodeMap.get(callee.object); const calleeObjType = util.getConstrainedTypeAtLocation( diff --git a/packages/eslint-plugin/src/rules/unbound-method.ts b/packages/eslint-plugin/src/rules/unbound-method.ts index e8217348a4a..246023fce10 100644 --- a/packages/eslint-plugin/src/rules/unbound-method.ts +++ b/packages/eslint-plugin/src/rules/unbound-method.ts @@ -118,9 +118,8 @@ const isNotImported = ( const getNodeName = (node: TSESTree.Node): string | null => node.type === AST_NODE_TYPES.Identifier ? node.name : null; -const getMemberFullName = ( - node: TSESTree.MemberExpression | TSESTree.OptionalMemberExpression, -): string => `${getNodeName(node.object)}.${getNodeName(node.property)}`; +const getMemberFullName = (node: TSESTree.MemberExpression): string => + `${getNodeName(node.object)}.${getNodeName(node.property)}`; export default util.createRule({ name: 'unbound-method', @@ -162,9 +161,7 @@ export default util.createRule({ ); return { - 'MemberExpression, OptionalMemberExpression'( - node: TSESTree.MemberExpression | TSESTree.OptionalMemberExpression, - ): void { + MemberExpression(node: TSESTree.MemberExpression): void { if (isSafeUse(node)) { return; } @@ -271,14 +268,12 @@ function isSafeUse(node: TSESTree.Node): boolean { case AST_NODE_TYPES.IfStatement: case AST_NODE_TYPES.ForStatement: case AST_NODE_TYPES.MemberExpression: - case AST_NODE_TYPES.OptionalMemberExpression: case AST_NODE_TYPES.SwitchStatement: case AST_NODE_TYPES.UpdateExpression: case AST_NODE_TYPES.WhileStatement: return true; case AST_NODE_TYPES.CallExpression: - case AST_NODE_TYPES.OptionalCallExpression: return parent.callee === node; case AST_NODE_TYPES.ConditionalExpression: @@ -299,6 +294,7 @@ function isSafeUse(node: TSESTree.Node): boolean { case AST_NODE_TYPES.AssignmentExpression: return parent.operator === '=' && node === parent.left; + case AST_NODE_TYPES.ChainExpression: case AST_NODE_TYPES.TSNonNullExpression: case AST_NODE_TYPES.TSAsExpression: case AST_NODE_TYPES.TSTypeAssertion: diff --git a/packages/eslint-plugin/src/util/explicitReturnTypeUtils.ts b/packages/eslint-plugin/src/util/explicitReturnTypeUtils.ts index 466e7d207eb..d2c3a684c86 100644 --- a/packages/eslint-plugin/src/util/explicitReturnTypeUtils.ts +++ b/packages/eslint-plugin/src/util/explicitReturnTypeUtils.ts @@ -194,10 +194,9 @@ function doesImmediatelyReturnFunctionExpression({ function isFunctionArgument( parent: TSESTree.Node, callee?: FunctionExpression, -): parent is TSESTree.CallExpression | TSESTree.OptionalCallExpression { +): parent is TSESTree.CallExpression { return ( - (parent.type === AST_NODE_TYPES.CallExpression || - parent.type === AST_NODE_TYPES.OptionalCallExpression) && + parent.type === AST_NODE_TYPES.CallExpression && // make sure this isn't an IIFE parent.callee !== callee ); diff --git a/packages/eslint-plugin/tests/rules/indent/indent.test.ts b/packages/eslint-plugin/tests/rules/indent/indent.test.ts index 6cec699c053..beb648d4f52 100644 --- a/packages/eslint-plugin/tests/rules/indent/indent.test.ts +++ b/packages/eslint-plugin/tests/rules/indent/indent.test.ts @@ -633,7 +633,7 @@ type Foo = string | { // valid test case is just the code acc.valid.push(code); - acc.invalid.push({ + const invalid = { // test the fixer by removing all the spaces code: code.replace(new RegExp(indent, 'g'), ''), output: code, @@ -661,7 +661,10 @@ type Foo = string | { (error): error is TSESLint.TestCaseError => error !== null, ), - }); + }; + if (invalid.errors.length > 0) { + acc.invalid.push(invalid); + } }); return acc; diff --git a/packages/experimental-utils/src/ast-utils/eslint-utils/astUtilities.ts b/packages/experimental-utils/src/ast-utils/eslint-utils/astUtilities.ts index 429b5a59cee..a7db43689a7 100644 --- a/packages/experimental-utils/src/ast-utils/eslint-utils/astUtilities.ts +++ b/packages/experimental-utils/src/ast-utils/eslint-utils/astUtilities.ts @@ -37,7 +37,6 @@ const getFunctionNameWithKind = eslintUtils.getFunctionNameWithKind as ( const getPropertyName = eslintUtils.getPropertyName as ( node: | TSESTree.MemberExpression - | TSESTree.OptionalMemberExpression | TSESTree.Property | TSESTree.MethodDefinition, initialScope?: TSESLint.Scope.Scope, diff --git a/packages/experimental-utils/src/ast-utils/predicates.ts b/packages/experimental-utils/src/ast-utils/predicates.ts index b12f5d9ad6f..c23f30f1707 100644 --- a/packages/experimental-utils/src/ast-utils/predicates.ts +++ b/packages/experimental-utils/src/ast-utils/predicates.ts @@ -25,11 +25,11 @@ function isNotNonNullAssertionPunctuator( /** * Returns true if and only if the node represents: foo?.() or foo.bar?.() */ -function isOptionalOptionalCallExpression( +function isOptionalCallExpression( node: TSESTree.Node, -): node is TSESTree.OptionalCallExpression & { optional: true } { +): node is TSESTree.CallExpression & { optional: true } { return ( - node.type === AST_NODE_TYPES.OptionalCallExpression && + node.type === AST_NODE_TYPES.CallExpression && // this flag means the call expression itself is option // i.e. it is foo.bar?.() and not foo?.bar() node.optional @@ -214,15 +214,6 @@ function isAwaitKeyword( return node?.type === AST_TOKEN_TYPES.Identifier && node.value === 'await'; } -function isMemberOrOptionalMemberExpression( - node: TSESTree.Node, -): node is TSESTree.MemberExpression | TSESTree.OptionalMemberExpression { - return ( - node.type === AST_NODE_TYPES.MemberExpression || - node.type === AST_NODE_TYPES.OptionalMemberExpression - ); -} - export { isAwaitExpression, isAwaitKeyword, @@ -233,12 +224,11 @@ export { isFunctionType, isIdentifier, isLogicalOrOperator, - isMemberOrOptionalMemberExpression, isNonNullAssertionPunctuator, isNotNonNullAssertionPunctuator, isNotOptionalChainPunctuator, isOptionalChainPunctuator, - isOptionalOptionalCallExpression, + isOptionalCallExpression, isSetter, isTSConstructorType, isTSFunctionType, diff --git a/packages/experimental-utils/src/ts-eslint/Rule.ts b/packages/experimental-utils/src/ts-eslint/Rule.ts index 287ea3f4369..d305b29125b 100644 --- a/packages/experimental-utils/src/ts-eslint/Rule.ts +++ b/packages/experimental-utils/src/ts-eslint/Rule.ts @@ -258,6 +258,7 @@ interface RuleListener { BreakStatement?: RuleFunction; CallExpression?: RuleFunction; CatchClause?: RuleFunction; + ChainExpression?: RuleFunction; ClassBody?: RuleFunction; ClassDeclaration?: RuleFunction; ClassExpression?: RuleFunction; @@ -309,8 +310,6 @@ interface RuleListener { NewExpression?: RuleFunction; ObjectExpression?: RuleFunction; ObjectPattern?: RuleFunction; - OptionalCallExpression?: RuleFunction; - OptionalMemberExpression?: RuleFunction; Program?: RuleFunction; Property?: RuleFunction; RestElement?: RuleFunction; diff --git a/packages/parser/src/analyze-scope.ts b/packages/parser/src/analyze-scope.ts index 2b6a7420c86..b2b9f056311 100644 --- a/packages/parser/src/analyze-scope.ts +++ b/packages/parser/src/analyze-scope.ts @@ -341,29 +341,6 @@ class Referencer extends TSESLintScope.Referencer { node.arguments.forEach(this.visit, this); } - /** - * Visit optional member expression. - * @param node The OptionalMemberExpression node to visit. - */ - OptionalMemberExpression(node: TSESTree.OptionalMemberExpression): void { - this.visit(node.object); - if (node.computed) { - this.visit(node.property); - } - } - - /** - * Visit optional call expression. - * @param node The OptionalMemberExpression node to visit. - */ - OptionalCallExpression(node: TSESTree.OptionalCallExpression): void { - this.visitTypeParameters(node); - - this.visit(node.callee); - - node.arguments.forEach(this.visit, this); - } - /** * Define the variable of this function declaration only once. * Because to avoid confusion of `no-redeclare` rule by overloading. diff --git a/packages/parser/tests/lib/__snapshots__/typescript.ts.snap b/packages/parser/tests/lib/__snapshots__/typescript.ts.snap index 82c3f822c80..2999d0f6f67 100644 --- a/packages/parser/tests/lib/__snapshots__/typescript.ts.snap +++ b/packages/parser/tests/lib/__snapshots__/typescript.ts.snap @@ -17623,7 +17623,7 @@ Object { exports[`typescript fixtures/basics/export-star-as-ns-from.src 1`] = ` Object { - "$id": 1, + "$id": 2, "block": Object { "range": Array [ 0, @@ -17633,7 +17633,7 @@ Object { }, "childScopes": Array [ Object { - "$id": 0, + "$id": 1, "block": Object { "range": Array [ 0, @@ -17644,15 +17644,37 @@ Object { "childScopes": Array [], "functionExpressionScope": false, "isStrict": true, - "references": Array [], - "throughReferences": Array [], + "references": Array [ + Object { + "$id": 0, + "from": Object { + "$ref": 1, + }, + "identifier": Object { + "name": "foo", + "range": Array [ + 12, + 15, + ], + "type": "Identifier", + }, + "kind": "r", + "resolved": null, + "writeExpr": undefined, + }, + ], + "throughReferences": Array [ + Object { + "$ref": 0, + }, + ], "type": "module", "upperScope": Object { - "$ref": 1, + "$ref": 2, }, "variableMap": Object {}, "variableScope": Object { - "$ref": 0, + "$ref": 1, }, "variables": Array [], }, @@ -17660,12 +17682,16 @@ Object { "functionExpressionScope": false, "isStrict": false, "references": Array [], - "throughReferences": Array [], + "throughReferences": Array [ + Object { + "$ref": 0, + }, + ], "type": "global", "upperScope": null, "variableMap": Object {}, "variableScope": Object { - "$ref": 1, + "$ref": 2, }, "variables": Array [], } diff --git a/packages/scope-manager/src/referencer/Referencer.ts b/packages/scope-manager/src/referencer/Referencer.ts index d3d13982340..302dda1c457 100644 --- a/packages/scope-manager/src/referencer/Referencer.ts +++ b/packages/scope-manager/src/referencer/Referencer.ts @@ -377,9 +377,7 @@ class Referencer extends Visitor { // don't reference the break statement's label } - protected CallExpression( - node: TSESTree.CallExpression | TSESTree.OptionalCallExpression, - ): void { + protected CallExpression(node: TSESTree.CallExpression): void { this.visitChildren(node, ['typeParameters']); this.visitType(node.typeParameters); } @@ -498,9 +496,7 @@ class Referencer extends Visitor { this.visit(node.body); } - protected MemberExpression( - node: TSESTree.MemberExpression | TSESTree.OptionalMemberExpression, - ): void { + protected MemberExpression(node: TSESTree.MemberExpression): void { this.visit(node.object); if (node.computed) { this.visit(node.property); @@ -520,18 +516,6 @@ class Referencer extends Visitor { this.visitType(node.typeParameters); } - protected OptionalCallExpression( - node: TSESTree.OptionalCallExpression, - ): void { - this.CallExpression(node); - } - - protected OptionalMemberExpression( - node: TSESTree.OptionalMemberExpression, - ): void { - this.MemberExpression(node); - } - protected Program(node: TSESTree.Program): void { const globalScope = this.scopeManager.nestGlobalScope(node); this.populateGlobalsFromLib(globalScope); diff --git a/packages/types/src/ast-node-types.ts b/packages/types/src/ast-node-types.ts index 29f5b0bfe51..d6523eb5c4a 100644 --- a/packages/types/src/ast-node-types.ts +++ b/packages/types/src/ast-node-types.ts @@ -10,6 +10,7 @@ enum AST_NODE_TYPES { BreakStatement = 'BreakStatement', CallExpression = 'CallExpression', CatchClause = 'CatchClause', + ChainExpression = 'ChainExpression', ClassBody = 'ClassBody', ClassDeclaration = 'ClassDeclaration', ClassExpression = 'ClassExpression', @@ -60,8 +61,6 @@ enum AST_NODE_TYPES { NewExpression = 'NewExpression', ObjectExpression = 'ObjectExpression', ObjectPattern = 'ObjectPattern', - OptionalCallExpression = 'OptionalCallExpression', - OptionalMemberExpression = 'OptionalMemberExpression', Program = 'Program', Property = 'Property', RestElement = 'RestElement', diff --git a/packages/types/src/ts-estree.ts b/packages/types/src/ts-estree.ts index ea6e1dfea1c..36df71a019a 100644 --- a/packages/types/src/ts-estree.ts +++ b/packages/types/src/ts-estree.ts @@ -151,6 +151,7 @@ export type Node = | BreakStatement | CallExpression | CatchClause + | ChainExpression | ClassBody | ClassDeclaration | ClassExpression @@ -201,8 +202,6 @@ export type Node = | NewExpression | ObjectExpression | ObjectPattern - | OptionalCallExpression - | OptionalMemberExpression | Program | Property | RestElement @@ -309,6 +308,7 @@ export type Node = export type Accessibility = 'public' | 'protected' | 'private'; export type BindingPattern = ArrayPattern | ObjectPattern; export type BindingName = BindingPattern | Identifier; +export type ChainElement = CallExpression | MemberExpression; export type ClassElement = | ClassProperty | MethodDefinition @@ -354,6 +354,7 @@ export type Expression = | ArrowFunctionExpression | AssignmentExpression | BinaryExpression + | ChainExpression | ConditionalExpression | ImportExpression | JSXClosingElement @@ -394,8 +395,6 @@ export type LeftHandSideExpression = | FunctionExpression | LiteralExpression | MemberExpression - | OptionalCallExpression - | OptionalMemberExpression | PrimaryExpression | TaggedTemplateExpression | TSNonNullExpression @@ -430,9 +429,6 @@ export type ObjectLiteralElementLike = | Property | SpreadElement | TSAbstractMethodDefinition; -export type OptionalMemberExpression = - | OptionalMemberExpressionComputedName - | OptionalMemberExpressionNonComputedName; export type Parameter = | ArrayPattern | AssignmentPattern @@ -824,9 +820,13 @@ export interface BreakStatement extends BaseNode { label: Identifier | null; } +export interface ChainExpression extends BaseNode { + type: AST_NODE_TYPES.ChainExpression; + expression: ChainElement; +} + export interface CallExpression extends CallExpressionBase { type: AST_NODE_TYPES.CallExpression; - optional: false; } export interface CatchClause extends BaseNode { @@ -1089,13 +1089,11 @@ export interface LogicalExpression extends BinaryExpressionBase { export interface MemberExpressionComputedName extends MemberExpressionComputedNameBase { type: AST_NODE_TYPES.MemberExpression; - optional: false; } export interface MemberExpressionNonComputedName extends MemberExpressionNonComputedNameBase { type: AST_NODE_TYPES.MemberExpression; - optional: false; } export interface MetaProperty extends BaseNode { @@ -1144,23 +1142,6 @@ export interface ObjectPattern extends BaseNode { decorators?: Decorator[]; } -export interface OptionalCallExpression extends CallExpressionBase { - type: AST_NODE_TYPES.OptionalCallExpression; - optional: boolean; -} - -export interface OptionalMemberExpressionComputedName - extends MemberExpressionComputedNameBase { - type: AST_NODE_TYPES.OptionalMemberExpression; - optional: boolean; -} - -export interface OptionalMemberExpressionNonComputedName - extends MemberExpressionNonComputedNameBase { - type: AST_NODE_TYPES.OptionalMemberExpression; - optional: boolean; -} - export interface Program extends BaseNode { type: AST_NODE_TYPES.Program; body: Statement[]; diff --git a/packages/typescript-estree/src/convert.ts b/packages/typescript-estree/src/convert.ts index 69ba262fa30..7522943694c 100644 --- a/packages/typescript-estree/src/convert.ts +++ b/packages/typescript-estree/src/convert.ts @@ -21,6 +21,7 @@ import { isOptional, TSError, unescapeStringLiteralText, + isChainExpression, } from './node-utils'; import { ParserWeakMap, ParserWeakMapESTreeToTSNode } from './parser-options'; import { @@ -400,6 +401,38 @@ export class Converter { }); } + private convertChainExpression( + node: TSESTree.ChainElement, + tsNode: + | ts.PropertyAccessExpression + | ts.ElementAccessExpression + | ts.CallExpression, + ): TSESTree.ChainExpression | TSESTree.ChainElement { + let child = (node.type === AST_NODE_TYPES.MemberExpression + ? node.object + : node.callee) as TSESTree.Node; + const isChildOptional = isChildOptionalChain(tsNode, child); + + if (!isChildOptional && !node.optional) { + return node; + } + + if (isChainExpression(child)) { + // unwrap the chain expression child + child = child.expression; + if (node.type === AST_NODE_TYPES.MemberExpression) { + node.object = child; + } else { + node.callee = child; + } + } + + return this.createNode(tsNode, { + type: AST_NODE_TYPES.ChainExpression, + expression: node, + }); + } + /** * For nodes that are copied directly from the TypeScript AST into * ESTree mostly as-is. The only difference is the addition of a type @@ -1774,27 +1807,15 @@ export class Converter { const property = this.convertChild(node.name); const computed = false; - const isLocallyOptional = node.questionDotToken !== undefined; - // the optional expression should propagate up the member expression tree - const isChildOptional = isChildOptionalChain(node, object); - - if (isLocallyOptional || isChildOptional) { - return this.createNode(node, { - type: AST_NODE_TYPES.OptionalMemberExpression, - object, - property, - computed, - optional: isLocallyOptional, - }); - } else { - return this.createNode(node, { - type: AST_NODE_TYPES.MemberExpression, - object, - property, - computed, - optional: false, - }); - } + const result = this.createNode(node, { + type: AST_NODE_TYPES.MemberExpression, + object, + property, + computed, + optional: node.questionDotToken !== undefined, + }); + + return this.convertChainExpression(result, node); } case SyntaxKind.ElementAccessExpression: { @@ -1802,27 +1823,15 @@ export class Converter { const property = this.convertChild(node.argumentExpression); const computed = true; - const isLocallyOptional = node.questionDotToken !== undefined; - // the optional expression should propagate up the member expression tree - const isChildOptional = isChildOptionalChain(node, object); - - if (isLocallyOptional || isChildOptional) { - return this.createNode(node, { - type: AST_NODE_TYPES.OptionalMemberExpression, - object, - property, - computed, - optional: isLocallyOptional, - }); - } else { - return this.createNode(node, { - type: AST_NODE_TYPES.MemberExpression, - object, - property, - computed, - optional: false, - }); - } + const result = this.createNode(node, { + type: AST_NODE_TYPES.MemberExpression, + object, + property, + computed, + optional: node.questionDotToken !== undefined, + }); + + return this.convertChainExpression(result, node); } case SyntaxKind.CallExpression: { @@ -1842,27 +1851,13 @@ export class Converter { const callee = this.convertChild(node.expression); const args = node.arguments.map(el => this.convertChild(el)); - let result; - - const isLocallyOptional = node.questionDotToken !== undefined; - // the optional expression should propagate up the member expression tree - const isChildOptional = isChildOptionalChain(node, callee); - - if (isLocallyOptional || isChildOptional) { - result = this.createNode(node, { - type: AST_NODE_TYPES.OptionalCallExpression, - callee, - arguments: args, - optional: isLocallyOptional, - }); - } else { - result = this.createNode(node, { - type: AST_NODE_TYPES.CallExpression, - callee, - arguments: args, - optional: false, - }); - } + + const result = this.createNode(node, { + type: AST_NODE_TYPES.CallExpression, + callee, + arguments: args, + optional: node.questionDotToken !== undefined, + }); if (node.typeArguments) { result.typeParameters = this.convertTypeArgumentsToTypeParameters( @@ -1870,7 +1865,8 @@ export class Converter { node, ); } - return result; + + return this.convertChainExpression(result, node); } case SyntaxKind.NewExpression: { diff --git a/packages/typescript-estree/src/node-utils.ts b/packages/typescript-estree/src/node-utils.ts index 82b98b29301..c40a0ddd1f6 100644 --- a/packages/typescript-estree/src/node-utils.ts +++ b/packages/typescript-estree/src/node-utils.ts @@ -443,13 +443,10 @@ export function isOptional(node: { /** * Returns true if the node is an optional chain node */ -export function isOptionalChain( +export function isChainExpression( node: TSESTree.Node, -): node is TSESTree.OptionalCallExpression | TSESTree.OptionalMemberExpression { - return ( - node.type === AST_NODE_TYPES.OptionalCallExpression || - node.type == AST_NODE_TYPES.OptionalMemberExpression - ); +): node is TSESTree.ChainExpression { + return node.type === AST_NODE_TYPES.ChainExpression; } /** @@ -460,10 +457,10 @@ export function isChildOptionalChain( | ts.PropertyAccessExpression | ts.ElementAccessExpression | ts.CallExpression, - object: TSESTree.LeftHandSideExpression, + child: TSESTree.Node, ): boolean { if ( - isOptionalChain(object) && + isChainExpression(child) && // (x?.y).z is semantically different, and as such .z is no longer optional node.expression.kind !== ts.SyntaxKind.ParenthesizedExpression ) { @@ -479,8 +476,8 @@ export function isChildOptionalChain( // Post-3.9, `x?.y!.z` means `x?.y!.z` - i.e. it just asserts that the property `y` is non-null, not the result of `x?.y` if ( - object.type !== AST_NODE_TYPES.TSNonNullExpression || - !isOptionalChain(object.expression) + child.type !== AST_NODE_TYPES.TSNonNullExpression || + !isChainExpression(child.expression) ) { return false; } diff --git a/packages/typescript-estree/src/ts-estree/estree-to-ts-node-types.ts b/packages/typescript-estree/src/ts-estree/estree-to-ts-node-types.ts index 7816ea3d0ca..e62efb7bb8b 100644 --- a/packages/typescript-estree/src/ts-estree/estree-to-ts-node-types.ts +++ b/packages/typescript-estree/src/ts-estree/estree-to-ts-node-types.ts @@ -20,6 +20,10 @@ export interface EstreeToTsNodeTypes { [AST_NODE_TYPES.BreakStatement]: ts.BreakStatement; [AST_NODE_TYPES.CallExpression]: ts.CallExpression; [AST_NODE_TYPES.CatchClause]: ts.CatchClause; + [AST_NODE_TYPES.ChainExpression]: + | ts.CallExpression + | ts.PropertyAccessExpression + | ts.ElementAccessExpression; [AST_NODE_TYPES.ClassBody]: ts.ClassDeclaration | ts.ClassExpression; [AST_NODE_TYPES.ClassDeclaration]: ts.ClassDeclaration; [AST_NODE_TYPES.ClassExpression]: ts.ClassExpression; @@ -113,10 +117,6 @@ export interface EstreeToTsNodeTypes { [AST_NODE_TYPES.ObjectPattern]: | ts.ObjectLiteralExpression | ts.ObjectBindingPattern; - [AST_NODE_TYPES.OptionalCallExpression]: ts.CallExpression; - [AST_NODE_TYPES.OptionalMemberExpression]: - | ts.PropertyAccessExpression - | ts.ElementAccessExpression; [AST_NODE_TYPES.Program]: ts.SourceFile; [AST_NODE_TYPES.Property]: | ts.PropertyAssignment diff --git a/packages/typescript-estree/tests/ast-fixtures.test.ts b/packages/typescript-estree/tests/ast-fixtures.test.ts index 8b10bd4bb02..265a5f6fac4 100644 --- a/packages/typescript-estree/tests/ast-fixtures.test.ts +++ b/packages/typescript-estree/tests/ast-fixtures.test.ts @@ -7,7 +7,7 @@ import { parseAndGenerateServices } from '../src/parser'; // Assign a segment set to this variable to limit the test to only this segment // This is super helpful if you need to debug why a specific fixture isn't producing the correct output -// eg. ['type-declaration', 'signatures', 'method-generic'] will only test /type-declaration/signatures/method-generic.ts +// eg. ['type-declaration', 'signatures', 'method-generic.src'] will only test /type-declaration/signatures/method-generic.src.ts // prettier-ignore const ONLY = [].join(path.sep); diff --git a/packages/typescript-estree/tests/snapshots/typescript/basics/optional-chain-call-with-non-null-assertion.src.ts.shot b/packages/typescript-estree/tests/snapshots/typescript/basics/optional-chain-call-with-non-null-assertion.src.ts.shot index 9d408743814..119ab05be33 100644 --- a/packages/typescript-estree/tests/snapshots/typescript/basics/optional-chain-call-with-non-null-assertion.src.ts.shot +++ b/packages/typescript-estree/tests/snapshots/typescript/basics/optional-chain-call-with-non-null-assertion.src.ts.shot @@ -9,66 +9,100 @@ Object { "body": Array [ Object { "expression": Object { - "arguments": Array [], - "callee": Object { - "expression": Object { - "computed": false, - "loc": Object { - "end": Object { - "column": 10, - "line": 2, - }, - "start": Object { - "column": 2, - "line": 2, - }, - }, - "object": Object { - "loc": Object { - "end": Object { - "column": 5, - "line": 2, + "expression": Object { + "arguments": Array [], + "callee": Object { + "expression": Object { + "expression": Object { + "computed": false, + "loc": Object { + "end": Object { + "column": 10, + "line": 2, + }, + "start": Object { + "column": 2, + "line": 2, + }, }, - "start": Object { - "column": 2, - "line": 2, + "object": Object { + "loc": Object { + "end": Object { + "column": 5, + "line": 2, + }, + "start": Object { + "column": 2, + "line": 2, + }, + }, + "name": "one", + "range": Array [ + 40, + 43, + ], + "type": "Identifier", + }, + "optional": true, + "property": Object { + "loc": Object { + "end": Object { + "column": 10, + "line": 2, + }, + "start": Object { + "column": 7, + "line": 2, + }, + }, + "name": "two", + "range": Array [ + 45, + 48, + ], + "type": "Identifier", }, + "range": Array [ + 40, + 48, + ], + "type": "MemberExpression", }, - "name": "one", - "range": Array [ - 40, - 43, - ], - "type": "Identifier", - }, - "optional": true, - "property": Object { "loc": Object { "end": Object { "column": 10, "line": 2, }, "start": Object { - "column": 7, + "column": 2, "line": 2, }, }, - "name": "two", "range": Array [ - 45, + 40, 48, ], - "type": "Identifier", + "type": "ChainExpression", + }, + "loc": Object { + "end": Object { + "column": 11, + "line": 2, + }, + "start": Object { + "column": 2, + "line": 2, + }, }, "range": Array [ 40, - 48, + 49, ], - "type": "OptionalMemberExpression", + "type": "TSNonNullExpression", }, "loc": Object { "end": Object { - "column": 11, + "column": 13, "line": 2, }, "start": Object { @@ -76,11 +110,12 @@ Object { "line": 2, }, }, + "optional": false, "range": Array [ 40, - 49, + 51, ], - "type": "TSNonNullExpression", + "type": "CallExpression", }, "loc": Object { "end": Object { @@ -92,12 +127,11 @@ Object { "line": 2, }, }, - "optional": false, "range": Array [ 40, 51, ], - "type": "OptionalCallExpression", + "type": "ChainExpression", }, "loc": Object { "end": Object { @@ -117,115 +151,150 @@ Object { }, Object { "expression": Object { - "arguments": Array [], - "callee": Object { - "computed": false, - "loc": Object { - "end": Object { - "column": 17, - "line": 3, - }, - "start": Object { - "column": 2, - "line": 3, - }, - }, - "object": Object { - "expression": Object { - "computed": false, - "loc": Object { - "end": Object { - "column": 10, - "line": 3, - }, - "start": Object { - "column": 2, - "line": 3, - }, + "expression": Object { + "arguments": Array [], + "callee": Object { + "computed": false, + "loc": Object { + "end": Object { + "column": 17, + "line": 3, }, - "object": Object { - "loc": Object { - "end": Object { - "column": 5, - "line": 3, + "start": Object { + "column": 2, + "line": 3, + }, + }, + "object": Object { + "expression": Object { + "expression": Object { + "computed": false, + "loc": Object { + "end": Object { + "column": 10, + "line": 3, + }, + "start": Object { + "column": 2, + "line": 3, + }, }, - "start": Object { - "column": 2, - "line": 3, + "object": Object { + "loc": Object { + "end": Object { + "column": 5, + "line": 3, + }, + "start": Object { + "column": 2, + "line": 3, + }, + }, + "name": "one", + "range": Array [ + 55, + 58, + ], + "type": "Identifier", + }, + "optional": true, + "property": Object { + "loc": Object { + "end": Object { + "column": 10, + "line": 3, + }, + "start": Object { + "column": 7, + "line": 3, + }, + }, + "name": "two", + "range": Array [ + 60, + 63, + ], + "type": "Identifier", }, + "range": Array [ + 55, + 63, + ], + "type": "MemberExpression", }, - "name": "one", - "range": Array [ - 55, - 58, - ], - "type": "Identifier", - }, - "optional": true, - "property": Object { "loc": Object { "end": Object { "column": 10, "line": 3, }, "start": Object { - "column": 7, + "column": 2, "line": 3, }, }, - "name": "two", "range": Array [ - 60, + 55, 63, ], - "type": "Identifier", + "type": "ChainExpression", + }, + "loc": Object { + "end": Object { + "column": 11, + "line": 3, + }, + "start": Object { + "column": 2, + "line": 3, + }, }, "range": Array [ 55, - 63, + 64, ], - "type": "OptionalMemberExpression", + "type": "TSNonNullExpression", }, - "loc": Object { - "end": Object { - "column": 11, - "line": 3, - }, - "start": Object { - "column": 2, - "line": 3, + "optional": false, + "property": Object { + "loc": Object { + "end": Object { + "column": 17, + "line": 3, + }, + "start": Object { + "column": 12, + "line": 3, + }, }, + "name": "three", + "range": Array [ + 65, + 70, + ], + "type": "Identifier", }, "range": Array [ 55, - 64, + 70, ], - "type": "TSNonNullExpression", + "type": "MemberExpression", }, - "optional": false, - "property": Object { - "loc": Object { - "end": Object { - "column": 17, - "line": 3, - }, - "start": Object { - "column": 12, - "line": 3, - }, + "loc": Object { + "end": Object { + "column": 19, + "line": 3, + }, + "start": Object { + "column": 2, + "line": 3, }, - "name": "three", - "range": Array [ - 65, - 70, - ], - "type": "Identifier", }, + "optional": false, "range": Array [ 55, - 70, + 72, ], - "type": "OptionalMemberExpression", + "type": "CallExpression", }, "loc": Object { "end": Object { @@ -237,12 +306,11 @@ Object { "line": 3, }, }, - "optional": false, "range": Array [ 55, 72, ], - "type": "OptionalCallExpression", + "type": "ChainExpression", }, "loc": Object { "end": Object { @@ -265,21 +333,11 @@ Object { "arguments": Array [], "callee": Object { "expression": Object { - "computed": false, - "loc": Object { - "end": Object { - "column": 11, - "line": 4, - }, - "start": Object { - "column": 3, - "line": 4, - }, - }, - "object": Object { + "expression": Object { + "computed": false, "loc": Object { "end": Object { - "column": 6, + "column": 11, "line": 4, }, "start": Object { @@ -287,37 +345,64 @@ Object { "line": 4, }, }, - "name": "one", - "range": Array [ - 77, - 80, - ], - "type": "Identifier", - }, - "optional": true, - "property": Object { - "loc": Object { - "end": Object { - "column": 11, - "line": 4, + "object": Object { + "loc": Object { + "end": Object { + "column": 6, + "line": 4, + }, + "start": Object { + "column": 3, + "line": 4, + }, }, - "start": Object { - "column": 8, - "line": 4, + "name": "one", + "range": Array [ + 77, + 80, + ], + "type": "Identifier", + }, + "optional": true, + "property": Object { + "loc": Object { + "end": Object { + "column": 11, + "line": 4, + }, + "start": Object { + "column": 8, + "line": 4, + }, }, + "name": "two", + "range": Array [ + 82, + 85, + ], + "type": "Identifier", }, - "name": "two", "range": Array [ - 82, + 77, 85, ], - "type": "Identifier", + "type": "MemberExpression", + }, + "loc": Object { + "end": Object { + "column": 11, + "line": 4, + }, + "start": Object { + "column": 3, + "line": 4, + }, }, "range": Array [ 77, 85, ], - "type": "OptionalMemberExpression", + "type": "ChainExpression", }, "loc": Object { "end": Object { @@ -385,21 +470,11 @@ Object { }, "object": Object { "expression": Object { - "computed": false, - "loc": Object { - "end": Object { - "column": 11, - "line": 5, - }, - "start": Object { - "column": 3, - "line": 5, - }, - }, - "object": Object { + "expression": Object { + "computed": false, "loc": Object { "end": Object { - "column": 6, + "column": 11, "line": 5, }, "start": Object { @@ -407,37 +482,64 @@ Object { "line": 5, }, }, - "name": "one", - "range": Array [ - 94, - 97, - ], - "type": "Identifier", - }, - "optional": true, - "property": Object { - "loc": Object { - "end": Object { - "column": 11, - "line": 5, + "object": Object { + "loc": Object { + "end": Object { + "column": 6, + "line": 5, + }, + "start": Object { + "column": 3, + "line": 5, + }, }, - "start": Object { - "column": 8, - "line": 5, + "name": "one", + "range": Array [ + 94, + 97, + ], + "type": "Identifier", + }, + "optional": true, + "property": Object { + "loc": Object { + "end": Object { + "column": 11, + "line": 5, + }, + "start": Object { + "column": 8, + "line": 5, + }, }, + "name": "two", + "range": Array [ + 99, + 102, + ], + "type": "Identifier", }, - "name": "two", "range": Array [ - 99, + 94, 102, ], - "type": "Identifier", + "type": "MemberExpression", + }, + "loc": Object { + "end": Object { + "column": 11, + "line": 5, + }, + "start": Object { + "column": 3, + "line": 5, + }, }, "range": Array [ 94, 102, ], - "type": "OptionalMemberExpression", + "type": "ChainExpression", }, "loc": Object { "end": Object { @@ -518,21 +620,11 @@ Object { "arguments": Array [], "callee": Object { "expression": Object { - "computed": false, - "loc": Object { - "end": Object { - "column": 11, - "line": 6, - }, - "start": Object { - "column": 3, - "line": 6, - }, - }, - "object": Object { + "expression": Object { + "computed": false, "loc": Object { "end": Object { - "column": 6, + "column": 11, "line": 6, }, "start": Object { @@ -540,37 +632,64 @@ Object { "line": 6, }, }, - "name": "one", - "range": Array [ - 117, - 120, - ], - "type": "Identifier", - }, - "optional": true, - "property": Object { - "loc": Object { - "end": Object { - "column": 11, - "line": 6, + "object": Object { + "loc": Object { + "end": Object { + "column": 6, + "line": 6, + }, + "start": Object { + "column": 3, + "line": 6, + }, }, - "start": Object { - "column": 8, - "line": 6, + "name": "one", + "range": Array [ + 117, + 120, + ], + "type": "Identifier", + }, + "optional": true, + "property": Object { + "loc": Object { + "end": Object { + "column": 11, + "line": 6, + }, + "start": Object { + "column": 8, + "line": 6, + }, }, + "name": "two", + "range": Array [ + 122, + 125, + ], + "type": "Identifier", }, - "name": "two", "range": Array [ - 122, + 117, 125, ], - "type": "Identifier", + "type": "MemberExpression", + }, + "loc": Object { + "end": Object { + "column": 11, + "line": 6, + }, + "start": Object { + "column": 3, + "line": 6, + }, }, "range": Array [ 117, 125, ], - "type": "OptionalMemberExpression", + "type": "ChainExpression", }, "loc": Object { "end": Object { @@ -638,21 +757,11 @@ Object { }, "object": Object { "expression": Object { - "computed": false, - "loc": Object { - "end": Object { - "column": 11, - "line": 7, - }, - "start": Object { - "column": 3, - "line": 7, - }, - }, - "object": Object { + "expression": Object { + "computed": false, "loc": Object { "end": Object { - "column": 6, + "column": 11, "line": 7, }, "start": Object { @@ -660,37 +769,64 @@ Object { "line": 7, }, }, - "name": "one", - "range": Array [ - 134, - 137, - ], - "type": "Identifier", - }, - "optional": true, - "property": Object { - "loc": Object { - "end": Object { - "column": 11, - "line": 7, + "object": Object { + "loc": Object { + "end": Object { + "column": 6, + "line": 7, + }, + "start": Object { + "column": 3, + "line": 7, + }, }, - "start": Object { - "column": 8, - "line": 7, + "name": "one", + "range": Array [ + 134, + 137, + ], + "type": "Identifier", + }, + "optional": true, + "property": Object { + "loc": Object { + "end": Object { + "column": 11, + "line": 7, + }, + "start": Object { + "column": 8, + "line": 7, + }, }, + "name": "two", + "range": Array [ + 139, + 142, + ], + "type": "Identifier", }, - "name": "two", "range": Array [ - 139, + 134, 142, ], - "type": "Identifier", + "type": "MemberExpression", + }, + "loc": Object { + "end": Object { + "column": 11, + "line": 7, + }, + "start": Object { + "column": 3, + "line": 7, + }, }, "range": Array [ 134, 142, ], - "type": "OptionalMemberExpression", + "type": "ChainExpression", }, "loc": Object { "end": Object { diff --git a/packages/typescript-estree/tests/snapshots/typescript/basics/optional-chain-call-with-parens.src.ts.shot b/packages/typescript-estree/tests/snapshots/typescript/basics/optional-chain-call-with-parens.src.ts.shot index 0c452078cc6..fb93938c467 100644 --- a/packages/typescript-estree/tests/snapshots/typescript/basics/optional-chain-call-with-parens.src.ts.shot +++ b/packages/typescript-estree/tests/snapshots/typescript/basics/optional-chain-call-with-parens.src.ts.shot @@ -9,23 +9,13 @@ Object { "body": Array [ Object { "expression": Object { - "arguments": Array [], - "callee": Object { - "computed": false, - "loc": Object { - "end": Object { - "column": 10, - "line": 2, - }, - "start": Object { - "column": 3, - "line": 2, - }, - }, - "object": Object { + "expression": Object { + "arguments": Array [], + "callee": Object { + "computed": false, "loc": Object { "end": Object { - "column": 6, + "column": 10, "line": 2, }, "start": Object { @@ -33,37 +23,65 @@ Object { "line": 2, }, }, - "name": "one", - "range": Array [ - 51, - 54, - ], - "type": "Identifier", - }, - "optional": true, - "property": Object { - "loc": Object { - "end": Object { - "column": 10, - "line": 2, + "object": Object { + "loc": Object { + "end": Object { + "column": 6, + "line": 2, + }, + "start": Object { + "column": 3, + "line": 2, + }, }, - "start": Object { - "column": 8, - "line": 2, + "name": "one", + "range": Array [ + 51, + 54, + ], + "type": "Identifier", + }, + "optional": true, + "property": Object { + "loc": Object { + "end": Object { + "column": 10, + "line": 2, + }, + "start": Object { + "column": 8, + "line": 2, + }, }, + "name": "fn", + "range": Array [ + 56, + 58, + ], + "type": "Identifier", }, - "name": "fn", "range": Array [ - 56, + 51, 58, ], - "type": "Identifier", + "type": "MemberExpression", }, + "loc": Object { + "end": Object { + "column": 12, + "line": 2, + }, + "start": Object { + "column": 3, + "line": 2, + }, + }, + "optional": false, "range": Array [ 51, - 58, + 60, ], - "type": "OptionalMemberExpression", + "type": "CallExpression", }, "loc": Object { "end": Object { @@ -75,12 +93,11 @@ Object { "line": 2, }, }, - "optional": false, "range": Array [ 51, 60, ], - "type": "OptionalCallExpression", + "type": "ChainExpression", }, "loc": Object { "end": Object { @@ -114,21 +131,11 @@ Object { }, }, "object": Object { - "computed": false, - "loc": Object { - "end": Object { - "column": 11, - "line": 3, - }, - "start": Object { - "column": 3, - "line": 3, - }, - }, - "object": Object { + "expression": Object { + "computed": false, "loc": Object { "end": Object { - "column": 6, + "column": 11, "line": 3, }, "start": Object { @@ -136,37 +143,64 @@ Object { "line": 3, }, }, - "name": "one", - "range": Array [ - 66, - 69, - ], - "type": "Identifier", - }, - "optional": true, - "property": Object { - "loc": Object { - "end": Object { - "column": 11, - "line": 3, + "object": Object { + "loc": Object { + "end": Object { + "column": 6, + "line": 3, + }, + "start": Object { + "column": 3, + "line": 3, + }, }, - "start": Object { - "column": 8, - "line": 3, + "name": "one", + "range": Array [ + 66, + 69, + ], + "type": "Identifier", + }, + "optional": true, + "property": Object { + "loc": Object { + "end": Object { + "column": 11, + "line": 3, + }, + "start": Object { + "column": 8, + "line": 3, + }, }, + "name": "two", + "range": Array [ + 71, + 74, + ], + "type": "Identifier", }, - "name": "two", "range": Array [ - 71, + 66, 74, ], - "type": "Identifier", + "type": "MemberExpression", + }, + "loc": Object { + "end": Object { + "column": 11, + "line": 3, + }, + "start": Object { + "column": 3, + "line": 3, + }, }, "range": Array [ 66, 74, ], - "type": "OptionalMemberExpression", + "type": "ChainExpression", }, "optional": false, "property": Object { @@ -228,24 +262,13 @@ Object { }, Object { "expression": Object { - "arguments": Array [], - "callee": Object { - "computed": false, - "loc": Object { - "end": Object { - "column": 14, - "line": 4, - }, - "start": Object { - "column": 3, - "line": 4, - }, - }, - "object": Object { + "expression": Object { + "arguments": Array [], + "callee": Object { "computed": false, "loc": Object { "end": Object { - "column": 10, + "column": 14, "line": 4, }, "start": Object { @@ -254,9 +277,10 @@ Object { }, }, "object": Object { + "computed": false, "loc": Object { "end": Object { - "column": 6, + "column": 10, "line": 4, }, "start": Object { @@ -264,62 +288,90 @@ Object { "line": 4, }, }, - "name": "one", + "object": Object { + "loc": Object { + "end": Object { + "column": 6, + "line": 4, + }, + "start": Object { + "column": 3, + "line": 4, + }, + }, + "name": "one", + "range": Array [ + 85, + 88, + ], + "type": "Identifier", + }, + "optional": false, + "property": Object { + "loc": Object { + "end": Object { + "column": 10, + "line": 4, + }, + "start": Object { + "column": 7, + "line": 4, + }, + }, + "name": "two", + "range": Array [ + 89, + 92, + ], + "type": "Identifier", + }, "range": Array [ 85, - 88, + 92, ], - "type": "Identifier", + "type": "MemberExpression", }, - "optional": false, + "optional": true, "property": Object { "loc": Object { "end": Object { - "column": 10, + "column": 14, "line": 4, }, "start": Object { - "column": 7, + "column": 12, "line": 4, }, }, - "name": "two", + "name": "fn", "range": Array [ - 89, - 92, + 94, + 96, ], "type": "Identifier", }, "range": Array [ 85, - 92, + 96, ], "type": "MemberExpression", }, - "optional": true, - "property": Object { - "loc": Object { - "end": Object { - "column": 14, - "line": 4, - }, - "start": Object { - "column": 12, - "line": 4, - }, + "loc": Object { + "end": Object { + "column": 16, + "line": 4, + }, + "start": Object { + "column": 3, + "line": 4, }, - "name": "fn", - "range": Array [ - 94, - 96, - ], - "type": "Identifier", }, + "optional": false, "range": Array [ 85, - 96, + 98, ], - "type": "OptionalMemberExpression", + "type": "CallExpression", }, "loc": Object { "end": Object { @@ -331,12 +383,11 @@ Object { "line": 4, }, }, - "optional": false, "range": Array [ 85, 98, ], - "type": "OptionalCallExpression", + "type": "ChainExpression", }, "loc": Object { "end": Object { @@ -370,22 +421,11 @@ Object { }, }, "object": Object { - "computed": false, - "loc": Object { - "end": Object { - "column": 17, - "line": 5, - }, - "start": Object { - "column": 3, - "line": 5, - }, - }, - "object": Object { + "expression": Object { "computed": false, "loc": Object { "end": Object { - "column": 10, + "column": 17, "line": 5, }, "start": Object { @@ -394,9 +434,10 @@ Object { }, }, "object": Object { + "computed": false, "loc": Object { "end": Object { - "column": 6, + "column": 10, "line": 5, }, "start": Object { @@ -404,62 +445,89 @@ Object { "line": 5, }, }, - "name": "one", + "object": Object { + "loc": Object { + "end": Object { + "column": 6, + "line": 5, + }, + "start": Object { + "column": 3, + "line": 5, + }, + }, + "name": "one", + "range": Array [ + 104, + 107, + ], + "type": "Identifier", + }, + "optional": false, + "property": Object { + "loc": Object { + "end": Object { + "column": 10, + "line": 5, + }, + "start": Object { + "column": 7, + "line": 5, + }, + }, + "name": "two", + "range": Array [ + 108, + 111, + ], + "type": "Identifier", + }, "range": Array [ 104, - 107, + 111, ], - "type": "Identifier", + "type": "MemberExpression", }, - "optional": false, + "optional": true, "property": Object { "loc": Object { "end": Object { - "column": 10, + "column": 17, "line": 5, }, "start": Object { - "column": 7, + "column": 12, "line": 5, }, }, - "name": "two", + "name": "three", "range": Array [ - 108, - 111, + 113, + 118, ], "type": "Identifier", }, "range": Array [ 104, - 111, + 118, ], "type": "MemberExpression", }, - "optional": true, - "property": Object { - "loc": Object { - "end": Object { - "column": 17, - "line": 5, - }, - "start": Object { - "column": 12, - "line": 5, - }, + "loc": Object { + "end": Object { + "column": 17, + "line": 5, + }, + "start": Object { + "column": 3, + "line": 5, }, - "name": "three", - "range": Array [ - 113, - 118, - ], - "type": "Identifier", }, "range": Array [ 104, 118, ], - "type": "OptionalMemberExpression", + "type": "ChainExpression", }, "optional": false, "property": Object { @@ -521,24 +589,13 @@ Object { }, Object { "expression": Object { - "arguments": Array [], - "callee": Object { - "computed": false, - "loc": Object { - "end": Object { - "column": 21, - "line": 6, - }, - "start": Object { - "column": 3, - "line": 6, - }, - }, - "object": Object { + "expression": Object { + "arguments": Array [], + "callee": Object { "computed": false, "loc": Object { "end": Object { - "column": 17, + "column": 21, "line": 6, }, "start": Object { @@ -550,7 +607,7 @@ Object { "computed": false, "loc": Object { "end": Object { - "column": 10, + "column": 17, "line": 6, }, "start": Object { @@ -559,9 +616,10 @@ Object { }, }, "object": Object { + "computed": false, "loc": Object { "end": Object { - "column": 6, + "column": 10, "line": 6, }, "start": Object { @@ -569,35 +627,71 @@ Object { "line": 6, }, }, - "name": "one", + "object": Object { + "loc": Object { + "end": Object { + "column": 6, + "line": 6, + }, + "start": Object { + "column": 3, + "line": 6, + }, + }, + "name": "one", + "range": Array [ + 129, + 132, + ], + "type": "Identifier", + }, + "optional": false, + "property": Object { + "loc": Object { + "end": Object { + "column": 10, + "line": 6, + }, + "start": Object { + "column": 7, + "line": 6, + }, + }, + "name": "two", + "range": Array [ + 133, + 136, + ], + "type": "Identifier", + }, "range": Array [ 129, - 132, + 136, ], - "type": "Identifier", + "type": "MemberExpression", }, - "optional": false, + "optional": true, "property": Object { "loc": Object { "end": Object { - "column": 10, + "column": 17, "line": 6, }, "start": Object { - "column": 7, + "column": 12, "line": 6, }, }, - "name": "two", + "name": "three", "range": Array [ - 133, - 136, + 138, + 143, ], "type": "Identifier", }, "range": Array [ 129, - 136, + 143, ], "type": "MemberExpression", }, @@ -605,51 +699,43 @@ Object { "property": Object { "loc": Object { "end": Object { - "column": 17, + "column": 21, "line": 6, }, "start": Object { - "column": 12, + "column": 19, "line": 6, }, }, - "name": "three", + "name": "fn", "range": Array [ - 138, - 143, + 145, + 147, ], "type": "Identifier", }, "range": Array [ 129, - 143, + 147, ], - "type": "OptionalMemberExpression", + "type": "MemberExpression", }, - "optional": true, - "property": Object { - "loc": Object { - "end": Object { - "column": 21, - "line": 6, - }, - "start": Object { - "column": 19, - "line": 6, - }, + "loc": Object { + "end": Object { + "column": 23, + "line": 6, + }, + "start": Object { + "column": 3, + "line": 6, }, - "name": "fn", - "range": Array [ - 145, - 147, - ], - "type": "Identifier", }, + "optional": false, "range": Array [ 129, - 147, + 149, ], - "type": "OptionalMemberExpression", + "type": "CallExpression", }, "loc": Object { "end": Object { @@ -661,12 +747,11 @@ Object { "line": 6, }, }, - "optional": false, "range": Array [ 129, 149, ], - "type": "OptionalCallExpression", + "type": "ChainExpression", }, "loc": Object { "end": Object { @@ -686,11 +771,29 @@ Object { }, Object { "expression": Object { - "arguments": Array [], - "callee": Object { + "expression": Object { + "arguments": Array [], + "callee": Object { + "loc": Object { + "end": Object { + "column": 6, + "line": 8, + }, + "start": Object { + "column": 3, + "line": 8, + }, + }, + "name": "one", + "range": Array [ + 156, + 159, + ], + "type": "Identifier", + }, "loc": Object { "end": Object { - "column": 6, + "column": 10, "line": 8, }, "start": Object { @@ -698,12 +801,12 @@ Object { "line": 8, }, }, - "name": "one", + "optional": true, "range": Array [ 156, - 159, + 163, ], - "type": "Identifier", + "type": "CallExpression", }, "loc": Object { "end": Object { @@ -715,12 +818,11 @@ Object { "line": 8, }, }, - "optional": true, "range": Array [ 156, 163, ], - "type": "OptionalCallExpression", + "type": "ChainExpression", }, "loc": Object { "end": Object { @@ -742,11 +844,29 @@ Object { "expression": Object { "arguments": Array [], "callee": Object { - "arguments": Array [], - "callee": Object { + "expression": Object { + "arguments": Array [], + "callee": Object { + "loc": Object { + "end": Object { + "column": 6, + "line": 9, + }, + "start": Object { + "column": 3, + "line": 9, + }, + }, + "name": "one", + "range": Array [ + 169, + 172, + ], + "type": "Identifier", + }, "loc": Object { "end": Object { - "column": 6, + "column": 10, "line": 9, }, "start": Object { @@ -754,12 +874,12 @@ Object { "line": 9, }, }, - "name": "one", + "optional": true, "range": Array [ 169, - 172, + 176, ], - "type": "Identifier", + "type": "CallExpression", }, "loc": Object { "end": Object { @@ -771,12 +891,11 @@ Object { "line": 9, }, }, - "optional": true, "range": Array [ 169, 176, ], - "type": "OptionalCallExpression", + "type": "ChainExpression", }, "loc": Object { "end": Object { @@ -813,13 +932,31 @@ Object { }, Object { "expression": Object { - "arguments": Array [], - "callee": Object { + "expression": Object { "arguments": Array [], "callee": Object { + "arguments": Array [], + "callee": Object { + "loc": Object { + "end": Object { + "column": 6, + "line": 10, + }, + "start": Object { + "column": 3, + "line": 10, + }, + }, + "name": "one", + "range": Array [ + 184, + 187, + ], + "type": "Identifier", + }, "loc": Object { "end": Object { - "column": 6, + "column": 10, "line": 10, }, "start": Object { @@ -827,29 +964,29 @@ Object { "line": 10, }, }, - "name": "one", + "optional": true, "range": Array [ 184, - 187, + 191, ], - "type": "Identifier", + "type": "CallExpression", }, "loc": Object { "end": Object { - "column": 10, + "column": 15, "line": 10, }, "start": Object { - "column": 3, + "column": 2, "line": 10, }, }, "optional": true, "range": Array [ - 184, - 191, + 183, + 196, ], - "type": "OptionalCallExpression", + "type": "CallExpression", }, "loc": Object { "end": Object { @@ -861,12 +998,11 @@ Object { "line": 10, }, }, - "optional": true, "range": Array [ 183, 196, ], - "type": "OptionalCallExpression", + "type": "ChainExpression", }, "loc": Object { "end": Object { @@ -898,11 +1034,29 @@ Object { }, }, "object": Object { - "arguments": Array [], - "callee": Object { + "expression": Object { + "arguments": Array [], + "callee": Object { + "loc": Object { + "end": Object { + "column": 6, + "line": 12, + }, + "start": Object { + "column": 3, + "line": 12, + }, + }, + "name": "one", + "range": Array [ + 202, + 205, + ], + "type": "Identifier", + }, "loc": Object { "end": Object { - "column": 6, + "column": 10, "line": 12, }, "start": Object { @@ -910,12 +1064,12 @@ Object { "line": 12, }, }, - "name": "one", + "optional": true, "range": Array [ 202, - 205, + 209, ], - "type": "Identifier", + "type": "CallExpression", }, "loc": Object { "end": Object { @@ -927,12 +1081,11 @@ Object { "line": 12, }, }, - "optional": true, "range": Array [ 202, 209, ], - "type": "OptionalCallExpression", + "type": "ChainExpression", }, "optional": false, "property": Object { diff --git a/packages/typescript-estree/tests/snapshots/typescript/basics/optional-chain-call.src.ts.shot b/packages/typescript-estree/tests/snapshots/typescript/basics/optional-chain-call.src.ts.shot index 4ea5344fee6..a1bc055e666 100644 --- a/packages/typescript-estree/tests/snapshots/typescript/basics/optional-chain-call.src.ts.shot +++ b/packages/typescript-estree/tests/snapshots/typescript/basics/optional-chain-call.src.ts.shot @@ -9,23 +9,13 @@ Object { "body": Array [ Object { "expression": Object { - "arguments": Array [], - "callee": Object { - "computed": false, - "loc": Object { - "end": Object { - "column": 9, - "line": 2, - }, - "start": Object { - "column": 2, - "line": 2, - }, - }, - "object": Object { + "expression": Object { + "arguments": Array [], + "callee": Object { + "computed": false, "loc": Object { "end": Object { - "column": 5, + "column": 9, "line": 2, }, "start": Object { @@ -33,37 +23,65 @@ Object { "line": 2, }, }, - "name": "one", - "range": Array [ - 44, - 47, - ], - "type": "Identifier", - }, - "optional": true, - "property": Object { - "loc": Object { - "end": Object { - "column": 9, - "line": 2, + "object": Object { + "loc": Object { + "end": Object { + "column": 5, + "line": 2, + }, + "start": Object { + "column": 2, + "line": 2, + }, }, - "start": Object { - "column": 7, - "line": 2, + "name": "one", + "range": Array [ + 44, + 47, + ], + "type": "Identifier", + }, + "optional": true, + "property": Object { + "loc": Object { + "end": Object { + "column": 9, + "line": 2, + }, + "start": Object { + "column": 7, + "line": 2, + }, }, + "name": "fn", + "range": Array [ + 49, + 51, + ], + "type": "Identifier", }, - "name": "fn", "range": Array [ - 49, + 44, 51, ], - "type": "Identifier", + "type": "MemberExpression", + }, + "loc": Object { + "end": Object { + "column": 11, + "line": 2, + }, + "start": Object { + "column": 2, + "line": 2, + }, }, + "optional": false, "range": Array [ 44, - 51, + 53, ], - "type": "OptionalMemberExpression", + "type": "CallExpression", }, "loc": Object { "end": Object { @@ -75,12 +93,11 @@ Object { "line": 2, }, }, - "optional": false, "range": Array [ 44, 53, ], - "type": "OptionalCallExpression", + "type": "ChainExpression", }, "loc": Object { "end": Object { @@ -100,24 +117,13 @@ Object { }, Object { "expression": Object { - "arguments": Array [], - "callee": Object { - "computed": false, - "loc": Object { - "end": Object { - "column": 13, - "line": 3, - }, - "start": Object { - "column": 2, - "line": 3, - }, - }, - "object": Object { + "expression": Object { + "arguments": Array [], + "callee": Object { "computed": false, "loc": Object { "end": Object { - "column": 10, + "column": 13, "line": 3, }, "start": Object { @@ -126,9 +132,10 @@ Object { }, }, "object": Object { + "computed": false, "loc": Object { "end": Object { - "column": 5, + "column": 10, "line": 3, }, "start": Object { @@ -136,62 +143,90 @@ Object { "line": 3, }, }, - "name": "one", + "object": Object { + "loc": Object { + "end": Object { + "column": 5, + "line": 3, + }, + "start": Object { + "column": 2, + "line": 3, + }, + }, + "name": "one", + "range": Array [ + 57, + 60, + ], + "type": "Identifier", + }, + "optional": true, + "property": Object { + "loc": Object { + "end": Object { + "column": 10, + "line": 3, + }, + "start": Object { + "column": 7, + "line": 3, + }, + }, + "name": "two", + "range": Array [ + 62, + 65, + ], + "type": "Identifier", + }, "range": Array [ 57, - 60, + 65, ], - "type": "Identifier", + "type": "MemberExpression", }, - "optional": true, + "optional": false, "property": Object { "loc": Object { "end": Object { - "column": 10, + "column": 13, "line": 3, }, "start": Object { - "column": 7, + "column": 11, "line": 3, }, }, - "name": "two", + "name": "fn", "range": Array [ - 62, - 65, + 66, + 68, ], "type": "Identifier", }, "range": Array [ 57, - 65, + 68, ], - "type": "OptionalMemberExpression", + "type": "MemberExpression", }, - "optional": false, - "property": Object { - "loc": Object { - "end": Object { - "column": 13, - "line": 3, - }, - "start": Object { - "column": 11, - "line": 3, - }, + "loc": Object { + "end": Object { + "column": 15, + "line": 3, + }, + "start": Object { + "column": 2, + "line": 3, }, - "name": "fn", - "range": Array [ - 66, - 68, - ], - "type": "Identifier", }, + "optional": false, "range": Array [ 57, - 68, + 70, ], - "type": "OptionalMemberExpression", + "type": "CallExpression", }, "loc": Object { "end": Object { @@ -203,12 +238,11 @@ Object { "line": 3, }, }, - "optional": false, "range": Array [ 57, 70, ], - "type": "OptionalCallExpression", + "type": "ChainExpression", }, "loc": Object { "end": Object { @@ -228,24 +262,13 @@ Object { }, Object { "expression": Object { - "arguments": Array [], - "callee": Object { - "computed": false, - "loc": Object { - "end": Object { - "column": 13, - "line": 4, - }, - "start": Object { - "column": 2, - "line": 4, - }, - }, - "object": Object { + "expression": Object { + "arguments": Array [], + "callee": Object { "computed": false, "loc": Object { "end": Object { - "column": 9, + "column": 13, "line": 4, }, "start": Object { @@ -254,9 +277,10 @@ Object { }, }, "object": Object { + "computed": false, "loc": Object { "end": Object { - "column": 5, + "column": 9, "line": 4, }, "start": Object { @@ -264,62 +288,90 @@ Object { "line": 4, }, }, - "name": "one", + "object": Object { + "loc": Object { + "end": Object { + "column": 5, + "line": 4, + }, + "start": Object { + "column": 2, + "line": 4, + }, + }, + "name": "one", + "range": Array [ + 74, + 77, + ], + "type": "Identifier", + }, + "optional": false, + "property": Object { + "loc": Object { + "end": Object { + "column": 9, + "line": 4, + }, + "start": Object { + "column": 6, + "line": 4, + }, + }, + "name": "two", + "range": Array [ + 78, + 81, + ], + "type": "Identifier", + }, "range": Array [ 74, - 77, + 81, ], - "type": "Identifier", + "type": "MemberExpression", }, - "optional": false, + "optional": true, "property": Object { "loc": Object { "end": Object { - "column": 9, + "column": 13, "line": 4, }, "start": Object { - "column": 6, + "column": 11, "line": 4, }, }, - "name": "two", + "name": "fn", "range": Array [ - 78, - 81, + 83, + 85, ], "type": "Identifier", }, "range": Array [ 74, - 81, + 85, ], "type": "MemberExpression", }, - "optional": true, - "property": Object { - "loc": Object { - "end": Object { - "column": 13, - "line": 4, - }, - "start": Object { - "column": 11, - "line": 4, - }, + "loc": Object { + "end": Object { + "column": 15, + "line": 4, + }, + "start": Object { + "column": 2, + "line": 4, }, - "name": "fn", - "range": Array [ - 83, - 85, - ], - "type": "Identifier", }, + "optional": false, "range": Array [ 74, - 85, + 87, ], - "type": "OptionalMemberExpression", + "type": "CallExpression", }, "loc": Object { "end": Object { @@ -331,12 +383,11 @@ Object { "line": 4, }, }, - "optional": false, "range": Array [ 74, 87, ], - "type": "OptionalCallExpression", + "type": "ChainExpression", }, "loc": Object { "end": Object { @@ -356,24 +407,13 @@ Object { }, Object { "expression": Object { - "arguments": Array [], - "callee": Object { - "computed": false, - "loc": Object { - "end": Object { - "column": 19, - "line": 5, - }, - "start": Object { - "column": 2, - "line": 5, - }, - }, - "object": Object { + "expression": Object { + "arguments": Array [], + "callee": Object { "computed": false, "loc": Object { "end": Object { - "column": 16, + "column": 19, "line": 5, }, "start": Object { @@ -385,7 +425,7 @@ Object { "computed": false, "loc": Object { "end": Object { - "column": 9, + "column": 16, "line": 5, }, "start": Object { @@ -394,9 +434,10 @@ Object { }, }, "object": Object { + "computed": false, "loc": Object { "end": Object { - "column": 5, + "column": 9, "line": 5, }, "start": Object { @@ -404,87 +445,115 @@ Object { "line": 5, }, }, - "name": "one", + "object": Object { + "loc": Object { + "end": Object { + "column": 5, + "line": 5, + }, + "start": Object { + "column": 2, + "line": 5, + }, + }, + "name": "one", + "range": Array [ + 91, + 94, + ], + "type": "Identifier", + }, + "optional": false, + "property": Object { + "loc": Object { + "end": Object { + "column": 9, + "line": 5, + }, + "start": Object { + "column": 6, + "line": 5, + }, + }, + "name": "two", + "range": Array [ + 95, + 98, + ], + "type": "Identifier", + }, "range": Array [ 91, - 94, + 98, ], - "type": "Identifier", + "type": "MemberExpression", }, - "optional": false, + "optional": true, "property": Object { "loc": Object { "end": Object { - "column": 9, + "column": 16, "line": 5, }, "start": Object { - "column": 6, + "column": 11, "line": 5, }, }, - "name": "two", + "name": "three", "range": Array [ - 95, - 98, + 100, + 105, ], "type": "Identifier", }, "range": Array [ 91, - 98, + 105, ], "type": "MemberExpression", }, - "optional": true, + "optional": false, "property": Object { "loc": Object { "end": Object { - "column": 16, + "column": 19, "line": 5, }, "start": Object { - "column": 11, + "column": 17, "line": 5, }, }, - "name": "three", + "name": "fn", "range": Array [ - 100, - 105, + 106, + 108, ], "type": "Identifier", }, "range": Array [ 91, - 105, + 108, ], - "type": "OptionalMemberExpression", + "type": "MemberExpression", }, - "optional": false, - "property": Object { - "loc": Object { - "end": Object { - "column": 19, - "line": 5, - }, - "start": Object { - "column": 17, - "line": 5, - }, + "loc": Object { + "end": Object { + "column": 21, + "line": 5, + }, + "start": Object { + "column": 2, + "line": 5, }, - "name": "fn", - "range": Array [ - 106, - 108, - ], - "type": "Identifier", }, + "optional": false, "range": Array [ 91, - 108, + 110, ], - "type": "OptionalMemberExpression", + "type": "CallExpression", }, "loc": Object { "end": Object { @@ -496,12 +565,11 @@ Object { "line": 5, }, }, - "optional": false, "range": Array [ 91, 110, ], - "type": "OptionalCallExpression", + "type": "ChainExpression", }, "loc": Object { "end": Object { @@ -521,24 +589,13 @@ Object { }, Object { "expression": Object { - "arguments": Array [], - "callee": Object { - "computed": false, - "loc": Object { - "end": Object { - "column": 20, - "line": 6, - }, - "start": Object { - "column": 2, - "line": 6, - }, - }, - "object": Object { + "expression": Object { + "arguments": Array [], + "callee": Object { "computed": false, "loc": Object { "end": Object { - "column": 16, + "column": 20, "line": 6, }, "start": Object { @@ -550,7 +607,7 @@ Object { "computed": false, "loc": Object { "end": Object { - "column": 9, + "column": 16, "line": 6, }, "start": Object { @@ -559,9 +616,10 @@ Object { }, }, "object": Object { + "computed": false, "loc": Object { "end": Object { - "column": 5, + "column": 9, "line": 6, }, "start": Object { @@ -569,35 +627,71 @@ Object { "line": 6, }, }, - "name": "one", + "object": Object { + "loc": Object { + "end": Object { + "column": 5, + "line": 6, + }, + "start": Object { + "column": 2, + "line": 6, + }, + }, + "name": "one", + "range": Array [ + 114, + 117, + ], + "type": "Identifier", + }, + "optional": false, + "property": Object { + "loc": Object { + "end": Object { + "column": 9, + "line": 6, + }, + "start": Object { + "column": 6, + "line": 6, + }, + }, + "name": "two", + "range": Array [ + 118, + 121, + ], + "type": "Identifier", + }, "range": Array [ 114, - 117, + 121, ], - "type": "Identifier", + "type": "MemberExpression", }, - "optional": false, + "optional": true, "property": Object { "loc": Object { "end": Object { - "column": 9, + "column": 16, "line": 6, }, "start": Object { - "column": 6, + "column": 11, "line": 6, }, }, - "name": "two", + "name": "three", "range": Array [ - 118, - 121, + 123, + 128, ], "type": "Identifier", }, "range": Array [ 114, - 121, + 128, ], "type": "MemberExpression", }, @@ -605,51 +699,43 @@ Object { "property": Object { "loc": Object { "end": Object { - "column": 16, + "column": 20, "line": 6, }, "start": Object { - "column": 11, + "column": 18, "line": 6, }, }, - "name": "three", + "name": "fn", "range": Array [ - 123, - 128, + 130, + 132, ], "type": "Identifier", }, "range": Array [ 114, - 128, + 132, ], - "type": "OptionalMemberExpression", + "type": "MemberExpression", }, - "optional": true, - "property": Object { - "loc": Object { - "end": Object { - "column": 20, - "line": 6, - }, - "start": Object { - "column": 18, - "line": 6, - }, + "loc": Object { + "end": Object { + "column": 22, + "line": 6, + }, + "start": Object { + "column": 2, + "line": 6, }, - "name": "fn", - "range": Array [ - 130, - 132, - ], - "type": "Identifier", }, + "optional": false, "range": Array [ 114, - 132, + 134, ], - "type": "OptionalMemberExpression", + "type": "CallExpression", }, "loc": Object { "end": Object { @@ -661,12 +747,11 @@ Object { "line": 6, }, }, - "optional": false, "range": Array [ 114, 134, ], - "type": "OptionalCallExpression", + "type": "ChainExpression", }, "loc": Object { "end": Object { @@ -686,11 +771,29 @@ Object { }, Object { "expression": Object { - "arguments": Array [], - "callee": Object { + "expression": Object { + "arguments": Array [], + "callee": Object { + "loc": Object { + "end": Object { + "column": 5, + "line": 8, + }, + "start": Object { + "column": 2, + "line": 8, + }, + }, + "name": "one", + "range": Array [ + 139, + 142, + ], + "type": "Identifier", + }, "loc": Object { "end": Object { - "column": 5, + "column": 9, "line": 8, }, "start": Object { @@ -698,12 +801,12 @@ Object { "line": 8, }, }, - "name": "one", + "optional": true, "range": Array [ 139, - 142, + 146, ], - "type": "Identifier", + "type": "CallExpression", }, "loc": Object { "end": Object { @@ -715,12 +818,11 @@ Object { "line": 8, }, }, - "optional": true, "range": Array [ 139, 146, ], - "type": "OptionalCallExpression", + "type": "ChainExpression", }, "loc": Object { "end": Object { @@ -740,13 +842,31 @@ Object { }, Object { "expression": Object { - "arguments": Array [], - "callee": Object { + "expression": Object { "arguments": Array [], "callee": Object { + "arguments": Array [], + "callee": Object { + "loc": Object { + "end": Object { + "column": 5, + "line": 9, + }, + "start": Object { + "column": 2, + "line": 9, + }, + }, + "name": "one", + "range": Array [ + 150, + 153, + ], + "type": "Identifier", + }, "loc": Object { "end": Object { - "column": 5, + "column": 9, "line": 9, }, "start": Object { @@ -754,16 +874,16 @@ Object { "line": 9, }, }, - "name": "one", + "optional": true, "range": Array [ 150, - 153, + 157, ], - "type": "Identifier", + "type": "CallExpression", }, "loc": Object { "end": Object { - "column": 9, + "column": 11, "line": 9, }, "start": Object { @@ -771,12 +891,12 @@ Object { "line": 9, }, }, - "optional": true, + "optional": false, "range": Array [ 150, - 157, + 159, ], - "type": "OptionalCallExpression", + "type": "CallExpression", }, "loc": Object { "end": Object { @@ -788,12 +908,11 @@ Object { "line": 9, }, }, - "optional": false, "range": Array [ 150, 159, ], - "type": "OptionalCallExpression", + "type": "ChainExpression", }, "loc": Object { "end": Object { @@ -813,13 +932,31 @@ Object { }, Object { "expression": Object { - "arguments": Array [], - "callee": Object { + "expression": Object { "arguments": Array [], "callee": Object { + "arguments": Array [], + "callee": Object { + "loc": Object { + "end": Object { + "column": 5, + "line": 10, + }, + "start": Object { + "column": 2, + "line": 10, + }, + }, + "name": "one", + "range": Array [ + 163, + 166, + ], + "type": "Identifier", + }, "loc": Object { "end": Object { - "column": 5, + "column": 9, "line": 10, }, "start": Object { @@ -827,16 +964,16 @@ Object { "line": 10, }, }, - "name": "one", + "optional": true, "range": Array [ 163, - 166, + 170, ], - "type": "Identifier", + "type": "CallExpression", }, "loc": Object { "end": Object { - "column": 9, + "column": 13, "line": 10, }, "start": Object { @@ -847,9 +984,9 @@ Object { "optional": true, "range": Array [ 163, - 170, + 174, ], - "type": "OptionalCallExpression", + "type": "CallExpression", }, "loc": Object { "end": Object { @@ -861,12 +998,11 @@ Object { "line": 10, }, }, - "optional": true, "range": Array [ 163, 174, ], - "type": "OptionalCallExpression", + "type": "ChainExpression", }, "loc": Object { "end": Object { @@ -886,23 +1022,41 @@ Object { }, Object { "expression": Object { - "computed": false, - "loc": Object { - "end": Object { - "column": 13, - "line": 12, - }, - "start": Object { - "column": 2, - "line": 12, + "expression": Object { + "computed": false, + "loc": Object { + "end": Object { + "column": 13, + "line": 12, + }, + "start": Object { + "column": 2, + "line": 12, + }, }, - }, - "object": Object { - "arguments": Array [], - "callee": Object { + "object": Object { + "arguments": Array [], + "callee": Object { + "loc": Object { + "end": Object { + "column": 5, + "line": 12, + }, + "start": Object { + "column": 2, + "line": 12, + }, + }, + "name": "one", + "range": Array [ + 179, + 182, + ], + "type": "Identifier", + }, "loc": Object { "end": Object { - "column": 5, + "column": 9, "line": 12, }, "start": Object { @@ -910,54 +1064,53 @@ Object { "line": 12, }, }, - "name": "one", + "optional": true, "range": Array [ 179, - 182, + 186, ], - "type": "Identifier", + "type": "CallExpression", }, - "loc": Object { - "end": Object { - "column": 9, - "line": 12, - }, - "start": Object { - "column": 2, - "line": 12, + "optional": false, + "property": Object { + "loc": Object { + "end": Object { + "column": 13, + "line": 12, + }, + "start": Object { + "column": 10, + "line": 12, + }, }, + "name": "two", + "range": Array [ + 187, + 190, + ], + "type": "Identifier", }, - "optional": true, "range": Array [ 179, - 186, + 190, ], - "type": "OptionalCallExpression", + "type": "MemberExpression", }, - "optional": false, - "property": Object { - "loc": Object { - "end": Object { - "column": 13, - "line": 12, - }, - "start": Object { - "column": 10, - "line": 12, - }, + "loc": Object { + "end": Object { + "column": 13, + "line": 12, + }, + "start": Object { + "column": 2, + "line": 12, }, - "name": "two", - "range": Array [ - 187, - 190, - ], - "type": "Identifier", }, "range": Array [ 179, 190, ], - "type": "OptionalMemberExpression", + "type": "ChainExpression", }, "loc": Object { "end": Object { diff --git a/packages/typescript-estree/tests/snapshots/typescript/basics/optional-chain-element-access-with-non-null-assertion.src.ts.shot b/packages/typescript-estree/tests/snapshots/typescript/basics/optional-chain-element-access-with-non-null-assertion.src.ts.shot index 689e6022960..bcbac3030b1 100644 --- a/packages/typescript-estree/tests/snapshots/typescript/basics/optional-chain-element-access-with-non-null-assertion.src.ts.shot +++ b/packages/typescript-estree/tests/snapshots/typescript/basics/optional-chain-element-access-with-non-null-assertion.src.ts.shot @@ -9,34 +9,79 @@ Object { "body": Array [ Object { "expression": Object { - "computed": false, - "loc": Object { - "end": Object { - "column": 21, - "line": 2, - }, - "start": Object { - "column": 2, - "line": 2, + "expression": Object { + "computed": false, + "loc": Object { + "end": Object { + "column": 21, + "line": 2, + }, + "start": Object { + "column": 2, + "line": 2, + }, }, - }, - "object": Object { - "expression": Object { - "computed": true, - "loc": Object { - "end": Object { - "column": 14, - "line": 2, - }, - "start": Object { - "column": 2, - "line": 2, + "object": Object { + "expression": Object { + "expression": Object { + "computed": true, + "loc": Object { + "end": Object { + "column": 14, + "line": 2, + }, + "start": Object { + "column": 2, + "line": 2, + }, + }, + "object": Object { + "loc": Object { + "end": Object { + "column": 5, + "line": 2, + }, + "start": Object { + "column": 2, + "line": 2, + }, + }, + "name": "one", + "range": Array [ + 40, + 43, + ], + "type": "Identifier", + }, + "optional": true, + "property": Object { + "loc": Object { + "end": Object { + "column": 13, + "line": 2, + }, + "start": Object { + "column": 8, + "line": 2, + }, + }, + "range": Array [ + 46, + 51, + ], + "raw": "'two'", + "type": "Literal", + "value": "two", + }, + "range": Array [ + 40, + 52, + ], + "type": "MemberExpression", }, - }, - "object": Object { "loc": Object { "end": Object { - "column": 5, + "column": 14, "line": 2, }, "start": Object { @@ -44,79 +89,68 @@ Object { "line": 2, }, }, - "name": "one", "range": Array [ 40, - 43, + 52, ], - "type": "Identifier", + "type": "ChainExpression", }, - "optional": true, - "property": Object { - "loc": Object { - "end": Object { - "column": 13, - "line": 2, - }, - "start": Object { - "column": 8, - "line": 2, - }, + "loc": Object { + "end": Object { + "column": 15, + "line": 2, + }, + "start": Object { + "column": 2, + "line": 2, }, - "range": Array [ - 46, - 51, - ], - "raw": "'two'", - "type": "Literal", - "value": "two", }, "range": Array [ 40, - 52, + 53, ], - "type": "OptionalMemberExpression", + "type": "TSNonNullExpression", }, - "loc": Object { - "end": Object { - "column": 15, - "line": 2, - }, - "start": Object { - "column": 2, - "line": 2, + "optional": false, + "property": Object { + "loc": Object { + "end": Object { + "column": 21, + "line": 2, + }, + "start": Object { + "column": 16, + "line": 2, + }, }, + "name": "three", + "range": Array [ + 54, + 59, + ], + "type": "Identifier", }, "range": Array [ 40, - 53, + 59, ], - "type": "TSNonNullExpression", + "type": "MemberExpression", }, - "optional": false, - "property": Object { - "loc": Object { - "end": Object { - "column": 21, - "line": 2, - }, - "start": Object { - "column": 16, - "line": 2, - }, + "loc": Object { + "end": Object { + "column": 21, + "line": 2, + }, + "start": Object { + "column": 2, + "line": 2, }, - "name": "three", - "range": Array [ - 54, - 59, - ], - "type": "Identifier", }, "range": Array [ 40, 59, ], - "type": "OptionalMemberExpression", + "type": "ChainExpression", }, "loc": Object { "end": Object { @@ -149,21 +183,11 @@ Object { }, "object": Object { "expression": Object { - "computed": true, - "loc": Object { - "end": Object { - "column": 15, - "line": 3, - }, - "start": Object { - "column": 3, - "line": 3, - }, - }, - "object": Object { + "expression": Object { + "computed": true, "loc": Object { "end": Object { - "column": 6, + "column": 15, "line": 3, }, "start": Object { @@ -171,38 +195,65 @@ Object { "line": 3, }, }, - "name": "one", - "range": Array [ - 64, - 67, - ], - "type": "Identifier", - }, - "optional": true, - "property": Object { - "loc": Object { - "end": Object { - "column": 14, - "line": 3, + "object": Object { + "loc": Object { + "end": Object { + "column": 6, + "line": 3, + }, + "start": Object { + "column": 3, + "line": 3, + }, }, - "start": Object { - "column": 9, - "line": 3, + "name": "one", + "range": Array [ + 64, + 67, + ], + "type": "Identifier", + }, + "optional": true, + "property": Object { + "loc": Object { + "end": Object { + "column": 14, + "line": 3, + }, + "start": Object { + "column": 9, + "line": 3, + }, }, + "range": Array [ + 70, + 75, + ], + "raw": "'two'", + "type": "Literal", + "value": "two", }, "range": Array [ - 70, - 75, + 64, + 76, ], - "raw": "'two'", - "type": "Literal", - "value": "two", + "type": "MemberExpression", + }, + "loc": Object { + "end": Object { + "column": 15, + "line": 3, + }, + "start": Object { + "column": 3, + "line": 3, + }, }, "range": Array [ 64, 76, ], - "type": "OptionalMemberExpression", + "type": "ChainExpression", }, "loc": Object { "end": Object { @@ -276,21 +327,11 @@ Object { }, "object": Object { "expression": Object { - "computed": true, - "loc": Object { - "end": Object { - "column": 15, - "line": 4, - }, - "start": Object { - "column": 3, - "line": 4, - }, - }, - "object": Object { + "expression": Object { + "computed": true, "loc": Object { "end": Object { - "column": 6, + "column": 15, "line": 4, }, "start": Object { @@ -298,38 +339,65 @@ Object { "line": 4, }, }, - "name": "one", - "range": Array [ - 89, - 92, - ], - "type": "Identifier", - }, - "optional": true, - "property": Object { - "loc": Object { - "end": Object { - "column": 14, - "line": 4, + "object": Object { + "loc": Object { + "end": Object { + "column": 6, + "line": 4, + }, + "start": Object { + "column": 3, + "line": 4, + }, }, - "start": Object { - "column": 9, - "line": 4, + "name": "one", + "range": Array [ + 89, + 92, + ], + "type": "Identifier", + }, + "optional": true, + "property": Object { + "loc": Object { + "end": Object { + "column": 14, + "line": 4, + }, + "start": Object { + "column": 9, + "line": 4, + }, }, + "range": Array [ + 95, + 100, + ], + "raw": "'two'", + "type": "Literal", + "value": "two", }, "range": Array [ - 95, - 100, + 89, + 101, ], - "raw": "'two'", - "type": "Literal", - "value": "two", + "type": "MemberExpression", + }, + "loc": Object { + "end": Object { + "column": 15, + "line": 4, + }, + "start": Object { + "column": 3, + "line": 4, + }, }, "range": Array [ 89, 101, ], - "type": "OptionalMemberExpression", + "type": "ChainExpression", }, "loc": Object { "end": Object { @@ -390,114 +458,148 @@ Object { }, Object { "expression": Object { - "computed": true, - "loc": Object { - "end": Object { - "column": 20, - "line": 5, - }, - "start": Object { - "column": 2, - "line": 5, - }, - }, - "object": Object { - "expression": Object { - "computed": false, - "loc": Object { - "end": Object { - "column": 10, - "line": 5, - }, - "start": Object { - "column": 2, - "line": 5, - }, + "expression": Object { + "computed": true, + "loc": Object { + "end": Object { + "column": 20, + "line": 5, }, - "object": Object { - "loc": Object { - "end": Object { - "column": 5, - "line": 5, + "start": Object { + "column": 2, + "line": 5, + }, + }, + "object": Object { + "expression": Object { + "expression": Object { + "computed": false, + "loc": Object { + "end": Object { + "column": 10, + "line": 5, + }, + "start": Object { + "column": 2, + "line": 5, + }, }, - "start": Object { - "column": 2, - "line": 5, + "object": Object { + "loc": Object { + "end": Object { + "column": 5, + "line": 5, + }, + "start": Object { + "column": 2, + "line": 5, + }, + }, + "name": "one", + "range": Array [ + 113, + 116, + ], + "type": "Identifier", + }, + "optional": true, + "property": Object { + "loc": Object { + "end": Object { + "column": 10, + "line": 5, + }, + "start": Object { + "column": 7, + "line": 5, + }, + }, + "name": "two", + "range": Array [ + 118, + 121, + ], + "type": "Identifier", }, + "range": Array [ + 113, + 121, + ], + "type": "MemberExpression", }, - "name": "one", - "range": Array [ - 113, - 116, - ], - "type": "Identifier", - }, - "optional": true, - "property": Object { "loc": Object { "end": Object { "column": 10, "line": 5, }, "start": Object { - "column": 7, + "column": 2, "line": 5, }, }, - "name": "two", "range": Array [ - 118, + 113, 121, ], - "type": "Identifier", + "type": "ChainExpression", + }, + "loc": Object { + "end": Object { + "column": 11, + "line": 5, + }, + "start": Object { + "column": 2, + "line": 5, + }, }, "range": Array [ 113, - 121, + 122, ], - "type": "OptionalMemberExpression", + "type": "TSNonNullExpression", }, - "loc": Object { - "end": Object { - "column": 11, - "line": 5, - }, - "start": Object { - "column": 2, - "line": 5, + "optional": false, + "property": Object { + "loc": Object { + "end": Object { + "column": 19, + "line": 5, + }, + "start": Object { + "column": 12, + "line": 5, + }, }, + "range": Array [ + 123, + 130, + ], + "raw": "'three'", + "type": "Literal", + "value": "three", }, "range": Array [ 113, - 122, + 131, ], - "type": "TSNonNullExpression", + "type": "MemberExpression", }, - "optional": false, - "property": Object { - "loc": Object { - "end": Object { - "column": 19, - "line": 5, - }, - "start": Object { - "column": 12, - "line": 5, - }, + "loc": Object { + "end": Object { + "column": 20, + "line": 5, + }, + "start": Object { + "column": 2, + "line": 5, }, - "range": Array [ - 123, - 130, - ], - "raw": "'three'", - "type": "Literal", - "value": "three", }, "range": Array [ 113, 131, ], - "type": "OptionalMemberExpression", + "type": "ChainExpression", }, "loc": Object { "end": Object { @@ -530,21 +632,11 @@ Object { }, "object": Object { "expression": Object { - "computed": false, - "loc": Object { - "end": Object { - "column": 11, - "line": 6, - }, - "start": Object { - "column": 3, - "line": 6, - }, - }, - "object": Object { + "expression": Object { + "computed": false, "loc": Object { "end": Object { - "column": 6, + "column": 11, "line": 6, }, "start": Object { @@ -552,37 +644,64 @@ Object { "line": 6, }, }, - "name": "one", - "range": Array [ - 136, - 139, - ], - "type": "Identifier", - }, - "optional": true, - "property": Object { - "loc": Object { - "end": Object { - "column": 11, - "line": 6, + "object": Object { + "loc": Object { + "end": Object { + "column": 6, + "line": 6, + }, + "start": Object { + "column": 3, + "line": 6, + }, }, - "start": Object { - "column": 8, - "line": 6, + "name": "one", + "range": Array [ + 136, + 139, + ], + "type": "Identifier", + }, + "optional": true, + "property": Object { + "loc": Object { + "end": Object { + "column": 11, + "line": 6, + }, + "start": Object { + "column": 8, + "line": 6, + }, }, + "name": "two", + "range": Array [ + 141, + 144, + ], + "type": "Identifier", }, - "name": "two", "range": Array [ - 141, + 136, 144, ], - "type": "Identifier", + "type": "MemberExpression", + }, + "loc": Object { + "end": Object { + "column": 11, + "line": 6, + }, + "start": Object { + "column": 3, + "line": 6, + }, }, "range": Array [ 136, 144, ], - "type": "OptionalMemberExpression", + "type": "ChainExpression", }, "loc": Object { "end": Object { @@ -657,21 +776,11 @@ Object { }, "object": Object { "expression": Object { - "computed": false, - "loc": Object { - "end": Object { - "column": 11, - "line": 7, - }, - "start": Object { - "column": 3, - "line": 7, - }, - }, - "object": Object { + "expression": Object { + "computed": false, "loc": Object { "end": Object { - "column": 6, + "column": 11, "line": 7, }, "start": Object { @@ -679,37 +788,64 @@ Object { "line": 7, }, }, - "name": "one", - "range": Array [ - 160, - 163, - ], - "type": "Identifier", - }, - "optional": true, - "property": Object { - "loc": Object { - "end": Object { - "column": 11, - "line": 7, + "object": Object { + "loc": Object { + "end": Object { + "column": 6, + "line": 7, + }, + "start": Object { + "column": 3, + "line": 7, + }, }, - "start": Object { - "column": 8, - "line": 7, + "name": "one", + "range": Array [ + 160, + 163, + ], + "type": "Identifier", + }, + "optional": true, + "property": Object { + "loc": Object { + "end": Object { + "column": 11, + "line": 7, + }, + "start": Object { + "column": 8, + "line": 7, + }, }, + "name": "two", + "range": Array [ + 165, + 168, + ], + "type": "Identifier", }, - "name": "two", "range": Array [ - 165, + 160, 168, ], - "type": "Identifier", + "type": "MemberExpression", + }, + "loc": Object { + "end": Object { + "column": 11, + "line": 7, + }, + "start": Object { + "column": 3, + "line": 7, + }, }, "range": Array [ 160, 168, ], - "type": "OptionalMemberExpression", + "type": "ChainExpression", }, "loc": Object { "end": Object { diff --git a/packages/typescript-estree/tests/snapshots/typescript/basics/optional-chain-element-access-with-parens.src.ts.shot b/packages/typescript-estree/tests/snapshots/typescript/basics/optional-chain-element-access-with-parens.src.ts.shot index 5f106bdedbc..bad9cf7b189 100644 --- a/packages/typescript-estree/tests/snapshots/typescript/basics/optional-chain-element-access-with-parens.src.ts.shot +++ b/packages/typescript-estree/tests/snapshots/typescript/basics/optional-chain-element-access-with-parens.src.ts.shot @@ -9,21 +9,11 @@ Object { "body": Array [ Object { "expression": Object { - "computed": true, - "loc": Object { - "end": Object { - "column": 11, - "line": 2, - }, - "start": Object { - "column": 3, - "line": 2, - }, - }, - "object": Object { + "expression": Object { + "computed": true, "loc": Object { "end": Object { - "column": 6, + "column": 11, "line": 2, }, "start": Object { @@ -31,38 +21,65 @@ Object { "line": 2, }, }, - "name": "one", - "range": Array [ - 54, - 57, - ], - "type": "Identifier", - }, - "optional": true, - "property": Object { - "loc": Object { - "end": Object { - "column": 10, - "line": 2, + "object": Object { + "loc": Object { + "end": Object { + "column": 6, + "line": 2, + }, + "start": Object { + "column": 3, + "line": 2, + }, }, - "start": Object { - "column": 9, - "line": 2, + "name": "one", + "range": Array [ + 54, + 57, + ], + "type": "Identifier", + }, + "optional": true, + "property": Object { + "loc": Object { + "end": Object { + "column": 10, + "line": 2, + }, + "start": Object { + "column": 9, + "line": 2, + }, }, + "range": Array [ + 60, + 61, + ], + "raw": "2", + "type": "Literal", + "value": 2, }, "range": Array [ - 60, - 61, + 54, + 62, ], - "raw": "2", - "type": "Literal", - "value": 2, + "type": "MemberExpression", + }, + "loc": Object { + "end": Object { + "column": 11, + "line": 2, + }, + "start": Object { + "column": 3, + "line": 2, + }, }, "range": Array [ 54, 62, ], - "type": "OptionalMemberExpression", + "type": "ChainExpression", }, "loc": Object { "end": Object { @@ -94,21 +111,11 @@ Object { }, }, "object": Object { - "computed": true, - "loc": Object { - "end": Object { - "column": 11, - "line": 3, - }, - "start": Object { - "column": 3, - "line": 3, - }, - }, - "object": Object { + "expression": Object { + "computed": true, "loc": Object { "end": Object { - "column": 6, + "column": 11, "line": 3, }, "start": Object { @@ -116,38 +123,65 @@ Object { "line": 3, }, }, - "name": "one", - "range": Array [ - 68, - 71, - ], - "type": "Identifier", - }, - "optional": true, - "property": Object { - "loc": Object { - "end": Object { - "column": 10, - "line": 3, + "object": Object { + "loc": Object { + "end": Object { + "column": 6, + "line": 3, + }, + "start": Object { + "column": 3, + "line": 3, + }, }, - "start": Object { - "column": 9, - "line": 3, + "name": "one", + "range": Array [ + 68, + 71, + ], + "type": "Identifier", + }, + "optional": true, + "property": Object { + "loc": Object { + "end": Object { + "column": 10, + "line": 3, + }, + "start": Object { + "column": 9, + "line": 3, + }, }, + "range": Array [ + 74, + 75, + ], + "raw": "2", + "type": "Literal", + "value": 2, }, "range": Array [ - 74, - 75, + 68, + 76, ], - "raw": "2", - "type": "Literal", - "value": 2, + "type": "MemberExpression", + }, + "loc": Object { + "end": Object { + "column": 11, + "line": 3, + }, + "start": Object { + "column": 3, + "line": 3, + }, }, "range": Array [ 68, 76, ], - "type": "OptionalMemberExpression", + "type": "ChainExpression", }, "optional": false, "property": Object { @@ -193,22 +227,11 @@ Object { }, Object { "expression": Object { - "computed": true, - "loc": Object { - "end": Object { - "column": 14, - "line": 4, - }, - "start": Object { - "column": 3, - "line": 4, - }, - }, - "object": Object { + "expression": Object { "computed": true, "loc": Object { "end": Object { - "column": 9, + "column": 14, "line": 4, }, "start": Object { @@ -217,9 +240,10 @@ Object { }, }, "object": Object { + "computed": true, "loc": Object { "end": Object { - "column": 6, + "column": 9, "line": 4, }, "start": Object { @@ -227,64 +251,91 @@ Object { "line": 4, }, }, - "name": "one", + "object": Object { + "loc": Object { + "end": Object { + "column": 6, + "line": 4, + }, + "start": Object { + "column": 3, + "line": 4, + }, + }, + "name": "one", + "range": Array [ + 85, + 88, + ], + "type": "Identifier", + }, + "optional": false, + "property": Object { + "loc": Object { + "end": Object { + "column": 8, + "line": 4, + }, + "start": Object { + "column": 7, + "line": 4, + }, + }, + "range": Array [ + 89, + 90, + ], + "raw": "2", + "type": "Literal", + "value": 2, + }, "range": Array [ 85, - 88, + 91, ], - "type": "Identifier", + "type": "MemberExpression", }, - "optional": false, + "optional": true, "property": Object { "loc": Object { "end": Object { - "column": 8, + "column": 13, "line": 4, }, "start": Object { - "column": 7, + "column": 12, "line": 4, }, }, "range": Array [ - 89, - 90, + 94, + 95, ], - "raw": "2", + "raw": "3", "type": "Literal", - "value": 2, + "value": 3, }, "range": Array [ 85, - 91, + 96, ], "type": "MemberExpression", }, - "optional": true, - "property": Object { - "loc": Object { - "end": Object { - "column": 13, - "line": 4, - }, - "start": Object { - "column": 12, - "line": 4, - }, + "loc": Object { + "end": Object { + "column": 14, + "line": 4, + }, + "start": Object { + "column": 3, + "line": 4, }, - "range": Array [ - 94, - 95, - ], - "raw": "3", - "type": "Literal", - "value": 3, }, "range": Array [ 85, 96, ], - "type": "OptionalMemberExpression", + "type": "ChainExpression", }, "loc": Object { "end": Object { @@ -316,22 +367,11 @@ Object { }, }, "object": Object { - "computed": true, - "loc": Object { - "end": Object { - "column": 14, - "line": 5, - }, - "start": Object { - "column": 3, - "line": 5, - }, - }, - "object": Object { + "expression": Object { "computed": true, "loc": Object { "end": Object { - "column": 9, + "column": 14, "line": 5, }, "start": Object { @@ -340,9 +380,10 @@ Object { }, }, "object": Object { + "computed": true, "loc": Object { "end": Object { - "column": 6, + "column": 9, "line": 5, }, "start": Object { @@ -350,64 +391,91 @@ Object { "line": 5, }, }, - "name": "one", + "object": Object { + "loc": Object { + "end": Object { + "column": 6, + "line": 5, + }, + "start": Object { + "column": 3, + "line": 5, + }, + }, + "name": "one", + "range": Array [ + 102, + 105, + ], + "type": "Identifier", + }, + "optional": false, + "property": Object { + "loc": Object { + "end": Object { + "column": 8, + "line": 5, + }, + "start": Object { + "column": 7, + "line": 5, + }, + }, + "range": Array [ + 106, + 107, + ], + "raw": "2", + "type": "Literal", + "value": 2, + }, "range": Array [ 102, - 105, + 108, ], - "type": "Identifier", + "type": "MemberExpression", }, - "optional": false, + "optional": true, "property": Object { "loc": Object { "end": Object { - "column": 8, + "column": 13, "line": 5, }, "start": Object { - "column": 7, + "column": 12, "line": 5, }, }, "range": Array [ - 106, - 107, + 111, + 112, ], - "raw": "2", + "raw": "3", "type": "Literal", - "value": 2, + "value": 3, }, "range": Array [ 102, - 108, + 113, ], "type": "MemberExpression", }, - "optional": true, - "property": Object { - "loc": Object { - "end": Object { - "column": 13, - "line": 5, - }, - "start": Object { - "column": 12, - "line": 5, - }, + "loc": Object { + "end": Object { + "column": 14, + "line": 5, + }, + "start": Object { + "column": 3, + "line": 5, }, - "range": Array [ - 111, - 112, - ], - "raw": "3", - "type": "Literal", - "value": 3, }, "range": Array [ 102, 113, ], - "type": "OptionalMemberExpression", + "type": "ChainExpression", }, "optional": false, "property": Object { @@ -453,22 +521,11 @@ Object { }, Object { "expression": Object { - "computed": true, - "loc": Object { - "end": Object { - "column": 19, - "line": 6, - }, - "start": Object { - "column": 3, - "line": 6, - }, - }, - "object": Object { + "expression": Object { "computed": true, "loc": Object { "end": Object { - "column": 14, + "column": 19, "line": 6, }, "start": Object { @@ -480,7 +537,7 @@ Object { "computed": true, "loc": Object { "end": Object { - "column": 9, + "column": 14, "line": 6, }, "start": Object { @@ -489,9 +546,10 @@ Object { }, }, "object": Object { + "computed": true, "loc": Object { "end": Object { - "column": 6, + "column": 9, "line": 6, }, "start": Object { @@ -499,36 +557,73 @@ Object { "line": 6, }, }, - "name": "one", + "object": Object { + "loc": Object { + "end": Object { + "column": 6, + "line": 6, + }, + "start": Object { + "column": 3, + "line": 6, + }, + }, + "name": "one", + "range": Array [ + 122, + 125, + ], + "type": "Identifier", + }, + "optional": false, + "property": Object { + "loc": Object { + "end": Object { + "column": 8, + "line": 6, + }, + "start": Object { + "column": 7, + "line": 6, + }, + }, + "range": Array [ + 126, + 127, + ], + "raw": "2", + "type": "Literal", + "value": 2, + }, "range": Array [ 122, - 125, + 128, ], - "type": "Identifier", + "type": "MemberExpression", }, - "optional": false, + "optional": true, "property": Object { "loc": Object { "end": Object { - "column": 8, + "column": 13, "line": 6, }, "start": Object { - "column": 7, + "column": 12, "line": 6, }, }, "range": Array [ - 126, - 127, + 131, + 132, ], - "raw": "2", + "raw": "3", "type": "Literal", - "value": 2, + "value": 3, }, "range": Array [ 122, - 128, + 133, ], "type": "MemberExpression", }, @@ -536,53 +631,43 @@ Object { "property": Object { "loc": Object { "end": Object { - "column": 13, + "column": 18, "line": 6, }, "start": Object { - "column": 12, + "column": 17, "line": 6, }, }, "range": Array [ - 131, - 132, + 136, + 137, ], - "raw": "3", + "raw": "4", "type": "Literal", - "value": 3, + "value": 4, }, "range": Array [ 122, - 133, + 138, ], - "type": "OptionalMemberExpression", + "type": "MemberExpression", }, - "optional": true, - "property": Object { - "loc": Object { - "end": Object { - "column": 18, - "line": 6, - }, - "start": Object { - "column": 17, - "line": 6, - }, + "loc": Object { + "end": Object { + "column": 19, + "line": 6, + }, + "start": Object { + "column": 3, + "line": 6, }, - "range": Array [ - 136, - 137, - ], - "raw": "4", - "type": "Literal", - "value": 4, }, "range": Array [ 122, 138, ], - "type": "OptionalMemberExpression", + "type": "ChainExpression", }, "loc": Object { "end": Object { @@ -614,22 +699,11 @@ Object { }, }, "object": Object { - "computed": true, - "loc": Object { - "end": Object { - "column": 19, - "line": 7, - }, - "start": Object { - "column": 3, - "line": 7, - }, - }, - "object": Object { + "expression": Object { "computed": true, "loc": Object { "end": Object { - "column": 14, + "column": 19, "line": 7, }, "start": Object { @@ -641,7 +715,7 @@ Object { "computed": true, "loc": Object { "end": Object { - "column": 9, + "column": 14, "line": 7, }, "start": Object { @@ -650,9 +724,10 @@ Object { }, }, "object": Object { + "computed": true, "loc": Object { "end": Object { - "column": 6, + "column": 9, "line": 7, }, "start": Object { @@ -660,36 +735,73 @@ Object { "line": 7, }, }, - "name": "one", + "object": Object { + "loc": Object { + "end": Object { + "column": 6, + "line": 7, + }, + "start": Object { + "column": 3, + "line": 7, + }, + }, + "name": "one", + "range": Array [ + 144, + 147, + ], + "type": "Identifier", + }, + "optional": false, + "property": Object { + "loc": Object { + "end": Object { + "column": 8, + "line": 7, + }, + "start": Object { + "column": 7, + "line": 7, + }, + }, + "range": Array [ + 148, + 149, + ], + "raw": "2", + "type": "Literal", + "value": 2, + }, "range": Array [ 144, - 147, + 150, ], - "type": "Identifier", + "type": "MemberExpression", }, - "optional": false, + "optional": true, "property": Object { "loc": Object { "end": Object { - "column": 8, + "column": 13, "line": 7, }, "start": Object { - "column": 7, + "column": 12, "line": 7, }, }, "range": Array [ - 148, - 149, + 153, + 154, ], - "raw": "2", + "raw": "3", "type": "Literal", - "value": 2, + "value": 3, }, "range": Array [ 144, - 150, + 155, ], "type": "MemberExpression", }, @@ -697,53 +809,43 @@ Object { "property": Object { "loc": Object { "end": Object { - "column": 13, + "column": 18, "line": 7, }, "start": Object { - "column": 12, + "column": 17, "line": 7, }, }, "range": Array [ - 153, - 154, + 158, + 159, ], - "raw": "3", + "raw": "4", "type": "Literal", - "value": 3, + "value": 4, }, "range": Array [ 144, - 155, + 160, ], - "type": "OptionalMemberExpression", + "type": "MemberExpression", }, - "optional": true, - "property": Object { - "loc": Object { - "end": Object { - "column": 18, - "line": 7, - }, - "start": Object { - "column": 17, - "line": 7, - }, + "loc": Object { + "end": Object { + "column": 19, + "line": 7, + }, + "start": Object { + "column": 3, + "line": 7, }, - "range": Array [ - 158, - 159, - ], - "raw": "4", - "type": "Literal", - "value": 4, }, "range": Array [ 144, 160, ], - "type": "OptionalMemberExpression", + "type": "ChainExpression", }, "optional": false, "property": Object { diff --git a/packages/typescript-estree/tests/snapshots/typescript/basics/optional-chain-element-access.src.ts.shot b/packages/typescript-estree/tests/snapshots/typescript/basics/optional-chain-element-access.src.ts.shot index f26479a0cbc..f2854d51f62 100644 --- a/packages/typescript-estree/tests/snapshots/typescript/basics/optional-chain-element-access.src.ts.shot +++ b/packages/typescript-estree/tests/snapshots/typescript/basics/optional-chain-element-access.src.ts.shot @@ -9,21 +9,11 @@ Object { "body": Array [ Object { "expression": Object { - "computed": true, - "loc": Object { - "end": Object { - "column": 10, - "line": 2, - }, - "start": Object { - "column": 2, - "line": 2, - }, - }, - "object": Object { + "expression": Object { + "computed": true, "loc": Object { "end": Object { - "column": 5, + "column": 10, "line": 2, }, "start": Object { @@ -31,38 +21,65 @@ Object { "line": 2, }, }, - "name": "one", - "range": Array [ - 47, - 50, - ], - "type": "Identifier", - }, - "optional": true, - "property": Object { - "loc": Object { - "end": Object { - "column": 9, - "line": 2, + "object": Object { + "loc": Object { + "end": Object { + "column": 5, + "line": 2, + }, + "start": Object { + "column": 2, + "line": 2, + }, }, - "start": Object { - "column": 8, - "line": 2, + "name": "one", + "range": Array [ + 47, + 50, + ], + "type": "Identifier", + }, + "optional": true, + "property": Object { + "loc": Object { + "end": Object { + "column": 9, + "line": 2, + }, + "start": Object { + "column": 8, + "line": 2, + }, }, + "range": Array [ + 53, + 54, + ], + "raw": "2", + "type": "Literal", + "value": 2, }, "range": Array [ - 53, - 54, + 47, + 55, ], - "raw": "2", - "type": "Literal", - "value": 2, + "type": "MemberExpression", + }, + "loc": Object { + "end": Object { + "column": 10, + "line": 2, + }, + "start": Object { + "column": 2, + "line": 2, + }, }, "range": Array [ 47, 55, ], - "type": "OptionalMemberExpression", + "type": "ChainExpression", }, "loc": Object { "end": Object { @@ -82,22 +99,11 @@ Object { }, Object { "expression": Object { - "computed": true, - "loc": Object { - "end": Object { - "column": 13, - "line": 3, - }, - "start": Object { - "column": 2, - "line": 3, - }, - }, - "object": Object { + "expression": Object { "computed": true, "loc": Object { "end": Object { - "column": 10, + "column": 13, "line": 3, }, "start": Object { @@ -106,9 +112,10 @@ Object { }, }, "object": Object { + "computed": true, "loc": Object { "end": Object { - "column": 5, + "column": 10, "line": 3, }, "start": Object { @@ -116,64 +123,91 @@ Object { "line": 3, }, }, - "name": "one", + "object": Object { + "loc": Object { + "end": Object { + "column": 5, + "line": 3, + }, + "start": Object { + "column": 2, + "line": 3, + }, + }, + "name": "one", + "range": Array [ + 59, + 62, + ], + "type": "Identifier", + }, + "optional": true, + "property": Object { + "loc": Object { + "end": Object { + "column": 9, + "line": 3, + }, + "start": Object { + "column": 8, + "line": 3, + }, + }, + "range": Array [ + 65, + 66, + ], + "raw": "2", + "type": "Literal", + "value": 2, + }, "range": Array [ 59, - 62, + 67, ], - "type": "Identifier", + "type": "MemberExpression", }, - "optional": true, + "optional": false, "property": Object { "loc": Object { "end": Object { - "column": 9, + "column": 12, "line": 3, }, "start": Object { - "column": 8, + "column": 11, "line": 3, }, }, "range": Array [ - 65, - 66, + 68, + 69, ], - "raw": "2", + "raw": "3", "type": "Literal", - "value": 2, + "value": 3, }, "range": Array [ 59, - 67, + 70, ], - "type": "OptionalMemberExpression", + "type": "MemberExpression", }, - "optional": false, - "property": Object { - "loc": Object { - "end": Object { - "column": 12, - "line": 3, - }, - "start": Object { - "column": 11, - "line": 3, - }, + "loc": Object { + "end": Object { + "column": 13, + "line": 3, + }, + "start": Object { + "column": 2, + "line": 3, }, - "range": Array [ - 68, - 69, - ], - "raw": "3", - "type": "Literal", - "value": 3, }, "range": Array [ 59, 70, ], - "type": "OptionalMemberExpression", + "type": "ChainExpression", }, "loc": Object { "end": Object { @@ -193,22 +227,11 @@ Object { }, Object { "expression": Object { - "computed": true, - "loc": Object { - "end": Object { - "column": 13, - "line": 4, - }, - "start": Object { - "column": 2, - "line": 4, - }, - }, - "object": Object { + "expression": Object { "computed": true, "loc": Object { "end": Object { - "column": 8, + "column": 13, "line": 4, }, "start": Object { @@ -217,9 +240,10 @@ Object { }, }, "object": Object { + "computed": true, "loc": Object { "end": Object { - "column": 5, + "column": 8, "line": 4, }, "start": Object { @@ -227,64 +251,91 @@ Object { "line": 4, }, }, - "name": "one", + "object": Object { + "loc": Object { + "end": Object { + "column": 5, + "line": 4, + }, + "start": Object { + "column": 2, + "line": 4, + }, + }, + "name": "one", + "range": Array [ + 74, + 77, + ], + "type": "Identifier", + }, + "optional": false, + "property": Object { + "loc": Object { + "end": Object { + "column": 7, + "line": 4, + }, + "start": Object { + "column": 6, + "line": 4, + }, + }, + "range": Array [ + 78, + 79, + ], + "raw": "2", + "type": "Literal", + "value": 2, + }, "range": Array [ 74, - 77, + 80, ], - "type": "Identifier", + "type": "MemberExpression", }, - "optional": false, + "optional": true, "property": Object { "loc": Object { "end": Object { - "column": 7, + "column": 12, "line": 4, }, "start": Object { - "column": 6, + "column": 11, "line": 4, }, }, "range": Array [ - 78, - 79, + 83, + 84, ], - "raw": "2", + "raw": "3", "type": "Literal", - "value": 2, + "value": 3, }, "range": Array [ 74, - 80, + 85, ], "type": "MemberExpression", }, - "optional": true, - "property": Object { - "loc": Object { - "end": Object { - "column": 12, - "line": 4, - }, - "start": Object { - "column": 11, - "line": 4, - }, + "loc": Object { + "end": Object { + "column": 13, + "line": 4, + }, + "start": Object { + "column": 2, + "line": 4, }, - "range": Array [ - 83, - 84, - ], - "raw": "3", - "type": "Literal", - "value": 3, }, "range": Array [ 74, 85, ], - "type": "OptionalMemberExpression", + "type": "ChainExpression", }, "loc": Object { "end": Object { @@ -304,22 +355,11 @@ Object { }, Object { "expression": Object { - "computed": true, - "loc": Object { - "end": Object { - "column": 13, - "line": 5, - }, - "start": Object { - "column": 2, - "line": 5, - }, - }, - "object": Object { + "expression": Object { "computed": true, "loc": Object { "end": Object { - "column": 8, + "column": 13, "line": 5, }, "start": Object { @@ -328,9 +368,10 @@ Object { }, }, "object": Object { + "computed": true, "loc": Object { "end": Object { - "column": 5, + "column": 8, "line": 5, }, "start": Object { @@ -338,64 +379,91 @@ Object { "line": 5, }, }, - "name": "one", + "object": Object { + "loc": Object { + "end": Object { + "column": 5, + "line": 5, + }, + "start": Object { + "column": 2, + "line": 5, + }, + }, + "name": "one", + "range": Array [ + 89, + 92, + ], + "type": "Identifier", + }, + "optional": false, + "property": Object { + "loc": Object { + "end": Object { + "column": 7, + "line": 5, + }, + "start": Object { + "column": 6, + "line": 5, + }, + }, + "range": Array [ + 93, + 94, + ], + "raw": "2", + "type": "Literal", + "value": 2, + }, "range": Array [ 89, - 92, + 95, ], - "type": "Identifier", + "type": "MemberExpression", }, - "optional": false, + "optional": true, "property": Object { "loc": Object { "end": Object { - "column": 7, + "column": 12, "line": 5, }, "start": Object { - "column": 6, + "column": 11, "line": 5, }, }, "range": Array [ - 93, - 94, + 98, + 99, ], - "raw": "2", + "raw": "3", "type": "Literal", - "value": 2, + "value": 3, }, "range": Array [ 89, - 95, + 100, ], "type": "MemberExpression", }, - "optional": true, - "property": Object { - "loc": Object { - "end": Object { - "column": 12, - "line": 5, - }, - "start": Object { - "column": 11, - "line": 5, - }, + "loc": Object { + "end": Object { + "column": 13, + "line": 5, + }, + "start": Object { + "column": 2, + "line": 5, }, - "range": Array [ - 98, - 99, - ], - "raw": "3", - "type": "Literal", - "value": 3, }, "range": Array [ 89, 100, ], - "type": "OptionalMemberExpression", + "type": "ChainExpression", }, "loc": Object { "end": Object { @@ -415,22 +483,11 @@ Object { }, Object { "expression": Object { - "computed": true, - "loc": Object { - "end": Object { - "column": 16, - "line": 6, - }, - "start": Object { - "column": 2, - "line": 6, - }, - }, - "object": Object { + "expression": Object { "computed": true, "loc": Object { "end": Object { - "column": 13, + "column": 16, "line": 6, }, "start": Object { @@ -442,7 +499,7 @@ Object { "computed": true, "loc": Object { "end": Object { - "column": 8, + "column": 13, "line": 6, }, "start": Object { @@ -451,9 +508,10 @@ Object { }, }, "object": Object { + "computed": true, "loc": Object { "end": Object { - "column": 5, + "column": 8, "line": 6, }, "start": Object { @@ -461,90 +519,117 @@ Object { "line": 6, }, }, - "name": "one", + "object": Object { + "loc": Object { + "end": Object { + "column": 5, + "line": 6, + }, + "start": Object { + "column": 2, + "line": 6, + }, + }, + "name": "one", + "range": Array [ + 104, + 107, + ], + "type": "Identifier", + }, + "optional": false, + "property": Object { + "loc": Object { + "end": Object { + "column": 7, + "line": 6, + }, + "start": Object { + "column": 6, + "line": 6, + }, + }, + "range": Array [ + 108, + 109, + ], + "raw": "2", + "type": "Literal", + "value": 2, + }, "range": Array [ 104, - 107, + 110, ], - "type": "Identifier", + "type": "MemberExpression", }, - "optional": false, + "optional": true, "property": Object { "loc": Object { "end": Object { - "column": 7, + "column": 12, "line": 6, }, "start": Object { - "column": 6, + "column": 11, "line": 6, }, }, "range": Array [ - 108, - 109, + 113, + 114, ], - "raw": "2", + "raw": "3", "type": "Literal", - "value": 2, + "value": 3, }, "range": Array [ 104, - 110, + 115, ], "type": "MemberExpression", }, - "optional": true, + "optional": false, "property": Object { "loc": Object { "end": Object { - "column": 12, + "column": 15, "line": 6, }, "start": Object { - "column": 11, + "column": 14, "line": 6, }, }, "range": Array [ - 113, - 114, + 116, + 117, ], - "raw": "3", + "raw": "4", "type": "Literal", - "value": 3, + "value": 4, }, "range": Array [ 104, - 115, + 118, ], - "type": "OptionalMemberExpression", + "type": "MemberExpression", }, - "optional": false, - "property": Object { - "loc": Object { - "end": Object { - "column": 15, - "line": 6, - }, - "start": Object { - "column": 14, - "line": 6, - }, + "loc": Object { + "end": Object { + "column": 16, + "line": 6, + }, + "start": Object { + "column": 2, + "line": 6, }, - "range": Array [ - 116, - 117, - ], - "raw": "4", - "type": "Literal", - "value": 4, }, "range": Array [ 104, 118, ], - "type": "OptionalMemberExpression", + "type": "ChainExpression", }, "loc": Object { "end": Object { @@ -564,22 +649,11 @@ Object { }, Object { "expression": Object { - "computed": true, - "loc": Object { - "end": Object { - "column": 18, - "line": 7, - }, - "start": Object { - "column": 2, - "line": 7, - }, - }, - "object": Object { + "expression": Object { "computed": true, "loc": Object { "end": Object { - "column": 13, + "column": 18, "line": 7, }, "start": Object { @@ -591,7 +665,7 @@ Object { "computed": true, "loc": Object { "end": Object { - "column": 8, + "column": 13, "line": 7, }, "start": Object { @@ -600,9 +674,10 @@ Object { }, }, "object": Object { + "computed": true, "loc": Object { "end": Object { - "column": 5, + "column": 8, "line": 7, }, "start": Object { @@ -610,36 +685,73 @@ Object { "line": 7, }, }, - "name": "one", + "object": Object { + "loc": Object { + "end": Object { + "column": 5, + "line": 7, + }, + "start": Object { + "column": 2, + "line": 7, + }, + }, + "name": "one", + "range": Array [ + 122, + 125, + ], + "type": "Identifier", + }, + "optional": false, + "property": Object { + "loc": Object { + "end": Object { + "column": 7, + "line": 7, + }, + "start": Object { + "column": 6, + "line": 7, + }, + }, + "range": Array [ + 126, + 127, + ], + "raw": "2", + "type": "Literal", + "value": 2, + }, "range": Array [ 122, - 125, + 128, ], - "type": "Identifier", + "type": "MemberExpression", }, - "optional": false, + "optional": true, "property": Object { "loc": Object { "end": Object { - "column": 7, + "column": 12, "line": 7, }, "start": Object { - "column": 6, + "column": 11, "line": 7, }, }, "range": Array [ - 126, - 127, + 131, + 132, ], - "raw": "2", + "raw": "3", "type": "Literal", - "value": 2, + "value": 3, }, "range": Array [ 122, - 128, + 133, ], "type": "MemberExpression", }, @@ -647,53 +759,43 @@ Object { "property": Object { "loc": Object { "end": Object { - "column": 12, + "column": 17, "line": 7, }, "start": Object { - "column": 11, + "column": 16, "line": 7, }, }, "range": Array [ - 131, - 132, + 136, + 137, ], - "raw": "3", + "raw": "4", "type": "Literal", - "value": 3, + "value": 4, }, "range": Array [ 122, - 133, + 138, ], - "type": "OptionalMemberExpression", + "type": "MemberExpression", }, - "optional": true, - "property": Object { - "loc": Object { - "end": Object { - "column": 17, - "line": 7, - }, - "start": Object { - "column": 16, - "line": 7, - }, + "loc": Object { + "end": Object { + "column": 18, + "line": 7, + }, + "start": Object { + "column": 2, + "line": 7, }, - "range": Array [ - 136, - 137, - ], - "raw": "4", - "type": "Literal", - "value": 4, }, "range": Array [ 122, 138, ], - "type": "OptionalMemberExpression", + "type": "ChainExpression", }, "loc": Object { "end": Object { diff --git a/packages/typescript-estree/tests/snapshots/typescript/basics/optional-chain-with-non-null-assertion.src.ts.shot b/packages/typescript-estree/tests/snapshots/typescript/basics/optional-chain-with-non-null-assertion.src.ts.shot index 98602745165..cb8e274c77e 100644 --- a/packages/typescript-estree/tests/snapshots/typescript/basics/optional-chain-with-non-null-assertion.src.ts.shot +++ b/packages/typescript-estree/tests/snapshots/typescript/basics/optional-chain-with-non-null-assertion.src.ts.shot @@ -9,113 +9,147 @@ Object { "body": Array [ Object { "expression": Object { - "computed": false, - "loc": Object { - "end": Object { - "column": 17, - "line": 2, - }, - "start": Object { - "column": 2, - "line": 2, - }, - }, - "object": Object { - "expression": Object { - "computed": false, - "loc": Object { - "end": Object { - "column": 10, - "line": 2, - }, - "start": Object { - "column": 2, - "line": 2, - }, + "expression": Object { + "computed": false, + "loc": Object { + "end": Object { + "column": 17, + "line": 2, }, - "object": Object { - "loc": Object { - "end": Object { - "column": 5, - "line": 2, + "start": Object { + "column": 2, + "line": 2, + }, + }, + "object": Object { + "expression": Object { + "expression": Object { + "computed": false, + "loc": Object { + "end": Object { + "column": 10, + "line": 2, + }, + "start": Object { + "column": 2, + "line": 2, + }, }, - "start": Object { - "column": 2, - "line": 2, + "object": Object { + "loc": Object { + "end": Object { + "column": 5, + "line": 2, + }, + "start": Object { + "column": 2, + "line": 2, + }, + }, + "name": "one", + "range": Array [ + 40, + 43, + ], + "type": "Identifier", }, + "optional": true, + "property": Object { + "loc": Object { + "end": Object { + "column": 10, + "line": 2, + }, + "start": Object { + "column": 7, + "line": 2, + }, + }, + "name": "two", + "range": Array [ + 45, + 48, + ], + "type": "Identifier", + }, + "range": Array [ + 40, + 48, + ], + "type": "MemberExpression", }, - "name": "one", - "range": Array [ - 40, - 43, - ], - "type": "Identifier", - }, - "optional": true, - "property": Object { "loc": Object { "end": Object { "column": 10, "line": 2, }, "start": Object { - "column": 7, + "column": 2, "line": 2, }, }, - "name": "two", "range": Array [ - 45, + 40, 48, ], - "type": "Identifier", + "type": "ChainExpression", + }, + "loc": Object { + "end": Object { + "column": 11, + "line": 2, + }, + "start": Object { + "column": 2, + "line": 2, + }, }, "range": Array [ 40, - 48, + 49, ], - "type": "OptionalMemberExpression", + "type": "TSNonNullExpression", }, - "loc": Object { - "end": Object { - "column": 11, - "line": 2, - }, - "start": Object { - "column": 2, - "line": 2, + "optional": false, + "property": Object { + "loc": Object { + "end": Object { + "column": 17, + "line": 2, + }, + "start": Object { + "column": 12, + "line": 2, + }, }, + "name": "three", + "range": Array [ + 50, + 55, + ], + "type": "Identifier", }, "range": Array [ 40, - 49, + 55, ], - "type": "TSNonNullExpression", + "type": "MemberExpression", }, - "optional": false, - "property": Object { - "loc": Object { - "end": Object { - "column": 17, - "line": 2, - }, - "start": Object { - "column": 12, - "line": 2, - }, + "loc": Object { + "end": Object { + "column": 17, + "line": 2, + }, + "start": Object { + "column": 2, + "line": 2, }, - "name": "three", - "range": Array [ - 50, - 55, - ], - "type": "Identifier", }, "range": Array [ 40, 55, ], - "type": "OptionalMemberExpression", + "type": "ChainExpression", }, "loc": Object { "end": Object { @@ -148,21 +182,11 @@ Object { }, "object": Object { "expression": Object { - "computed": false, - "loc": Object { - "end": Object { - "column": 11, - "line": 3, - }, - "start": Object { - "column": 3, - "line": 3, - }, - }, - "object": Object { + "expression": Object { + "computed": false, "loc": Object { "end": Object { - "column": 6, + "column": 11, "line": 3, }, "start": Object { @@ -170,37 +194,64 @@ Object { "line": 3, }, }, - "name": "one", - "range": Array [ - 60, - 63, - ], - "type": "Identifier", - }, - "optional": true, - "property": Object { - "loc": Object { - "end": Object { - "column": 11, - "line": 3, + "object": Object { + "loc": Object { + "end": Object { + "column": 6, + "line": 3, + }, + "start": Object { + "column": 3, + "line": 3, + }, }, - "start": Object { - "column": 8, - "line": 3, + "name": "one", + "range": Array [ + 60, + 63, + ], + "type": "Identifier", + }, + "optional": true, + "property": Object { + "loc": Object { + "end": Object { + "column": 11, + "line": 3, + }, + "start": Object { + "column": 8, + "line": 3, + }, }, + "name": "two", + "range": Array [ + 65, + 68, + ], + "type": "Identifier", }, - "name": "two", "range": Array [ - 65, + 60, 68, ], - "type": "Identifier", + "type": "MemberExpression", + }, + "loc": Object { + "end": Object { + "column": 11, + "line": 3, + }, + "start": Object { + "column": 3, + "line": 3, + }, }, "range": Array [ 60, 68, ], - "type": "OptionalMemberExpression", + "type": "ChainExpression", }, "loc": Object { "end": Object { @@ -274,21 +325,11 @@ Object { }, "object": Object { "expression": Object { - "computed": false, - "loc": Object { - "end": Object { - "column": 11, - "line": 4, - }, - "start": Object { - "column": 3, - "line": 4, - }, - }, - "object": Object { + "expression": Object { + "computed": false, "loc": Object { "end": Object { - "column": 6, + "column": 11, "line": 4, }, "start": Object { @@ -296,37 +337,64 @@ Object { "line": 4, }, }, - "name": "one", - "range": Array [ - 81, - 84, - ], - "type": "Identifier", - }, - "optional": true, - "property": Object { - "loc": Object { - "end": Object { - "column": 11, - "line": 4, + "object": Object { + "loc": Object { + "end": Object { + "column": 6, + "line": 4, + }, + "start": Object { + "column": 3, + "line": 4, + }, }, - "start": Object { - "column": 8, - "line": 4, + "name": "one", + "range": Array [ + 81, + 84, + ], + "type": "Identifier", + }, + "optional": true, + "property": Object { + "loc": Object { + "end": Object { + "column": 11, + "line": 4, + }, + "start": Object { + "column": 8, + "line": 4, + }, }, + "name": "two", + "range": Array [ + 86, + 89, + ], + "type": "Identifier", }, - "name": "two", "range": Array [ - 86, + 81, 89, ], - "type": "Identifier", + "type": "MemberExpression", + }, + "loc": Object { + "end": Object { + "column": 11, + "line": 4, + }, + "start": Object { + "column": 3, + "line": 4, + }, }, "range": Array [ 81, 89, ], - "type": "OptionalMemberExpression", + "type": "ChainExpression", }, "loc": Object { "end": Object { diff --git a/packages/typescript-estree/tests/snapshots/typescript/basics/optional-chain-with-parens.src.ts.shot b/packages/typescript-estree/tests/snapshots/typescript/basics/optional-chain-with-parens.src.ts.shot index e107d4b0a91..25d8a21935a 100644 --- a/packages/typescript-estree/tests/snapshots/typescript/basics/optional-chain-with-parens.src.ts.shot +++ b/packages/typescript-estree/tests/snapshots/typescript/basics/optional-chain-with-parens.src.ts.shot @@ -9,21 +9,11 @@ Object { "body": Array [ Object { "expression": Object { - "computed": false, - "loc": Object { - "end": Object { - "column": 11, - "line": 2, - }, - "start": Object { - "column": 3, - "line": 2, - }, - }, - "object": Object { + "expression": Object { + "computed": false, "loc": Object { "end": Object { - "column": 6, + "column": 11, "line": 2, }, "start": Object { @@ -31,37 +21,64 @@ Object { "line": 2, }, }, - "name": "one", - "range": Array [ - 47, - 50, - ], - "type": "Identifier", - }, - "optional": true, - "property": Object { - "loc": Object { - "end": Object { - "column": 11, - "line": 2, + "object": Object { + "loc": Object { + "end": Object { + "column": 6, + "line": 2, + }, + "start": Object { + "column": 3, + "line": 2, + }, }, - "start": Object { - "column": 8, - "line": 2, + "name": "one", + "range": Array [ + 47, + 50, + ], + "type": "Identifier", + }, + "optional": true, + "property": Object { + "loc": Object { + "end": Object { + "column": 11, + "line": 2, + }, + "start": Object { + "column": 8, + "line": 2, + }, }, + "name": "two", + "range": Array [ + 52, + 55, + ], + "type": "Identifier", }, - "name": "two", "range": Array [ - 52, + 47, 55, ], - "type": "Identifier", + "type": "MemberExpression", + }, + "loc": Object { + "end": Object { + "column": 11, + "line": 2, + }, + "start": Object { + "column": 3, + "line": 2, + }, }, "range": Array [ 47, 55, ], - "type": "OptionalMemberExpression", + "type": "ChainExpression", }, "loc": Object { "end": Object { @@ -93,21 +110,11 @@ Object { }, }, "object": Object { - "computed": false, - "loc": Object { - "end": Object { - "column": 11, - "line": 3, - }, - "start": Object { - "column": 3, - "line": 3, - }, - }, - "object": Object { + "expression": Object { + "computed": false, "loc": Object { "end": Object { - "column": 6, + "column": 11, "line": 3, }, "start": Object { @@ -115,37 +122,64 @@ Object { "line": 3, }, }, - "name": "one", - "range": Array [ - 61, - 64, - ], - "type": "Identifier", - }, - "optional": true, - "property": Object { - "loc": Object { - "end": Object { - "column": 11, - "line": 3, + "object": Object { + "loc": Object { + "end": Object { + "column": 6, + "line": 3, + }, + "start": Object { + "column": 3, + "line": 3, + }, }, - "start": Object { - "column": 8, - "line": 3, + "name": "one", + "range": Array [ + 61, + 64, + ], + "type": "Identifier", + }, + "optional": true, + "property": Object { + "loc": Object { + "end": Object { + "column": 11, + "line": 3, + }, + "start": Object { + "column": 8, + "line": 3, + }, }, + "name": "two", + "range": Array [ + 66, + 69, + ], + "type": "Identifier", }, - "name": "two", "range": Array [ - 66, + 61, 69, ], - "type": "Identifier", + "type": "MemberExpression", + }, + "loc": Object { + "end": Object { + "column": 11, + "line": 3, + }, + "start": Object { + "column": 3, + "line": 3, + }, }, "range": Array [ 61, 69, ], - "type": "OptionalMemberExpression", + "type": "ChainExpression", }, "optional": false, "property": Object { @@ -190,22 +224,11 @@ Object { }, Object { "expression": Object { - "computed": false, - "loc": Object { - "end": Object { - "column": 17, - "line": 4, - }, - "start": Object { - "column": 3, - "line": 4, - }, - }, - "object": Object { + "expression": Object { "computed": false, "loc": Object { "end": Object { - "column": 10, + "column": 17, "line": 4, }, "start": Object { @@ -214,9 +237,10 @@ Object { }, }, "object": Object { + "computed": false, "loc": Object { "end": Object { - "column": 6, + "column": 10, "line": 4, }, "start": Object { @@ -224,62 +248,89 @@ Object { "line": 4, }, }, - "name": "one", + "object": Object { + "loc": Object { + "end": Object { + "column": 6, + "line": 4, + }, + "start": Object { + "column": 3, + "line": 4, + }, + }, + "name": "one", + "range": Array [ + 81, + 84, + ], + "type": "Identifier", + }, + "optional": false, + "property": Object { + "loc": Object { + "end": Object { + "column": 10, + "line": 4, + }, + "start": Object { + "column": 7, + "line": 4, + }, + }, + "name": "two", + "range": Array [ + 85, + 88, + ], + "type": "Identifier", + }, "range": Array [ 81, - 84, + 88, ], - "type": "Identifier", + "type": "MemberExpression", }, - "optional": false, + "optional": true, "property": Object { "loc": Object { "end": Object { - "column": 10, + "column": 17, "line": 4, }, "start": Object { - "column": 7, + "column": 12, "line": 4, }, }, - "name": "two", + "name": "three", "range": Array [ - 85, - 88, + 90, + 95, ], "type": "Identifier", }, "range": Array [ 81, - 88, + 95, ], "type": "MemberExpression", }, - "optional": true, - "property": Object { - "loc": Object { - "end": Object { - "column": 17, - "line": 4, - }, - "start": Object { - "column": 12, - "line": 4, - }, + "loc": Object { + "end": Object { + "column": 17, + "line": 4, + }, + "start": Object { + "column": 3, + "line": 4, }, - "name": "three", - "range": Array [ - 90, - 95, - ], - "type": "Identifier", }, "range": Array [ 81, 95, ], - "type": "OptionalMemberExpression", + "type": "ChainExpression", }, "loc": Object { "end": Object { @@ -311,22 +362,11 @@ Object { }, }, "object": Object { - "computed": false, - "loc": Object { - "end": Object { - "column": 17, - "line": 5, - }, - "start": Object { - "column": 3, - "line": 5, - }, - }, - "object": Object { + "expression": Object { "computed": false, "loc": Object { "end": Object { - "column": 10, + "column": 17, "line": 5, }, "start": Object { @@ -335,9 +375,10 @@ Object { }, }, "object": Object { + "computed": false, "loc": Object { "end": Object { - "column": 6, + "column": 10, "line": 5, }, "start": Object { @@ -345,62 +386,89 @@ Object { "line": 5, }, }, - "name": "one", + "object": Object { + "loc": Object { + "end": Object { + "column": 6, + "line": 5, + }, + "start": Object { + "column": 3, + "line": 5, + }, + }, + "name": "one", + "range": Array [ + 101, + 104, + ], + "type": "Identifier", + }, + "optional": false, + "property": Object { + "loc": Object { + "end": Object { + "column": 10, + "line": 5, + }, + "start": Object { + "column": 7, + "line": 5, + }, + }, + "name": "two", + "range": Array [ + 105, + 108, + ], + "type": "Identifier", + }, "range": Array [ 101, - 104, + 108, ], - "type": "Identifier", + "type": "MemberExpression", }, - "optional": false, + "optional": true, "property": Object { "loc": Object { "end": Object { - "column": 10, + "column": 17, "line": 5, }, "start": Object { - "column": 7, + "column": 12, "line": 5, }, }, - "name": "two", + "name": "three", "range": Array [ - 105, - 108, + 110, + 115, ], "type": "Identifier", }, "range": Array [ 101, - 108, + 115, ], "type": "MemberExpression", }, - "optional": true, - "property": Object { - "loc": Object { - "end": Object { - "column": 17, - "line": 5, - }, - "start": Object { - "column": 12, - "line": 5, - }, + "loc": Object { + "end": Object { + "column": 17, + "line": 5, + }, + "start": Object { + "column": 3, + "line": 5, }, - "name": "three", - "range": Array [ - 110, - 115, - ], - "type": "Identifier", }, "range": Array [ 101, 115, ], - "type": "OptionalMemberExpression", + "type": "ChainExpression", }, "optional": false, "property": Object { @@ -445,22 +513,11 @@ Object { }, Object { "expression": Object { - "computed": false, - "loc": Object { - "end": Object { - "column": 23, - "line": 6, - }, - "start": Object { - "column": 3, - "line": 6, - }, - }, - "object": Object { + "expression": Object { "computed": false, "loc": Object { "end": Object { - "column": 17, + "column": 23, "line": 6, }, "start": Object { @@ -472,7 +529,7 @@ Object { "computed": false, "loc": Object { "end": Object { - "column": 10, + "column": 17, "line": 6, }, "start": Object { @@ -481,9 +538,10 @@ Object { }, }, "object": Object { + "computed": false, "loc": Object { "end": Object { - "column": 6, + "column": 10, "line": 6, }, "start": Object { @@ -491,35 +549,71 @@ Object { "line": 6, }, }, - "name": "one", + "object": Object { + "loc": Object { + "end": Object { + "column": 6, + "line": 6, + }, + "start": Object { + "column": 3, + "line": 6, + }, + }, + "name": "one", + "range": Array [ + 126, + 129, + ], + "type": "Identifier", + }, + "optional": false, + "property": Object { + "loc": Object { + "end": Object { + "column": 10, + "line": 6, + }, + "start": Object { + "column": 7, + "line": 6, + }, + }, + "name": "two", + "range": Array [ + 130, + 133, + ], + "type": "Identifier", + }, "range": Array [ 126, - 129, + 133, ], - "type": "Identifier", + "type": "MemberExpression", }, - "optional": false, + "optional": true, "property": Object { "loc": Object { "end": Object { - "column": 10, + "column": 17, "line": 6, }, "start": Object { - "column": 7, + "column": 12, "line": 6, }, }, - "name": "two", + "name": "three", "range": Array [ - 130, - 133, + 135, + 140, ], "type": "Identifier", }, "range": Array [ 126, - 133, + 140, ], "type": "MemberExpression", }, @@ -527,51 +621,42 @@ Object { "property": Object { "loc": Object { "end": Object { - "column": 17, + "column": 23, "line": 6, }, "start": Object { - "column": 12, + "column": 19, "line": 6, }, }, - "name": "three", + "name": "four", "range": Array [ - 135, - 140, + 142, + 146, ], "type": "Identifier", }, "range": Array [ 126, - 140, + 146, ], - "type": "OptionalMemberExpression", + "type": "MemberExpression", }, - "optional": true, - "property": Object { - "loc": Object { - "end": Object { - "column": 23, - "line": 6, - }, - "start": Object { - "column": 19, - "line": 6, - }, + "loc": Object { + "end": Object { + "column": 23, + "line": 6, + }, + "start": Object { + "column": 3, + "line": 6, }, - "name": "four", - "range": Array [ - 142, - 146, - ], - "type": "Identifier", }, "range": Array [ 126, 146, ], - "type": "OptionalMemberExpression", + "type": "ChainExpression", }, "loc": Object { "end": Object { @@ -603,22 +688,11 @@ Object { }, }, "object": Object { - "computed": false, - "loc": Object { - "end": Object { - "column": 23, - "line": 7, - }, - "start": Object { - "column": 3, - "line": 7, - }, - }, - "object": Object { + "expression": Object { "computed": false, "loc": Object { "end": Object { - "column": 17, + "column": 23, "line": 7, }, "start": Object { @@ -630,7 +704,7 @@ Object { "computed": false, "loc": Object { "end": Object { - "column": 10, + "column": 17, "line": 7, }, "start": Object { @@ -639,9 +713,10 @@ Object { }, }, "object": Object { + "computed": false, "loc": Object { "end": Object { - "column": 6, + "column": 10, "line": 7, }, "start": Object { @@ -649,35 +724,71 @@ Object { "line": 7, }, }, - "name": "one", + "object": Object { + "loc": Object { + "end": Object { + "column": 6, + "line": 7, + }, + "start": Object { + "column": 3, + "line": 7, + }, + }, + "name": "one", + "range": Array [ + 152, + 155, + ], + "type": "Identifier", + }, + "optional": false, + "property": Object { + "loc": Object { + "end": Object { + "column": 10, + "line": 7, + }, + "start": Object { + "column": 7, + "line": 7, + }, + }, + "name": "two", + "range": Array [ + 156, + 159, + ], + "type": "Identifier", + }, "range": Array [ 152, - 155, + 159, ], - "type": "Identifier", + "type": "MemberExpression", }, - "optional": false, + "optional": true, "property": Object { "loc": Object { "end": Object { - "column": 10, + "column": 17, "line": 7, }, "start": Object { - "column": 7, + "column": 12, "line": 7, }, }, - "name": "two", + "name": "three", "range": Array [ - 156, - 159, + 161, + 166, ], "type": "Identifier", }, "range": Array [ 152, - 159, + 166, ], "type": "MemberExpression", }, @@ -685,51 +796,42 @@ Object { "property": Object { "loc": Object { "end": Object { - "column": 17, + "column": 23, "line": 7, }, "start": Object { - "column": 12, + "column": 19, "line": 7, }, }, - "name": "three", + "name": "four", "range": Array [ - 161, - 166, + 168, + 172, ], "type": "Identifier", }, "range": Array [ 152, - 166, + 172, ], - "type": "OptionalMemberExpression", + "type": "MemberExpression", }, - "optional": true, - "property": Object { - "loc": Object { - "end": Object { - "column": 23, - "line": 7, - }, - "start": Object { - "column": 19, - "line": 7, - }, + "loc": Object { + "end": Object { + "column": 23, + "line": 7, + }, + "start": Object { + "column": 3, + "line": 7, }, - "name": "four", - "range": Array [ - 168, - 172, - ], - "type": "Identifier", }, "range": Array [ 152, 172, ], - "type": "OptionalMemberExpression", + "type": "ChainExpression", }, "optional": false, "property": Object { diff --git a/packages/typescript-estree/tests/snapshots/typescript/basics/optional-chain.src.ts.shot b/packages/typescript-estree/tests/snapshots/typescript/basics/optional-chain.src.ts.shot index 410790eb69b..cce78104239 100644 --- a/packages/typescript-estree/tests/snapshots/typescript/basics/optional-chain.src.ts.shot +++ b/packages/typescript-estree/tests/snapshots/typescript/basics/optional-chain.src.ts.shot @@ -9,21 +9,11 @@ Object { "body": Array [ Object { "expression": Object { - "computed": false, - "loc": Object { - "end": Object { - "column": 10, - "line": 2, - }, - "start": Object { - "column": 2, - "line": 2, - }, - }, - "object": Object { + "expression": Object { + "computed": false, "loc": Object { "end": Object { - "column": 5, + "column": 10, "line": 2, }, "start": Object { @@ -31,37 +21,64 @@ Object { "line": 2, }, }, - "name": "one", - "range": Array [ - 40, - 43, - ], - "type": "Identifier", - }, - "optional": true, - "property": Object { - "loc": Object { - "end": Object { - "column": 10, - "line": 2, + "object": Object { + "loc": Object { + "end": Object { + "column": 5, + "line": 2, + }, + "start": Object { + "column": 2, + "line": 2, + }, }, - "start": Object { - "column": 7, - "line": 2, + "name": "one", + "range": Array [ + 40, + 43, + ], + "type": "Identifier", + }, + "optional": true, + "property": Object { + "loc": Object { + "end": Object { + "column": 10, + "line": 2, + }, + "start": Object { + "column": 7, + "line": 2, + }, }, + "name": "two", + "range": Array [ + 45, + 48, + ], + "type": "Identifier", }, - "name": "two", "range": Array [ - 45, + 40, 48, ], - "type": "Identifier", + "type": "MemberExpression", + }, + "loc": Object { + "end": Object { + "column": 10, + "line": 2, + }, + "start": Object { + "column": 2, + "line": 2, + }, }, "range": Array [ 40, 48, ], - "type": "OptionalMemberExpression", + "type": "ChainExpression", }, "loc": Object { "end": Object { @@ -81,22 +98,11 @@ Object { }, Object { "expression": Object { - "computed": false, - "loc": Object { - "end": Object { - "column": 16, - "line": 3, - }, - "start": Object { - "column": 2, - "line": 3, - }, - }, - "object": Object { + "expression": Object { "computed": false, "loc": Object { "end": Object { - "column": 10, + "column": 16, "line": 3, }, "start": Object { @@ -105,9 +111,10 @@ Object { }, }, "object": Object { + "computed": false, "loc": Object { "end": Object { - "column": 5, + "column": 10, "line": 3, }, "start": Object { @@ -115,62 +122,89 @@ Object { "line": 3, }, }, - "name": "one", + "object": Object { + "loc": Object { + "end": Object { + "column": 5, + "line": 3, + }, + "start": Object { + "column": 2, + "line": 3, + }, + }, + "name": "one", + "range": Array [ + 52, + 55, + ], + "type": "Identifier", + }, + "optional": true, + "property": Object { + "loc": Object { + "end": Object { + "column": 10, + "line": 3, + }, + "start": Object { + "column": 7, + "line": 3, + }, + }, + "name": "two", + "range": Array [ + 57, + 60, + ], + "type": "Identifier", + }, "range": Array [ 52, - 55, + 60, ], - "type": "Identifier", + "type": "MemberExpression", }, - "optional": true, + "optional": false, "property": Object { "loc": Object { "end": Object { - "column": 10, + "column": 16, "line": 3, }, "start": Object { - "column": 7, + "column": 11, "line": 3, }, }, - "name": "two", + "name": "three", "range": Array [ - 57, - 60, + 61, + 66, ], "type": "Identifier", }, "range": Array [ 52, - 60, + 66, ], - "type": "OptionalMemberExpression", + "type": "MemberExpression", }, - "optional": false, - "property": Object { - "loc": Object { - "end": Object { - "column": 16, - "line": 3, - }, - "start": Object { - "column": 11, - "line": 3, - }, + "loc": Object { + "end": Object { + "column": 16, + "line": 3, + }, + "start": Object { + "column": 2, + "line": 3, }, - "name": "three", - "range": Array [ - 61, - 66, - ], - "type": "Identifier", }, "range": Array [ 52, 66, ], - "type": "OptionalMemberExpression", + "type": "ChainExpression", }, "loc": Object { "end": Object { @@ -190,22 +224,11 @@ Object { }, Object { "expression": Object { - "computed": false, - "loc": Object { - "end": Object { - "column": 16, - "line": 4, - }, - "start": Object { - "column": 2, - "line": 4, - }, - }, - "object": Object { + "expression": Object { "computed": false, "loc": Object { "end": Object { - "column": 9, + "column": 16, "line": 4, }, "start": Object { @@ -214,9 +237,10 @@ Object { }, }, "object": Object { + "computed": false, "loc": Object { "end": Object { - "column": 5, + "column": 9, "line": 4, }, "start": Object { @@ -224,62 +248,89 @@ Object { "line": 4, }, }, - "name": "one", + "object": Object { + "loc": Object { + "end": Object { + "column": 5, + "line": 4, + }, + "start": Object { + "column": 2, + "line": 4, + }, + }, + "name": "one", + "range": Array [ + 70, + 73, + ], + "type": "Identifier", + }, + "optional": false, + "property": Object { + "loc": Object { + "end": Object { + "column": 9, + "line": 4, + }, + "start": Object { + "column": 6, + "line": 4, + }, + }, + "name": "two", + "range": Array [ + 74, + 77, + ], + "type": "Identifier", + }, "range": Array [ 70, - 73, + 77, ], - "type": "Identifier", + "type": "MemberExpression", }, - "optional": false, + "optional": true, "property": Object { "loc": Object { "end": Object { - "column": 9, + "column": 16, "line": 4, }, "start": Object { - "column": 6, + "column": 11, "line": 4, }, }, - "name": "two", + "name": "three", "range": Array [ - 74, - 77, + 79, + 84, ], "type": "Identifier", }, "range": Array [ 70, - 77, + 84, ], "type": "MemberExpression", }, - "optional": true, - "property": Object { - "loc": Object { - "end": Object { - "column": 16, - "line": 4, - }, - "start": Object { - "column": 11, - "line": 4, - }, + "loc": Object { + "end": Object { + "column": 16, + "line": 4, + }, + "start": Object { + "column": 2, + "line": 4, }, - "name": "three", - "range": Array [ - 79, - 84, - ], - "type": "Identifier", }, "range": Array [ 70, 84, ], - "type": "OptionalMemberExpression", + "type": "ChainExpression", }, "loc": Object { "end": Object { @@ -299,22 +350,11 @@ Object { }, Object { "expression": Object { - "computed": false, - "loc": Object { - "end": Object { - "column": 21, - "line": 5, - }, - "start": Object { - "column": 2, - "line": 5, - }, - }, - "object": Object { + "expression": Object { "computed": false, "loc": Object { "end": Object { - "column": 16, + "column": 21, "line": 5, }, "start": Object { @@ -326,7 +366,7 @@ Object { "computed": false, "loc": Object { "end": Object { - "column": 9, + "column": 16, "line": 5, }, "start": Object { @@ -335,9 +375,10 @@ Object { }, }, "object": Object { + "computed": false, "loc": Object { "end": Object { - "column": 5, + "column": 9, "line": 5, }, "start": Object { @@ -345,87 +386,114 @@ Object { "line": 5, }, }, - "name": "one", + "object": Object { + "loc": Object { + "end": Object { + "column": 5, + "line": 5, + }, + "start": Object { + "column": 2, + "line": 5, + }, + }, + "name": "one", + "range": Array [ + 88, + 91, + ], + "type": "Identifier", + }, + "optional": false, + "property": Object { + "loc": Object { + "end": Object { + "column": 9, + "line": 5, + }, + "start": Object { + "column": 6, + "line": 5, + }, + }, + "name": "two", + "range": Array [ + 92, + 95, + ], + "type": "Identifier", + }, "range": Array [ 88, - 91, + 95, ], - "type": "Identifier", + "type": "MemberExpression", }, - "optional": false, + "optional": true, "property": Object { "loc": Object { "end": Object { - "column": 9, + "column": 16, "line": 5, }, "start": Object { - "column": 6, + "column": 11, "line": 5, }, }, - "name": "two", + "name": "three", "range": Array [ - 92, - 95, + 97, + 102, ], "type": "Identifier", }, "range": Array [ 88, - 95, + 102, ], "type": "MemberExpression", }, - "optional": true, + "optional": false, "property": Object { "loc": Object { "end": Object { - "column": 16, + "column": 21, "line": 5, }, "start": Object { - "column": 11, + "column": 17, "line": 5, }, }, - "name": "three", + "name": "four", "range": Array [ - 97, - 102, + 103, + 107, ], "type": "Identifier", }, "range": Array [ 88, - 102, + 107, ], - "type": "OptionalMemberExpression", + "type": "MemberExpression", }, - "optional": false, - "property": Object { - "loc": Object { - "end": Object { - "column": 21, - "line": 5, - }, - "start": Object { - "column": 17, - "line": 5, - }, + "loc": Object { + "end": Object { + "column": 21, + "line": 5, + }, + "start": Object { + "column": 2, + "line": 5, }, - "name": "four", - "range": Array [ - 103, - 107, - ], - "type": "Identifier", }, "range": Array [ 88, 107, ], - "type": "OptionalMemberExpression", + "type": "ChainExpression", }, "loc": Object { "end": Object { @@ -445,22 +513,11 @@ Object { }, Object { "expression": Object { - "computed": false, - "loc": Object { - "end": Object { - "column": 22, - "line": 6, - }, - "start": Object { - "column": 2, - "line": 6, - }, - }, - "object": Object { + "expression": Object { "computed": false, "loc": Object { "end": Object { - "column": 16, + "column": 22, "line": 6, }, "start": Object { @@ -472,7 +529,7 @@ Object { "computed": false, "loc": Object { "end": Object { - "column": 9, + "column": 16, "line": 6, }, "start": Object { @@ -481,9 +538,10 @@ Object { }, }, "object": Object { + "computed": false, "loc": Object { "end": Object { - "column": 5, + "column": 9, "line": 6, }, "start": Object { @@ -491,35 +549,71 @@ Object { "line": 6, }, }, - "name": "one", + "object": Object { + "loc": Object { + "end": Object { + "column": 5, + "line": 6, + }, + "start": Object { + "column": 2, + "line": 6, + }, + }, + "name": "one", + "range": Array [ + 111, + 114, + ], + "type": "Identifier", + }, + "optional": false, + "property": Object { + "loc": Object { + "end": Object { + "column": 9, + "line": 6, + }, + "start": Object { + "column": 6, + "line": 6, + }, + }, + "name": "two", + "range": Array [ + 115, + 118, + ], + "type": "Identifier", + }, "range": Array [ 111, - 114, + 118, ], - "type": "Identifier", + "type": "MemberExpression", }, - "optional": false, + "optional": true, "property": Object { "loc": Object { "end": Object { - "column": 9, + "column": 16, "line": 6, }, "start": Object { - "column": 6, + "column": 11, "line": 6, }, }, - "name": "two", + "name": "three", "range": Array [ - 115, - 118, + 120, + 125, ], "type": "Identifier", }, "range": Array [ 111, - 118, + 125, ], "type": "MemberExpression", }, @@ -527,51 +621,42 @@ Object { "property": Object { "loc": Object { "end": Object { - "column": 16, + "column": 22, "line": 6, }, "start": Object { - "column": 11, + "column": 18, "line": 6, }, }, - "name": "three", + "name": "four", "range": Array [ - 120, - 125, + 127, + 131, ], "type": "Identifier", }, "range": Array [ 111, - 125, + 131, ], - "type": "OptionalMemberExpression", + "type": "MemberExpression", }, - "optional": true, - "property": Object { - "loc": Object { - "end": Object { - "column": 22, - "line": 6, - }, - "start": Object { - "column": 18, - "line": 6, - }, + "loc": Object { + "end": Object { + "column": 22, + "line": 6, + }, + "start": Object { + "column": 2, + "line": 6, }, - "name": "four", - "range": Array [ - 127, - 131, - ], - "type": "Identifier", }, "range": Array [ 111, 131, ], - "type": "OptionalMemberExpression", + "type": "ChainExpression", }, "loc": Object { "end": Object { diff --git a/packages/typescript-estree/tests/snapshots/typescript/expressions/optional-call-expression-type-arguments.src.ts.shot b/packages/typescript-estree/tests/snapshots/typescript/expressions/optional-call-expression-type-arguments.src.ts.shot index 10586ac70b6..e5c1aeba3c9 100644 --- a/packages/typescript-estree/tests/snapshots/typescript/expressions/optional-call-expression-type-arguments.src.ts.shot +++ b/packages/typescript-estree/tests/snapshots/typescript/expressions/optional-call-expression-type-arguments.src.ts.shot @@ -5,23 +5,13 @@ Object { "body": Array [ Object { "expression": Object { - "arguments": Array [], - "callee": Object { - "computed": false, - "loc": Object { - "end": Object { - "column": 8, - "line": 1, - }, - "start": Object { - "column": 0, - "line": 1, - }, - }, - "object": Object { + "expression": Object { + "arguments": Array [], + "callee": Object { + "computed": false, "loc": Object { "end": Object { - "column": 3, + "column": 8, "line": 1, }, "start": Object { @@ -29,83 +19,78 @@ Object { "line": 1, }, }, - "name": "foo", - "range": Array [ - 0, - 3, - ], - "type": "Identifier", - }, - "optional": true, - "property": Object { - "loc": Object { - "end": Object { - "column": 8, - "line": 1, + "object": Object { + "loc": Object { + "end": Object { + "column": 3, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, }, - "start": Object { - "column": 5, - "line": 1, + "name": "foo", + "range": Array [ + 0, + 3, + ], + "type": "Identifier", + }, + "optional": true, + "property": Object { + "loc": Object { + "end": Object { + "column": 8, + "line": 1, + }, + "start": Object { + "column": 5, + "line": 1, + }, }, + "name": "bar", + "range": Array [ + 5, + 8, + ], + "type": "Identifier", }, - "name": "bar", "range": Array [ - 5, + 0, 8, ], - "type": "Identifier", - }, - "range": Array [ - 0, - 8, - ], - "type": "OptionalMemberExpression", - }, - "loc": Object { - "end": Object { - "column": 13, - "line": 1, - }, - "start": Object { - "column": 0, - "line": 1, + "type": "MemberExpression", }, - }, - "optional": false, - "range": Array [ - 0, - 13, - ], - "type": "OptionalCallExpression", - "typeParameters": Object { "loc": Object { "end": Object { - "column": 11, + "column": 13, "line": 1, }, "start": Object { - "column": 8, + "column": 0, "line": 1, }, }, - "params": Array [ - Object { - "loc": Object { - "end": Object { - "column": 10, - "line": 1, - }, - "start": Object { - "column": 9, - "line": 1, - }, + "optional": false, + "range": Array [ + 0, + 13, + ], + "type": "CallExpression", + "typeParameters": Object { + "loc": Object { + "end": Object { + "column": 11, + "line": 1, }, - "range": Array [ - 9, - 10, - ], - "type": "TSTypeReference", - "typeName": Object { + "start": Object { + "column": 8, + "line": 1, + }, + }, + "params": Array [ + Object { "loc": Object { "end": Object { "column": 10, @@ -116,22 +101,54 @@ Object { "line": 1, }, }, - "name": "A", "range": Array [ 9, 10, ], - "type": "Identifier", + "type": "TSTypeReference", + "typeName": Object { + "loc": Object { + "end": Object { + "column": 10, + "line": 1, + }, + "start": Object { + "column": 9, + "line": 1, + }, + }, + "name": "A", + "range": Array [ + 9, + 10, + ], + "type": "Identifier", + }, + "typeParameters": undefined, }, - "typeParameters": undefined, - }, - ], - "range": Array [ - 8, - 11, - ], - "type": "TSTypeParameterInstantiation", + ], + "range": Array [ + 8, + 11, + ], + "type": "TSTypeParameterInstantiation", + }, + }, + "loc": Object { + "end": Object { + "column": 13, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, }, + "range": Array [ + 0, + 13, + ], + "type": "ChainExpression", }, "loc": Object { "end": Object { @@ -151,23 +168,13 @@ Object { }, Object { "expression": Object { - "arguments": Array [], - "callee": Object { - "computed": false, - "loc": Object { - "end": Object { - "column": 8, - "line": 2, - }, - "start": Object { - "column": 0, - "line": 2, - }, - }, - "object": Object { + "expression": Object { + "arguments": Array [], + "callee": Object { + "computed": false, "loc": Object { "end": Object { - "column": 3, + "column": 8, "line": 2, }, "start": Object { @@ -175,37 +182,101 @@ Object { "line": 2, }, }, - "name": "foo", + "object": Object { + "loc": Object { + "end": Object { + "column": 3, + "line": 2, + }, + "start": Object { + "column": 0, + "line": 2, + }, + }, + "name": "foo", + "range": Array [ + 15, + 18, + ], + "type": "Identifier", + }, + "optional": true, + "property": Object { + "loc": Object { + "end": Object { + "column": 8, + "line": 2, + }, + "start": Object { + "column": 5, + "line": 2, + }, + }, + "name": "bar", + "range": Array [ + 20, + 23, + ], + "type": "Identifier", + }, "range": Array [ 15, - 18, + 23, ], - "type": "Identifier", + "type": "MemberExpression", + }, + "loc": Object { + "end": Object { + "column": 18, + "line": 2, + }, + "start": Object { + "column": 0, + "line": 2, + }, }, - "optional": true, - "property": Object { + "optional": false, + "range": Array [ + 15, + 33, + ], + "type": "CallExpression", + "typeParameters": Object { "loc": Object { "end": Object { - "column": 8, + "column": 16, "line": 2, }, "start": Object { - "column": 5, + "column": 8, "line": 2, }, }, - "name": "bar", + "params": Array [ + Object { + "loc": Object { + "end": Object { + "column": 15, + "line": 2, + }, + "start": Object { + "column": 9, + "line": 2, + }, + }, + "range": Array [ + 24, + 30, + ], + "type": "TSNumberKeyword", + }, + ], "range": Array [ - 20, 23, + 31, ], - "type": "Identifier", + "type": "TSTypeParameterInstantiation", }, - "range": Array [ - 15, - 23, - ], - "type": "OptionalMemberExpression", }, "loc": Object { "end": Object { @@ -217,48 +288,11 @@ Object { "line": 2, }, }, - "optional": false, "range": Array [ 15, 33, ], - "type": "OptionalCallExpression", - "typeParameters": Object { - "loc": Object { - "end": Object { - "column": 16, - "line": 2, - }, - "start": Object { - "column": 8, - "line": 2, - }, - }, - "params": Array [ - Object { - "loc": Object { - "end": Object { - "column": 15, - "line": 2, - }, - "start": Object { - "column": 9, - "line": 2, - }, - }, - "range": Array [ - 24, - 30, - ], - "type": "TSNumberKeyword", - }, - ], - "range": Array [ - 23, - 31, - ], - "type": "TSTypeParameterInstantiation", - }, + "type": "ChainExpression", }, "loc": Object { "end": Object { diff --git a/packages/visitor-keys/package.json b/packages/visitor-keys/package.json index bb45e82f32f..6923dda7431 100644 --- a/packages/visitor-keys/package.json +++ b/packages/visitor-keys/package.json @@ -36,10 +36,11 @@ "typecheck": "tsc -p tsconfig.json --noEmit" }, "dependencies": { - "eslint-visitor-keys": "^1.1.0" + "@typescript-eslint/types": "3.10.1", + "eslint-visitor-keys": "^1.3.0" }, "devDependencies": { - "@typescript-eslint/types": "3.10.1" + "@types/eslint-visitor-keys": "^1.0.0" }, "funding": { "type": "opencollective", diff --git a/packages/visitor-keys/src/get-keys.ts b/packages/visitor-keys/src/get-keys.ts new file mode 100644 index 00000000000..f1219ca196a --- /dev/null +++ b/packages/visitor-keys/src/get-keys.ts @@ -0,0 +1,6 @@ +import { TSESTree } from '@typescript-eslint/types'; +import { getKeys as getKeysOriginal } from 'eslint-visitor-keys'; + +const getKeys: (node: TSESTree.Node) => ReadonlyArray = getKeysOriginal; + +export { getKeys }; diff --git a/packages/visitor-keys/src/index.ts b/packages/visitor-keys/src/index.ts index 24571eff0c3..04aa6515863 100644 --- a/packages/visitor-keys/src/index.ts +++ b/packages/visitor-keys/src/index.ts @@ -1 +1,2 @@ +export { getKeys } from './get-keys'; export { visitorKeys, VisitorKeys } from './visitor-keys'; diff --git a/packages/visitor-keys/src/visitor-keys.ts b/packages/visitor-keys/src/visitor-keys.ts index e71e59d3eec..a8434dcbd4e 100644 --- a/packages/visitor-keys/src/visitor-keys.ts +++ b/packages/visitor-keys/src/visitor-keys.ts @@ -59,8 +59,6 @@ const additionalKeys: AdditionalKeys = { // Additional Nodes. ClassProperty: ['decorators', 'key', 'typeAnnotation', 'value'], Decorator: ['expression'], - OptionalCallExpression: ['callee', 'typeParameters', 'arguments'], - OptionalMemberExpression: ['object', 'property'], // TS-prefixed nodes TSAbstractClassProperty: ['decorators', 'key', 'typeAnnotation', 'value'], diff --git a/yarn.lock b/yarn.lock index dcf99787368..8e3e650c01c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1813,11 +1813,16 @@ acorn@^6.0.1: resolved "https://registry.yarnpkg.com/acorn/-/acorn-6.4.1.tgz#531e58ba3f51b9dacb9a6646ca4debf5b14ca474" integrity sha512-ZVA9k326Nwrj3Cj9jlh3wGFutC2ZornPNARZwsNYqQYgN0EsV2d53w5RN/co65Ohn4sUAUtb1rSUAOD6XN9idA== -acorn@^7.1.0, acorn@^7.2.0: +acorn@^7.1.0: version "7.2.0" resolved "https://registry.yarnpkg.com/acorn/-/acorn-7.2.0.tgz#17ea7e40d7c8640ff54a694c889c26f31704effe" integrity sha512-apwXVmYVpQ34m/i71vrApRrRKCWQnZZF1+npOD0WV5xZFfwWOmKGQ2RWlfdy9vWITsenisM8M0Qeq8agcFHNiQ== +acorn@^7.3.1: + version "7.3.1" + resolved "https://registry.yarnpkg.com/acorn/-/acorn-7.3.1.tgz#85010754db53c3fbaf3b9ea3e083aa5c5d147ffd" + integrity sha512-tLc0wSnatxAQHVHUapaHdz72pi9KUyHjq5KyHjGg9Y8Ifdc79pTh2XvI6I1/chZbnM7QtNKzh66ooDogPZSleA== + agent-base@4, agent-base@^4.3.0: version "4.3.0" resolved "https://registry.yarnpkg.com/agent-base/-/agent-base-4.3.0.tgz#8165f01c436009bccad0b1d122f05ed770efc6ee" @@ -1878,6 +1883,11 @@ ansi-colors@^3.2.1: resolved "https://registry.yarnpkg.com/ansi-colors/-/ansi-colors-3.2.4.tgz#e3a3da4bfbae6c86a9c285625de124a234026fbf" integrity sha512-hHUXGagefjN2iRrID63xckIvotOXOojhQKWIPUZ4mNUZ9nLZW+7FMNoE1lOkEhNWYsx/7ysGIuJYCiMAA9FnrA== +ansi-colors@^4.1.1: + version "4.1.1" + resolved "https://registry.yarnpkg.com/ansi-colors/-/ansi-colors-4.1.1.tgz#cbb9ae256bf750af1eab344f229aa27fe94ba348" + integrity sha512-JoX0apGbHaUJBNl6yF+p6JAFYZ666/hhCGKN5t9QFjbJQKUU/g8MNbFDbvfrgKXvI1QpZplPOnwIo99lX/AAmA== + ansi-escapes@^3.2.0: version "3.2.0" resolved "https://registry.yarnpkg.com/ansi-escapes/-/ansi-escapes-3.2.0.tgz#8780b98ff9dbf5638152d1f1fe5c1d7b4442976b" @@ -3533,6 +3543,13 @@ enquirer@^2.3.4: dependencies: ansi-colors "^3.2.1" +enquirer@^2.3.5: + version "2.3.6" + resolved "https://registry.yarnpkg.com/enquirer/-/enquirer-2.3.6.tgz#2a7fe5dd634a1e4125a975ec994ff5456dc3734d" + integrity sha512-yjNnPr315/FjS4zIsUxYguYUPP2e1NK4d7E7ZOLiyYCcbFBiTMyID+2wvm2w6+pZ/odMA7cRkjhsPbltwBOrLg== + dependencies: + ansi-colors "^4.1.1" + entities@~2.0.0: version "2.0.2" resolved "https://registry.yarnpkg.com/entities/-/entities-2.0.2.tgz#ac74db0bba8d33808bbf36809c3a5c3683531436" @@ -3692,20 +3709,27 @@ eslint-utils@^2.0.0: dependencies: eslint-visitor-keys "^1.1.0" +eslint-utils@^2.1.0: + version "2.1.0" + resolved "https://registry.yarnpkg.com/eslint-utils/-/eslint-utils-2.1.0.tgz#d2de5e03424e707dc10c74068ddedae708741b27" + integrity sha512-w94dQYoauyvlDc43XnGB8lU3Zt713vNChgt4EWwhXAP2XkBvndfxF0AgIqKOOasjPIPzj9JqgwkwbCYD0/V3Zg== + dependencies: + eslint-visitor-keys "^1.1.0" + eslint-visitor-keys@^1.1.0: version "1.1.0" resolved "https://registry.yarnpkg.com/eslint-visitor-keys/-/eslint-visitor-keys-1.1.0.tgz#e2a82cea84ff246ad6fb57f9bde5b46621459ec2" integrity sha512-8y9YjtM1JBJU/A9Kc+SbaOV4y29sSWckBwMHa+FGtVj5gN/sbnKDf6xJUl+8g7FAij9LVaP8C24DUiH/f/2Z9A== -eslint-visitor-keys@^1.2.0: - version "1.2.0" - resolved "https://registry.yarnpkg.com/eslint-visitor-keys/-/eslint-visitor-keys-1.2.0.tgz#74415ac884874495f78ec2a97349525344c981fa" - integrity sha512-WFb4ihckKil6hu3Dp798xdzSfddwKKU3+nGniKF6HfeW6OLd2OUDEPP7TcHtB5+QXOKg2s6B2DaMPE1Nn/kxKQ== +eslint-visitor-keys@^1.3.0: + version "1.3.0" + resolved "https://registry.yarnpkg.com/eslint-visitor-keys/-/eslint-visitor-keys-1.3.0.tgz#30ebd1ef7c2fdff01c3a4f151044af25fab0523e" + integrity sha512-6J72N8UNa462wa/KFODt/PJ3IU60SDpC3QXC1Hjc1BXXpfL2C9R5+AU7jhe0F6GREqVMh4Juu+NY7xn+6dipUQ== -eslint@^7.2.0: - version "7.2.0" - resolved "https://registry.yarnpkg.com/eslint/-/eslint-7.2.0.tgz#d41b2e47804b30dbabb093a967fb283d560082e6" - integrity sha512-B3BtEyaDKC5MlfDa2Ha8/D6DsS4fju95zs0hjS3HdGazw+LNayai38A25qMppK37wWGWNYSPOR6oYzlz5MHsRQ== +eslint@^7.5.0: + version "7.5.0" + resolved "https://registry.yarnpkg.com/eslint/-/eslint-7.5.0.tgz#9ecbfad62216d223b82ac9ffea7ef3444671d135" + integrity sha512-vlUP10xse9sWt9SGRtcr1LAC67BENcQMFeV+w5EvLEoFe3xJ8cF1Skd0msziRx/VMC+72B4DxreCE+OR12OA6Q== dependencies: "@babel/code-frame" "^7.0.0" ajv "^6.10.0" @@ -3713,10 +3737,11 @@ eslint@^7.2.0: cross-spawn "^7.0.2" debug "^4.0.1" doctrine "^3.0.0" + enquirer "^2.3.5" eslint-scope "^5.1.0" - eslint-utils "^2.0.0" - eslint-visitor-keys "^1.2.0" - espree "^7.1.0" + eslint-utils "^2.1.0" + eslint-visitor-keys "^1.3.0" + espree "^7.2.0" esquery "^1.2.0" esutils "^2.0.2" file-entry-cache "^5.0.1" @@ -3726,12 +3751,11 @@ eslint@^7.2.0: ignore "^4.0.6" import-fresh "^3.0.0" imurmurhash "^0.1.4" - inquirer "^7.0.0" is-glob "^4.0.0" js-yaml "^3.13.1" json-stable-stringify-without-jsonify "^1.0.1" levn "^0.4.1" - lodash "^4.17.14" + lodash "^4.17.19" minimatch "^3.0.4" natural-compare "^1.4.0" optionator "^0.9.1" @@ -3744,14 +3768,14 @@ eslint@^7.2.0: text-table "^0.2.0" v8-compile-cache "^2.0.3" -espree@^7.1.0: - version "7.1.0" - resolved "https://registry.yarnpkg.com/espree/-/espree-7.1.0.tgz#a9c7f18a752056735bf1ba14cb1b70adc3a5ce1c" - integrity sha512-dcorZSyfmm4WTuTnE5Y7MEN1DyoPYy1ZR783QW1FJoenn7RailyWFsq/UL6ZAAA7uXurN9FIpYyUs3OfiIW+Qw== +espree@^7.2.0: + version "7.2.0" + resolved "https://registry.yarnpkg.com/espree/-/espree-7.2.0.tgz#1c263d5b513dbad0ac30c4991b93ac354e948d69" + integrity sha512-H+cQ3+3JYRMEIOl87e7QdHX70ocly5iW4+dttuR8iYSPr/hXKFb+7dBsZ7+u1adC4VrnPlTkv0+OwuPnDop19g== dependencies: - acorn "^7.2.0" + acorn "^7.3.1" acorn-jsx "^5.2.0" - eslint-visitor-keys "^1.2.0" + eslint-visitor-keys "^1.3.0" esprima@^2.7.0: version "2.7.3" @@ -4778,7 +4802,7 @@ inquirer@^6.2.0: strip-ansi "^5.1.0" through "^2.3.6" -inquirer@^7.0.0, inquirer@^7.0.4: +inquirer@^7.0.4: version "7.1.0" resolved "https://registry.yarnpkg.com/inquirer/-/inquirer-7.1.0.tgz#1298a01859883e17c7264b82870ae1034f92dd29" integrity sha512-5fJMWEmikSYu0nv/flMc475MhGbB7TSPd/2IpFV4I4rMklboCH2rQjYY5kKiYGHqUF9gvaambupcJFFG9dvReg==