fix(parser): treat JSX element tags starting with _ or $ as IdentifierReferences (#5343)

#5223 added a new variant `JSXElementName::IdentifierReference` for JSX identifiers which are treated as references (e.g. `<Foo>`) as opposed to `JSXElementName::Identifier` which is for lowercase (e.g. `<div>`).

But we were incorrectly categorizing identifiers beginning with `_` or `$` - these should also be treated as references.

(as discussed in https://github.com/oxc-project/oxc/pull/5339#issuecomment-2321037779)
This commit is contained in:
overlookmotel 2024-08-30 14:47:06 +00:00
parent 83b9a8240e
commit 8a178075b7
2 changed files with 16 additions and 4 deletions

View file

@ -20,9 +20,12 @@ impl<'a> fmt::Display for JSXIdentifier<'a> {
}
impl<'a> JSXIdentifier<'a> {
/// Determines whether the given current identifier is a reference
/// Determines whether the given current identifier is a reference.
///
/// References begin with a capital letter, `_` or `$`.
/// <https://babeljs.io/repl#?code_lz=DwMQ9mAED0B8DcAoYAzCMHIPpqnJwAJLhkkA&presets=react>
pub fn is_reference(&self) -> bool {
self.name.chars().next().map_or(false, char::is_uppercase)
self.name.chars().next().map_or(false, |c| c.is_uppercase() || c == '_' || c == '$')
}
}

View file

@ -5195,6 +5195,12 @@ tasks/coverage/typescript/tests/cases/compiler/doubleUnderscoreReactNamespace.ts
semantic error: Bindings mismatch:
after transform: ScopeId(0): ["__foot", "_jsxFileName", "global", "thing"]
rebuilt : ScopeId(0): ["_jsxFileName", "thing"]
Reference symbol mismatch:
after transform: ReferenceId(0): Some("__foot")
rebuilt : ReferenceId(1): None
Unresolved references mismatch:
after transform: ["React"]
rebuilt : ["React", "__foot"]
tasks/coverage/typescript/tests/cases/compiler/downlevelLetConst13.ts
semantic error: Namespaces exporting non-const are not supported by Babel. Change to const or see: https://babeljs.io/docs/en/babel-plugin-transform-typescript
@ -19016,11 +19022,14 @@ Reference symbol mismatch:
after transform: ReferenceId(5): Some("x")
rebuilt : ReferenceId(14): None
Reference symbol mismatch:
after transform: ReferenceId(6): Some("x")
after transform: ReferenceId(6): Some("_Bar")
rebuilt : ReferenceId(17): None
Reference symbol mismatch:
after transform: ReferenceId(7): Some("x")
rebuilt : ReferenceId(18): None
Unresolved references mismatch:
after transform: ["React"]
rebuilt : ["Bar", "React", "x"]
rebuilt : ["Bar", "React", "_Bar", "x"]
tasks/coverage/typescript/tests/cases/compiler/reactReadonlyHOCAssignabilityReal.tsx
semantic error: Bindings mismatch: