Skip to content

Commit 6ed1715

Browse files
authored
fix(es/resolver): Skip resolving lowercase JSXIdentifiers (#9686)
**Related issue:** - Closes #9685
1 parent 4b4dcfa commit 6ed1715

File tree

7 files changed

+47
-0
lines changed

7 files changed

+47
-0
lines changed

.changeset/fluffy-eyes-hope.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
swc_ecma_transforms_base: patch
3+
swc_core: patch
4+
---
5+
6+
fix(es/resolver): Skip resolving lowercase JSXIdentifiers
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export namespace form {
2+
export const input = null;
3+
export const test = <input />
4+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
(function(form) {
2+
form.input = null;
3+
form.test = /*#__PURE__*/ React.createElement("input", null);
4+
})(form || (form = {}));
5+
export var form;

crates/swc_ecma_transforms_base/src/resolver/mod.rs

+22
Original file line numberDiff line numberDiff line change
@@ -920,6 +920,28 @@ impl VisitMut for Resolver<'_> {
920920
f.body.visit_mut_with(self);
921921
}
922922

923+
fn visit_mut_jsx_element_name(&mut self, node: &mut JSXElementName) {
924+
if let JSXElementName::Ident(i) = node {
925+
if i.as_ref().starts_with(|c: char| c.is_ascii_lowercase()) {
926+
if cfg!(debug_assertions) && LOG {
927+
debug!("\t -> JSXElementName");
928+
}
929+
930+
let ctxt = i.ctxt.apply_mark(self.config.unresolved_mark);
931+
932+
if cfg!(debug_assertions) && LOG {
933+
debug!("\t -> {:?}", ctxt);
934+
}
935+
936+
i.ctxt = ctxt;
937+
938+
return;
939+
}
940+
}
941+
942+
node.visit_mut_children_with(self);
943+
}
944+
923945
fn visit_mut_ident(&mut self, i: &mut Ident) {
924946
if i.ctxt != SyntaxContext::empty() {
925947
return;

crates/swc_ecma_transforms_base/tests/fixture.rs

+2
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,12 @@ fn test_resolver(input: PathBuf) {
8484
}
8585

8686
#[fixture("tests/ts-resolver/**/input.ts")]
87+
#[fixture("tests/ts-resolver/**/input.tsx")]
8788
fn test_ts_resolver(input: PathBuf) {
8889
run(
8990
Syntax::Typescript(TsSyntax {
9091
decorators: true,
92+
tsx: input.extension().filter(|ext| *ext == "tsx").is_some(),
9193
..Default::default()
9294
}),
9395
&input,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export namespace form {
2+
export const input = null;
3+
export const test = <input />;
4+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export namespace form__2 {
2+
export const input__3 = null;
3+
export const test__3 = <input/>;
4+
}

0 commit comments

Comments
 (0)