[parser] Add support for TS declare modifier on fields#10484
[parser] Add support for TS declare modifier on fields#10484nicolo-ribaudo merged 3 commits intobabel:feat-7.7/ts-declare-fieldsfrom
Conversation
|
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/11658/ |
|
Note that the combined PR that I intend to merge is microsoft/TypeScript#33509. |
| this.raise(startPos, `Duplicate modifier: '${modifier}'`); | ||
| } | ||
| modifiers[modifier] = true; | ||
| } |
There was a problem hiding this comment.
This seems to allow any modifier whitelisted by the parameter in any order; I presume that's okay? or are there some modifiers which have a specific required order (e.g. declare first)
There was a problem hiding this comment.
Some modifiers must come in a specific order, some others don't. For example, abstract and readonly can be swapped, but public must be before them.
We parse them using a logic similar to this one, which ensures the correct order:
this.tsParseModifiers(["public"]);
this.tsParseModifiers(["abstract", "readonly"]);There was a problem hiding this comment.
Not super important, but it might be nice to add a comment around modifier order/usage.
| } | ||
|
|
||
| tsParseModifiers<T: TsModifier>(allowedModifiers: T[]): { [*]: true } { | ||
| const modifiers = {}; |
There was a problem hiding this comment.
I'd feel better with Object.create(null) but it probably isn't really relevant here.
24822b8 to
3f89e3c
Compare
|
I'll merge this to a separate branch so that I can start working on the transform. |
* [parser] Add support for TS declare modifier on fields * Use Object.create(null) * Comment
* [parser] Add support for TS declare modifier on fields * Use Object.create(null) * Comment
* [parser] Add support for TS declare modifier on fields * Use Object.create(null) * Comment
* [parser] Add support for TS declare modifier on fields * Use Object.create(null) * Comment
* [parser] Add support for TS declare modifier on fields (#10484) * [parser] Add support for TS declare modifier on fields * Use Object.create(null) * Comment * Add support for TS declare types to types and generator (#10544) * Transform TypeScript "declare" fields (#10546) * Transform TypeScript "declare" fields * Remove multiple spaces * declareFields -> allowDeclareFields * Update after rebase
Ref: microsoft/TypeScript#33401
I also updated the parser to generate more useful errors when a class member has a disallowed modifier (e.g.
readonly method() {})cc @babel/typescript