Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
dc73483
Parse type-only import specifiers
andrewbranch Sep 16, 2021
ad27364
Add type-only export specifiers
andrewbranch Sep 16, 2021
0ba00b9
Update transform and emit
andrewbranch Sep 16, 2021
eb63b02
Update checking
andrewbranch Sep 16, 2021
9b31bd1
Fix elision when combined with importsNotUsedAsValues=preserve
andrewbranch Sep 16, 2021
02d4ff9
Accept baselines
andrewbranch Sep 17, 2021
ac9b14b
Add test
andrewbranch Sep 20, 2021
577868d
WIP auto imports updates
andrewbranch Sep 20, 2021
c41f8ee
First auto-imports test working
andrewbranch Sep 20, 2021
d34544c
More auto-import tests
andrewbranch Sep 20, 2021
76da8c7
Fix auto imports of type-only exports
andrewbranch Sep 21, 2021
487f585
Add test for promoting type-only import
andrewbranch Sep 21, 2021
b6ea3ac
Sort import/export specifiers by type-onlyness
andrewbranch Sep 21, 2021
9a1765e
Update completions for `import { type |`
andrewbranch Sep 22, 2021
9e1878d
Update other completions tests
andrewbranch Sep 22, 2021
f7248e1
Respect organize imports sorting when promoting type-only to regular …
andrewbranch Sep 22, 2021
06063f2
Fix comment mistakes
andrewbranch Sep 24, 2021
4ba367b
Update src/services/codefixes/importFixes.ts
andrewbranch Sep 24, 2021
75a2909
Rearrange some order of assignments in parser
andrewbranch Sep 24, 2021
b55acde
Split huge if statement
andrewbranch Sep 24, 2021
414f38b
Remove redundant check
andrewbranch Sep 24, 2021
3768d0a
Merge branch 'main' into feature/type-only-specifiers
andrewbranch Sep 24, 2021
39e72d8
Update new transformer
andrewbranch Sep 24, 2021
9033c72
Fix import statement completions
andrewbranch Sep 24, 2021
adcb331
Fix type keyword completions good grief
andrewbranch Sep 27, 2021
d64c923
Fix last tests
andrewbranch Sep 27, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Accept baselines
  • Loading branch information
