Skip to content

Commit

Permalink
inject swc helpers (vercel/turborepo#4060)
Browse files Browse the repository at this point in the history
### Description

This fixed the `_extends` is not defined issue.
  • Loading branch information
sokra authored Mar 4, 2023
1 parent a0ce6b6 commit 5fb804f
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { useEffect } from "react";

export default function Page() {
useEffect(() => {
// Only run on client
import("@turbo/pack-test-harness").then(runTests);
});

const props1 = { className: "foo" };
const props2 = { style: { color: "red" } };
// this will require the `_extends` helper on SSR
return (
<div id="test" {...props1} {...props2}>
Hello World
</div>
);
}

function runTests() {
it("should render the #test element in red and with class foo", () => {
const el = document.getElementById("test");
expect(el.style.color).toBe("red");
expect(el.className).toBe("foo");
});
}
4 changes: 4 additions & 0 deletions crates/turbopack-ecmascript/src/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,10 @@ async fn parse_content(
transform.apply(&mut parsed_program, &context).await?;
}

parsed_program.visit_mut_with(
&mut swc_core::ecma::transforms::base::helpers::inject_helpers(unresolved_mark),
);

let eval_context = EvalContext::new(&parsed_program, unresolved_mark);

Ok::<ParseResult, anyhow::Error>(ParseResult::Ok {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 5fb804f

Please sign in to comment.