Skip to content

[Babel 8] Parse export import = as an ExportNamedDeclaration#17073

Merged
JLHwung merged 4 commits intobabel:mainfrom
JLHwung:export-ts-import-equals
Jan 24, 2025
Merged

[Babel 8] Parse export import = as an ExportNamedDeclaration#17073
JLHwung merged 4 commits intobabel:mainfrom
JLHwung:export-ts-import-equals

Conversation

@JLHwung
Copy link
Copy Markdown
Contributor

@JLHwung JLHwung commented Jan 21, 2025

Q                       A
Fixed Issues? #16679
Patch: Bug Fix?
Major: Breaking Change? Yes
Minor: New Feature?
Tests Added + Pass? Yes
Documentation PR Link babel/website#3043
Any Dependency Changes?
License MIT

In this PR we parse the TSImportEqualsDeclaration { isExport: true } as a vanilla TSImportEqualsDeclaration within an ExportNamedDeclaration. The isExport field is therefore removed.

@JLHwung JLHwung added PR: Breaking Change 💥 A type of pull request used for our changelog categories for next major release pkg: parser PR: Needs Docs labels Jan 21, 2025
@JLHwung JLHwung force-pushed the export-ts-import-equals branch from a0efb71 to f074683 Compare January 21, 2025 16:13
@babel-bot
Copy link
Copy Markdown
Collaborator

babel-bot commented Jan 21, 2025

Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/58625

@JLHwung JLHwung marked this pull request as ready for review January 21, 2025 17:11
if (this.match(tt._import)) {
// `export import A = B;`
const nodeImportEquals = process.env.BABEL_8_BREAKING
? this.startNode<N.TsImportEqualsDeclaration>()
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that in Babel 8, TSImportEqualsDeclaration always starts with the import keyword, while the preceding export keyword starts the ExportNamedDeclaration.

!isExport &&
(process.env.BABEL_8_BREAKING ||
// @ts-ignore(Babel 7 vs Babel 8) Babel 7 AST
!stmt.node.isExport) &&
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here we are checking top level statements, since a top-level TSImportEqualsDeclaration will be always an import declaration in Babel 8, we don't need the !isExport check here.

| VariableDeclaration
| ClassDeclaration
| FunctionDeclaration
| TsImportEqualsDeclaration
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to do the same thing in @babel/types.

@JLHwung JLHwung merged commit 1988499 into babel:main Jan 24, 2025
@JLHwung JLHwung deleted the export-ts-import-equals branch January 24, 2025 15:39
laine-hallot pushed a commit to laine-hallot/uwu-parser that referenced this pull request Mar 31, 2025
…#17073)

* breaking: parse export import = as ExportNamedDeclaration

* update AST fixtures

* fix Babel 8 typing errors

* add TSImportEqualsDeclaration to Declaration
@github-actions github-actions bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Apr 26, 2025
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 26, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

outdated A closed issue/PR that is archived due to age. Recommended to make a new issue pkg: parser PR: Breaking Change 💥 A type of pull request used for our changelog categories for next major release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants