Skip to content

Commit

Permalink
fix: ensure var_decl_imports transform occurs before TypeScript pass (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
dsherret committed Oct 23, 2023
1 parent f36d646 commit fe26ec5
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/transpiling/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,12 @@ pub fn fold_program(
}),
proposal::explicit_resource_management::explicit_resource_management(),
helpers::inject_helpers(top_level_mark),
// transform imports to var decls before doing the typescript pass
// so that swc doesn't do any optimizations on the import declarations
Optional::new(
transforms::ImportDeclsToVarDeclsFolder,
options.var_decl_imports
),
Optional::new(
typescript::typescript(options.as_typescript_config(), top_level_mark),
!options.transform_jsx
Expand Down Expand Up @@ -333,9 +339,11 @@ pub fn fold_program(
),
options.transform_jsx
),
// if using var decl imports, do another pass in order to transform the
// automatically inserted jsx runtime import to a var decl
Optional::new(
transforms::ImportDeclsToVarDeclsFolder,
options.var_decl_imports
options.var_decl_imports && options.transform_jsx
),
fixer(Some(comments)),
hygiene(),
Expand Down Expand Up @@ -840,6 +848,7 @@ function App() {
ModuleSpecifier::parse("https://deno.land/x/mod.tsx").unwrap();
let source = r#"
/** @jsxImportSource jsx_lib */
import * as example from "example";
function App() {
return (
Expand All @@ -861,6 +870,7 @@ function App() {
};
let code = module.transpile(&emit_options).unwrap().text;
let expected = r#"/** @jsxImportSource jsx_lib */ const { "jsx": _jsx, "Fragment": _Fragment } = await import("jsx_lib/jsx-runtime");
const example = await import("example");
function App() {
return /*#__PURE__*/ _jsx("div", {
children: /*#__PURE__*/ _jsx(_Fragment, {})
Expand Down

0 comments on commit fe26ec5

Please sign in to comment.