Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ast-spec): remove deprecated type params #8933

Merged
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 0 additions & 4 deletions packages/ast-spec/src/base/ClassBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
3 changes: 0 additions & 3 deletions packages/ast-spec/src/base/TSHeritageBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
4 changes: 0 additions & 4 deletions packages/ast-spec/src/expression/CallExpression/spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
3 changes: 0 additions & 3 deletions packages/ast-spec/src/expression/NewExpression/spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,4 @@ export interface NewExpression extends BaseNode {
callee: LeftHandSideExpression;
arguments: CallExpressionArgument[];
typeArguments: TSTypeParameterInstantiation | undefined;

/** @deprecated Use {@link `typeArguments`} instead. */
typeParameters: TSTypeParameterInstantiation | undefined;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
4 changes: 0 additions & 4 deletions packages/ast-spec/src/jsx/JSXOpeningElement/spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)[];
Expand Down
3 changes: 0 additions & 3 deletions packages/ast-spec/src/type/TSImportType/spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
3 changes: 0 additions & 3 deletions packages/ast-spec/src/type/TSTypeQuery/spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
4 changes: 0 additions & 4 deletions packages/ast-spec/src/type/TSTypeReference/spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
2 changes: 0 additions & 2 deletions packages/eslint-plugin/src/rules/indent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,6 @@ export default createRule<Options, MessageIds>({
decorators: [],
implements: [],
superTypeArguments: undefined,
superTypeParameters: undefined,
typeParameters: undefined,

// location data
Expand Down Expand Up @@ -479,7 +478,6 @@ export default createRule<Options, MessageIds>({
name: name as any,
attributes: attributes as any,
typeArguments: undefined,
typeParameters: undefined,

// location data
parent: node.parent,
Expand Down
1 change: 0 additions & 1 deletion packages/typescript-estree/src/convert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2889,7 +2889,6 @@ export class Converter {
type: AST_NODE_TYPES.TSTypeQuery,
exprName: result,
typeArguments: undefined,
typeParameters: undefined,
});
}
return result;
Expand Down
39 changes: 19 additions & 20 deletions packages/typescript-estree/tests/lib/convert.test.ts
abrahamguo marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -279,12 +279,11 @@ describe('convert', () => {
});

describe('suppressDeprecatedPropertyWarnings', () => {
const getEsCallExpression = (
const getEsImportDeclaration = (
converterOptions?: ConverterOptions,
): TSESTree.CallExpression => {
const ast = convertCode(`callee<T>();`);
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,
Expand All @@ -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 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',
);
});
Expand All @@ -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);
Expand All @@ -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');
});
});
});