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(48445): import { type X } not flagged in JavaScript #48449

Merged
merged 1 commit into from
Mar 29, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/compiler/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2273,6 +2273,13 @@ namespace ts {
return "skip";
}
break;
case SyntaxKind.ImportSpecifier:
case SyntaxKind.ExportSpecifier:
if ((node as ImportOrExportSpecifier).isTypeOnly) {
diagnostics.push(createDiagnosticForNode(node, Diagnostics._0_declarations_can_only_be_used_in_TypeScript_files, isImportSpecifier(node) ? "import...type" : "export...type"));
return "skip";
}
break;
case SyntaxKind.ImportEqualsDeclaration:
diagnostics.push(createDiagnosticForNode(node, Diagnostics.import_can_only_be_used_in_TypeScript_files));
return "skip";
Expand Down
9 changes: 9 additions & 0 deletions tests/baselines/reference/exportSpecifiers_js.errors.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
tests/cases/conformance/externalModules/typeOnly/a.js(2,10): error TS8006: 'export...type' declarations can only be used in TypeScript files.


==== tests/cases/conformance/externalModules/typeOnly/a.js (1 errors) ====
const foo = 0;
export { type foo };
~~~~~~~~
!!! error TS8006: 'export...type' declarations can only be used in TypeScript files.

7 changes: 7 additions & 0 deletions tests/baselines/reference/exportSpecifiers_js.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
=== tests/cases/conformance/externalModules/typeOnly/a.js ===
const foo = 0;
>foo : Symbol(foo, Decl(a.js, 0, 5))

export { type foo };
>foo : Symbol(foo, Decl(a.js, 1, 8))

8 changes: 8 additions & 0 deletions tests/baselines/reference/exportSpecifiers_js.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
=== tests/cases/conformance/externalModules/typeOnly/a.js ===
const foo = 0;
>foo : 0
>0 : 0

export { type foo };
>foo : 0

11 changes: 11 additions & 0 deletions tests/baselines/reference/importSpecifiers_js.errors.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
tests/cases/conformance/externalModules/typeOnly/a.js(1,10): error TS8006: 'import...type' declarations can only be used in TypeScript files.


==== tests/cases/conformance/externalModules/typeOnly/a.ts (0 errors) ====
export interface A {}

==== tests/cases/conformance/externalModules/typeOnly/a.js (1 errors) ====
import { type A } from "./a";
~~~~~~
!!! error TS8006: 'import...type' declarations can only be used in TypeScript files.

8 changes: 8 additions & 0 deletions tests/baselines/reference/importSpecifiers_js.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
=== tests/cases/conformance/externalModules/typeOnly/a.ts ===
export interface A {}
>A : Symbol(A, Decl(a.ts, 0, 0))

=== tests/cases/conformance/externalModules/typeOnly/a.js ===
import { type A } from "./a";
>A : Symbol(A, Decl(a.js, 0, 8))

7 changes: 7 additions & 0 deletions tests/baselines/reference/importSpecifiers_js.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
=== tests/cases/conformance/externalModules/typeOnly/a.ts ===
export interface A {}
No type information for this code.
No type information for this code.=== tests/cases/conformance/externalModules/typeOnly/a.js ===
import { type A } from "./a";
>A : any

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// @allowJs: true
// @checkJs: true
// @noEmit: true

// @Filename: ./a.js
const foo = 0;
export { type foo };
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// @allowJs: true
// @checkJs: true
// @noEmit: true

// @Filename: ./a.ts
export interface A {}

// @Filename: ./a.js
import { type A } from "./a";