diff --git a/.changeset/fluffy-eyes-hope.md b/.changeset/fluffy-eyes-hope.md new file mode 100644 index 00000000000..37f3dbc4c35 --- /dev/null +++ b/.changeset/fluffy-eyes-hope.md @@ -0,0 +1,6 @@ +--- +swc_ecma_transforms_base: patch +swc_core: patch +--- + +fix(es/resolver): Skip resolving lowercase JSXIdentifiers diff --git a/crates/swc/tests/fixture/issues-9xxx/9685/input/index.tsx b/crates/swc/tests/fixture/issues-9xxx/9685/input/index.tsx new file mode 100644 index 00000000000..2abe5b4f9a2 --- /dev/null +++ b/crates/swc/tests/fixture/issues-9xxx/9685/input/index.tsx @@ -0,0 +1,4 @@ +export namespace form { + export const input = null; + export const test = +} \ No newline at end of file diff --git a/crates/swc/tests/fixture/issues-9xxx/9685/output/index.tsx b/crates/swc/tests/fixture/issues-9xxx/9685/output/index.tsx new file mode 100644 index 00000000000..3f7f9480bc1 --- /dev/null +++ b/crates/swc/tests/fixture/issues-9xxx/9685/output/index.tsx @@ -0,0 +1,5 @@ +(function(form) { + form.input = null; + form.test = /*#__PURE__*/ React.createElement("input", null); +})(form || (form = {})); +export var form; diff --git a/crates/swc_ecma_transforms_base/src/resolver/mod.rs b/crates/swc_ecma_transforms_base/src/resolver/mod.rs index cdc807094df..9181ff1afb1 100644 --- a/crates/swc_ecma_transforms_base/src/resolver/mod.rs +++ b/crates/swc_ecma_transforms_base/src/resolver/mod.rs @@ -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; diff --git a/crates/swc_ecma_transforms_base/tests/fixture.rs b/crates/swc_ecma_transforms_base/tests/fixture.rs index a1272c88c98..51d21e543bc 100644 --- a/crates/swc_ecma_transforms_base/tests/fixture.rs +++ b/crates/swc_ecma_transforms_base/tests/fixture.rs @@ -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, diff --git a/crates/swc_ecma_transforms_base/tests/ts-resolver/issue-9685/1/input.tsx b/crates/swc_ecma_transforms_base/tests/ts-resolver/issue-9685/1/input.tsx new file mode 100644 index 00000000000..fe895160bae --- /dev/null +++ b/crates/swc_ecma_transforms_base/tests/ts-resolver/issue-9685/1/input.tsx @@ -0,0 +1,4 @@ +export namespace form { + export const input = null; + export const test = ; +} diff --git a/crates/swc_ecma_transforms_base/tests/ts-resolver/issue-9685/1/output.tsx b/crates/swc_ecma_transforms_base/tests/ts-resolver/issue-9685/1/output.tsx new file mode 100644 index 00000000000..07614752300 --- /dev/null +++ b/crates/swc_ecma_transforms_base/tests/ts-resolver/issue-9685/1/output.tsx @@ -0,0 +1,4 @@ +export namespace form__2 { + export const input__3 = null; + export const test__3 = ; +}