Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(es/minifier): Mark usage in TaggedTpl as ref #8975

Merged
merged 6 commits into from
May 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 { }
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
Loading