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

fix(ast-spec): remove more invalid properties #6243

Merged
Show file tree
Hide file tree
Changes from 3 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
2 changes: 0 additions & 2 deletions packages/ast-spec/src/base/MethodDefinitionBase.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import type { FunctionExpression } from '../expression/FunctionExpression/spec';
import type { TSEmptyBodyFunctionExpression } from '../expression/TSEmptyBodyFunctionExpression/spec';
import type { Decorator } from '../special/Decorator/spec';
import type { TSTypeParameterDeclaration } from '../special/TSTypeParameterDeclaration/spec';
import type {
ClassPropertyNameNonComputed,
PropertyName,
Expand All @@ -21,7 +20,6 @@ interface MethodDefinitionBase extends BaseNode {
optional?: boolean;
decorators?: Decorator[];
accessibility?: Accessibility;
typeParameters?: TSTypeParameterDeclaration;
override?: boolean;
}

Expand Down
1 change: 0 additions & 1 deletion packages/ast-spec/src/element/TSIndexSignature/spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,5 @@ export interface TSIndexSignature extends BaseNode {
typeAnnotation?: TSTypeAnnotation;
readonly?: boolean;
accessibility?: Accessibility;
export?: boolean;
static?: boolean;
}
1 change: 0 additions & 1 deletion packages/ast-spec/src/element/TSMethodSignature/spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ interface TSMethodSignatureBase extends BaseNode {
readonly?: boolean;
typeParameters?: TSTypeParameterDeclaration;
accessibility?: Accessibility;
export?: boolean;
static?: boolean;
kind: 'get' | 'method' | 'set';
}
Expand Down
3 changes: 0 additions & 3 deletions packages/ast-spec/src/element/TSPropertySignature/spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import type { AST_NODE_TYPES } from '../../ast-node-types';
import type { Accessibility } from '../../base/Accessibility';
import type { BaseNode } from '../../base/BaseNode';
import type { TSTypeAnnotation } from '../../special/TSTypeAnnotation/spec';
import type { Expression } from '../../unions/Expression';
import type {
PropertyName,
PropertyNameComputed,
Expand All @@ -15,10 +14,8 @@ interface TSPropertySignatureBase extends BaseNode {
optional?: boolean;
computed: boolean;
typeAnnotation?: TSTypeAnnotation;
initializer?: Expression;
readonly?: boolean;
static?: boolean;
export?: boolean;
accessibility?: Accessibility;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ export interface TSParameterProperty extends BaseNode {
accessibility?: Accessibility;
readonly?: boolean;
static?: boolean;
export?: boolean;
override?: boolean;
parameter: AssignmentPattern | BindingName | RestElement;
decorators?: Decorator[];
Expand Down
74 changes: 59 additions & 15 deletions packages/typescript-estree/src/convert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -661,10 +661,6 @@ export class Converter {
result.accessibility = accessibility;
}

if (hasModifier(SyntaxKind.ExportKeyword, node)) {
result.export = true;
}

if (hasModifier(SyntaxKind.StaticKeyword, node)) {
result.static = true;
}
Expand Down Expand Up @@ -1047,6 +1043,20 @@ export class Converter {
}

case SyntaxKind.PropertyAssignment:
this.#throwErrorIfDeprecatedPropertyExists(
node,
// eslint-disable-next-line deprecation/deprecation
node.questionToken,
'A property assignment cannot have a question token.',
);

this.#throwErrorIfDeprecatedPropertyExists(
node,
// eslint-disable-next-line deprecation/deprecation
node.exclamationToken,
'A property assignment cannot have an exclamation token.',
);

return this.createNode<TSESTree.Property>(node, {
type: AST_NODE_TYPES.Property,
key: this.convertChild(node.name),
Expand All @@ -1058,6 +1068,27 @@ export class Converter {
});

case SyntaxKind.ShorthandPropertyAssignment: {
this.#throwErrorIfDeprecatedPropertyExists(
node,
// eslint-disable-next-line deprecation/deprecation
node.modifiers,
'A shorthand property assignment cannot have modifiers.',
);

this.#throwErrorIfDeprecatedPropertyExists(
node,
// eslint-disable-next-line deprecation/deprecation
node.questionToken,
'A shorthand property assignment cannot have a question token.',
);

this.#throwErrorIfDeprecatedPropertyExists(
node,
// eslint-disable-next-line deprecation/deprecation
node.exclamationToken,
'A shorthand property assignment cannot have an exclamation token.',
);

if (node.objectAssignmentInitializer) {
return this.createNode<TSESTree.Property>(node, {
type: AST_NODE_TYPES.Property,
Expand Down Expand Up @@ -1615,7 +1646,6 @@ export class Converter {
readonly:
hasModifier(SyntaxKind.ReadonlyKeyword, node) || undefined,
static: hasModifier(SyntaxKind.StaticKeyword, node) || undefined,
export: hasModifier(SyntaxKind.ExportKeyword, node) || undefined,
override:
hasModifier(SyntaxKind.OverrideKeyword, node) || undefined,
parameter: result,
Expand Down Expand Up @@ -2458,6 +2488,13 @@ export class Converter {
}

case SyntaxKind.PropertySignature: {
this.#throwErrorIfDeprecatedPropertyExists(
node,
// eslint-disable-next-line deprecation/deprecation
node.initializer,
'A property signature cannot have an initializer.',
);

const result = this.createNode<TSESTree.TSPropertySignature>(node, {
type: AST_NODE_TYPES.TSPropertySignature,
optional: isOptional(node) || undefined,
Expand All @@ -2466,14 +2503,8 @@ export class Converter {
typeAnnotation: node.type
? this.convertTypeAnnotation(node.type, node)
: undefined,
initializer:
this.convertChild(
// eslint-disable-next-line deprecation/deprecation -- TODO breaking change remove this from the AST
node.initializer,
) || undefined,
readonly: hasModifier(SyntaxKind.ReadonlyKeyword, node) || undefined,
static: hasModifier(SyntaxKind.StaticKeyword, node) || undefined,
export: hasModifier(SyntaxKind.ExportKeyword, node) || undefined,
JoshuaKGoldberg marked this conversation as resolved.
Show resolved Hide resolved
});

const accessibility = getTSNodeAccessibility(node);
Expand Down Expand Up @@ -2503,10 +2534,6 @@ export class Converter {
result.accessibility = accessibility;
}

if (hasModifier(SyntaxKind.ExportKeyword, node)) {
result.export = true;
}

if (hasModifier(SyntaxKind.StaticKeyword, node)) {
result.static = true;
}
Expand All @@ -2531,6 +2558,13 @@ export class Converter {
}

case SyntaxKind.FunctionType:
this.#throwErrorIfDeprecatedPropertyExists(
node,
// eslint-disable-next-line deprecation/deprecation
node.modifiers,
'A function type cannot have modifiers.',
);
// intentional fallthrough
case SyntaxKind.ConstructSignature:
case SyntaxKind.CallSignature: {
const type =
Expand Down Expand Up @@ -2906,4 +2940,14 @@ export class Converter {
return this.deeplyCopy(node);
}
}

#throwErrorIfDeprecatedPropertyExists<Node extends ts.Node>(
node: Node,
property: unknown,
message: string,
): void {
if (property) {
throw createError(this.ast, node.pos, message);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,6 @@ Object {
"members": Array [
Object {
"computed": false,
"export": undefined,
"initializer": undefined,
"key": Object {
"loc": Object {
"end": Object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ Object {
"params": Array [
Object {
"accessibility": "protected",
"export": undefined,
"loc": Object {
"end": Object {
"column": 55,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ Object {
"params": Array [
Object {
"accessibility": undefined,
"export": undefined,
"loc": Object {
"end": Object {
"column": 36,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ Object {
"params": Array [
Object {
"accessibility": undefined,
"export": true,
"loc": Object {
"end": Object {
"column": 32,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ Object {
"params": Array [
Object {
"accessibility": "private",
"export": undefined,
"loc": Object {
"end": Object {
"column": 39,
Expand Down Expand Up @@ -154,7 +153,6 @@ Object {
},
Object {
"accessibility": "private",
"export": undefined,
"loc": Object {
"end": Object {
"column": 47,
Expand Down Expand Up @@ -228,7 +226,6 @@ Object {
},
Object {
"accessibility": "private",
"export": undefined,
"loc": Object {
"end": Object {
"column": 38,
Expand Down Expand Up @@ -338,7 +335,6 @@ Object {
},
Object {
"accessibility": "private",
"export": undefined,
"loc": Object {
"end": Object {
"column": 55,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ Object {
"params": Array [
Object {
"accessibility": "protected",
"export": undefined,
"loc": Object {
"end": Object {
"column": 41,
Expand Down Expand Up @@ -154,7 +153,6 @@ Object {
},
Object {
"accessibility": "protected",
"export": undefined,
"loc": Object {
"end": Object {
"column": 49,
Expand Down Expand Up @@ -228,7 +226,6 @@ Object {
},
Object {
"accessibility": "protected",
"export": undefined,
"loc": Object {
"end": Object {
"column": 40,
Expand Down Expand Up @@ -338,7 +335,6 @@ Object {
},
Object {
"accessibility": "protected",
"export": undefined,
"loc": Object {
"end": Object {
"column": 57,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ Object {
"params": Array [
Object {
"accessibility": "public",
"export": undefined,
"loc": Object {
"end": Object {
"column": 38,
Expand Down Expand Up @@ -154,7 +153,6 @@ Object {
},
Object {
"accessibility": "public",
"export": undefined,
"loc": Object {
"end": Object {
"column": 46,
Expand Down Expand Up @@ -228,7 +226,6 @@ Object {
},
Object {
"accessibility": "public",
"export": undefined,
"loc": Object {
"end": Object {
"column": 37,
Expand Down Expand Up @@ -338,7 +335,6 @@ Object {
},
Object {
"accessibility": "public",
"export": undefined,
"loc": Object {
"end": Object {
"column": 54,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ Object {
"params": Array [
Object {
"accessibility": undefined,
"export": undefined,
"loc": Object {
"end": Object {
"column": 40,
Expand Down Expand Up @@ -154,7 +153,6 @@ Object {
},
Object {
"accessibility": undefined,
"export": undefined,
"loc": Object {
"end": Object {
"column": 49,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ Object {
"params": Array [
Object {
"accessibility": undefined,
"export": undefined,
"loc": Object {
"end": Object {
"column": 32,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,6 @@ Object {
"members": Array [
Object {
"computed": false,
"export": undefined,
"initializer": undefined,
"key": Object {
"loc": Object {
"end": Object {
Expand Down Expand Up @@ -291,8 +289,6 @@ Object {
},
Object {
"computed": false,
"export": undefined,
"initializer": undefined,
"key": Object {
"loc": Object {
"end": Object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,6 @@ Object {
"members": Array [
Object {
"computed": false,
"export": undefined,
"initializer": undefined,
"key": Object {
"loc": Object {
"end": Object {
Expand Down Expand Up @@ -291,8 +289,6 @@ Object {
},
Object {
"computed": false,
"export": undefined,
"initializer": undefined,
"key": Object {
"loc": Object {
"end": Object {
Expand Down