Skip to content
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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 52 additions & 1 deletion docs/v8-migration-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
it is not represented as a single `TSModuleDeclaration` whose name is a `TSQualifiedName(X, Y)`. This change
it is now represented as a single `TSModuleDeclaration` whose name is a `TSQualifiedName(X, Y)`. This change

aligns the AST with `@typescript-eslint`. parser.
Copy link
Member

Choose a reason for hiding this comment

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

Is the . here accidental?

Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
aligns the AST with `@typescript-eslint`. parser.
aligns the AST with the `@typescript-eslint` parser.


```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 = ({});
Expand Down Expand Up @@ -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))
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
- The second argument (`body`) of `TSModuleDeclaration` cannot be a `TSModuleDeclaration` anymore ([#16982](https://github.com/babel/babel/pull/16982))
- The second argument (`body`) of `t.tsModuleDeclaration` cannot be a `TSModuleDeclaration` node anymore ([#16982](https://github.com/babel/babel/pull/16982))


__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([])
- )
)
```
Copy link
Contributor

Choose a reason for hiding this comment

The 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))
Expand Down