Skip to content

Allow keywords in TS qualified types#14362

Merged
nicolo-ribaudo merged 3 commits intobabel:mainfrom
nicolo-ribaudo:ts-kw-in-qualified-type
Mar 16, 2022
Merged

Allow keywords in TS qualified types#14362
nicolo-ribaudo merged 3 commits intobabel:mainfrom
nicolo-ribaudo:ts-kw-in-qualified-type

Conversation

@nicolo-ribaudo
Copy link
Copy Markdown
Member

@nicolo-ribaudo nicolo-ribaudo commented Mar 15, 2022

Q                       A
Fixed Issues? Fixes #14357
Patch: Bug Fix? Yes
Major: Breaking Change?
Minor: New Feature?
Tests Added + Pass? Yes
Documentation PR Link
Any Dependency Changes?
License MIT

TypeScript is way more liberal than the restrictions we introduced in #14320: it allows keywords in qualified types almost everywhere, and it handles keywords as normal identifiers.

I believe that some valid syntax will always result in a type checking error, for example type A = if. However, the TypeScript parser happily accepts it and only reports if as not being defined (I don't know if it's possible to use something like jsdoc or external declaration files to declare an if global type).

@nicolo-ribaudo nicolo-ribaudo added PR: Bug Fix 🐛 A type of pull request used for our changelog categories pkg: parser area: typescript labels Mar 15, 2022
allowReservedEntityName: false,
allowReservedQualifiers: false,
});
: this.tsParseEntityName(/* allowReservedWords */ false);
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I think this is a TS bug (microsoft/TypeScript#48274), but I decided to match the TS behavior and throw.

@babel-bot
Copy link
Copy Markdown
Collaborator

babel-bot commented Mar 15, 2022

Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/51493/

It's just moving test names in order, and `defaultIsNotVisibleInLocalScope.ts` is deleted
@tychenjiajun
Copy link
Copy Markdown

Build successful! You can test your changes in the REPL here: babeljs.io/repl/build/51491

#14357 fixed

classExtendsMultipleBaseClasses.ts
classOverloadForFunction.ts
classWithEmptyTypeParameter.ts
# TypeScript doesn't allow a parameter to be named arguments even in non-strict mode, which we don't catch.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can we modify the generator to preserve such comments?

Copy link
Copy Markdown
Member Author

@nicolo-ribaudo nicolo-ribaudo Mar 16, 2022

Choose a reason for hiding this comment

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

They were already supported but they must be inline. I now moved them.

@nicolo-ribaudo nicolo-ribaudo merged commit 01380a6 into babel:main Mar 16, 2022
@nicolo-ribaudo nicolo-ribaudo deleted the ts-kw-in-qualified-type branch March 16, 2022 22:02
@github-actions github-actions bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Jun 16, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 16, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area: typescript i: regression outdated A closed issue/PR that is archived due to age. Recommended to make a new issue pkg: parser PR: Bug Fix 🐛 A type of pull request used for our changelog categories

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: typeof this.foo throws Unexpected keyword 'this'.

5 participants