Repository navigation
fix(64627): reject deferred imports without namespace bindings #64640
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
Open
Oleksandr Tarasiuk (a-tarasyuk)
wants to merge
2
commits into
microsoft:main
Choose a base branch
from
a-tarasyuk:fix/64627
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+298
−38
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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
47 changes: 47 additions & 0 deletions
47
...ata/baselines/reference/conformance/importDeferInvalidDefault(module=commonjs).errors.txt
This file contains hidden or 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,47 @@ | ||
| b.ts(1,8): error TS18058: Default imports are not allowed in a deferred import. | ||
| b.ts(5,8): error TS18116: A deferred import must specify a namespace binding. | ||
| b.ts(6,8): error TS18116: A deferred import must specify a namespace binding. | ||
| b.ts(6,23): error TS2823: Import attributes are only supported when the '--module' option is set to 'esnext', 'node18', 'node20', 'nodenext', or 'preserve'. | ||
| c.js(2,8): error TS18116: A deferred import must specify a namespace binding. | ||
| c.js(3,8): error TS18116: A deferred import must specify a namespace binding. | ||
| c.js(3,23): error TS2823: Import attributes are only supported when the '--module' option is set to 'esnext', 'node18', 'node20', 'nodenext', or 'preserve'. | ||
| d.js(1,8): error TS18116: A deferred import must specify a namespace binding. | ||
|
|
||
|
|
||
| ==== a.ts (0 errors) ==== | ||
| export default function foo() { | ||
| console.log("foo from a"); | ||
| } | ||
|
|
||
| ==== b.ts (4 errors) ==== | ||
| import defer foo from "./a"; | ||
| ~~~~~~~~~ | ||
| !!! error TS18058: Default imports are not allowed in a deferred import. | ||
|
|
||
| foo(); | ||
|
|
||
| import defer "./a.js"; | ||
| ~~~~~ | ||
| !!! error TS18116: A deferred import must specify a namespace binding. | ||
| import defer "./a.js" with { type: "json" }; | ||
| ~~~~~ | ||
| !!! error TS18116: A deferred import must specify a namespace binding. | ||
| ~~~~~~~~~~~~~~~~~~~~~ | ||
| !!! error TS2823: Import attributes are only supported when the '--module' option is set to 'esnext', 'node18', 'node20', 'nodenext', or 'preserve'. | ||
|
|
||
| ==== c.js (3 errors) ==== | ||
| // @ts-check | ||
| import defer "./a.js"; | ||
| ~~~~~ | ||
| !!! error TS18116: A deferred import must specify a namespace binding. | ||
| import defer "./a.js" with { type: "json" }; | ||
| ~~~~~ | ||
| !!! error TS18116: A deferred import must specify a namespace binding. | ||
| ~~~~~~~~~~~~~~~~~~~~~ | ||
| !!! error TS2823: Import attributes are only supported when the '--module' option is set to 'esnext', 'node18', 'node20', 'nodenext', or 'preserve'. | ||
|
|
||
| ==== d.js (1 errors) ==== | ||
| import defer "./a.js"; | ||
| ~~~~~ | ||
| !!! error TS18116: A deferred import must specify a namespace binding. | ||
|
|
49 changes: 49 additions & 0 deletions
49
tsc/testdata/baselines/reference/conformance/importDeferInvalidDefault(module=commonjs).js
This file contains hidden or 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,49 @@ | ||
| //// [tests/cases/conformance/importDefer/importDeferInvalidDefault.ts] //// | ||
|
|
||
| //// [a.ts] | ||
| export default function foo() { | ||
| console.log("foo from a"); | ||
| } | ||
|
|
||
| //// [b.ts] | ||
| import defer foo from "./a"; | ||
|
|
||
| foo(); | ||
|
|
||
| import defer "./a.js"; | ||
| import defer "./a.js" with { type: "json" }; | ||
|
|
||
| //// [c.js] | ||
| // @ts-check | ||
| import defer "./a.js"; | ||
| import defer "./a.js" with { type: "json" }; | ||
|
|
||
| //// [d.js] | ||
| import defer "./a.js"; | ||
|
|
||
|
|
||
| //// [a.js] | ||
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.default = foo; | ||
| function foo() { | ||
| console.log("foo from a"); | ||
| } | ||
| //// [b.js] | ||
| "use strict"; | ||
| var __importDefault = (this && this.__importDefault) || function (mod) { | ||
| return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
| }; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| const a_1 = __importDefault(require("./a")); | ||
| (0, a_1.default)(); | ||
| //// [c.js] | ||
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| // @ts-check | ||
| const a_js_1 = require("./a.js"); | ||
| const a_js_2 = require("./a.js"); | ||
| //// [d.js] | ||
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| const a_js_1 = require("./a.js"); |
This file contains hidden or 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 hidden or 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
41 changes: 41 additions & 0 deletions
41
...tdata/baselines/reference/conformance/importDeferInvalidDefault(module=esnext).errors.txt
This file contains hidden or 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,41 @@ | ||
| b.ts(1,8): error TS18058: Default imports are not allowed in a deferred import. | ||
| b.ts(5,8): error TS18116: A deferred import must specify a namespace binding. | ||
| b.ts(6,8): error TS18116: A deferred import must specify a namespace binding. | ||
| c.js(2,8): error TS18116: A deferred import must specify a namespace binding. | ||
| c.js(3,8): error TS18116: A deferred import must specify a namespace binding. | ||
| d.js(1,8): error TS18116: A deferred import must specify a namespace binding. | ||
|
|
||
|
|
||
| ==== a.ts (0 errors) ==== | ||
| export default function foo() { | ||
| console.log("foo from a"); | ||
| } | ||
|
|
||
| ==== b.ts (3 errors) ==== | ||
| import defer foo from "./a"; | ||
| ~~~~~~~~~ | ||
| !!! error TS18058: Default imports are not allowed in a deferred import. | ||
|
|
||
| foo(); | ||
|
|
||
| import defer "./a.js"; | ||
| ~~~~~ | ||
| !!! error TS18116: A deferred import must specify a namespace binding. | ||
| import defer "./a.js" with { type: "json" }; | ||
| ~~~~~ | ||
| !!! error TS18116: A deferred import must specify a namespace binding. | ||
|
|
||
| ==== c.js (2 errors) ==== | ||
| // @ts-check | ||
| import defer "./a.js"; | ||
| ~~~~~ | ||
| !!! error TS18116: A deferred import must specify a namespace binding. | ||
| import defer "./a.js" with { type: "json" }; | ||
| ~~~~~ | ||
| !!! error TS18116: A deferred import must specify a namespace binding. | ||
|
|
||
| ==== d.js (1 errors) ==== | ||
| import defer "./a.js"; | ||
| ~~~~~ | ||
| !!! error TS18116: A deferred import must specify a namespace binding. | ||
|
|
37 changes: 37 additions & 0 deletions
37
tsc/testdata/baselines/reference/conformance/importDeferInvalidDefault(module=esnext).js
This file contains hidden or 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,37 @@ | ||
| //// [tests/cases/conformance/importDefer/importDeferInvalidDefault.ts] //// | ||
|
|
||
| //// [a.ts] | ||
| export default function foo() { | ||
| console.log("foo from a"); | ||
| } | ||
|
|
||
| //// [b.ts] | ||
| import defer foo from "./a"; | ||
|
|
||
| foo(); | ||
|
|
||
| import defer "./a.js"; | ||
| import defer "./a.js" with { type: "json" }; | ||
|
|
||
| //// [c.js] | ||
| // @ts-check | ||
| import defer "./a.js"; | ||
| import defer "./a.js" with { type: "json" }; | ||
|
|
||
| //// [d.js] | ||
| import defer "./a.js"; | ||
|
|
||
|
|
||
| //// [a.js] | ||
| export default function foo() { | ||
| console.log("foo from a"); | ||
| } | ||
| //// [b.js] | ||
| import defer foo from "./a"; | ||
| foo(); | ||
| //// [c.js] | ||
| // @ts-check | ||
| import defer from "./a.js"; | ||
| import defer from "./a.js" with { type: "json" }; | ||
| //// [d.js] | ||
| import defer from "./a.js"; |
32 changes: 32 additions & 0 deletions
32
...testdata/baselines/reference/conformance/importDeferInvalidDefault(module=esnext).symbols
This file contains hidden or 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,32 @@ | ||
| //// [tests/cases/conformance/importDefer/importDeferInvalidDefault.ts] //// | ||
|
|
||
| === a.ts === | ||
| export default function foo() { | ||
| >foo : Symbol(foo, Decl(a.ts, 0, 0)) | ||
|
|
||
| console.log("foo from a"); | ||
| >console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) | ||
| >console : Symbol(console, Decl(lib.dom.d.ts, --, --)) | ||
| >log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) | ||
| } | ||
|
|
||
| === b.ts === | ||
| import defer foo from "./a"; | ||
| >foo : Symbol(foo, Decl(b.ts, 0, 6)) | ||
|
|
||
| foo(); | ||
| >foo : Symbol(foo, Decl(b.ts, 0, 6)) | ||
|
|
||
| import defer "./a.js"; | ||
| import defer "./a.js" with { type: "json" }; | ||
|
|
||
| === c.js === | ||
|
|
||
| // @ts-check | ||
| import defer "./a.js"; | ||
| import defer "./a.js" with { type: "json" }; | ||
|
|
||
| === d.js === | ||
|
|
||
| import defer "./a.js"; | ||
|
|
36 changes: 36 additions & 0 deletions
36
tsc/testdata/baselines/reference/conformance/importDeferInvalidDefault(module=esnext).types
This file contains hidden or 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,36 @@ | ||
| //// [tests/cases/conformance/importDefer/importDeferInvalidDefault.ts] //// | ||
|
|
||
| === a.ts === | ||
| export default function foo() { | ||
| >foo : () => void | ||
|
|
||
| console.log("foo from a"); | ||
| >console.log("foo from a") : void | ||
| >console.log : (...data: any[]) => void | ||
| >console : Console | ||
| >log : (...data: any[]) => void | ||
| >"foo from a" : "foo from a" | ||
| } | ||
|
|
||
| === b.ts === | ||
| import defer foo from "./a"; | ||
| >foo : () => void | ||
|
|
||
| foo(); | ||
| >foo() : void | ||
| >foo : () => void | ||
|
|
||
| import defer "./a.js"; | ||
| import defer "./a.js" with { type: "json" }; | ||
| >type : any | ||
|
|
||
| === c.js === | ||
| // @ts-check | ||
| import defer "./a.js"; | ||
| import defer "./a.js" with { type: "json" }; | ||
| >type : any | ||
|
|
||
| === d.js === | ||
|
|
||
| import defer "./a.js"; | ||
|
|
14 changes: 0 additions & 14 deletions
14
tsc/testdata/baselines/reference/conformance/importDeferInvalidDefault.errors.txt
This file was deleted.
Oops, something went wrong.
19 changes: 0 additions & 19 deletions
19
tsc/testdata/baselines/reference/conformance/importDeferInvalidDefault.js
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.