andrewbranch committed Sep 17, 2021
commit 02d4ff989db14919fa85c5038310de17670cc8e5
18 changes: 10 additions & 8 deletions tests/baselines/reference/api/tsserverlibrary.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1679,10 +1679,12 @@ declare namespace ts {
readonly parent: NamedImports;
readonly propertyName?: Identifier;
readonly name: Identifier;
readonly isTypeOnly: boolean;
}
export interface ExportSpecifier extends NamedDeclaration {
readonly kind: SyntaxKind.ExportSpecifier;
readonly parent: NamedExports;
readonly isTypeOnly: boolean;
readonly propertyName?: Identifier;
readonly name: Identifier;
}
Expand Down Expand Up @@ -3529,16 +3531,16 @@ declare namespace ts {
updateNamespaceExport(node: NamespaceExport, name: Identifier): NamespaceExport;
createNamedImports(elements: readonly ImportSpecifier[]): NamedImports;
updateNamedImports(node: NamedImports, elements: readonly ImportSpecifier[]): NamedImports;
createImportSpecifier(propertyName: Identifier | undefined, name: Identifier): ImportSpecifier;
updateImportSpecifier(node: ImportSpecifier, propertyName: Identifier | undefined, name: Identifier): ImportSpecifier;
createImportSpecifier(isTypeOnly: boolean, propertyName: Identifier | undefined, name: Identifier): ImportSpecifier;
updateImportSpecifier(node: ImportSpecifier, isTypeOnly: boolean, propertyName: Identifier | undefined, name: Identifier): ImportSpecifier;
createExportAssignment(decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, isExportEquals: boolean | undefined, expression: Expression): ExportAssignment;
updateExportAssignment(node: ExportAssignment, decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, expression: Expression): ExportAssignment;
createExportDeclaration(decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, isTypeOnly: boolean, exportClause: NamedExportBindings | undefined, moduleSpecifier?: Expression): ExportDeclaration;
updateExportDeclaration(node: ExportDeclaration, decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, isTypeOnly: boolean, exportClause: NamedExportBindings | undefined, moduleSpecifier: Expression | undefined): ExportDeclaration;
createNamedExports(elements: readonly ExportSpecifier[]): NamedExports;
updateNamedExports(node: NamedExports, elements: readonly ExportSpecifier[]): NamedExports;
createExportSpecifier(propertyName: string | Identifier | undefined, name: string | Identifier): ExportSpecifier;
updateExportSpecifier(node: ExportSpecifier, propertyName: Identifier | undefined, name: Identifier): ExportSpecifier;
createExportSpecifier(isTypeOnly: boolean, propertyName: string | Identifier | undefined, name: string | Identifier): ExportSpecifier;
updateExportSpecifier(node: ExportSpecifier, isTypeOnly: boolean, propertyName: Identifier | undefined, name: Identifier): ExportSpecifier;
createExternalModuleReference(expression: Expression): ExternalModuleReference;
updateExternalModuleReference(node: ExternalModuleReference, expression: Expression): ExternalModuleReference;
createJSDocAllType(): JSDocAllType;
Expand Down Expand Up @@ -10973,9 +10975,9 @@ declare namespace ts {
/** @deprecated Use `factory.updateNamedImports` or the factory supplied by your transformation context instead. */
const updateNamedImports: (node: NamedImports, elements: readonly ImportSpecifier[]) => NamedImports;
/** @deprecated Use `factory.createImportSpecifier` or the factory supplied by your transformation context instead. */
const createImportSpecifier: (propertyName: Identifier | undefined, name: Identifier) => ImportSpecifier;
const createImportSpecifier: (isTypeOnly: boolean, propertyName: Identifier | undefined, name: Identifier) => ImportSpecifier;
/** @deprecated Use `factory.updateImportSpecifier` or the factory supplied by your transformation context instead. */
const updateImportSpecifier: (node: ImportSpecifier, propertyName: Identifier | undefined, name: Identifier) => ImportSpecifier;
const updateImportSpecifier: (node: ImportSpecifier, isTypeOnly: boolean, propertyName: Identifier | undefined, name: Identifier) => ImportSpecifier;
/** @deprecated Use `factory.createExportAssignment` or the factory supplied by your transformation context instead. */
const createExportAssignment: (decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, isExportEquals: boolean | undefined, expression: Expression) => ExportAssignment;
/** @deprecated Use `factory.updateExportAssignment` or the factory supplied by your transformation context instead. */
Expand All @@ -10985,9 +10987,9 @@ declare namespace ts {
/** @deprecated Use `factory.updateNamedExports` or the factory supplied by your transformation context instead. */
const updateNamedExports: (node: NamedExports, elements: readonly ExportSpecifier[]) => NamedExports;
/** @deprecated Use `factory.createExportSpecifier` or the factory supplied by your transformation context instead. */
const createExportSpecifier: (propertyName: string | Identifier | undefined, name: string | Identifier) => ExportSpecifier;
const createExportSpecifier: (isTypeOnly: boolean, propertyName: string | Identifier | undefined, name: string | Identifier) => ExportSpecifier;
/** @deprecated Use `factory.updateExportSpecifier` or the factory supplied by your transformation context instead. */
const updateExportSpecifier: (node: ExportSpecifier, propertyName: Identifier | undefined, name: Identifier) => ExportSpecifier;
const updateExportSpecifier: (node: ExportSpecifier, isTypeOnly: boolean, propertyName: Identifier | undefined, name: Identifier) => ExportSpecifier;
/** @deprecated Use `factory.createExternalModuleReference` or the factory supplied by your transformation context instead. */
const createExternalModuleReference: (expression: Expression) => ExternalModuleReference;
/** @deprecated Use `factory.updateExternalModuleReference` or the factory supplied by your transformation context instead. */
Expand Down
18 changes: 10 additions & 8 deletions tests/baselines/reference/api/typescript.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1679,10 +1679,12 @@ declare namespace ts {
readonly parent: NamedImports;
readonly propertyName?: Identifier;
readonly name: Identifier;
readonly isTypeOnly: boolean;
}
export interface ExportSpecifier extends NamedDeclaration {
readonly kind: SyntaxKind.ExportSpecifier;
readonly parent: NamedExports;
readonly isTypeOnly: boolean;
readonly propertyName?: Identifier;
readonly name: Identifier;
}
Expand Down Expand Up @@ -3529,16 +3531,16 @@ declare namespace ts {
updateNamespaceExport(node: NamespaceExport, name: Identifier): NamespaceExport;
createNamedImports(elements: readonly ImportSpecifier[]): NamedImports;
updateNamedImports(node: NamedImports, elements: readonly ImportSpecifier[]): NamedImports;
createImportSpecifier(propertyName: Identifier | undefined, name: Identifier): ImportSpecifier;
updateImportSpecifier(node: ImportSpecifier, propertyName: Identifier | undefined, name: Identifier): ImportSpecifier;
createImportSpecifier(isTypeOnly: boolean, propertyName: Identifier | undefined, name: Identifier): ImportSpecifier;
updateImportSpecifier(node: ImportSpecifier, isTypeOnly: boolean, propertyName: Identifier | undefined, name: Identifier): ImportSpecifier;
createExportAssignment(decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, isExportEquals: boolean | undefined, expression: Expression): ExportAssignment;
updateExportAssignment(node: ExportAssignment, decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, expression: Expression): ExportAssignment;
createExportDeclaration(decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, isTypeOnly: boolean, exportClause: NamedExportBindings | undefined, moduleSpecifier?: Expression): ExportDeclaration;
updateExportDeclaration(node: ExportDeclaration, decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, isTypeOnly: boolean, exportClause: NamedExportBindings | undefined, moduleSpecifier: Expression | undefined): ExportDeclaration;
createNamedExports(elements: readonly ExportSpecifier[]): NamedExports;
updateNamedExports(node: NamedExports, elements: readonly ExportSpecifier[]): NamedExports;
createExportSpecifier(propertyName: string | Identifier | undefined, name: string | Identifier): ExportSpecifier;
updateExportSpecifier(node: ExportSpecifier, propertyName: Identifier | undefined, name: Identifier): ExportSpecifier;
createExportSpecifier(isTypeOnly: boolean, propertyName: string | Identifier | undefined, name: string | Identifier): ExportSpecifier;
updateExportSpecifier(node: ExportSpecifier, isTypeOnly: boolean, propertyName: Identifier | undefined, name: Identifier): ExportSpecifier;
createExternalModuleReference(expression: Expression): ExternalModuleReference;
updateExternalModuleReference(node: ExternalModuleReference, expression: Expression): ExternalModuleReference;
createJSDocAllType(): JSDocAllType;
Expand Down Expand Up @@ -7173,9 +7175,9 @@ declare namespace ts {
/** @deprecated Use `factory.updateNamedImports` or the factory supplied by your transformation context instead. */
const updateNamedImports: (node: NamedImports, elements: readonly ImportSpecifier[]) => NamedImports;
/** @deprecated Use `factory.createImportSpecifier` or the factory supplied by your transformation context instead. */
const createImportSpecifier: (propertyName: Identifier | undefined, name: Identifier) => ImportSpecifier;
const createImportSpecifier: (isTypeOnly: boolean, propertyName: Identifier | undefined, name: Identifier) => ImportSpecifier;
/** @deprecated Use `factory.updateImportSpecifier` or the factory supplied by your transformation context instead. */
const updateImportSpecifier: (node: ImportSpecifier, propertyName: Identifier | undefined, name: Identifier) => ImportSpecifier;
const updateImportSpecifier: (node: ImportSpecifier, isTypeOnly: boolean, propertyName: Identifier | undefined, name: Identifier) => ImportSpecifier;
/** @deprecated Use `factory.createExportAssignment` or the factory supplied by your transformation context instead. */
const createExportAssignment: (decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, isExportEquals: boolean | undefined, expression: Expression) => ExportAssignment;
/** @deprecated Use `factory.updateExportAssignment` or the factory supplied by your transformation context instead. */
Expand All @@ -7185,9 +7187,9 @@ declare namespace ts {
/** @deprecated Use `factory.updateNamedExports` or the factory supplied by your transformation context instead. */
const updateNamedExports: (node: NamedExports, elements: readonly ExportSpecifier[]) => NamedExports;
/** @deprecated Use `factory.createExportSpecifier` or the factory supplied by your transformation context instead. */
const createExportSpecifier: (propertyName: string | Identifier | undefined, name: string | Identifier) => ExportSpecifier;
const createExportSpecifier: (isTypeOnly: boolean, propertyName: string | Identifier | undefined, name: string | Identifier) => ExportSpecifier;
/** @deprecated Use `factory.updateExportSpecifier` or the factory supplied by your transformation context instead. */
const updateExportSpecifier: (node: ExportSpecifier, propertyName: Identifier | undefined, name: Identifier) => ExportSpecifier;
const updateExportSpecifier: (node: ExportSpecifier, isTypeOnly: boolean, propertyName: Identifier | undefined, name: Identifier) => ExportSpecifier;
/** @deprecated Use `factory.createExternalModuleReference` or the factory supplied by your transformation context instead. */
const createExternalModuleReference: (expression: Expression) => ExternalModuleReference;
/** @deprecated Use `factory.updateExternalModuleReference` or the factory supplied by your transformation context instead. */
Expand Down
40 changes: 40 additions & 0 deletions tests/baselines/reference/exportSpecifiers.errors.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/exports.ts(9,15): error TS2207: The 'type' modifier cannot be used on a named export when 'export type' is used on its export statement.
/imports.ts(3,1): error TS1362: 'as' cannot be used as a value because it was exported using 'export type'.
/imports.ts(4,1): error TS1362: 'something' cannot be used as a value because it was exported using 'export type'.
/imports.ts(5,1): error TS1362: 'foo' cannot be used as a value because it was exported using 'export type'.
/imports.ts(6,1): error TS1362: 'bar' cannot be used as a value because it was exported using 'export type'.


==== /imports.ts (4 errors) ====
import { type, as, something, foo, bar } from "./exports.js";
type;
as; // Error (used in emitting position)
~~
!!! error TS1362: 'as' cannot be used as a value because it was exported using 'export type'.
!!! related TS1377 /exports.ts:5:10: 'as' was exported here.
something; // Error (used in emitting position)
~~~~~~~~~
!!! error TS1362: 'something' cannot be used as a value because it was exported using 'export type'.
!!! related TS1377 /exports.ts:6:10: 'something' was exported here.
foo; // Error (used in emitting position)
~~~
!!! error TS1362: 'foo' cannot be used as a value because it was exported using 'export type'.
!!! related TS1377 /exports.ts:7:10: 'foo' was exported here.
bar; // Error (used in emitting position)
~~~
!!! error TS1362: 'bar' cannot be used as a value because it was exported using 'export type'.
!!! related TS1377 /exports.ts:8:10: 'bar' was exported here.

==== /exports.ts (1 errors) ====
const type = 0;
const as = 0;
const something = 0;
export { type };
export { type as };
export { type something };
export { type type as foo };
export { type as as bar };
export type { type something as whatever }; // Error
~~~~
!!! error TS2207: The 'type' modifier cannot be used on a named export when 'export type' is used on its export statement.

48 changes: 48 additions & 0 deletions tests/baselines/reference/exportSpecifiers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
//// [tests/cases/conformance/externalModules/typeOnly/exportSpecifiers.ts] ////

//// [imports.ts]
import { type, as, something, foo, bar } from "./exports.js";
type;
as; // Error (used in emitting position)
something; // Error (used in emitting position)
foo; // Error (used in emitting position)
bar; // Error (used in emitting position)

//// [exports.ts]
const type = 0;
const as = 0;
const something = 0;
export { type };
export { type as };
export { type something };
export { type type as foo };
export { type as as bar };
export type { type something as whatever }; // Error


//// [exports.js]
var type = 0;
var as = 0;
var something = 0;
export { type };
//// [imports.js]
import { type } from "./exports.js";
type;
as; // Error (used in emitting position)
something; // Error (used in emitting position)
foo; // Error (used in emitting position)
bar; // Error (used in emitting position)


//// [exports.d.ts]
declare const type = 0;
declare const as = 0;
declare const something = 0;
export { type };
export { type as };
export { type something };
export { type type as foo };
export { type as as bar };
export type { type something as whatever };
//// [imports.d.ts]
export {};
54 changes: 54 additions & 0 deletions tests/baselines/reference/exportSpecifiers.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
=== /imports.ts ===
import { type, as, something, foo, bar } from "./exports.js";
>type : Symbol(type, Decl(imports.ts, 0, 8))
>as : Symbol(as, Decl(imports.ts, 0, 14))
>something : Symbol(something, Decl(imports.ts, 0, 18))
>foo : Symbol(foo, Decl(imports.ts, 0, 29))
>bar : Symbol(bar, Decl(imports.ts, 0, 34))

type;
>type : Symbol(type, Decl(imports.ts, 0, 8))

as; // Error (used in emitting position)
>as : Symbol(as, Decl(imports.ts, 0, 14))

something; // Error (used in emitting position)
>something : Symbol(something, Decl(imports.ts, 0, 18))

foo; // Error (used in emitting position)
>foo : Symbol(foo, Decl(imports.ts, 0, 29))

bar; // Error (used in emitting position)
>bar : Symbol(bar, Decl(imports.ts, 0, 34))

=== /exports.ts ===
const type = 0;
>type : Symbol(type, Decl(exports.ts, 0, 5))

const as = 0;
>as : Symbol(as, Decl(exports.ts, 1, 5))

const something = 0;
>something : Symbol(something, Decl(exports.ts, 2, 5))

export { type };
>type : Symbol(type, Decl(exports.ts, 3, 8))

export { type as };
>as : Symbol(as, Decl(exports.ts, 4, 8))

export { type something };
>something : Symbol(something, Decl(exports.ts, 5, 8))

export { type type as foo };
>type : Symbol(type, Decl(exports.ts, 0, 5))
>foo : Symbol(foo, Decl(exports.ts, 6, 8))

export { type as as bar };
>as : Symbol(as, Decl(exports.ts, 1, 5))
>bar : Symbol(bar, Decl(exports.ts, 7, 8))

export type { type something as whatever }; // Error
>something : Symbol(something, Decl(exports.ts, 2, 5))
>whatever : Symbol(whatever, Decl(exports.ts, 8, 13))

57 changes: 57 additions & 0 deletions tests/baselines/reference/exportSpecifiers.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
=== /imports.ts ===
import { type, as, something, foo, bar } from "./exports.js";
>type : 0
>as : 0
>something : 0
>foo : 0
>bar : 0

type;
>type : 0

as; // Error (used in emitting position)
>as : 0

something; // Error (used in emitting position)
>something : 0

foo; // Error (used in emitting position)
>foo : 0

bar; // Error (used in emitting position)
>bar : 0

=== /exports.ts ===
const type = 0;
>type : 0
>0 : 0

const as = 0;
>as : 0
>0 : 0

const something = 0;
>something : 0
>0 : 0

export { type };
>type : 0

export { type as };
>as : 0

export { type something };
>something : 0

export { type type as foo };
>type : 0
>foo : 0

export { type as as bar };
>as : 0
>bar : 0

export type { type something as whatever }; // Error
>something : 0
>whatever : any

Loading