fix(es/resolver): Skip resolving lowercase JSXIdentifiers (#9686)
Some checks are pending
CI / Cargo fmt (push) Waiting to run
CI / Cargo clippy (push) Waiting to run
CI / Check license of dependencies (push) Waiting to run
CI / Check (macos-latest) (push) Waiting to run
CI / Check (ubuntu-latest) (push) Waiting to run
CI / Check (windows-latest) (push) Waiting to run
CI / Test wasm (binding_core_wasm) (push) Waiting to run
CI / Test wasm (binding_minifier_wasm) (push) Waiting to run
CI / Test wasm (binding_typescript_wasm) (push) Waiting to run
CI / List crates (push) Waiting to run
CI / Test - ${{ matrix.settings.crate }} - ${{ matrix.settings.os }} (push) Blocked by required conditions
CI / Test node bindings - ${{ matrix.os }} (macos-latest) (push) Waiting to run
CI / Test node bindings - ${{ matrix.os }} (windows-latest) (push) Waiting to run
CI / Test with @swc/cli (push) Waiting to run
CI / Miri (better_scoped_tls) (push) Waiting to run
CI / Miri (string_enum) (push) Waiting to run
CI / Miri (swc) (push) Waiting to run
CI / Miri (swc_bundler) (push) Waiting to run
CI / Done (push) Blocked by required conditions
Benchmark / Bench everything (push) Waiting to run
Publish crates (auto) / Publish cargo crates (push) Waiting to run

**Related issue:**

- Closes https://github.com/swc-project/swc/issues/9685
This commit is contained in:
magic-akari 2024-10-30 17:37:30 +08:00 committed by GitHub
parent 4b4dcfa4d8
commit 6ed1715b93
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 47 additions and 0 deletions

View File

@ -0,0 +1,6 @@
---
swc_ecma_transforms_base: patch
swc_core: patch
---
fix(es/resolver): Skip resolving lowercase JSXIdentifiers

View File

@ -0,0 +1,4 @@
export namespace form {
export const input = null;
export const test = <input />
}

View File

@ -0,0 +1,5 @@
(function(form) {
form.input = null;
form.test = /*#__PURE__*/ React.createElement("input", null);
})(form || (form = {}));
export var form;

View File

@ -920,6 +920,28 @@ impl VisitMut for Resolver<'_> {
f.body.visit_mut_with(self);
}
fn visit_mut_jsx_element_name(&mut self, node: &mut JSXElementName) {
if let JSXElementName::Ident(i) = node {
if i.as_ref().starts_with(|c: char| c.is_ascii_lowercase()) {
if cfg!(debug_assertions) && LOG {
debug!("\t -> JSXElementName");
}
let ctxt = i.ctxt.apply_mark(self.config.unresolved_mark);
if cfg!(debug_assertions) && LOG {
debug!("\t -> {:?}", ctxt);
}
i.ctxt = ctxt;
return;
}
}
node.visit_mut_children_with(self);
}
fn visit_mut_ident(&mut self, i: &mut Ident) {
if i.ctxt != SyntaxContext::empty() {
return;

View File

@ -84,10 +84,12 @@ fn test_resolver(input: PathBuf) {
}
#[fixture("tests/ts-resolver/**/input.ts")]
#[fixture("tests/ts-resolver/**/input.tsx")]
fn test_ts_resolver(input: PathBuf) {
run(
Syntax::Typescript(TsSyntax {
decorators: true,
tsx: input.extension().filter(|ext| *ext == "tsx").is_some(),
..Default::default()
}),
&input,

View File

@ -0,0 +1,4 @@
export namespace form {
export const input = null;
export const test = <input />;
}

View File

@ -0,0 +1,4 @@
export namespace form__2 {
export const input__3 = null;
export const test__3 = <input/>;
}