From e85a086672ec0f0614d3d26faa28803bd3976e24 Mon Sep 17 00:00:00 2001 From: Abraham Guo Date: Mon, 15 Apr 2024 18:17:07 -0500 Subject: [PATCH 01/13] remove unused type params --- packages/ast-spec/src/base/ClassBase.ts | 4 ---- packages/ast-spec/src/base/TSHeritageBase.ts | 3 --- packages/ast-spec/src/expression/CallExpression/spec.ts | 4 ---- packages/ast-spec/src/expression/NewExpression/spec.ts | 3 --- .../ast-spec/src/expression/TSInstantiationExpression/spec.ts | 3 --- .../ast-spec/src/expression/TaggedTemplateExpression/spec.ts | 4 ---- packages/ast-spec/src/jsx/JSXOpeningElement/spec.ts | 4 ---- packages/ast-spec/src/type/TSImportType/spec.ts | 3 --- packages/ast-spec/src/type/TSTypeQuery/spec.ts | 3 --- packages/ast-spec/src/type/TSTypeReference/spec.ts | 4 ---- 10 files changed, 35 deletions(-) diff --git a/packages/ast-spec/src/base/ClassBase.ts b/packages/ast-spec/src/base/ClassBase.ts index 595d1393ac48..d96c37deb9fc 100644 --- a/packages/ast-spec/src/base/ClassBase.ts +++ b/packages/ast-spec/src/base/ClassBase.ts @@ -53,10 +53,6 @@ export interface ClassBase extends BaseNode { * The generic type parameters passed to the superClass. */ superTypeArguments: TSTypeParameterInstantiation | undefined; - - /** @deprecated Use {@link `superTypeArguments`} instead. */ - superTypeParameters: TSTypeParameterInstantiation | undefined; - /** * The generic type parameters declared for the class. */ diff --git a/packages/ast-spec/src/base/TSHeritageBase.ts b/packages/ast-spec/src/base/TSHeritageBase.ts index dc7f701f0f1a..8ff7e3a361f8 100644 --- a/packages/ast-spec/src/base/TSHeritageBase.ts +++ b/packages/ast-spec/src/base/TSHeritageBase.ts @@ -6,7 +6,4 @@ export interface TSHeritageBase extends BaseNode { // TODO(#1852) - this should be restricted to MemberExpression | Identifier expression: Expression; typeArguments: TSTypeParameterInstantiation | undefined; - - /** @deprecated Use {@link `typeArguments`} instead. */ - typeParameters: TSTypeParameterInstantiation | undefined; } diff --git a/packages/ast-spec/src/expression/CallExpression/spec.ts b/packages/ast-spec/src/expression/CallExpression/spec.ts index b7569c9892e2..3480b0a1041a 100644 --- a/packages/ast-spec/src/expression/CallExpression/spec.ts +++ b/packages/ast-spec/src/expression/CallExpression/spec.ts @@ -9,9 +9,5 @@ export interface CallExpression extends BaseNode { callee: LeftHandSideExpression; arguments: CallExpressionArgument[]; typeArguments: TSTypeParameterInstantiation | undefined; - - /** @deprecated Use {@link `typeArguments`} instead. */ - typeParameters: TSTypeParameterInstantiation | undefined; - optional: boolean; } diff --git a/packages/ast-spec/src/expression/NewExpression/spec.ts b/packages/ast-spec/src/expression/NewExpression/spec.ts index 51aea284158f..af88c9a5d2b1 100644 --- a/packages/ast-spec/src/expression/NewExpression/spec.ts +++ b/packages/ast-spec/src/expression/NewExpression/spec.ts @@ -9,7 +9,4 @@ export interface NewExpression extends BaseNode { callee: LeftHandSideExpression; arguments: CallExpressionArgument[]; typeArguments: TSTypeParameterInstantiation | undefined; - - /** @deprecated Use {@link `typeArguments`} instead. */ - typeParameters: TSTypeParameterInstantiation | undefined; } diff --git a/packages/ast-spec/src/expression/TSInstantiationExpression/spec.ts b/packages/ast-spec/src/expression/TSInstantiationExpression/spec.ts index 064dd30612f7..2219a440bdf7 100644 --- a/packages/ast-spec/src/expression/TSInstantiationExpression/spec.ts +++ b/packages/ast-spec/src/expression/TSInstantiationExpression/spec.ts @@ -7,7 +7,4 @@ export interface TSInstantiationExpression extends BaseNode { type: AST_NODE_TYPES.TSInstantiationExpression; expression: Expression; typeArguments: TSTypeParameterInstantiation; - - /** @deprecated Use {@link `typeArguments`} instead. */ - typeParameters?: TSTypeParameterInstantiation; } diff --git a/packages/ast-spec/src/expression/TaggedTemplateExpression/spec.ts b/packages/ast-spec/src/expression/TaggedTemplateExpression/spec.ts index b673ca5f0db7..a11bc58325eb 100644 --- a/packages/ast-spec/src/expression/TaggedTemplateExpression/spec.ts +++ b/packages/ast-spec/src/expression/TaggedTemplateExpression/spec.ts @@ -7,10 +7,6 @@ import type { TemplateLiteral } from '../TemplateLiteral/spec'; export interface TaggedTemplateExpression extends BaseNode { type: AST_NODE_TYPES.TaggedTemplateExpression; typeArguments: TSTypeParameterInstantiation | undefined; - - /** @deprecated Use {@link `typeArguments`} instead. */ - typeParameters: TSTypeParameterInstantiation | undefined; - tag: LeftHandSideExpression; quasi: TemplateLiteral; } diff --git a/packages/ast-spec/src/jsx/JSXOpeningElement/spec.ts b/packages/ast-spec/src/jsx/JSXOpeningElement/spec.ts index 1c4ca8af452d..157512bc7908 100644 --- a/packages/ast-spec/src/jsx/JSXOpeningElement/spec.ts +++ b/packages/ast-spec/src/jsx/JSXOpeningElement/spec.ts @@ -8,10 +8,6 @@ import type { JSXSpreadAttribute } from '../JSXSpreadAttribute/spec'; export interface JSXOpeningElement extends BaseNode { type: AST_NODE_TYPES.JSXOpeningElement; typeArguments: TSTypeParameterInstantiation | undefined; - - /** @deprecated Use {@link `typeArguments`} instead. */ - typeParameters: TSTypeParameterInstantiation | undefined; - selfClosing: boolean; name: JSXTagNameExpression; attributes: (JSXAttribute | JSXSpreadAttribute)[]; diff --git a/packages/ast-spec/src/type/TSImportType/spec.ts b/packages/ast-spec/src/type/TSImportType/spec.ts index 3eb30235d9b0..f85074de7154 100644 --- a/packages/ast-spec/src/type/TSImportType/spec.ts +++ b/packages/ast-spec/src/type/TSImportType/spec.ts @@ -9,7 +9,4 @@ export interface TSImportType extends BaseNode { argument: TypeNode; qualifier: EntityName | null; typeArguments: TSTypeParameterInstantiation | null; - - /** @deprecated Use {@link `typeArguments`} instead. */ - typeParameters: TSTypeParameterInstantiation | null; } diff --git a/packages/ast-spec/src/type/TSTypeQuery/spec.ts b/packages/ast-spec/src/type/TSTypeQuery/spec.ts index b6ec9fdf6ec2..e5cad59b9c71 100644 --- a/packages/ast-spec/src/type/TSTypeQuery/spec.ts +++ b/packages/ast-spec/src/type/TSTypeQuery/spec.ts @@ -8,7 +8,4 @@ export interface TSTypeQuery extends BaseNode { type: AST_NODE_TYPES.TSTypeQuery; exprName: EntityName | TSImportType; typeArguments: TSTypeParameterInstantiation | undefined; - - /** @deprecated Use {@link `typeArguments`} instead. */ - typeParameters: TSTypeParameterInstantiation | undefined; } diff --git a/packages/ast-spec/src/type/TSTypeReference/spec.ts b/packages/ast-spec/src/type/TSTypeReference/spec.ts index c7b5b340b2f4..5ffa64e64062 100644 --- a/packages/ast-spec/src/type/TSTypeReference/spec.ts +++ b/packages/ast-spec/src/type/TSTypeReference/spec.ts @@ -6,9 +6,5 @@ import type { EntityName } from '../../unions/EntityName'; export interface TSTypeReference extends BaseNode { type: AST_NODE_TYPES.TSTypeReference; typeArguments: TSTypeParameterInstantiation | undefined; - - /** @deprecated Use {@link `typeArguments`} instead. */ - typeParameters: TSTypeParameterInstantiation | undefined; - typeName: EntityName; } From f6857ec378ba56876d4391a122fa30549eaa9323 Mon Sep 17 00:00:00 2001 From: Abraham Guo Date: Mon, 15 Apr 2024 18:30:57 -0500 Subject: [PATCH 02/13] fix ts errors --- packages/eslint-plugin/src/rules/indent.ts | 2 -- packages/typescript-estree/src/convert.ts | 1 - 2 files changed, 3 deletions(-) diff --git a/packages/eslint-plugin/src/rules/indent.ts b/packages/eslint-plugin/src/rules/indent.ts index 9ebb23d75844..748049994624 100644 --- a/packages/eslint-plugin/src/rules/indent.ts +++ b/packages/eslint-plugin/src/rules/indent.ts @@ -369,7 +369,6 @@ export default createRule({ decorators: [], implements: [], superTypeArguments: undefined, - superTypeParameters: undefined, typeParameters: undefined, // location data @@ -479,7 +478,6 @@ export default createRule({ name: name as any, attributes: attributes as any, typeArguments: undefined, - typeParameters: undefined, // location data parent: node.parent, diff --git a/packages/typescript-estree/src/convert.ts b/packages/typescript-estree/src/convert.ts index 9d068cbf2432..13e698fb34e5 100644 --- a/packages/typescript-estree/src/convert.ts +++ b/packages/typescript-estree/src/convert.ts @@ -2889,7 +2889,6 @@ export class Converter { type: AST_NODE_TYPES.TSTypeQuery, exprName: result, typeArguments: undefined, - typeParameters: undefined, }); } return result; From aad8917fd4eac7d8c8d7e8de6f467494a1a60718 Mon Sep 17 00:00:00 2001 From: Abraham Guo Date: Tue, 16 Apr 2024 07:01:36 -0500 Subject: [PATCH 03/13] update tests --- .../tests/lib/convert.test.ts | 39 +++++++++---------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/packages/typescript-estree/tests/lib/convert.test.ts b/packages/typescript-estree/tests/lib/convert.test.ts index 9988c969b6a7..a9cfed1cc4f0 100644 --- a/packages/typescript-estree/tests/lib/convert.test.ts +++ b/packages/typescript-estree/tests/lib/convert.test.ts @@ -279,12 +279,11 @@ describe('convert', () => { }); describe('suppressDeprecatedPropertyWarnings', () => { - const getEsCallExpression = ( + const getEsImportDeclaration = ( converterOptions?: ConverterOptions, - ): TSESTree.CallExpression => { - const ast = convertCode(`callee();`); - const tsCallExpression = (ast.statements[0] as ts.ExpressionStatement) - .expression as ts.CallExpression; + ): TSESTree.ImportDeclaration => { + const ast = convertCode('import ""'); + const tsImportDeclaration = ast.statements[0] as ts.ImportDeclaration; const instance = new Converter(ast, { shouldPreserveNodeMaps: true, ...converterOptions, @@ -294,22 +293,22 @@ describe('convert', () => { const maps = instance.getASTMaps(); - return maps.tsNodeToESTreeNodeMap.get(tsCallExpression); + return maps.tsNodeToESTreeNodeMap.get(tsImportDeclaration); }; it('warns on a deprecated property access when suppressDeprecatedPropertyWarnings is false', () => { const emitWarning = jest .spyOn(process, 'emitWarning') .mockImplementation(); - const esCallExpression = getEsCallExpression({ + const esImportDeclaration = getEsImportDeclaration({ suppressDeprecatedPropertyWarnings: false, }); // eslint-disable-next-line deprecation/deprecation - esCallExpression.typeParameters; + esImportDeclaration.assertions; expect(emitWarning).toHaveBeenCalledWith( - `The 'typeParameters' property is deprecated on CallExpression nodes. Use 'typeArguments' instead. See https://typescript-eslint.io/linting/troubleshooting#the-key-property-is-deprecated-on-type-nodes-use-key-instead-warnings.`, + `The 'assertions' property is deprecated on CallExpression nodes. Use 'attributes' instead. See https://typescript-eslint.io/linting/troubleshooting#the-key-property-is-deprecated-on-type-nodes-use-key-instead-warnings.`, 'DeprecationWarning', ); }); @@ -318,13 +317,13 @@ describe('convert', () => { const emitWarning = jest .spyOn(process, 'emitWarning') .mockImplementation(); - const esCallExpression = getEsCallExpression({ + const esImportDeclaration = getEsImportDeclaration({ suppressDeprecatedPropertyWarnings: false, }); /* eslint-disable deprecation/deprecation */ - esCallExpression.typeParameters; - esCallExpression.typeParameters; + esImportDeclaration.assertions; + esImportDeclaration.assertions; /* eslint-enable deprecation/deprecation */ expect(emitWarning).toHaveBeenCalledTimes(1); @@ -334,31 +333,31 @@ describe('convert', () => { const emitWarning = jest .spyOn(process, 'emitWarning') .mockImplementation(); - const esCallExpression = getEsCallExpression({ + const esImportDeclaration = getEsImportDeclaration({ suppressDeprecatedPropertyWarnings: true, }); // eslint-disable-next-line deprecation/deprecation - esCallExpression.typeParameters; + esImportDeclaration.assertions; expect(emitWarning).not.toHaveBeenCalled(); }); it('does not allow enumeration of deprecated properties', () => { - const esCallExpression = getEsCallExpression(); + const esImportDeclaration = getEsImportDeclaration(); - expect(Object.keys(esCallExpression)).not.toContain('typeParameters'); + expect(Object.keys(esImportDeclaration)).not.toContain('assertions'); }); it('allows writing to the deprecated property as a new enumerable value', () => { - const esCallExpression = getEsCallExpression(); + const esImportDeclaration = getEsImportDeclaration(); // eslint-disable-next-line deprecation/deprecation - esCallExpression.typeParameters = undefined; + esImportDeclaration.assertions = []; // eslint-disable-next-line deprecation/deprecation - expect(esCallExpression.typeParameters).toBeUndefined(); - expect(Object.keys(esCallExpression)).toContain('typeParameters'); + expect(esImportDeclaration.assertions).toBeUndefined(); + expect(Object.keys(esImportDeclaration)).toContain('assertions'); }); }); }); From 81b6a2bb537873fe991fee3d86352ae8ad632f73 Mon Sep 17 00:00:00 2001 From: Abraham Guo Date: Tue, 16 Apr 2024 07:25:44 -0500 Subject: [PATCH 04/13] update message --- packages/typescript-estree/tests/lib/convert.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/typescript-estree/tests/lib/convert.test.ts b/packages/typescript-estree/tests/lib/convert.test.ts index a9cfed1cc4f0..05882bf56e0d 100644 --- a/packages/typescript-estree/tests/lib/convert.test.ts +++ b/packages/typescript-estree/tests/lib/convert.test.ts @@ -308,7 +308,7 @@ describe('convert', () => { esImportDeclaration.assertions; expect(emitWarning).toHaveBeenCalledWith( - `The 'assertions' property is deprecated on CallExpression nodes. Use 'attributes' instead. See https://typescript-eslint.io/linting/troubleshooting#the-key-property-is-deprecated-on-type-nodes-use-key-instead-warnings.`, + `The 'assertions' property is deprecated on ImportDeclaration nodes. Use 'attributes' instead. See https://typescript-eslint.io/linting/troubleshooting#the-key-property-is-deprecated-on-type-nodes-use-key-instead-warnings.`, 'DeprecationWarning', ); }); From ac7f0e26dac46e2404a92748fbe9d27c7b805412 Mon Sep 17 00:00:00 2001 From: Abraham Guo Date: Mon, 22 Apr 2024 21:01:06 -0500 Subject: [PATCH 05/13] remove deprecated aliases --- packages/typescript-estree/src/convert.ts | 317 +++++++++------------- 1 file changed, 121 insertions(+), 196 deletions(-) diff --git a/packages/typescript-estree/src/convert.ts b/packages/typescript-estree/src/convert.ts index 13e698fb34e5..7fcc952b7d70 100644 --- a/packages/typescript-estree/src/convert.ts +++ b/packages/typescript-estree/src/convert.ts @@ -504,11 +504,6 @@ export class Converter { node, ) : null; - this.#withDeprecatedAliasGetter( - result, - 'typeParameters', - 'typeArguments', - ); } if ('typeParameters' in node) { result.typeParameters = @@ -1631,24 +1626,17 @@ export class Converter { } case SyntaxKind.TaggedTemplateExpression: - return this.createNode( - node, - this.#withDeprecatedAliasGetter( - { - type: AST_NODE_TYPES.TaggedTemplateExpression, - typeArguments: - node.typeArguments && - this.convertTypeArgumentsToTypeParameterInstantiation( - node.typeArguments, - node, - ), - tag: this.convertChild(node.tag), - quasi: this.convertChild(node.template), - }, - 'typeParameters', - 'typeArguments', - ), - ); + return this.createNode(node, { + type: AST_NODE_TYPES.TaggedTemplateExpression, + typeArguments: + node.typeArguments && + this.convertTypeArgumentsToTypeParameterInstantiation( + node.typeArguments, + node, + ), + tag: this.convertChild(node.tag), + quasi: this.convertChild(node.template), + }); case SyntaxKind.TemplateHead: case SyntaxKind.TemplateMiddle: @@ -1825,39 +1813,32 @@ export class Converter { const result = this.createNode< TSESTree.ClassDeclaration | TSESTree.ClassExpression - >( - node, - this.#withDeprecatedAliasGetter( - { - type: classNodeType, - abstract: hasModifier(SyntaxKind.AbstractKeyword, node), - body: this.createNode(node, { - type: AST_NODE_TYPES.ClassBody, - body: node.members - .filter(isESTreeClassMember) - .map(el => this.convertChild(el)), - range: [node.members.pos - 1, node.end], - }), - declare: hasModifier(SyntaxKind.DeclareKeyword, node), - decorators: - getDecorators(node)?.map(el => this.convertChild(el)) ?? [], - id: this.convertChild(node.name), - implements: - implementsClause?.types.map(el => this.convertChild(el)) ?? [], - superClass: extendsClause?.types[0] - ? this.convertChild(extendsClause.types[0].expression) - : null, - superTypeArguments: undefined, - typeParameters: - node.typeParameters && - this.convertTSTypeParametersToTypeParametersDeclaration( - node.typeParameters, - ), - }, - 'superTypeParameters', - 'superTypeArguments', - ), - ); + >(node, { + type: classNodeType, + abstract: hasModifier(SyntaxKind.AbstractKeyword, node), + body: this.createNode(node, { + type: AST_NODE_TYPES.ClassBody, + body: node.members + .filter(isESTreeClassMember) + .map(el => this.convertChild(el)), + range: [node.members.pos - 1, node.end], + }), + declare: hasModifier(SyntaxKind.DeclareKeyword, node), + decorators: + getDecorators(node)?.map(el => this.convertChild(el)) ?? [], + id: this.convertChild(node.name), + implements: + implementsClause?.types.map(el => this.convertChild(el)) ?? [], + superClass: extendsClause?.types[0] + ? this.convertChild(extendsClause.types[0].expression) + : null, + superTypeArguments: undefined, + typeParameters: + node.typeParameters && + this.convertTSTypeParametersToTypeParametersDeclaration( + node.typeParameters, + ), + }); if (extendsClause?.types[0]?.typeArguments) { result.superTypeArguments = @@ -2198,20 +2179,13 @@ export class Converter { node, ); - const result = this.createNode( - node, - this.#withDeprecatedAliasGetter( - { - type: AST_NODE_TYPES.CallExpression, - callee, - arguments: args, - optional: node.questionDotToken !== undefined, - typeArguments, - }, - 'typeParameters', - 'typeArguments', - ), - ); + const result = this.createNode(node, { + type: AST_NODE_TYPES.CallExpression, + callee, + arguments: args, + optional: node.questionDotToken !== undefined, + typeArguments, + }); return this.convertChainExpression(result, node); } @@ -2225,21 +2199,14 @@ export class Converter { ); // NOTE - NewExpression cannot have an optional chain in it - return this.createNode( - node, - this.#withDeprecatedAliasGetter( - { - type: AST_NODE_TYPES.NewExpression, - arguments: node.arguments - ? node.arguments.map(el => this.convertChild(el)) - : [], - callee: this.convertChild(node.expression), - typeArguments, - }, - 'typeParameters', - 'typeArguments', - ), - ); + return this.createNode(node, { + type: AST_NODE_TYPES.NewExpression, + arguments: node.arguments + ? node.arguments.map(el => this.convertChild(el)) + : [], + callee: this.convertChild(node.expression), + typeArguments, + }); } case SyntaxKind.ConditionalExpression: @@ -2394,55 +2361,41 @@ export class Converter { * Convert SyntaxKind.JsxSelfClosingElement to SyntaxKind.JsxOpeningElement, * TypeScript does not seem to have the idea of openingElement when tag is self-closing */ - openingElement: this.createNode( - node, - this.#withDeprecatedAliasGetter( - { - type: AST_NODE_TYPES.JSXOpeningElement, - typeArguments: node.typeArguments - ? this.convertTypeArgumentsToTypeParameterInstantiation( - node.typeArguments, - node, - ) - : undefined, - selfClosing: true, - name: this.convertJSXTagName(node.tagName, node), - attributes: node.attributes.properties.map(el => - this.convertChild(el), - ), - range: getRange(node, this.ast), - }, - 'typeParameters', - 'typeArguments', + openingElement: this.createNode(node, { + type: AST_NODE_TYPES.JSXOpeningElement, + typeArguments: node.typeArguments + ? this.convertTypeArgumentsToTypeParameterInstantiation( + node.typeArguments, + node, + ) + : undefined, + selfClosing: true, + name: this.convertJSXTagName(node.tagName, node), + attributes: node.attributes.properties.map(el => + this.convertChild(el), ), - ), + range: getRange(node, this.ast), + }), closingElement: null, children: [], }); } case SyntaxKind.JsxOpeningElement: { - return this.createNode( - node, - this.#withDeprecatedAliasGetter( - { - type: AST_NODE_TYPES.JSXOpeningElement, - typeArguments: - node.typeArguments && - this.convertTypeArgumentsToTypeParameterInstantiation( - node.typeArguments, - node, - ), - selfClosing: false, - name: this.convertJSXTagName(node.tagName, node), - attributes: node.attributes.properties.map(el => - this.convertChild(el), - ), - }, - 'typeParameters', - 'typeArguments', + return this.createNode(node, { + type: AST_NODE_TYPES.JSXOpeningElement, + typeArguments: + node.typeArguments && + this.convertTypeArgumentsToTypeParameterInstantiation( + node.typeArguments, + node, + ), + selfClosing: false, + name: this.convertJSXTagName(node.tagName, node), + attributes: node.attributes.properties.map(el => + this.convertChild(el), ), - ); + }); } case SyntaxKind.JsxClosingElement: @@ -2519,23 +2472,16 @@ export class Converter { // TypeScript specific case SyntaxKind.TypeReference: - return this.createNode( - node, - this.#withDeprecatedAliasGetter( - { - type: AST_NODE_TYPES.TSTypeReference, - typeName: this.convertChild(node.typeName), - typeArguments: - node.typeArguments && - this.convertTypeArgumentsToTypeParameterInstantiation( - node.typeArguments, - node, - ), - }, - 'typeParameters', - 'typeArguments', - ), - ); + return this.createNode(node, { + type: AST_NODE_TYPES.TSTypeReference, + typeName: this.convertChild(node.typeName), + typeArguments: + node.typeArguments && + this.convertTypeArgumentsToTypeParameterInstantiation( + node.typeArguments, + node, + ), + }); case SyntaxKind.TypeParameter: { return this.createNode(node, { @@ -2613,23 +2559,16 @@ export class Converter { } case SyntaxKind.TypeQuery: - return this.createNode( - node, - this.#withDeprecatedAliasGetter( - { - type: AST_NODE_TYPES.TSTypeQuery, - exprName: this.convertChild(node.exprName), - typeArguments: - node.typeArguments && - this.convertTypeArgumentsToTypeParameterInstantiation( - node.typeArguments, - node, - ), - }, - 'typeParameters', - 'typeArguments', - ), - ); + return this.createNode(node, { + type: AST_NODE_TYPES.TSTypeQuery, + exprName: this.convertChild(node.exprName), + typeArguments: + node.typeArguments && + this.convertTypeArgumentsToTypeParameterInstantiation( + node.typeArguments, + node, + ), + }); case SyntaxKind.MappedType: { if (node.members && node.members.length > 0) { @@ -2776,23 +2715,16 @@ export class Converter { | TSESTree.TSClassImplements | TSESTree.TSInstantiationExpression | TSESTree.TSInterfaceHeritage - >( - node, - this.#withDeprecatedAliasGetter( - { - type, - expression: this.convertChild(node.expression), - typeArguments: - node.typeArguments && - this.convertTypeArgumentsToTypeParameterInstantiation( - node.typeArguments, - node, - ), - }, - 'typeParameters', - 'typeArguments', - ), - ); + >(node, { + type, + expression: this.convertChild(node.expression), + typeArguments: + node.typeArguments && + this.convertTypeArgumentsToTypeParameterInstantiation( + node.typeArguments, + node, + ), + }); } case SyntaxKind.InterfaceDeclaration: { @@ -2864,25 +2796,18 @@ export class Converter { const token = findNextToken(node.getFirstToken()!, node, this.ast)!; range[0] = token.getStart(this.ast); } - const result = this.createNode( - node, - this.#withDeprecatedAliasGetter( - { - type: AST_NODE_TYPES.TSImportType, - argument: this.convertChild(node.argument), - qualifier: this.convertChild(node.qualifier), - typeArguments: node.typeArguments - ? this.convertTypeArgumentsToTypeParameterInstantiation( - node.typeArguments, - node, - ) - : null, - range: range, - }, - 'typeParameters', - 'typeArguments', - ), - ); + const result = this.createNode(node, { + type: AST_NODE_TYPES.TSImportType, + argument: this.convertChild(node.argument), + qualifier: this.convertChild(node.qualifier), + typeArguments: node.typeArguments + ? this.convertTypeArgumentsToTypeParameterInstantiation( + node.typeArguments, + node, + ) + : null, + range: range, + }); if (node.isTypeOf) { return this.createNode(node, { From 2ebf76cc7383e8d7dc5059ec559108efa47eb08b Mon Sep 17 00:00:00 2001 From: Abraham Guo Date: Tue, 23 Apr 2024 06:28:41 -0500 Subject: [PATCH 06/13] remove outdated tests --- .../tests/lib/convert.test.ts | 47 ------------------- 1 file changed, 47 deletions(-) diff --git a/packages/typescript-estree/tests/lib/convert.test.ts b/packages/typescript-estree/tests/lib/convert.test.ts index 05882bf56e0d..f6edceb894b9 100644 --- a/packages/typescript-estree/tests/lib/convert.test.ts +++ b/packages/typescript-estree/tests/lib/convert.test.ts @@ -296,53 +296,6 @@ describe('convert', () => { return maps.tsNodeToESTreeNodeMap.get(tsImportDeclaration); }; - it('warns on a deprecated property access when suppressDeprecatedPropertyWarnings is false', () => { - const emitWarning = jest - .spyOn(process, 'emitWarning') - .mockImplementation(); - const esImportDeclaration = getEsImportDeclaration({ - suppressDeprecatedPropertyWarnings: false, - }); - - // eslint-disable-next-line deprecation/deprecation - esImportDeclaration.assertions; - - expect(emitWarning).toHaveBeenCalledWith( - `The 'assertions' property is deprecated on ImportDeclaration nodes. Use 'attributes' instead. See https://typescript-eslint.io/linting/troubleshooting#the-key-property-is-deprecated-on-type-nodes-use-key-instead-warnings.`, - 'DeprecationWarning', - ); - }); - - it('does not warn on a subsequent deprecated property access when suppressDeprecatedPropertyWarnings is false', () => { - const emitWarning = jest - .spyOn(process, 'emitWarning') - .mockImplementation(); - const esImportDeclaration = getEsImportDeclaration({ - suppressDeprecatedPropertyWarnings: false, - }); - - /* eslint-disable deprecation/deprecation */ - esImportDeclaration.assertions; - esImportDeclaration.assertions; - /* eslint-enable deprecation/deprecation */ - - expect(emitWarning).toHaveBeenCalledTimes(1); - }); - - it('does not warn on a deprecated property access when suppressDeprecatedPropertyWarnings is true', () => { - const emitWarning = jest - .spyOn(process, 'emitWarning') - .mockImplementation(); - const esImportDeclaration = getEsImportDeclaration({ - suppressDeprecatedPropertyWarnings: true, - }); - - // eslint-disable-next-line deprecation/deprecation - esImportDeclaration.assertions; - - expect(emitWarning).not.toHaveBeenCalled(); - }); - it('does not allow enumeration of deprecated properties', () => { const esImportDeclaration = getEsImportDeclaration(); From 12ace2313b2f914221387d0c6549d1317329c139 Mon Sep 17 00:00:00 2001 From: Abraham Guo Date: Tue, 23 Apr 2024 07:27:36 -0500 Subject: [PATCH 07/13] turn off prop types --- eslint.config.mjs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/eslint.config.mjs b/eslint.config.mjs index bb2c0c491044..3e8bee66af13 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -513,6 +513,10 @@ export default tseslint.config( 'react/jsx-no-target-blank': 'off', 'react/no-unescaped-entities': 'off', 'react-hooks/exhaustive-deps': 'warn', // TODO: enable it later + /* This rule + (1) causes false reports because it reads from `typeParameters` rather than `typeArguments`, and + (2) is unnecessary in TypeScript components */ + 'react/prop-types': 'off', }, settings: { react: { From ccc1e5c925f132dd362490d2e6145a30d780f761 Mon Sep 17 00:00:00 2001 From: Abraham Guo Date: Thu, 25 Apr 2024 07:20:15 -0500 Subject: [PATCH 08/13] change to different deprecated property --- .../tests/lib/convert.test.ts | 55 +++++++++---------- 1 file changed, 26 insertions(+), 29 deletions(-) diff --git a/packages/typescript-estree/tests/lib/convert.test.ts b/packages/typescript-estree/tests/lib/convert.test.ts index 640a3d9946ab..d5f5fb3aad1f 100644 --- a/packages/typescript-estree/tests/lib/convert.test.ts +++ b/packages/typescript-estree/tests/lib/convert.test.ts @@ -279,12 +279,11 @@ describe('convert', () => { }); describe('suppressDeprecatedPropertyWarnings', () => { - const getEsCallExpression = ( + const getEsTsEnumDeclaration = ( converterOptions?: ConverterOptions, - ): TSESTree.CallExpression => { - const ast = convertCode(`callee();`); - const tsCallExpression = (ast.statements[0] as ts.ExpressionStatement) - .expression as ts.CallExpression; + ): TSESTree.TSEnumDeclaration => { + const ast = convertCode(`enum E {}`); + const tsEnumDeclaration = ast.statements[0] as ts.EnumDeclaration; const instance = new Converter(ast, { shouldPreserveNodeMaps: true, ...converterOptions, @@ -294,10 +293,10 @@ describe('convert', () => { const maps = instance.getASTMaps(); - return maps.tsNodeToESTreeNodeMap.get(tsCallExpression); + return maps.tsNodeToESTreeNodeMap.get(tsEnumDeclaration); }; - const getTsMappedType = ( + const getEsTsMappedType = ( converterOptions?: ConverterOptions, ): TSESTree.TSMappedType => { const ast = convertCode(` @@ -314,24 +313,22 @@ describe('convert', () => { instance.convertProgram(); - const maps = instance.getASTMaps(); - - return maps.tsNodeToESTreeNodeMap.get(tsMappedType); + return instance.getASTMaps().tsNodeToESTreeNodeMap.get(tsMappedType); }; it('warns on a deprecated aliased property access when suppressDeprecatedPropertyWarnings is false', () => { const emitWarning = jest .spyOn(process, 'emitWarning') .mockImplementation(); - const esCallExpression = getEsCallExpression({ + const esTsEnumDeclaration = getEsTsEnumDeclaration({ suppressDeprecatedPropertyWarnings: false, }); // eslint-disable-next-line deprecation/deprecation - esCallExpression.typeParameters; + esTsEnumDeclaration.members; expect(emitWarning).toHaveBeenCalledWith( - `The 'typeParameters' property is deprecated on CallExpression nodes. Use 'typeArguments' instead. See https://typescript-eslint.io/linting/troubleshooting#the-key-property-is-deprecated-on-type-nodes-use-key-instead-warnings.`, + `The 'members' property is deprecated on CallExpression nodes. Use 'typeArguments' instead. See https://typescript-eslint.io/linting/troubleshooting#the-key-property-is-deprecated-on-type-nodes-use-key-instead-warnings.`, 'DeprecationWarning', ); }); @@ -340,13 +337,13 @@ describe('convert', () => { const emitWarning = jest .spyOn(process, 'emitWarning') .mockImplementation(); - const esCallExpression = getEsCallExpression({ + const esTsEnumDeclaration = getEsTsEnumDeclaration({ suppressDeprecatedPropertyWarnings: false, }); /* eslint-disable deprecation/deprecation */ - esCallExpression.typeParameters; - esCallExpression.typeParameters; + esTsEnumDeclaration.members; + esTsEnumDeclaration.members; /* eslint-enable deprecation/deprecation */ expect(emitWarning).toHaveBeenCalledTimes(1); @@ -356,38 +353,38 @@ describe('convert', () => { const emitWarning = jest .spyOn(process, 'emitWarning') .mockImplementation(); - const esCallExpression = getEsCallExpression({ + const esTsEnumDeclaration = getEsTsEnumDeclaration({ suppressDeprecatedPropertyWarnings: true, }); // eslint-disable-next-line deprecation/deprecation - esCallExpression.typeParameters; + esTsEnumDeclaration.members; expect(emitWarning).not.toHaveBeenCalled(); }); it('does not allow enumeration of deprecated aliased properties', () => { - const esCallExpression = getEsCallExpression(); + const esTsEnumDeclaration = getEsTsEnumDeclaration(); - expect(Object.keys(esCallExpression)).not.toContain('typeParameters'); + expect(Object.keys(esTsEnumDeclaration)).not.toContain('members'); }); it('allows writing to the deprecated aliased property as a new enumerable value', () => { - const esCallExpression = getEsCallExpression(); + const esTsEnumDeclaration = getEsTsEnumDeclaration(); // eslint-disable-next-line deprecation/deprecation - esCallExpression.typeParameters = undefined; + esTsEnumDeclaration.members = []; // eslint-disable-next-line deprecation/deprecation - expect(esCallExpression.typeParameters).toBeUndefined(); - expect(Object.keys(esCallExpression)).toContain('typeParameters'); + expect(esTsEnumDeclaration.members).toBeUndefined(); + expect(Object.keys(esTsEnumDeclaration)).toContain('members'); }); it('warns on a deprecated getter property access when suppressDeprecatedPropertyWarnings is false', () => { const emitWarning = jest .spyOn(process, 'emitWarning') .mockImplementation(); - const tsMappedType = getTsMappedType({ + const tsMappedType = getEsTsMappedType({ suppressDeprecatedPropertyWarnings: false, }); @@ -404,7 +401,7 @@ describe('convert', () => { const emitWarning = jest .spyOn(process, 'emitWarning') .mockImplementation(); - const tsMappedType = getTsMappedType({ + const tsMappedType = getEsTsMappedType({ suppressDeprecatedPropertyWarnings: false, }); @@ -420,7 +417,7 @@ describe('convert', () => { const emitWarning = jest .spyOn(process, 'emitWarning') .mockImplementation(); - const tsMappedType = getTsMappedType({ + const tsMappedType = getEsTsMappedType({ suppressDeprecatedPropertyWarnings: true, }); @@ -431,13 +428,13 @@ describe('convert', () => { }); it('does not allow enumeration of deprecated getter properties', () => { - const tsMappedType = getTsMappedType(); + const tsMappedType = getEsTsMappedType(); expect(Object.keys(tsMappedType)).not.toContain('typeParameter'); }); it('allows writing to the deprecated getter property as a new enumerable value', () => { - const tsMappedType = getTsMappedType(); + const tsMappedType = getEsTsMappedType(); // eslint-disable-next-line deprecation/deprecation tsMappedType.typeParameter = undefined!; From 3f9f6301245c5256fa2791c2929b2101a0216f8d Mon Sep 17 00:00:00 2001 From: Abraham Guo Date: Thu, 25 Apr 2024 07:28:57 -0500 Subject: [PATCH 09/13] refactor --- .../tests/lib/convert.test.ts | 65 +++++++++---------- 1 file changed, 30 insertions(+), 35 deletions(-) diff --git a/packages/typescript-estree/tests/lib/convert.test.ts b/packages/typescript-estree/tests/lib/convert.test.ts index d5f5fb3aad1f..f5d30aad9b69 100644 --- a/packages/typescript-estree/tests/lib/convert.test.ts +++ b/packages/typescript-estree/tests/lib/convert.test.ts @@ -279,42 +279,37 @@ describe('convert', () => { }); describe('suppressDeprecatedPropertyWarnings', () => { - const getEsTsEnumDeclaration = ( - converterOptions?: ConverterOptions, - ): TSESTree.TSEnumDeclaration => { - const ast = convertCode(`enum E {}`); - const tsEnumDeclaration = ast.statements[0] as ts.EnumDeclaration; - const instance = new Converter(ast, { - shouldPreserveNodeMaps: true, - ...converterOptions, - }); - - instance.convertProgram(); - - const maps = instance.getASTMaps(); - - return maps.tsNodeToESTreeNodeMap.get(tsEnumDeclaration); - }; - - const getEsTsMappedType = ( - converterOptions?: ConverterOptions, - ): TSESTree.TSMappedType => { - const ast = convertCode(` - type MappedType = { - [Key in Type]: Value; - }; - `); - const tsMappedType = (ast.statements[0] as ts.TypeAliasDeclaration) - .type as ts.MappedTypeNode; - const instance = new Converter(ast, { - shouldPreserveNodeMaps: true, - ...converterOptions, - }); - - instance.convertProgram(); + const makeNodeGetter = + ( + code: string, + tsToEsNode: (statement: S) => TSNode, + ) => + (converterOptions?: ConverterOptions): T => { + const ast = convertCode(code); + const instance = new Converter(ast, { + shouldPreserveNodeMaps: true, + ...converterOptions, + }); + + instance.convertProgram(); + + return instance + .getASTMaps() + .tsNodeToESTreeNodeMap.get(tsToEsNode(ast.statements[0] as S)); + }; - return instance.getASTMaps().tsNodeToESTreeNodeMap.get(tsMappedType); - }; + const getEsTsEnumDeclaration = makeNodeGetter< + ts.EnumDeclaration, + TSESTree.TSEnumDeclaration + >('enum Enum {}', enumDeclaration => enumDeclaration); + + const getEsTsMappedType = makeNodeGetter< + ts.TypeAliasDeclaration, + TSESTree.TSMappedType + >( + 'type MappedType = { [Key in Type]: Value };', + ({ type }) => type as ts.MappedTypeNode, + ); it('warns on a deprecated aliased property access when suppressDeprecatedPropertyWarnings is false', () => { const emitWarning = jest From 9e8433f49c34db70c065b69957e7c832863731cd Mon Sep 17 00:00:00 2001 From: Abraham Guo Date: Thu, 25 Apr 2024 07:30:48 -0500 Subject: [PATCH 10/13] change message --- packages/typescript-estree/tests/lib/convert.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/typescript-estree/tests/lib/convert.test.ts b/packages/typescript-estree/tests/lib/convert.test.ts index f5d30aad9b69..ca3da030ad3d 100644 --- a/packages/typescript-estree/tests/lib/convert.test.ts +++ b/packages/typescript-estree/tests/lib/convert.test.ts @@ -323,7 +323,7 @@ describe('convert', () => { esTsEnumDeclaration.members; expect(emitWarning).toHaveBeenCalledWith( - `The 'members' property is deprecated on CallExpression nodes. Use 'typeArguments' instead. See https://typescript-eslint.io/linting/troubleshooting#the-key-property-is-deprecated-on-type-nodes-use-key-instead-warnings.`, + `The 'members' property is deprecated on CallExpression nodes. Use 'body.members' instead. See https://typescript-eslint.io/linting/troubleshooting#the-key-property-is-deprecated-on-type-nodes-use-key-instead-warnings.`, 'DeprecationWarning', ); }); From 6d0bde982ee469b6f14db55b523cf3ec509525cc Mon Sep 17 00:00:00 2001 From: Abraham Guo Date: Thu, 25 Apr 2024 07:38:53 -0500 Subject: [PATCH 11/13] change message --- packages/typescript-estree/tests/lib/convert.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/typescript-estree/tests/lib/convert.test.ts b/packages/typescript-estree/tests/lib/convert.test.ts index ca3da030ad3d..a57e24187745 100644 --- a/packages/typescript-estree/tests/lib/convert.test.ts +++ b/packages/typescript-estree/tests/lib/convert.test.ts @@ -323,7 +323,7 @@ describe('convert', () => { esTsEnumDeclaration.members; expect(emitWarning).toHaveBeenCalledWith( - `The 'members' property is deprecated on CallExpression nodes. Use 'body.members' instead. See https://typescript-eslint.io/linting/troubleshooting#the-key-property-is-deprecated-on-type-nodes-use-key-instead-warnings.`, + `The 'members' property is deprecated on TSEnumDeclaration nodes. Use 'body.members' instead. See https://typescript-eslint.io/linting/troubleshooting#the-key-property-is-deprecated-on-type-nodes-use-key-instead-warnings.`, 'DeprecationWarning', ); }); From da3fc57c8d9a2297229c09f31583636dce4f24f3 Mon Sep 17 00:00:00 2001 From: Abraham Guo Date: Thu, 25 Apr 2024 09:23:24 -0500 Subject: [PATCH 12/13] empty array --- packages/typescript-estree/tests/lib/convert.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/typescript-estree/tests/lib/convert.test.ts b/packages/typescript-estree/tests/lib/convert.test.ts index a57e24187745..04cdecac39ab 100644 --- a/packages/typescript-estree/tests/lib/convert.test.ts +++ b/packages/typescript-estree/tests/lib/convert.test.ts @@ -301,7 +301,7 @@ describe('convert', () => { const getEsTsEnumDeclaration = makeNodeGetter< ts.EnumDeclaration, TSESTree.TSEnumDeclaration - >('enum Enum {}', enumDeclaration => enumDeclaration); + >('enum Enum { A }', enumDeclaration => enumDeclaration); const getEsTsMappedType = makeNodeGetter< ts.TypeAliasDeclaration, @@ -371,7 +371,7 @@ describe('convert', () => { esTsEnumDeclaration.members = []; // eslint-disable-next-line deprecation/deprecation - expect(esTsEnumDeclaration.members).toBeUndefined(); + expect(esTsEnumDeclaration.members).toEqual([]); expect(Object.keys(esTsEnumDeclaration)).toContain('members'); }); From 95d71899775eb4fdbe822b1c2494e1586c74a5d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Josh=20Goldberg=20=E2=9C=A8?= Date: Fri, 24 May 2024 11:34:14 +0300 Subject: [PATCH 13/13] Update eslint.config.mjs --- eslint.config.mjs | 3 --- 1 file changed, 3 deletions(-) diff --git a/eslint.config.mjs b/eslint.config.mjs index 3e8bee66af13..338aeb05a7d2 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -513,9 +513,6 @@ export default tseslint.config( 'react/jsx-no-target-blank': 'off', 'react/no-unescaped-entities': 'off', 'react-hooks/exhaustive-deps': 'warn', // TODO: enable it later - /* This rule - (1) causes false reports because it reads from `typeParameters` rather than `typeArguments`, and - (2) is unnecessary in TypeScript components */ 'react/prop-types': 'off', }, settings: { pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy