[Babel 8] Create TSEnumBody for TSEnumDeclaration#16979
Conversation
|
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/58555 |
| if (process.env.BABEL_8_BREAKING) { | ||
| node.body = this.tsParseEnumBody(); | ||
| } else { | ||
| this.expect(tt.braceL); |
There was a problem hiding this comment.
We didn't reuse the tsParseEnumBody function for Babel 7 because it will otherwise remove comments between the enum identifier and the enum body as an EnumBody node will be created but never used.
d277235 to
5ae02fa
Compare
|
I always did it manually, this script seems useful :) |
Thanks, I should have just created this script from the day one we introduced |
| rm tests/format/typescript/conformance/internalModules/importDeclarations/format.test.js | ||
| rm tests/format/typescript/keywords/format.test.js | ||
| rm tests/format/typescript/declare/format.test.js | ||
| rm tests/format/typescript/const/format.test.js |
There was a problem hiding this comment.
/cc @fisker These tests will be impacted by this AST change.
nicolo-ribaudo
left a comment
There was a problem hiding this comment.
Left a minor comment, but overall looks good
| this.printList(node.members, { | ||
| indent: true, | ||
| statement: true, | ||
| // TODO: Default to false for consistency with everything else |
There was a problem hiding this comment.
While we are changing this code, could you make this default to process.env.BABEL_8_BREAKING ? false : true? :)
| const: validateOptional(bool), | ||
| id: validateType("Identifier"), | ||
| members: validateArrayOfType("TSEnumMember"), | ||
| initializer: validateOptionalType("Expression"), |
There was a problem hiding this comment.
The initializer field is also removed in Babel 8. The TS enum declaration does not support initializer (enum { ... } = initializer) and the babel parser does not use this field either. It probably refers to the initializer property in the TSEnumMember.
|
Rebased without any further changes. I will test this branch on |
|
You can use typescript-eslint/typescript-eslint#10452 to help with that. There are also some difference about optional properties, but those are probably fine. |
Added 3 todo items in #16679. I will add more later today. Please subscribe that issue. |
70e3af3 to
f0801f1
Compare
Co-authored-by: Nicolò Ribaudo <hello@nicr.dev>
* update babel-types definitions * breaking: create TSEnumBody for Babel 8 * update test fixtures * breaking: remove unused initializer field * fix typings * print TSEnumBody * support Babel 8 AST in typescript transform * fix: inherit enum member's comments * add TSEnumBody printer method * polish: adjust inner comments for TSEnumDeclaration * fix printer test * define TSEnumBody for Babel 7 * update artifacts * fix: adapt to Babel 8 AST * purge failing prettier test due to the AST change * Update packages/babel-generator/src/generators/typescript.ts Co-authored-by: Nicolò Ribaudo <hello@nicr.dev> * fix typings * print trailing comma only according to original source * update test fixtures * modify according to the changed interface --------- Co-authored-by: Nicolò Ribaudo <hello@nicr.dev>
Updated the TSEnum AST per typescript-eslint/typescript-eslint#8920.
Added a new script to automatically create Babel 7 AST test cases. I can't recall whether we already have such script in the repo: I have tried to search within the codebase but no luck, so I come up with a new script.
To fix the typing errors, this PR also introduces the
TSEnumBodyAST type to Babel 7. However, the parser will not generateTSEnumBodyand the generator will not recognizeTSEnumBodyeven if users manually assignbodytoTSEnumDeclaration. So this PR should not break Babel 7 users.