-
Notifications
You must be signed in to change notification settings - Fork 12.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve errors on module: node12 and extensionless relative imports (#…
…46486) * add new error + suggestions * push down assert defined * remove comment * fix esm module import detection, update baselines * add and update new tests * fix review comments * remove renamed baseline references * update node modules test baselines * fix error message, add new tests * update old tests with new error message
- Loading branch information
Showing
47 changed files
with
854 additions
and
404 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
tests/baselines/reference/moduleResolutionWithoutExtension1.errors.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/src/bar.mts(2,21): error TS2835: Relative import paths need explicit file extensions in EcmaScript imports when '--moduleResolution' is 'node12' or 'nodenext'. Did you mean './foo.mjs'? | ||
/src/bar.mts(3,21): error TS2834: Relative import paths need explicit file extensions in EcmaScript imports when '--moduleResolution' is 'node12' or 'nodenext'. Consider adding an extension to the import path. | ||
|
||
|
||
==== /src/foo.mts (0 errors) ==== | ||
export function foo() { | ||
return ""; | ||
} | ||
|
||
==== /src/bar.mts (2 errors) ==== | ||
// Extensionless relative path ES import in an ES module | ||
import { foo } from "./foo"; // should error, suggest adding ".mjs" | ||
~~~~~~~ | ||
!!! error TS2835: Relative import paths need explicit file extensions in EcmaScript imports when '--moduleResolution' is 'node12' or 'nodenext'. Did you mean './foo.mjs'? | ||
import { baz } from "./baz"; // should error, ask for extension, no extension suggestion | ||
~~~~~~~ | ||
!!! error TS2834: Relative import paths need explicit file extensions in EcmaScript imports when '--moduleResolution' is 'node12' or 'nodenext'. Consider adding an extension to the import path. | ||
|
19 changes: 19 additions & 0 deletions
19
tests/baselines/reference/moduleResolutionWithoutExtension1.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
//// [tests/cases/conformance/externalModules/moduleResolutionWithoutExtension1.ts] //// | ||
|
||
//// [foo.mts] | ||
export function foo() { | ||
return ""; | ||
} | ||
|
||
//// [bar.mts] | ||
// Extensionless relative path ES import in an ES module | ||
import { foo } from "./foo"; // should error, suggest adding ".mjs" | ||
import { baz } from "./baz"; // should error, ask for extension, no extension suggestion | ||
|
||
|
||
//// [foo.mjs] | ||
export function foo() { | ||
return ""; | ||
} | ||
//// [bar.mjs] | ||
export {}; |
15 changes: 15 additions & 0 deletions
15
tests/baselines/reference/moduleResolutionWithoutExtension1.symbols
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
=== /src/foo.mts === | ||
export function foo() { | ||
>foo : Symbol(foo, Decl(foo.mts, 0, 0)) | ||
|
||
return ""; | ||
} | ||
|
||
=== /src/bar.mts === | ||
// Extensionless relative path ES import in an ES module | ||
import { foo } from "./foo"; // should error, suggest adding ".mjs" | ||
>foo : Symbol(foo, Decl(bar.mts, 1, 8)) | ||
|
||
import { baz } from "./baz"; // should error, ask for extension, no extension suggestion | ||
>baz : Symbol(baz, Decl(bar.mts, 2, 8)) | ||
|
16 changes: 16 additions & 0 deletions
16
tests/baselines/reference/moduleResolutionWithoutExtension1.types
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
=== /src/foo.mts === | ||
export function foo() { | ||
>foo : () => string | ||
|
||
return ""; | ||
>"" : "" | ||
} | ||
|
||
=== /src/bar.mts === | ||
// Extensionless relative path ES import in an ES module | ||
import { foo } from "./foo"; // should error, suggest adding ".mjs" | ||
>foo : any | ||
|
||
import { baz } from "./baz"; // should error, ask for extension, no extension suggestion | ||
>baz : any | ||
|
8 changes: 8 additions & 0 deletions
8
tests/baselines/reference/moduleResolutionWithoutExtension2.errors.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/src/buzz.mts(2,22): error TS2307: Cannot find module './foo' or its corresponding type declarations. | ||
|
||
|
||
==== /src/buzz.mts (1 errors) ==== | ||
// Extensionless relative path cjs import in an ES module | ||
import foo = require("./foo"); // should error, should not ask for extension | ||
~~~~~~~ | ||
!!! error TS2307: Cannot find module './foo' or its corresponding type declarations. |
6 changes: 6 additions & 0 deletions
6
tests/baselines/reference/moduleResolutionWithoutExtension2.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
//// [buzz.mts] | ||
// Extensionless relative path cjs import in an ES module | ||
import foo = require("./foo"); // should error, should not ask for extension | ||
|
||
//// [buzz.mjs] | ||
export {}; |
5 changes: 5 additions & 0 deletions
5
tests/baselines/reference/moduleResolutionWithoutExtension2.symbols
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
=== /src/buzz.mts === | ||
// Extensionless relative path cjs import in an ES module | ||
import foo = require("./foo"); // should error, should not ask for extension | ||
>foo : Symbol(foo, Decl(buzz.mts, 0, 0)) | ||
|
5 changes: 5 additions & 0 deletions
5
tests/baselines/reference/moduleResolutionWithoutExtension2.types
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
=== /src/buzz.mts === | ||
// Extensionless relative path cjs import in an ES module | ||
import foo = require("./foo"); // should error, should not ask for extension | ||
>foo : any | ||
|
14 changes: 14 additions & 0 deletions
14
tests/baselines/reference/moduleResolutionWithoutExtension3.errors.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/src/bar.mts(2,21): error TS2835: Relative import paths need explicit file extensions in EcmaScript imports when '--moduleResolution' is 'node12' or 'nodenext'. Did you mean './foo.jsx'? | ||
|
||
|
||
==== /src/foo.tsx (0 errors) ==== | ||
export function foo() { | ||
return ""; | ||
} | ||
|
||
==== /src/bar.mts (1 errors) ==== | ||
// Extensionless relative path ES import in an ES module | ||
import { foo } from "./foo"; // should error, suggest adding ".jsx" | ||
~~~~~~~ | ||
!!! error TS2835: Relative import paths need explicit file extensions in EcmaScript imports when '--moduleResolution' is 'node12' or 'nodenext'. Did you mean './foo.jsx'? | ||
|
22 changes: 22 additions & 0 deletions
22
tests/baselines/reference/moduleResolutionWithoutExtension3.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
//// [tests/cases/conformance/externalModules/moduleResolutionWithoutExtension3.ts] //// | ||
|
||
//// [foo.tsx] | ||
export function foo() { | ||
return ""; | ||
} | ||
|
||
//// [bar.mts] | ||
// Extensionless relative path ES import in an ES module | ||
import { foo } from "./foo"; // should error, suggest adding ".jsx" | ||
|
||
|
||
//// [foo.jsx] | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.foo = void 0; | ||
function foo() { | ||
return ""; | ||
} | ||
exports.foo = foo; | ||
//// [bar.mjs] | ||
export {}; |
12 changes: 12 additions & 0 deletions
12
tests/baselines/reference/moduleResolutionWithoutExtension3.symbols
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
=== /src/foo.tsx === | ||
export function foo() { | ||
>foo : Symbol(foo, Decl(foo.tsx, 0, 0)) | ||
|
||
return ""; | ||
} | ||
|
||
=== /src/bar.mts === | ||
// Extensionless relative path ES import in an ES module | ||
import { foo } from "./foo"; // should error, suggest adding ".jsx" | ||
>foo : Symbol(foo, Decl(bar.mts, 1, 8)) | ||
|
13 changes: 13 additions & 0 deletions
13
tests/baselines/reference/moduleResolutionWithoutExtension3.types
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
=== /src/foo.tsx === | ||
export function foo() { | ||
>foo : () => string | ||
|
||
return ""; | ||
>"" : "" | ||
} | ||
|
||
=== /src/bar.mts === | ||
// Extensionless relative path ES import in an ES module | ||
import { foo } from "./foo"; // should error, suggest adding ".jsx" | ||
>foo : any | ||
|
14 changes: 14 additions & 0 deletions
14
tests/baselines/reference/moduleResolutionWithoutExtension4.errors.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/src/bar.mts(2,21): error TS2835: Relative import paths need explicit file extensions in EcmaScript imports when '--moduleResolution' is 'node12' or 'nodenext'. Did you mean './foo.js'? | ||
|
||
|
||
==== /src/foo.tsx (0 errors) ==== | ||
export function foo() { | ||
return ""; | ||
} | ||
|
||
==== /src/bar.mts (1 errors) ==== | ||
// Extensionless relative path ES import in an ES module | ||
import { foo } from "./foo"; // should error, suggest adding ".js" | ||
~~~~~~~ | ||
!!! error TS2835: Relative import paths need explicit file extensions in EcmaScript imports when '--moduleResolution' is 'node12' or 'nodenext'. Did you mean './foo.js'? | ||
|
22 changes: 22 additions & 0 deletions
22
tests/baselines/reference/moduleResolutionWithoutExtension4.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
//// [tests/cases/conformance/externalModules/moduleResolutionWithoutExtension4.ts] //// | ||
|
||
//// [foo.tsx] | ||
export function foo() { | ||
return ""; | ||
} | ||
|
||
//// [bar.mts] | ||
// Extensionless relative path ES import in an ES module | ||
import { foo } from "./foo"; // should error, suggest adding ".js" | ||
|
||
|
||
//// [foo.js] | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.foo = void 0; | ||
function foo() { | ||
return ""; | ||
} | ||
exports.foo = foo; | ||
//// [bar.mjs] | ||
export {}; |
12 changes: 12 additions & 0 deletions
12
tests/baselines/reference/moduleResolutionWithoutExtension4.symbols
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
=== /src/foo.tsx === | ||
export function foo() { | ||
>foo : Symbol(foo, Decl(foo.tsx, 0, 0)) | ||
|
||
return ""; | ||
} | ||
|
||
=== /src/bar.mts === | ||
// Extensionless relative path ES import in an ES module | ||
import { foo } from "./foo"; // should error, suggest adding ".js" | ||
>foo : Symbol(foo, Decl(bar.mts, 1, 8)) | ||
|
13 changes: 13 additions & 0 deletions
13
tests/baselines/reference/moduleResolutionWithoutExtension4.types
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
=== /src/foo.tsx === | ||
export function foo() { | ||
>foo : () => string | ||
|
||
return ""; | ||
>"" : "" | ||
} | ||
|
||
=== /src/bar.mts === | ||
// Extensionless relative path ES import in an ES module | ||
import { foo } from "./foo"; // should error, suggest adding ".js" | ||
>foo : any | ||
|
8 changes: 8 additions & 0 deletions
8
tests/baselines/reference/moduleResolutionWithoutExtension5.errors.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/src/buzz.mts(2,8): error TS2834: Relative import paths need explicit file extensions in EcmaScript imports when '--moduleResolution' is 'node12' or 'nodenext'. Consider adding an extension to the import path. | ||
|
||
|
||
==== /src/buzz.mts (1 errors) ==== | ||
// Extensionless relative path dynamic import in an ES module | ||
import("./foo").then(x => x); // should error, ask for extension | ||
~~~~~~~ | ||
!!! error TS2834: Relative import paths need explicit file extensions in EcmaScript imports when '--moduleResolution' is 'node12' or 'nodenext'. Consider adding an extension to the import path. |
7 changes: 7 additions & 0 deletions
7
tests/baselines/reference/moduleResolutionWithoutExtension5.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
//// [buzz.mts] | ||
// Extensionless relative path dynamic import in an ES module | ||
import("./foo").then(x => x); // should error, ask for extension | ||
|
||
//// [buzz.mjs] | ||
// Extensionless relative path dynamic import in an ES module | ||
import("./foo").then(x => x); // should error, ask for extension |
8 changes: 8 additions & 0 deletions
8
tests/baselines/reference/moduleResolutionWithoutExtension5.symbols
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
=== /src/buzz.mts === | ||
// Extensionless relative path dynamic import in an ES module | ||
import("./foo").then(x => x); // should error, ask for extension | ||
>import("./foo").then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --)) | ||
>then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --)) | ||
>x : Symbol(x, Decl(buzz.mts, 1, 21)) | ||
>x : Symbol(x, Decl(buzz.mts, 1, 21)) | ||
|
12 changes: 12 additions & 0 deletions
12
tests/baselines/reference/moduleResolutionWithoutExtension5.types
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
=== /src/buzz.mts === | ||
// Extensionless relative path dynamic import in an ES module | ||
import("./foo").then(x => x); // should error, ask for extension | ||
>import("./foo").then(x => x) : Promise<any> | ||
>import("./foo").then : <TResult1 = any, TResult2 = never>(onfulfilled?: (value: any) => TResult1 | PromiseLike<TResult1>, onrejected?: (reason: any) => TResult2 | PromiseLike<TResult2>) => Promise<TResult1 | TResult2> | ||
>import("./foo") : Promise<any> | ||
>"./foo" : "./foo" | ||
>then : <TResult1 = any, TResult2 = never>(onfulfilled?: (value: any) => TResult1 | PromiseLike<TResult1>, onrejected?: (reason: any) => TResult2 | PromiseLike<TResult2>) => Promise<TResult1 | TResult2> | ||
>x => x : (x: any) => any | ||
>x : any | ||
>x : any | ||
|
10 changes: 10 additions & 0 deletions
10
tests/baselines/reference/moduleResolutionWithoutExtension6.errors.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/src/bar.cts(4,21): error TS2307: Cannot find module './foo' or its corresponding type declarations. | ||
|
||
|
||
==== /src/bar.cts (1 errors) ==== | ||
// Extensionless relative path import statement in a cjs module | ||
// Import statements are not allowed in cjs files, | ||
// but other errors should not assume that they are allowed | ||
import { foo } from "./foo"; // should error, should not ask for extension | ||
~~~~~~~ | ||
!!! error TS2307: Cannot find module './foo' or its corresponding type declarations. |
9 changes: 9 additions & 0 deletions
9
tests/baselines/reference/moduleResolutionWithoutExtension6.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
//// [bar.cts] | ||
// Extensionless relative path import statement in a cjs module | ||
// Import statements are not allowed in cjs files, | ||
// but other errors should not assume that they are allowed | ||
import { foo } from "./foo"; // should error, should not ask for extension | ||
|
||
//// [bar.cjs] | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); |
Oops, something went wrong.