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(typescript-estree): wrap import = declaration in an export node #5885

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
7a25528
fix(typescript-estree): wrap import = declaration in an export node
JoshuaKGoldberg Oct 25, 2022
0414e4d
fix(utils): removed `TRuleListener` generic from the `createRule` (#5…
Andarist Oct 25, 2022
04488c2
feat: create TSTypeQuery node when TSImportType has isTypeOf (#3076)
armano2 Oct 26, 2022
ee2fbfa
Merge branch 'main' into v6
JoshuaKGoldberg Oct 26, 2022
c446386
feat(scope-manager): ignore ECMA version (#5889)
JoshuaKGoldberg Oct 26, 2022
cf2956f
feat: remove semantically invalid properties from TSEnumDeclaration, …
juank1809 Oct 26, 2022
b90e7c3
fix(eslint-plugin): remove valid-typeof disable in eslint-recommended…
JoshuaKGoldberg Oct 26, 2022
fff0e29
feat(utils): remove (ts-)eslint-scope types (#5256)
JoshuaKGoldberg Oct 26, 2022
a027cec
Updated snapshots again
JoshuaKGoldberg Oct 26, 2022
3d85274
Merge branch 'main' into v6
JoshuaKGoldberg Oct 26, 2022
51d97ae
Merge branch 'v6' into import-equals-wrap-node
JoshuaKGoldberg Oct 26, 2022
16a5cfb
Merge branch 'main' into import-equals-wrap-node
JoshuaKGoldberg Nov 18, 2022
74839f9
Merge branch 'v6' into import-equals-wrap-node
JoshuaKGoldberg Nov 28, 2022
8dd2a42
Remove silly comment
JoshuaKGoldberg Nov 28, 2022
58c4d34
Merge branch 'v6' into import-equals-wrap-node
JoshuaKGoldberg Dec 11, 2022
b36507f
Just a bit of cleanup
JoshuaKGoldberg Dec 11, 2022
dd858f6
Merge branch 'v6' into import-equals-wrap-node
JoshuaKGoldberg Dec 16, 2022
28863a4
Remove from ignoreSourceType
JoshuaKGoldberg Dec 16, 2022
b331c98
Remove more fixtures-to-test changes
JoshuaKGoldberg Dec 16, 2022
a128343
Revert "Remove more fixtures-to-test changes"
JoshuaKGoldberg Dec 16, 2022
c60da02
Explained ignoring in comment
JoshuaKGoldberg Dec 16, 2022
d2d052d
remove the wat
JoshuaKGoldberg Dec 16, 2022
c7ea8eb
Merge branch 'v6' into import-equals-wrap-node
JoshuaKGoldberg Dec 16, 2022
a738b91
Merge branch 'v6' into import-equals-wrap-node
JoshuaKGoldberg Dec 16, 2022
79a5f81
Merge branch 'v6' into import-equals-wrap-node
JoshuaKGoldberg Feb 4, 2023
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
Expand Up @@ -17,7 +17,6 @@ Program {
},
},
importKind: "value",
isExport: false,
JoshuaKGoldberg marked this conversation as resolved.
Show resolved Hide resolved
moduleReference: TSQualifiedName {
type: "TSQualifiedName",
left: TSQualifiedName {
Expand Down
Expand Up @@ -2,5 +2,88 @@

exports[`AST Fixtures declaration TSImportEqualsDeclaration entity-name-many AST Alignment - AST 1`] = `
"Snapshot Diff:
Compared values have no visual difference."
- TSESTree
+ Babel

Program {
type: 'Program',
body: Array [
TSImportEqualsDeclaration {
type: 'TSImportEqualsDeclaration',
id: Identifier {
type: 'Identifier',
name: 'F',

range: [7, 8],
loc: {
start: { column: 7, line: 1 },
end: { column: 8, line: 1 },
},
},
importKind: 'value',
+ isExport: false,
JoshuaKGoldberg marked this conversation as resolved.
Show resolved Hide resolved
moduleReference: TSQualifiedName {
type: 'TSQualifiedName',
left: TSQualifiedName {
type: 'TSQualifiedName',
left: Identifier {
type: 'Identifier',
name: 'A',

range: [11, 12],
loc: {
start: { column: 11, line: 1 },
end: { column: 12, line: 1 },
},
},
right: Identifier {
type: 'Identifier',
name: 'B',

range: [13, 14],
loc: {
start: { column: 13, line: 1 },
end: { column: 14, line: 1 },
},
},

range: [11, 14],
loc: {
start: { column: 11, line: 1 },
end: { column: 14, line: 1 },
},
},
right: Identifier {
type: 'Identifier',
name: 'C',

range: [15, 16],
loc: {
start: { column: 15, line: 1 },
end: { column: 16, line: 1 },
},
},

range: [11, 16],
loc: {
start: { column: 11, line: 1 },
end: { column: 16, line: 1 },
},
},

range: [0, 17],
loc: {
start: { column: 0, line: 1 },
end: { column: 17, line: 1 },
},
},
],
sourceType: 'script',

range: [0, 18],
loc: {
start: { column: 0, line: 1 },
end: { column: 0, line: 2 },
},
}"
`;
Expand Up @@ -17,7 +17,6 @@ Program {
},
},
importKind: "value",
isExport: false,
moduleReference: Identifier {
type: "Identifier",
name: "A",
Expand Down
Expand Up @@ -2,5 +2,50 @@

exports[`AST Fixtures declaration TSImportEqualsDeclaration entity-name-one AST Alignment - AST 1`] = `
"Snapshot Diff:
Compared values have no visual difference."
- TSESTree
+ Babel

Program {
type: 'Program',
body: Array [
TSImportEqualsDeclaration {
type: 'TSImportEqualsDeclaration',
id: Identifier {
type: 'Identifier',
name: 'F',

range: [7, 8],
loc: {
start: { column: 7, line: 1 },
end: { column: 8, line: 1 },
},
},
importKind: 'value',
+ isExport: false,
moduleReference: Identifier {
type: 'Identifier',
name: 'A',

range: [11, 12],
loc: {
start: { column: 11, line: 1 },
end: { column: 12, line: 1 },
},
},

range: [0, 13],
loc: {
start: { column: 0, line: 1 },
end: { column: 13, line: 1 },
},
},
],
sourceType: 'script',

range: [0, 14],
loc: {
start: { column: 0, line: 1 },
end: { column: 0, line: 2 },
},
}"
`;
Expand Up @@ -17,7 +17,6 @@ Program {
},
},
importKind: "value",
isExport: false,
moduleReference: TSExternalModuleReference {
type: "TSExternalModuleReference",
expression: Literal {
Expand Down
Expand Up @@ -21,7 +21,7 @@ exports[`AST Fixtures declaration TSImportEqualsDeclaration external-module-ref-
},
},
importKind: 'value',
isExport: false,
+ isExport: false,
moduleReference: TSExternalModuleReference {
type: 'TSExternalModuleReference',
expression: Literal {
Expand Down
Expand Up @@ -22,12 +22,4 @@ export interface TSImportEqualsDeclaration extends BaseNode {
moduleReference: EntityName | TSExternalModuleReference;
// TODO(#1852) - breaking change remove this as it is invalid
importKind: ImportKind;
/**
* Whether this is immediately exported
* ```
* export import F = A;
* ```
*/
// TODO(#4130) - this should be represented in the AST
isExport: boolean;
}
2 changes: 2 additions & 0 deletions packages/ast-spec/src/unions/ExportDeclaration.ts
Expand Up @@ -8,6 +8,7 @@ import type {
} from '../declaration/FunctionDeclaration/spec';
import type { TSDeclareFunction } from '../declaration/TSDeclareFunction/spec';
import type { TSEnumDeclaration } from '../declaration/TSEnumDeclaration/spec';
import type { TSImportEqualsDeclaration } from '../declaration/TSImportEqualsDeclaration/spec';
import type { TSInterfaceDeclaration } from '../declaration/TSInterfaceDeclaration/spec';
import type { TSModuleDeclaration } from '../declaration/TSModuleDeclaration/spec';
import type { TSTypeAliasDeclaration } from '../declaration/TSTypeAliasDeclaration/spec';
Expand Down Expand Up @@ -37,6 +38,7 @@ export type NamedExportDeclarations =
| FunctionDeclarationWithOptionalName
| TSDeclareFunction
| TSEnumDeclaration
| TSImportEqualsDeclaration
| TSInterfaceDeclaration
| TSModuleDeclaration
| TSTypeAliasDeclaration
Expand Down
2 changes: 2 additions & 0 deletions packages/ast-spec/tests/fixtures-with-differences-ast.shot
Expand Up @@ -17,6 +17,8 @@ Set {
"declaration/FunctionDeclaration/fixtures/type-param-one/fixture.ts",
"declaration/TSDeclareFunction/fixtures/type-param-many/fixture.ts",
"declaration/TSDeclareFunction/fixtures/type-param-one/fixture.ts",
"declaration/TSImportEqualsDeclaration/fixtures/entity-name-many/fixture.ts",
"declaration/TSImportEqualsDeclaration/fixtures/entity-name-one/fixture.ts",
"declaration/TSImportEqualsDeclaration/fixtures/external-module-ref-string/fixture.ts",
"declaration/TSInterfaceDeclaration/fixtures/extends-many/fixture.ts",
"declaration/TSInterfaceDeclaration/fixtures/extends-one/fixture.ts",
Expand Down
34 changes: 20 additions & 14 deletions packages/typescript-estree/src/convert.ts
Expand Up @@ -143,6 +143,7 @@ export class Converter {
| ts.ClassDeclaration
| ts.ClassExpression
| ts.TypeAliasDeclaration
| ts.ImportEqualsDeclaration
| ts.InterfaceDeclaration
| ts.EnumDeclaration
| ts.ModuleDeclaration,
Expand All @@ -159,7 +160,7 @@ export class Converter {
const exportKeyword = modifiers[0];
const nextModifier = modifiers[1];
const declarationIsDefault =
nextModifier && nextModifier.kind === SyntaxKind.DefaultKeyword;
nextModifier?.kind === SyntaxKind.DefaultKeyword;

const varToken = declarationIsDefault
? findNextToken(nextModifier, this.ast, this.ast)
Expand All @@ -169,12 +170,15 @@ export class Converter {
result.loc = getLocFor(result.range[0], result.range[1], this.ast);

if (declarationIsDefault) {
return this.createNode<TSESTree.ExportDefaultDeclaration>(node, {
type: AST_NODE_TYPES.ExportDefaultDeclaration,
declaration: result,
range: [exportKeyword.getStart(this.ast), result.range[1]],
exportKind: 'value',
});
return this.createNode<TSESTree.ExportDefaultDeclaration>(
node as Exclude<typeof node, ts.ImportEqualsDeclaration>,
{
type: AST_NODE_TYPES.ExportDefaultDeclaration,
declaration: result as TSESTree.DefaultExportDeclarations,
range: [exportKeyword.getStart(this.ast), result.range[1]],
exportKind: 'value',
},
);
} else {
const isType =
result.type === AST_NODE_TYPES.TSInterfaceDeclaration ||
Expand Down Expand Up @@ -2778,13 +2782,15 @@ export class Converter {
});
}
case SyntaxKind.ImportEqualsDeclaration: {
return this.createNode<TSESTree.TSImportEqualsDeclaration>(node, {
type: AST_NODE_TYPES.TSImportEqualsDeclaration,
id: this.convertChild(node.name),
moduleReference: this.convertChild(node.moduleReference),
importKind: node.isTypeOnly ? 'type' : 'value',
isExport: hasModifier(SyntaxKind.ExportKeyword, node),
});
return this.fixExports(
node,
this.createNode<TSESTree.TSImportEqualsDeclaration>(node, {
type: AST_NODE_TYPES.TSImportEqualsDeclaration,
id: this.convertChild(node.name),
importKind: node.isTypeOnly ? 'type' : 'value',
moduleReference: this.convertChild(node.moduleReference),
}),
);
}
case SyntaxKind.ExternalModuleReference: {
return this.createNode<TSESTree.TSExternalModuleReference>(node, {
Expand Down
Expand Up @@ -55,6 +55,7 @@ export interface EstreeToTsNodeTypes {
| ts.ClassDeclaration
| ts.ClassExpression
| ts.TypeAliasDeclaration
| ts.ImportEqualsDeclaration
| ts.InterfaceDeclaration
| ts.EnumDeclaration
| ts.ModuleDeclaration;
Expand Down
14 changes: 10 additions & 4 deletions packages/typescript-estree/tests/ast-alignment/fixtures-to-test.ts
Expand Up @@ -371,6 +371,16 @@ tester.addFixturePatternConfig('typescript/basics', {
'class-with-two-methods-computed-constructor',
'export-type-star-from',
'import-type-error',

/**
* Babel's 'typescript' transform gives these TypeScript-like properties
* such as `isExport: false`, but we don't include those in our AST.
*/
'import-equal-declaration',
'import-export-equal-declaration',
'import-equal-type-declaration',
'import-export-equal-type-declaration',
bradzacher marked this conversation as resolved.
Show resolved Hide resolved

/**
* [TS-ESTREE ERRORED, BUT BABEL DID NOT]
* This is intentional; babel is not checking types
Expand Down Expand Up @@ -404,10 +414,6 @@ tester.addFixturePatternConfig('typescript/basics', {
* @see https://github.com/babel/babel/issues/9213
*/
'export-assignment',
'import-equal-declaration',
'import-export-equal-declaration',
'import-equal-type-declaration',
'import-export-equal-type-declaration',
// babel treats declare and types as not a module
'export-declare-const-named-enum',
'export-declare-named-enum',
Expand Down
Expand Up @@ -23,7 +23,6 @@ Object {
"type": "Identifier",
},
"importKind": "value",
"isExport": false,
"loc": Object {
"end": Object {
"column": 28,
Expand Down
Expand Up @@ -23,7 +23,6 @@ Object {
"type": "Identifier",
},
"importKind": "type",
"isExport": false,
"loc": Object {
"end": Object {
"column": 33,
Expand Down