Skip to content

Commit

Permalink
fix: Fix tree shaking even more (#8864)
Browse files Browse the repository at this point in the history
### Description

Fix server action and rename the injected variable.

The previous code fails if the name of the top-level variable is `v`.
This was not a problem for almost all modules, but some packages like
[`@firebase/webchannel-wrapper`](https://unpkg.com/@firebase/[email protected]/dist/index.esm.js)
is published after mangling, so it can be a problem



### Testing Instructions

See vercel/next.js#66689
  • Loading branch information
kdy1 authored Jul 30, 2024
1 parent 30a8bb8 commit deee36b
Show file tree
Hide file tree
Showing 11 changed files with 53 additions and 51 deletions.
8 changes: 5 additions & 3 deletions crates/turbopack-ecmascript/src/references/esm/export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -442,8 +442,9 @@ impl CodeGenerateable for EsmExports {
EsmExport::LocalBinding(name, mutable) => {
if *mutable {
Some(quote!(
"([() => $local, (v) => $local = v])" as Expr,
local = Ident::new((name as &str).into(), DUMMY_SP)
"([() => $local, ($new) => $local = $new])" as Expr,
local = Ident::new((name as &str).into(), DUMMY_SP),
new = Ident::new(format!("{name}_new_value").into(), DUMMY_SP),
))
} else {
Some(quote!(
Expand All @@ -470,8 +471,9 @@ impl CodeGenerateable for EsmExports {
});
if *mutable {
quote!(
"([() => $expr, (v) => $expr = v])" as Expr,
"([() => $expr, ($new) => $expr = $new])" as Expr,
expr: Expr = expr,
new = Ident::new(format!("{name}_new_value").into(), DUMMY_SP),
)
} else {
quote!(
Expand Down
2 changes: 1 addition & 1 deletion crates/turbopack-ecmascript/src/tree_shake/asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ impl Module for EcmascriptModulePartAsset {
impl Asset for EcmascriptModulePartAsset {
#[turbo_tasks::function]
fn content(&self) -> Vc<AssetContent> {
todo!()
self.full_module.content()
}
}

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.

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.

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.

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

Loading

0 comments on commit deee36b

Please sign in to comment.