Skip to content

Commit 6dee723

Browse files
committed
fix
1 parent 5f9e21d commit 6dee723

File tree

6 files changed

+54
-48
lines changed

6 files changed

+54
-48
lines changed

crates/swc_ecma_transforms_react/src/jsx/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -299,18 +299,18 @@ where
299299

300300
match runtime {
301301
Runtime::Automatic(config) => (
302+
None,
302303
Some(automatic(
303304
config,
304305
common,
305306
unresolved_mark,
306307
comments.clone(),
307308
cm.clone(),
308309
)),
309-
None,
310310
),
311311
Runtime::Classic(config) => (
312-
None,
313312
Some(classic(config, common, comments.clone(), cm.clone())),
313+
None,
314314
),
315315
Runtime::Preserve => (None, None),
316316
}
Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
/** @jsx h */ import { jsx as _jsx } from "react/jsx-runtime";
2-
import html, { h } from "example";
1+
/** @jsxRuntime classic */ /** @jsx h */ import html, { h } from "example";
32
serve((_req)=>html({
4-
body: /*#__PURE__*/ _jsx("div", {
5-
children: "Hello World!"
6-
})
3+
body: /*#__PURE__*/ h("div", null, "Hello World!")
74
}));
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
#!/usr/bin/env -S deno run -A
2-
import { jsx as _jsx } from "react/jsx-runtime";
3-
/** @jsx h */ import html, { h } from "example";
2+
/** @jsxRuntime classic */ /** @jsx h */ import html, { h } from "example";
43
serve((_req)=>html({
5-
body: /*#__PURE__*/ _jsx("div", {
6-
children: "Hello World!"
7-
})
4+
body: /*#__PURE__*/ h("div", null, "Hello World!")
85
}));

crates/swc_ecma_transforms_typescript/tests/fixture/issue-6923/output.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/* @jsxRuntime classic */ //
2+
import React from "react";
23
import ReactDOM from "react-dom";
34
import { _Component } from "./Component";
45
const App = /*#__PURE__*/ React.createElement("div", null, /*#__PURE__*/ React.createElement(_Component, null), /*#__PURE__*/ React.createElement("p", null, "Hello World"));

crates/swc_ecma_transforms_typescript/tests/strip.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1805,7 +1805,8 @@ test!(
18051805
}),
18061806
|t| tsxr(t),
18071807
imports_not_used_as_values_jsx_prag,
1808-
r#"/** @jsx h */
1808+
r#"/** @jsxRuntime classic */
1809+
/** @jsx h */
18091810
import html, { h } from "example";
18101811
serve((_req) =>
18111812
html({
@@ -1823,6 +1824,7 @@ test!(
18231824
|t| tsxr(t),
18241825
imports_not_used_as_values_shebang_jsx_prag,
18251826
r#"#!/usr/bin/env -S deno run -A
1827+
/** @jsxRuntime classic */
18261828
/** @jsx h */
18271829
import html, { h } from "example";
18281830
serve((_req) =>

crates/swc_ts_fast_strip/src/lib.rs

Lines changed: 44 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,49 @@ pub fn operate(
415415
let top_level_mark = Mark::new();
416416

417417
HELPERS.set(&Helpers::new(false), || {
418+
let transform = options.transform.unwrap_or_default();
419+
420+
#[cfg(feature = "nightly")]
421+
let mut jsx_pass = {
422+
let (mut before_resolver_jsx, after_resolver_jsx) =
423+
swc_ecma_transforms_react::jsx(
424+
cm.clone(),
425+
Some(comments.clone()),
426+
swc_ecma_transforms_react::Options {
427+
runtime: match &transform.jsx {
428+
Some(jsx_config) => {
429+
let import_source =
430+
jsx_config.import_source.clone().unwrap_or_else(
431+
swc_ecma_transforms_react::default_import_source,
432+
);
433+
swc_ecma_transforms_react::Runtime::Automatic(
434+
swc_ecma_transforms_react::AutomaticConfig {
435+
import_source,
436+
},
437+
)
438+
}
439+
None => swc_ecma_transforms_react::Runtime::Automatic(
440+
Default::default(),
441+
),
442+
},
443+
common: swc_ecma_transforms_react::CommonConfig {
444+
development: transform
445+
.jsx
446+
.as_ref()
447+
.and_then(|jsx| jsx.transform.as_ref())
448+
.map(|t| matches!(t, JsxTransform::ReactJsxDev))
449+
.unwrap_or(false)
450+
.into(),
451+
..Default::default()
452+
},
453+
refresh: None,
454+
},
455+
unresolved_mark,
456+
);
457+
program.mutate(&mut before_resolver_jsx);
458+
after_resolver_jsx
459+
};
460+
418461
program.mutate(&mut resolver(unresolved_mark, top_level_mark, true));
419462

420463
if deprecated_ts_module_as_error {
@@ -434,48 +477,14 @@ pub fn operate(
434477
}
435478
}
436479

437-
let transform = options.transform.unwrap_or_default();
438-
439480
program.mutate(&mut typescript::typescript(
440481
transform.typescript,
441482
unresolved_mark,
442483
top_level_mark,
443484
));
444485

445486
#[cfg(feature = "nightly")]
446-
program.mutate(&mut swc_ecma_transforms_react::jsx(
447-
cm.clone(),
448-
Some(comments.clone()),
449-
swc_ecma_transforms_react::Options {
450-
runtime: match &transform.jsx {
451-
Some(jsx_config) => {
452-
let import_source =
453-
jsx_config.import_source.clone().unwrap_or_else(
454-
swc_ecma_transforms_react::default_import_source,
455-
);
456-
swc_ecma_transforms_react::Runtime::Automatic(
457-
swc_ecma_transforms_react::AutomaticConfig { import_source },
458-
)
459-
}
460-
None => {
461-
swc_ecma_transforms_react::Runtime::Automatic(Default::default())
462-
}
463-
},
464-
common: swc_ecma_transforms_react::CommonConfig {
465-
development: transform
466-
.jsx
467-
.as_ref()
468-
.and_then(|jsx| jsx.transform.as_ref())
469-
.map(|t| matches!(t, JsxTransform::ReactJsxDev))
470-
.unwrap_or(false)
471-
.into(),
472-
..Default::default()
473-
},
474-
refresh: None,
475-
},
476-
top_level_mark,
477-
unresolved_mark,
478-
));
487+
program.mutate(&mut jsx_pass);
479488

480489
program.mutate(&mut inject_helpers(unresolved_mark));
481490

0 commit comments

Comments
 (0)