-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Restore import defer =
parsing
#61837
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
Merged
DanielRosenwasser
merged 1 commit into
microsoft:main
from
nicolo-ribaudo:restore-import-defer-equals
Jun 9, 2025
Merged
Changes from all commits
Commits
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
//// [tests/cases/conformance/importDefer/importBindingDefer.ts] //// | ||
|
||
//// [a.ts] | ||
export default 2; | ||
|
||
//// [b.ts] | ||
import defer from "./a.js"; | ||
|
||
|
||
//// [a.js] | ||
export default 2; | ||
//// [b.js] | ||
export {}; |
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,10 @@ | ||
//// [tests/cases/conformance/importDefer/importBindingDefer.ts] //// | ||
|
||
=== a.ts === | ||
|
||
export default 2; | ||
|
||
=== b.ts === | ||
import defer from "./a.js"; | ||
>defer : Symbol(defer, Decl(b.ts, 0, 6)) | ||
|
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,11 @@ | ||
//// [tests/cases/conformance/importDefer/importBindingDefer.ts] //// | ||
|
||
=== a.ts === | ||
|
||
export default 2; | ||
|
||
=== b.ts === | ||
import defer from "./a.js"; | ||
>defer : 2 | ||
> : ^ | ||
|
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,13 @@ | ||
//// [tests/cases/conformance/importDefer/importBindingDefer2.ts] //// | ||
|
||
//// [a.ts] | ||
export default 2; | ||
|
||
//// [b.ts] | ||
import defer, {} from "./a.js"; | ||
|
||
|
||
//// [a.js] | ||
export default 2; | ||
//// [b.js] | ||
export {}; |
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,10 @@ | ||
//// [tests/cases/conformance/importDefer/importBindingDefer2.ts] //// | ||
|
||
=== a.ts === | ||
|
||
export default 2; | ||
|
||
=== b.ts === | ||
import defer, {} from "./a.js"; | ||
>defer : Symbol(defer, Decl(b.ts, 0, 6)) | ||
|
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,11 @@ | ||
//// [tests/cases/conformance/importDefer/importBindingDefer2.ts] //// | ||
|
||
=== a.ts === | ||
|
||
export default 2; | ||
|
||
=== b.ts === | ||
import defer, {} from "./a.js"; | ||
>defer : 2 | ||
> : ^ | ||
|
11 changes: 11 additions & 0 deletions
11
tests/baselines/reference/importDeferFromInvalid.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,11 @@ | ||
b.ts(1,8): error TS18058: Default imports are not allowed in a deferred import. | ||
|
||
|
||
==== a.ts (0 errors) ==== | ||
export default 2; | ||
|
||
==== b.ts (1 errors) ==== | ||
import defer from from "./a.js"; | ||
~~~~~~~~~~ | ||
!!! error TS18058: Default imports are not allowed in a deferred import. | ||
|
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,13 @@ | ||
//// [tests/cases/conformance/importDefer/importDeferFromInvalid.ts] //// | ||
|
||
//// [a.ts] | ||
export default 2; | ||
|
||
//// [b.ts] | ||
import defer from from "./a.js"; | ||
|
||
|
||
//// [a.js] | ||
export default 2; | ||
//// [b.js] | ||
export {}; |
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,10 @@ | ||
//// [tests/cases/conformance/importDefer/importDeferFromInvalid.ts] //// | ||
|
||
=== a.ts === | ||
|
||
export default 2; | ||
|
||
=== b.ts === | ||
import defer from from "./a.js"; | ||
>from : Symbol(from, Decl(b.ts, 0, 6)) | ||
|
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,11 @@ | ||
//// [tests/cases/conformance/importDefer/importDeferFromInvalid.ts] //// | ||
|
||
=== a.ts === | ||
|
||
export default 2; | ||
|
||
=== b.ts === | ||
import defer from from "./a.js"; | ||
>from : 2 | ||
> : ^ | ||
|
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,15 @@ | ||
//// [tests/cases/conformance/importDefer/importEqualsBindingDefer.ts] //// | ||
|
||
//// [a.ts] | ||
export = 2; | ||
|
||
//// [b.ts] | ||
import defer = require("./a"); | ||
|
||
|
||
//// [a.js] | ||
"use strict"; | ||
module.exports = 2; | ||
//// [b.js] | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); |
10 changes: 10 additions & 0 deletions
10
tests/baselines/reference/importEqualsBindingDefer.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,10 @@ | ||
//// [tests/cases/conformance/importDefer/importEqualsBindingDefer.ts] //// | ||
|
||
=== b.ts === | ||
import defer = require("./a"); | ||
>defer : Symbol(defer, Decl(b.ts, 0, 0)) | ||
|
||
=== a.ts === | ||
|
||
export = 2; | ||
|
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,11 @@ | ||
//// [tests/cases/conformance/importDefer/importEqualsBindingDefer.ts] //// | ||
|
||
=== b.ts === | ||
import defer = require("./a"); | ||
>defer : 2 | ||
> : ^ | ||
|
||
=== a.ts === | ||
|
||
export = 2; | ||
|
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,8 @@ | ||
// @module: esnext | ||
// @target: es2020 | ||
|
||
// @filename: a.ts | ||
export default 2; | ||
|
||
// @filename: b.ts | ||
import defer from "./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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// @module: esnext | ||
// @target: es2020 | ||
|
||
// @filename: a.ts | ||
export default 2; | ||
|
||
// @filename: b.ts | ||
import defer, {} from "./a.js"; |
8 changes: 8 additions & 0 deletions
8
tests/cases/conformance/importDefer/importDeferFromInvalid.ts
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,8 @@ | ||
// @module: esnext | ||
// @target: es2020 | ||
|
||
// @filename: a.ts | ||
export default 2; | ||
|
||
// @filename: b.ts | ||
import defer from from "./a.js"; |
8 changes: 8 additions & 0 deletions
8
tests/cases/conformance/importDefer/importEqualsBindingDefer.ts
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,8 @@ | ||
// @module: commonjs | ||
// @target: es2020 | ||
|
||
// @filename: a.ts | ||
export = 2; | ||
|
||
// @filename: b.ts | ||
import defer = require("./a"); |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why isn't this just the same as what's done for
type
above? You can't mixtype
anddefer
, so I would have expected both to parse in the same fashion.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The difference is that the
type
parsing considerstype
as a modifier inimport type foo =
, while thedefer
parsing doesn't inimport defer foo =
.Do you prefer if I unify the path, but then add a "nice" error for
import defer foo =
rather than just complaining about the unexpectedfoo
/=
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Daniel pointed out there's a difference between them in other ways like
import type foo, { bar } from "..."
is not legal as it's ambiguous whether or notbar
is type or not. So, all good.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well technically we could still unify parsing for them and report that
type
case as an "early error" while still building the proper AST.(I'm happy to both keep the code as-is or to update it)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After thinking more, technically neither allow named bindings or defaults. I think this is okay as-is. I'll make a second PR to add more tests.