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: remove semantically invalid properties from TSEnumDeclaration, TSInterfaceDeclaration and TSModuleDeclaration #4863

Merged
merged 5 commits into from
Oct 26, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 0 additions & 3 deletions packages/ast-spec/src/declaration/TSEnumDeclaration/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 { BaseNode } from '../../base/BaseNode';
import type { TSEnumMember } from '../../element/TSEnumMember/spec';
import type { Identifier } from '../../expression/Identifier/spec';
import type { Modifier } from '../../unions/Modifier';

export interface TSEnumDeclaration extends BaseNode {
type: AST_NODE_TYPES.TSEnumDeclaration;
Expand Down Expand Up @@ -30,6 +29,4 @@ export interface TSEnumDeclaration extends BaseNode {
* The enum members.
*/
members: TSEnumMember[];
// TODO(#4759) - breaking change remove this
modifiers?: Modifier[];
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import type { TSTypeParameterDeclaration } from '../../special/TSTypeParameterDe

export interface TSInterfaceDeclaration extends BaseNode {
type: AST_NODE_TYPES.TSInterfaceDeclaration;
// TODO(#4759) - breaking change remove this
abstract?: boolean;
/**
* The body of the interface
*/
Expand All @@ -26,8 +24,6 @@ export interface TSInterfaceDeclaration extends BaseNode {
* The name of this interface
*/
id: Identifier;
// TODO(#4759) - breaking change remove this
implements?: TSInterfaceHeritage[];
/**
* The generic type parameters declared for the interface.
* This is `undefined` if there are no generic type parameters declared.
Expand Down
3 changes: 0 additions & 3 deletions packages/ast-spec/src/declaration/TSModuleDeclaration/spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import type { BaseNode } from '../../base/BaseNode';
import type { Identifier } from '../../expression/Identifier/spec';
import type { TSModuleBlock } from '../../special/TSModuleBlock/spec';
import type { Literal } from '../../unions/Literal';
import type { Modifier } from '../../unions/Modifier';

export interface TSModuleDeclaration extends BaseNode {
type: AST_NODE_TYPES.TSModuleDeclaration;
Expand Down Expand Up @@ -49,6 +48,4 @@ export interface TSModuleDeclaration extends BaseNode {
*/
// TODO(#5020) - make this `false` if it is not `declare`d
declare?: boolean;
// TODO(#4759) - breaking change remove this
modifiers?: Modifier[];
}
1 change: 0 additions & 1 deletion packages/ast-spec/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ export * from './unions/JSXTagNameExpression';
export * from './unions/LeftHandSideExpression';
export * from './unions/Literal';
export * from './unions/LiteralExpression';
export * from './unions/Modifier';
export * from './unions/Node';
export * from './unions/ObjectLiteralElement';
export * from './unions/Parameter';
Expand Down
16 changes: 0 additions & 16 deletions packages/ast-spec/src/unions/Modifier.ts

This file was deleted.

1 change: 0 additions & 1 deletion packages/scope-manager/src/referencer/TypeVisitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,6 @@ class TypeVisitor extends Visitor {
}

node.extends?.forEach(this.visit, this);
node.implements?.forEach(this.visit, this);
this.visit(node.body);

if (node.typeParameters) {
Expand Down
85 changes: 12 additions & 73 deletions packages/typescript-estree/src/convert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -696,62 +696,6 @@ export class Converter {
: node.elements.map(element => this.convertChild(element));
}

/**
* Applies the given TS modifiers to the given result object.
*
* This method adds not standardized `modifiers` property in nodes
*
* @param result
* @param modifiers original ts.Nodes from the node.modifiers array
* @returns the current result object will be mutated
*/
private applyModifiersToResult(
result: TSESTree.TSEnumDeclaration | TSESTree.TSModuleDeclaration,
modifiers: Iterable<ts.Modifier> | undefined,
): void {
if (!modifiers) {
return;
}

const remainingModifiers: TSESTree.Modifier[] = [];
/**
* Some modifiers are explicitly handled by applying them as
* boolean values on the result node. As well as adding them
* to the result, we remove them from the array, so that they
* are not handled twice.
*/
for (const modifier of modifiers) {
switch (modifier.kind) {
/**
* Ignore ExportKeyword and DefaultKeyword, they are handled
* via the fixExports utility function
*/
case SyntaxKind.ExportKeyword:
case SyntaxKind.DefaultKeyword:
break;
case SyntaxKind.ConstKeyword:
(result as any).const = true;
break;
case SyntaxKind.DeclareKeyword:
result.declare = true;
break;
default:
remainingModifiers.push(
this.convertChild(modifier) as TSESTree.Modifier,
);
break;
}
}
/**
* If there are still valid modifiers available which have
* not been explicitly handled above, we just convert and
* add the modifiers array to the result node.
*/
if (remainingModifiers.length > 0) {
result.modifiers = remainingModifiers;
}
}

/**
* Uses the provided range location to adjust the location data of the given Node
* @param result The node that will have its location data mutated
Expand Down Expand Up @@ -2674,7 +2618,6 @@ export class Converter {

if (interfaceHeritageClauses.length > 0) {
const interfaceExtends: TSESTree.TSInterfaceHeritage[] = [];
const interfaceImplements: TSESTree.TSInterfaceHeritage[] = [];

for (const heritageClause of interfaceHeritageClauses) {
if (heritageClause.token === SyntaxKind.ExtendsKeyword) {
Expand All @@ -2683,27 +2626,14 @@ export class Converter {
this.convertChild(n, node) as TSESTree.TSInterfaceHeritage,
);
}
} else {
for (const n of heritageClause.types) {
interfaceImplements.push(
this.convertChild(n, node) as TSESTree.TSInterfaceHeritage,
);
}
}
}

if (interfaceExtends.length) {
if (interfaceExtends.length > 0) {
result.extends = interfaceExtends;
}

if (interfaceImplements.length) {
result.implements = interfaceImplements;
}
}

if (hasModifier(SyntaxKind.AbstractKeyword, node)) {
result.abstract = true;
}
if (hasModifier(SyntaxKind.DeclareKeyword, node)) {
result.declare = true;
}
Expand Down Expand Up @@ -2764,7 +2694,14 @@ export class Converter {
members: node.members.map(el => this.convertChild(el)),
});
// apply modifiers first...
this.applyModifiersToResult(result, getModifiers(node));
if (hasModifier(SyntaxKind.DeclareKeyword, node)) {
result.declare = true;
}

if (hasModifier(SyntaxKind.ConstKeyword, node)) {
result.const = true;
}

// ...then check for exports
return this.fixExports(node, result);
}
Expand Down Expand Up @@ -2792,7 +2729,9 @@ export class Converter {
result.body = this.convertChild(node.body);
}
// apply modifiers first...
this.applyModifiersToResult(result, getModifiers(node));
if (hasModifier(SyntaxKind.DeclareKeyword, node)) {
result.declare = true;
}
if (node.flags & ts.NodeFlags.GlobalAugmentation) {
result.global = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ Object {
Object {
"assertions": Array [],
"declaration": Object {
"abstract": true,
"body": Object {
"body": Array [],
"loc": Object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,127 +35,6 @@ Object {
},
},
"members": Array [],
"modifiers": Array [
Object {
"loc": Object {
"end": Object {
"column": 14,
"line": 1,
},
"start": Object {
"column": 7,
"line": 1,
},
},
"range": Array [
7,
14,
],
"type": "TSPrivateKeyword",
},
Object {
"loc": Object {
"end": Object {
"column": 21,
"line": 1,
},
"start": Object {
"column": 15,
"line": 1,
},
},
"range": Array [
15,
21,
],
"type": "TSPublicKeyword",
},
Object {
"loc": Object {
"end": Object {
"column": 31,
"line": 1,
},
"start": Object {
"column": 22,
"line": 1,
},
},
"range": Array [
22,
31,
],
"type": "TSProtectedKeyword",
},
Object {
"loc": Object {
"end": Object {
"column": 38,
"line": 1,
},
"start": Object {
"column": 32,
"line": 1,
},
},
"range": Array [
32,
38,
],
"type": "TSStaticKeyword",
},
Object {
"loc": Object {
"end": Object {
"column": 47,
"line": 1,
},
"start": Object {
"column": 39,
"line": 1,
},
},
"range": Array [
39,
47,
],
"type": "TSReadonlyKeyword",
},
Object {
"loc": Object {
"end": Object {
"column": 56,
"line": 1,
},
"start": Object {
"column": 48,
"line": 1,
},
},
"range": Array [
48,
56,
],
"type": "TSAbstractKeyword",
},
Object {
"loc": Object {
"end": Object {
"column": 62,
"line": 1,
},
"start": Object {
"column": 57,
"line": 1,
},
},
"range": Array [
57,
62,
],
"type": "TSAsyncKeyword",
},
],
"range": Array [
7,
72,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,43 +40,6 @@ Object {
],
"type": "Identifier",
},
"implements": Array [
Object {
"expression": Object {
"loc": Object {
"end": Object {
"column": 24,
"line": 1,
},
"start": Object {
"column": 23,
"line": 1,
},
},
"name": "e",
"range": Array [
23,
24,
],
"type": "Identifier",
},
"loc": Object {
"end": Object {
"column": 24,
"line": 1,
},
"start": Object {
"column": 23,
"line": 1,
},
},
"range": Array [
23,
24,
],
"type": "TSInterfaceHeritage",
},
],
"loc": Object {
"end": Object {
"column": 27,
Expand Down