Skip to content

Commit

Permalink
fix(parser): treat JSX element tags starting with _ or $ as `Iden…
Browse files Browse the repository at this point in the history
…tifierReference`s
  • Loading branch information
overlookmotel committed Aug 30, 2024
1 parent 7e8c3fa commit 337c2ec
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
6 changes: 4 additions & 2 deletions crates/oxc_ast/src/ast_impl/jsx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@ 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 `$`.
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 == '$')
}
}

Expand Down
13 changes: 11 additions & 2 deletions tasks/coverage/semantic_typescript.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 337c2ec

Please sign in to comment.