diff --git a/crates/swc_ecma_minifier/tests/fixture/issues/8974/config.json b/crates/swc_ecma_minifier/tests/fixture/issues/8974/config.json new file mode 100644 index 00000000000..7e144b291fa --- /dev/null +++ b/crates/swc_ecma_minifier/tests/fixture/issues/8974/config.json @@ -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 +} diff --git a/crates/swc_ecma_minifier/tests/fixture/issues/8974/input.js b/crates/swc_ecma_minifier/tests/fixture/issues/8974/input.js new file mode 100644 index 00000000000..131c3632cd2 --- /dev/null +++ b/crates/swc_ecma_minifier/tests/fixture/issues/8974/input.js @@ -0,0 +1,13 @@ +const one = { + kind: "Document", + definitions: [], + loc: {} +}; +const two = { + kind: "Document", + definitions: one.definitions, +}; + +const three = a`${one}`; + +export { } \ No newline at end of file diff --git a/crates/swc_ecma_minifier/tests/fixture/issues/8974/output.js b/crates/swc_ecma_minifier/tests/fixture/issues/8974/output.js new file mode 100644 index 00000000000..054e52a677c --- /dev/null +++ b/crates/swc_ecma_minifier/tests/fixture/issues/8974/output.js @@ -0,0 +1,7 @@ +const one = { + kind: "Document", + definitions: [], + loc: {} +}; +one.definitions, a`${one}`; +export { }; diff --git a/crates/swc_ecma_usage_analyzer/src/analyzer/mod.rs b/crates/swc_ecma_usage_analyzer/src/analyzer/mod.rs index a125c4116f3..1c0b0d3520d 100644 --- a/crates/swc_ecma_usage_analyzer/src/analyzer/mod.rs +++ b/crates/swc_ecma_usage_analyzer/src/analyzer/mod.rs @@ -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))]