Skip to content

Commit

Permalink
fix(es/minifier): Mark usage in TaggedTpl as ref (#8975)
Browse files Browse the repository at this point in the history
**Related issue:**

 - Closes #8974
  • Loading branch information
kdy1 committed May 24, 2024
1 parent a15474c commit a753c8d
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 5 deletions.
47 changes: 47 additions & 0 deletions crates/swc_ecma_minifier/tests/fixture/issues/8974/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"defaults": true,
"arguments": false,
"arrows": true,
"booleans": true,
"booleans_as_integers": false,
"collapse_vars": true,
"comparisons": true,
"computed_props": true,
"conditionals": true,
"dead_code": true,
"directives": true,
"drop_console": false,
"drop_debugger": true,
"evaluate": true,
"expression": false,
"hoist_funs": false,
"hoist_props": true,
"hoist_vars": false,
"if_return": true,
"join_vars": true,
"keep_classnames": false,
"keep_fargs": true,
"keep_fnames": false,
"keep_infinity": false,
"loops": true,
"negate_iife": true,
"properties": true,
"reduce_funcs": false,
"reduce_vars": false,
"side_effects": true,
"switches": true,
"typeofs": true,
"unsafe": false,
"unsafe_arrows": false,
"unsafe_comps": false,
"unsafe_Function": false,
"unsafe_math": false,
"unsafe_symbols": false,
"unsafe_methods": false,
"unsafe_proto": false,
"unsafe_regexp": false,
"unsafe_undefined": false,
"unused": true,
"const_to_let": true,
"pristine_globals": true
}
13 changes: 13 additions & 0 deletions crates/swc_ecma_minifier/tests/fixture/issues/8974/input.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const one = {
kind: "Document",
definitions: [],
loc: {}
};
const two = {
kind: "Document",
definitions: one.definitions,
};

const three = a`${one}`;

export { }
7 changes: 7 additions & 0 deletions crates/swc_ecma_minifier/tests/fixture/issues/8974/output.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const one = {
kind: "Document",
definitions: [],
loc: {}
};
one.definitions, a`${one}`;
export { };
22 changes: 17 additions & 5 deletions crates/swc_ecma_usage_analyzer/src/analyzer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1168,12 +1168,24 @@ where

#[cfg_attr(feature = "debug", tracing::instrument(skip_all))]
fn visit_tagged_tpl(&mut self, n: &TaggedTpl) {
let ctx = Ctx {
is_id_ref: false,
..self.ctx
};
{
let ctx = Ctx {
is_id_ref: false,
..self.ctx
};

n.visit_children_with(&mut *self.with_ctx(ctx))
n.tag.visit_with(&mut *self.with_ctx(ctx));
}

{
let ctx = Ctx {
is_id_ref: true,
..self.ctx
};

// Bypass visit_tpl
n.tpl.visit_children_with(&mut *self.with_ctx(ctx))
}
}

#[cfg_attr(feature = "debug", tracing::instrument(skip_all))]
Expand Down

0 comments on commit a753c8d

Please sign in to comment.