mirror of
https://github.com/swc-project/swc.git
synced 2024-11-28 02:29:04 +03:00
fix(es/minifier): Preserve this
of tagged template literals (#6165)
**Related issue:** - Closes https://github.com/swc-project/swc/issues/6146
This commit is contained in:
parent
ba6d714fe7
commit
aec5cdacc6
@ -2263,12 +2263,19 @@ where
|
||||
.enumerate()
|
||||
.identify_last()
|
||||
.filter_map(|(last, (idx, expr))| {
|
||||
#[cfg(feature = "debug")]
|
||||
let _span =
|
||||
tracing::span!(tracing::Level::ERROR, "seq_expr_with_children").entered();
|
||||
|
||||
expr.visit_mut_with(&mut *self.with_ctx(ctx));
|
||||
let is_injected_zero = match &**expr {
|
||||
Expr::Lit(Lit::Num(v)) => v.span.is_dummy(),
|
||||
_ => false,
|
||||
};
|
||||
|
||||
#[cfg(feature = "debug")]
|
||||
let _span = tracing::span!(tracing::Level::ERROR, "seq_expr").entered();
|
||||
|
||||
let can_remove = !last
|
||||
&& (idx != 0
|
||||
|| !is_injected_zero
|
||||
@ -2580,7 +2587,10 @@ where
|
||||
/// We don't optimize [Tpl] contained in [TaggedTpl].
|
||||
#[cfg_attr(feature = "debug", tracing::instrument(skip_all))]
|
||||
fn visit_mut_tagged_tpl(&mut self, n: &mut TaggedTpl) {
|
||||
n.tag.visit_mut_with(self);
|
||||
n.tag.visit_mut_with(&mut *self.with_ctx(Ctx {
|
||||
is_this_aware_callee: true,
|
||||
..self.ctx
|
||||
}));
|
||||
|
||||
n.tpl.exprs.visit_mut_with(self);
|
||||
}
|
||||
|
@ -0,0 +1,6 @@
|
||||
let o = {
|
||||
f() {
|
||||
assert.ok(this !== o);
|
||||
}
|
||||
};
|
||||
(1, o.f)``;
|
@ -0,0 +1,6 @@
|
||||
let o = {
|
||||
f () {
|
||||
assert.ok(this !== o);
|
||||
}
|
||||
};
|
||||
(0, o.f)``;
|
@ -9,7 +9,7 @@ import _JSXStyle from "styled-jsx/style";
|
||||
top ? "column" : "column-reverse"
|
||||
]
|
||||
]
|
||||
]), _JSXStyle.dynamic([
|
||||
]), Sidebar, _JSXStyle.dynamic([
|
||||
[
|
||||
"4507deac72c40d6c",
|
||||
[
|
||||
|
@ -1,3 +1,3 @@
|
||||
console.log(({
|
||||
y: ()=>String.raw
|
||||
}).y()`\4321\u\x`), console.log(String.raw`\4321\u\x`);
|
||||
}).y()`\4321\u\x`), console.log((0, String.raw)`\4321\u\x`);
|
||||
|
@ -1504,7 +1504,9 @@ impl VisitMut for SimplifyExpr {
|
||||
}
|
||||
}
|
||||
|
||||
Expr::Lit(..) | Expr::Ident(..) if self.in_callee => {
|
||||
Expr::Lit(..) | Expr::Ident(..)
|
||||
if self.in_callee && !expr.may_have_side_effects(&self.expr_ctx) =>
|
||||
{
|
||||
if exprs.is_empty() {
|
||||
self.changed = true;
|
||||
|
||||
@ -1584,6 +1586,18 @@ impl VisitMut for SimplifyExpr {
|
||||
self.is_modifying = old;
|
||||
}
|
||||
|
||||
fn visit_mut_tagged_tpl(&mut self, n: &mut TaggedTpl) {
|
||||
let old = self.in_callee;
|
||||
self.in_callee = true;
|
||||
|
||||
n.tag.visit_mut_with(self);
|
||||
|
||||
self.in_callee = false;
|
||||
n.tpl.visit_mut_with(self);
|
||||
|
||||
self.in_callee = old;
|
||||
}
|
||||
|
||||
fn visit_mut_with_stmt(&mut self, n: &mut WithStmt) {
|
||||
n.obj.visit_mut_with(self);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user