Skip to content

Conversation

@poteto
Copy link
Member

@poteto poteto commented Aug 27, 2025

Our previous error message was correctly identifying the generation of identifiers where the name is a reserved keyword in JS. That error still makes sense (we don't want to generate invalid identifiers) as an invariant, but in some cases can be a confusing error as it's not helpful to tell the user that eg this is a reserved identifier name.

This PR adds a specific check for this up into HIRBuilder, denoting that this is not syntax that is supported by React Compiler. Note that this also catches the case where this is used in parameter position (a TS feature) even if it might not actually use this in the block statement, but it's unlikely someone would type this and not use it so I opted to just have a single error message and not special case the this type annotation.

Closes #34311

@meta-cla meta-cla bot added the CLA Signed label Aug 27, 2025
@github-actions github-actions bot added the React Core Team Opened by a member of the React Core Team label Aug 27, 2025
Our previous error message was correctly identifying the generation of identifiers where the name is a reserved keyword in JS. That error still makes sense (we don't want to generate invalid identifiers) as an invariant, but in some cases can be a confusing error as it's not helpful to tell the user that eg `this` is a reserved identifier name.

This PR adds a specific check for `this` up into HIRBuilder, denoting that `this` is not syntax that is supported by React Compiler. Note that this also catches the case where `this` is used in parameter position (a [TS feature](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-0.html#specifying-the-type-of-this-for-functions)) even if it might not actually use `this` in the block statement, but it's unlikely someone would type `this` and not use it so I opted to just have a single error message.

Closes #34311
Copy link
Member

@josephsavona josephsavona left a comment

Choose a reason for hiding this comment

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

nice, thanks!

@poteto poteto merged commit bd5b1b7 into main Aug 27, 2025
21 checks passed
@poteto poteto deleted the pr34322 branch August 27, 2025 21:58
github-actions bot pushed a commit that referenced this pull request Aug 27, 2025
github-actions bot pushed a commit that referenced this pull request Aug 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed React Core Team Opened by a member of the React Core Team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Compiler Bug]: errors when the this type is declared in a function

3 participants