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

docs: add TSEnumBody migration #3018

Merged
merged 1 commit into from
Jan 9, 2025
Merged
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
56 changes: 56 additions & 0 deletions docs/v8-migration-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -697,6 +697,42 @@ Most of the changes to our TypeScript-specific AST nodes are to reduce the diffe
}
```

- <a name="ast-TSEnumDeclaration"></a> Wrap the `members` of `TSEnumDeclaration` within a `TSEnumBody` node ([#16979](https://github.com/babel/babel/pull/16979))

```ts title=input.ts
// Example input
enum ColorType {
Red,
Green,
Blue,
}

// AST in Babel 7
{
type: "TSEnumDeclaration",
id: Identifier("ColorType")
members: [
EnumMember("Red"),
EnumMember("Green"),
EnumMember("Blue")
]
}

// AST in Babel 8
{
type: "TSEnumDeclaration",
id: Identifier("ColorType")
body: {
type: "TSEnumBody",
members: [
EnumMember("Red"),
EnumMember("Green"),
EnumMember("Blue")
]
}
}
```

- Create `TSAbstractMethodDefinition` and `TSPropertyDefinition` when both `estree` and `typescript` parser plugins are enabled ([#16679](https://github.com/babel/babel/issues/16679), [#17014](https://github.com/babel/babel/pull/17014))

__Migration__: This breaking change is part of the efforts to libraries and ESLint plugins that can work both with `typescript-eslint` and `@babel/eslint-parser`. For most Babel plugin developers you can safely ignore this change as it does not affect the typescript transform and codemod. That said, if you are trying to develop a custom ESLint rule with `@babel/eslint-parser`, this change aligns the Babel AST to the `typescript-eslint` AST.
Expand Down Expand Up @@ -828,6 +864,26 @@ Most of the changes to our TypeScript-specific AST nodes are to reduce the diffe
)
```

- Require a `TSEnumBody` node as the second argument of `t.tsEnumDeclaration` ([#16979](https://github.com/babel/babel/pull/16979))

This is due to the corresponding [AST shape change](#ast-TSEnumDeclaration).

__Migration__: Wrap the `members` array within the `tsEnumBody` builder

```diff title="my-babel-codemod.js"
// Create `enum ColorType { Red, Green, Blue }`
t.tsEnumDeclaration(
t.identifier("ColorType"),
- [
+ t.tsEnumBody([
t.tsEnumMember(t.identifier("Red")),
t.tsEnumMember(t.identifier("Green")),
t.tsEnumMember(t.identifier("Blue"))
- ],
+ ]),
)
```

- Update the `t.tsMappedType` signature ([#16733](https://github.com/babel/babel/pull/16733))

This is due to the corresponding [AST shape change](#ast-TSMappedType).
Expand Down