Skip to content

Commit

Permalink
fix(typescript-estree): wrap import = declaration in an export node (#…
Browse files Browse the repository at this point in the history
…5885)

* fix(typescript-estree): wrap import = declaration in an export node

* fix(utils): removed `TRuleListener` generic from the `createRule` (#5036)

* refactor(utils)!: removed `TRuleListener` generic from the `createRule`

* refactor!: removed `TRuleListener` generic from the `CLIEngine` and `RuleCreateFunction`

* chore: document and refactor 'extra' to 'parserSettings' (#5834)

* chore(website): fix renamed Sponsorship docs link (#5882)

* docs: Mention wide globs performance implications in monorepos docs and parser README (#5864)

* docs: Mention wide globs performance implications in monorepos docs and parser readme

* Update docs/linting/typed-linting/MONOREPOS.md

Co-authored-by: Josh Goldberg <git@joshuakgoldberg.com>

Co-authored-by: Josh Goldberg <git@joshuakgoldberg.com>
Co-authored-by: Adnan Hashmi <56730784+adnanhashmi09@users.noreply.github.com>

* feat: create TSTypeQuery node when TSImportType has isTypeOf (#3076)

* feat: update TSImportType node

* fix: update visitor keys

* chore: document and refactor 'extra' to 'parserSettings' (#5834)

* chore(website): fix renamed Sponsorship docs link (#5882)

* docs: Mention wide globs performance implications in monorepos docs and parser README (#5864)

* docs: Mention wide globs performance implications in monorepos docs and parser readme

* Update docs/linting/typed-linting/MONOREPOS.md

Co-authored-by: Josh Goldberg <git@joshuakgoldberg.com>

Co-authored-by: Josh Goldberg <git@joshuakgoldberg.com>
Co-authored-by: Adnan Hashmi <56730784+adnanhashmi09@users.noreply.github.com>

* feat(scope-manager): ignore ECMA version (#5889)

* feat(scope-manager): ignore ECMA version

* chore: document and refactor 'extra' to 'parserSettings' (#5834)

* chore(website): fix renamed Sponsorship docs link (#5882)

* Remove much more

* Fix WebLinter lint

* docs: Mention wide globs performance implications in monorepos docs and parser README (#5864)

* docs: Mention wide globs performance implications in monorepos docs and parser readme

* Update docs/linting/typed-linting/MONOREPOS.md

Co-authored-by: Josh Goldberg <git@joshuakgoldberg.com>

* chore: add auto-canary release for v6 (#5883)

Co-authored-by: Adnan Hashmi <56730784+adnanhashmi09@users.noreply.github.com>

* feat: remove semantically invalid properties from TSEnumDeclaration, TSInterfaceDeclaration and TSModuleDeclaration (#4863)

* chore: remove invalid properties from ast nodes

* chore: remove invalid code in scope-manager and typescript-estree

* chore: re-write snapshots that were using invalid properties

* feat: remove modifiers union from ast types

Co-authored-by: Juan García <juank1809@gmail.com>
Co-authored-by: Josh Goldberg <git@joshuakgoldberg.com>

* fix(eslint-plugin): remove valid-typeof disable in eslint-recommended (#5381)

* feat(utils): remove (ts-)eslint-scope types (#5256)

* chore(utils)\!: remove (ts-)eslint-scope types

* Remove eslint-scope dep

* More file deletions

* Updated snapshots again

* Remove silly comment

* Just a bit of cleanup

* Remove from ignoreSourceType

* Remove more fixtures-to-test changes

* Revert "Remove more fixtures-to-test changes"

This reverts commit b331c98.

* Explained ignoring in comment

* remove the wat

---------

Co-authored-by: Mateusz Burzyński <mateuszburzynski@gmail.com>
Co-authored-by: Adnan Hashmi <56730784+adnanhashmi09@users.noreply.github.com>
Co-authored-by: Armano <armano2@users.noreply.github.com>
Co-authored-by: Juan García <82288753+juank1809@users.noreply.github.com>
Co-authored-by: Juan García <juank1809@gmail.com>
  • Loading branch information
6 people committed Feb 4, 2023
1 parent 9c17395 commit 1c3f470
Show file tree
Hide file tree
Showing 16 changed files with 296 additions and 124 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ Program {
},
},
importKind: "value",
isExport: false,
moduleReference: TSQualifiedName {
type: "TSQualifiedName",
left: TSQualifiedName {
Expand Down
Original file line number Diff line number Diff line change
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,
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 },
},
}"
`;
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ Program {
},
},
importKind: "value",
isExport: false,
moduleReference: Identifier {
type: "Identifier",
name: "A",
Expand Down
Original file line number Diff line number Diff line change
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 },
},
}"
`;
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ Program {
},
},
importKind: "value",
isExport: false,
moduleReference: TSExternalModuleReference {
type: "TSExternalModuleReference",
expression: Literal {
Expand Down
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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',

/**
* [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
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ Object {
"type": "Identifier",
},
"importKind": "value",
"isExport": false,
"loc": Object {
"end": Object {
"column": 28,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ Object {
"type": "Identifier",
},
"importKind": "type",
"isExport": false,
"loc": Object {
"end": Object {
"column": 33,
Expand Down

0 comments on commit 1c3f470

Please sign in to comment.