-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Add migration for TSModuleDeclaration AST change #3021
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -110,9 +110,42 @@ Check out the [v8-migration guide](v8-migration.md) for other user-level changes | |||||
|
||||||
__Migration__: If you have a customized plugin accessing `typeParameter` of a `TSMappedType` node, use `node.key` and `node.constraint` in Babel 8. | ||||||
|
||||||
- Use `TSQualifiedName` for `namespace X.Y {}`'s name ([#16982](https://github.com/babel/babel/pull/16982)) | ||||||
|
||||||
Rather than representing `namespace X.Y {}` as two nested `TSModuleDeclaration` nodes with names `X` and `Y`, | ||||||
it is not represented as a single `TSModuleDeclaration` whose name is a `TSQualifiedName(X, Y)`. This change | ||||||
aligns the AST with `@typescript-eslint`. parser. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
```ts | ||||||
// Example input | ||||||
namespace X.Y {} | ||||||
|
||||||
// AST in Babel 7 | ||||||
{ | ||||||
type: "TSModuleDeclaration", | ||||||
id: Identifier("X"), | ||||||
body: { | ||||||
type: "TSModuleDeclaration", | ||||||
id: Identifier("Y") | ||||||
body: TSModuleBlock([]), | ||||||
}, | ||||||
} | ||||||
|
||||||
// AST in Babel 8 | ||||||
{ | ||||||
type: "TSModuleDeclaration", | ||||||
id: { | ||||||
type: "TSQualifiedName", | ||||||
left: Identifier("X"), | ||||||
right: Identifier("Y"), | ||||||
}, | ||||||
body: TSModuleBlock([]), | ||||||
} | ||||||
``` | ||||||
|
||||||
![low](https://img.shields.io/badge/risk%20of%20breakage%3F-low-yellowgreen.svg) | ||||||
|
||||||
- Don't generate `TSParenthesizedType` unless `createParenthesizedExpression` is enabled([#9546](https://github.com/babel/babel/issues/9546), [#12608](https://github.com/babel/babel/pull/12608)) | ||||||
- Don't generate `TSParenthesizedType` unless `createParenthesizedExpression` is enabled ([#9546](https://github.com/babel/babel/issues/9546), [#12608](https://github.com/babel/babel/pull/12608)) | ||||||
|
||||||
```ts title="input.ts" | ||||||
type T = ({}); | ||||||
|
@@ -204,6 +237,24 @@ Check out the [v8-migration guide](v8-migration.md) for other user-level changes | |||||
} | ||||||
``` | ||||||
|
||||||
- The second argument (`body`) of `TSModuleDeclaration` cannot be a `TSModuleDeclaration` anymore ([#16982](https://github.com/babel/babel/pull/16982)) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
__Migration__: Either create a `TSModuleBlock` body that exports the `TSModuleDeclaration`, or create a | ||||||
single `TSModuleDeclaration` that has a `TSQualifiedName` as its name. | ||||||
|
||||||
```diff title="my-babel-codemod.js" | ||||||
// Create `namespace X.Y {}` | ||||||
t.tsModuleDeclaration( | ||||||
+ t.tsQualifiedName( | ||||||
t.identifier("X"), | ||||||
- t.tsModuleDeclaration( | ||||||
t.identifier("Y"), | ||||||
+ ), | ||||||
t.tsModuleBlock([]) | ||||||
- ) | ||||||
) | ||||||
``` | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would expect there are two examples here since we have mentioned two migration approaches. This example seems to be of the second one. Could you add an example for the first approach? |
||||||
|
||||||
![low](https://img.shields.io/badge/risk%20of%20breakage%3F-low-yellowgreen.svg) | ||||||
|
||||||
- Remove `t.jSX*` and `t.tS*` builder aliases ([#6989](https://github.com/babel/babel/issues/6989), [#15527](https://github.com/babel/babel/pull/15527)) | ||||||
|
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.