Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 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,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 == '$')
}
}

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