Skip to content

Commit

Permalink
fix(48445): show errors on type-only import/export specifiers in Java…
Browse files Browse the repository at this point in the history
…Script files (#48449)
  • Loading branch information
a-tarasyuk committed Mar 29, 2022
1 parent d962091 commit bf7bfa1
Show file tree
Hide file tree
Showing 9 changed files with 73 additions and 0 deletions.
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";

0 comments on commit bf7bfa1

Please sign in to comment.