mirror of
https://github.com/swc-project/swc.git
synced 2024-12-24 22:22:34 +03:00
fix(es/minifier): Inline into interpolations in tagged template literals (#3287)
swc_ecma_minifier: - Inline into tagged template literals. (Closes #2923)
This commit is contained in:
parent
023fc956ae
commit
fa5c063144
@ -14,4 +14,4 @@ tempFun`${(x)=>x
|
||||
} ${(x)=>x
|
||||
} ${10}`, tempFun`${(x)=>x
|
||||
} ${(x)=>x
|
||||
} ${undefined}`;
|
||||
} ${void 0}`;
|
||||
|
@ -1,23 +1,16 @@
|
||||
function tempTag1(...rest) {}
|
||||
tempTag1`${(x)=>{
|
||||
x(undefined);
|
||||
return x;
|
||||
return x(void 0), x;
|
||||
}}${10}`, tempTag1`${(x)=>{
|
||||
x(undefined);
|
||||
return x;
|
||||
return x(void 0), x;
|
||||
}}${(y)=>{
|
||||
y(undefined);
|
||||
return y;
|
||||
return y(void 0), y;
|
||||
}}${10}`, tempTag1`${(x)=>{
|
||||
x(undefined);
|
||||
return x;
|
||||
return x(void 0), x;
|
||||
}}${(y)=>{
|
||||
y(undefined);
|
||||
return y;
|
||||
}}${undefined}`, tempTag1`${(x)=>{
|
||||
x(undefined);
|
||||
return x;
|
||||
return y(void 0), y;
|
||||
}}${void 0}`, tempTag1`${(x)=>{
|
||||
return x(void 0), x;
|
||||
}}${(y)=>{
|
||||
y(undefined);
|
||||
return y;
|
||||
}}${undefined}`;
|
||||
return y(void 0), y;
|
||||
}}${void 0}`;
|
||||
|
@ -1,14 +1,10 @@
|
||||
function tempTag2(...rest) {}
|
||||
tempTag2`${(x)=>{
|
||||
x(undefined);
|
||||
return x;
|
||||
return x(void 0), x;
|
||||
}}${0}`, tempTag2`${(x)=>{
|
||||
x(undefined);
|
||||
return x;
|
||||
return x(void 0), x;
|
||||
}}${(y)=>{
|
||||
y(null);
|
||||
return y;
|
||||
return y(null), y;
|
||||
}}${"hello"}`, tempTag2`${(x)=>{
|
||||
x(undefined);
|
||||
return x;
|
||||
}}${undefined}${"hello"}`;
|
||||
return x(void 0), x;
|
||||
}}${void 0}${"hello"}`;
|
||||
|
@ -9,13 +9,13 @@ function someGenerics9(strs, a, b, c) {
|
||||
}
|
||||
(function(n) {})``, (function(n) {})``, (function(n, m) {})`${3}`, (function(n, m) {})`${3}`, (function(strs, n) {})`${(n)=>n
|
||||
}`, (function(strs, n) {})`${(n, x)=>n
|
||||
}`, someGenerics3`${()=>''
|
||||
}`, someGenerics3`${()=>undefined
|
||||
}`, someGenerics3`${()=>""
|
||||
}`, someGenerics3`${()=>void 0
|
||||
}`, someGenerics3`${()=>3
|
||||
}`, someGenerics4`${4}${()=>null
|
||||
}`, someGenerics4`${''}${()=>3
|
||||
}`, someGenerics4`${""}${()=>3
|
||||
}`, someGenerics4`${null}${null}`, someGenerics5`${4} ${()=>null
|
||||
}`, someGenerics5`${''}${()=>3
|
||||
}`, someGenerics5`${""}${()=>3
|
||||
}`, someGenerics5`${null}${null}`, someGenerics6`${(n)=>n
|
||||
}${(n)=>n
|
||||
}${(n)=>n
|
||||
@ -36,16 +36,16 @@ function someGenerics9(strs, a, b, c) {
|
||||
}${(n)=>n
|
||||
}`, (function(strs, n) {
|
||||
return n;
|
||||
})`${someGenerics7}``${null}${null}${null}`, someGenerics9`${''}${0}${[]}`, someGenerics9`${undefined}${{
|
||||
})`${someGenerics7}``${null}${null}${null}`, someGenerics9`${""}${0}${[]}`, someGenerics9`${void 0}${{
|
||||
x: 6,
|
||||
z: new Date()
|
||||
}}${{
|
||||
x: 6,
|
||||
y: ''
|
||||
y: ""
|
||||
}}`, someGenerics9`${{
|
||||
x: 3
|
||||
}}${{
|
||||
x: 6
|
||||
}}${{
|
||||
x: 6
|
||||
}}`, someGenerics9`${7}${anyVar}${4}`, someGenerics9`${[]}${null}${undefined}`;
|
||||
}}`, someGenerics9`${7}${anyVar}${4}`, someGenerics9`${[]}${null}${void 0}`;
|
||||
|
@ -9,13 +9,13 @@ function someGenerics9(strs, a, b, c) {
|
||||
}
|
||||
(function(n) {})``, (function(n) {})``, (function(n, m) {})`${3}`, (function(n, m) {})`${3}`, (function(strs, n) {})`${(n)=>n
|
||||
}`, (function(strs, n) {})`${(n, x)=>n
|
||||
}`, someGenerics3`${()=>''
|
||||
}`, someGenerics3`${()=>undefined
|
||||
}`, someGenerics3`${()=>""
|
||||
}`, someGenerics3`${()=>void 0
|
||||
}`, someGenerics3`${()=>3
|
||||
}`, someGenerics4`${4}${()=>null
|
||||
}`, someGenerics4`${''}${()=>3
|
||||
}`, someGenerics4`${""}${()=>3
|
||||
}`, someGenerics4`${null}${null}`, someGenerics5`${4} ${()=>null
|
||||
}`, someGenerics5`${''}${()=>3
|
||||
}`, someGenerics5`${""}${()=>3
|
||||
}`, someGenerics5`${null}${null}`, someGenerics6`${(n)=>n
|
||||
}${(n)=>n
|
||||
}${(n)=>n
|
||||
@ -36,16 +36,16 @@ function someGenerics9(strs, a, b, c) {
|
||||
}${(n)=>n
|
||||
}`, (function(strs, n) {
|
||||
return n;
|
||||
})`${someGenerics7}``${null}${null}${null}`, someGenerics9`${''}${0}${[]}`, someGenerics9`${undefined}${{
|
||||
})`${someGenerics7}``${null}${null}${null}`, someGenerics9`${""}${0}${[]}`, someGenerics9`${void 0}${{
|
||||
x: 6,
|
||||
z: new Date()
|
||||
}}${{
|
||||
x: 6,
|
||||
y: ''
|
||||
y: ""
|
||||
}}`, someGenerics9`${{
|
||||
x: 3
|
||||
}}${{
|
||||
x: 6
|
||||
}}${{
|
||||
x: 6
|
||||
}}`, someGenerics9`${7}${anyVar}${4}`, someGenerics9`${[]}${null}${undefined}`;
|
||||
}}`, someGenerics9`${7}${anyVar}${4}`, someGenerics9`${[]}${null}${void 0}`;
|
||||
|
@ -1,2 +1,2 @@
|
||||
var f;
|
||||
f`abc`, f`abc${1}def${2}ghi`, f`abc`.member, f`abc${1}def${2}ghi`.member, f`abc`.member, f`abc${1}def${2}ghi`.member, f`abc`[0].member`abc${1}def${2}ghi`, f`abc${1}def${2}ghi`.member.member`abc${1}def${2}ghi`, f`abc${true}def${true}ghi`.member.member`abc${1}def${2}ghi`, f.thisIsNotATag("abc"), f.thisIsNotATag("abc1def2ghi");
|
||||
f`abc`, f`abc${1}def${2}ghi`, f`abc`.member, f`abc${1}def${2}ghi`.member, f`abc`.member, f`abc${1}def${2}ghi`.member, f`abc`[0].member`abc${1}def${2}ghi`, f`abc${1}def${2}ghi`.member.member`abc${1}def${2}ghi`, f`abc${!0}def${!0}ghi`.member.member`abc${1}def${2}ghi`, f.thisIsNotATag("abc"), f.thisIsNotATag("abc1def2ghi");
|
||||
|
@ -1,2 +1,2 @@
|
||||
var f;
|
||||
f`abc`, f`abc${1}def${2}ghi`, f`abc`.member, f`abc${1}def${2}ghi`.member, f`abc`.member, f`abc${1}def${2}ghi`.member, f`abc`[0].member`abc${1}def${2}ghi`, f`abc${1}def${2}ghi`.member.member`abc${1}def${2}ghi`, f`abc${true}def${true}ghi`.member.member`abc${1}def${2}ghi`, f.thisIsNotATag("abc"), f.thisIsNotATag("abc1def2ghi");
|
||||
f`abc`, f`abc${1}def${2}ghi`, f`abc`.member, f`abc${1}def${2}ghi`.member, f`abc`.member, f`abc${1}def${2}ghi`.member, f`abc`[0].member`abc${1}def${2}ghi`, f`abc${1}def${2}ghi`.member.member`abc${1}def${2}ghi`, f`abc${!0}def${!0}ghi`.member.member`abc${1}def${2}ghi`, f.thisIsNotATag("abc"), f.thisIsNotATag("abc1def2ghi");
|
||||
|
@ -1,2 +1,2 @@
|
||||
function foo(...stuff) {}
|
||||
foo([]), foo([], 1), foo([], 1, 2), foo([], 1, !0), foo([], 1, "2"), foo([], 1, 2, 3), foo``, foo`${1}`, foo`${1}${2}`, foo`${1}${true}`, foo`${1}${"2"}`, foo`${1}${2}${3}`;
|
||||
foo([]), foo([], 1), foo([], 1, 2), foo([], 1, !0), foo([], 1, "2"), foo([], 1, 2, 3), foo``, foo`${1}`, foo`${1}${2}`, foo`${1}${!0}`, foo`${1}${"2"}`, foo`${1}${2}${3}`;
|
||||
|
@ -1,2 +1,2 @@
|
||||
function foo(...stuff) {}
|
||||
foo([]), foo([], 1), foo([], 1, 2), foo([], 1, !0), foo([], 1, "2"), foo([], 1, 2, 3), foo``, foo`${1}`, foo`${1}${2}`, foo`${1}${true}`, foo`${1}${"2"}`, foo`${1}${2}${3}`;
|
||||
foo([]), foo([], 1), foo([], 1, 2), foo([], 1, !0), foo([], 1, "2"), foo([], 1, 2, 3), foo``, foo`${1}`, foo`${1}${2}`, foo`${1}${!0}`, foo`${1}${"2"}`, foo`${1}${2}${3}`;
|
||||
|
@ -2,13 +2,13 @@ function fn1() {
|
||||
return null;
|
||||
}
|
||||
function fn2() {}
|
||||
fn1`${undefined}`, fn1`${{}}`;
|
||||
var d1 = fn2`${0}${undefined}`, d2 = fn2`${0}${undefined}`;
|
||||
fn1`${void 0}`, fn1`${{}}`;
|
||||
var d1 = fn2`${0}${void 0}`, d2 = fn2`${0}${void 0}`;
|
||||
function fn3() {
|
||||
return null;
|
||||
}
|
||||
function fn4() {}
|
||||
function fn5() {}
|
||||
d1.foo(), d2(), fn2`${0}${''}`, fn2`${''}${0}`, fn3`${3}`, fn3`${''}${3}${''}`, fn3`${5}${5}${5}`, fn3`${4}`, fn3`${''}${''}${''}`, fn3`${''}${''}${3}`, fn3``, fn4`${''}${3}`, fn4`${3}${''}`, fn4`${3}${undefined}`, fn4`${''}${null}`, fn4`${null}${null}`, fn4`${true}${null}`, fn4`${null}${true}`, fn5`${(n)=>n.toFixed()
|
||||
d1.foo(), d2(), fn2`${0}${""}`, fn2`${""}${0}`, fn3`${3}`, fn3`${""}${3}${""}`, fn3`${5}${5}${5}`, fn3`${4}`, fn3`${""}${""}${""}`, fn3`${""}${""}${3}`, fn3``, fn4`${""}${3}`, fn4`${3}${""}`, fn4`${3}${void 0}`, fn4`${""}${null}`, fn4`${null}${null}`, fn4`${!0}${null}`, fn4`${null}${!0}`, fn5`${(n)=>n.toFixed()
|
||||
}`, fn5`${(n)=>n.substr(0)
|
||||
}`;
|
||||
|
@ -2,13 +2,13 @@ function fn1() {
|
||||
return null;
|
||||
}
|
||||
function fn2() {}
|
||||
fn1`${undefined}`, fn1`${{}}`;
|
||||
var d1 = fn2`${0}${undefined}`, d2 = fn2`${0}${undefined}`;
|
||||
fn1`${void 0}`, fn1`${{}}`;
|
||||
var d1 = fn2`${0}${void 0}`, d2 = fn2`${0}${void 0}`;
|
||||
function fn3() {
|
||||
return null;
|
||||
}
|
||||
function fn4() {}
|
||||
function fn5() {}
|
||||
d1.foo(), d2(), fn2`${0}${''}`, fn2`${''}${0}`, fn3`${3}`, fn3`${''}${3}${''}`, fn3`${5}${5}${5}`, fn3`${4}`, fn3`${''}${''}${''}`, fn3`${''}${''}${3}`, fn3``, fn4`${''}${3}`, fn4`${3}${''}`, fn4`${3}${undefined}`, fn4`${''}${null}`, fn4`${null}${null}`, fn4`${true}${null}`, fn4`${null}${true}`, fn5`${(n)=>n.toFixed()
|
||||
d1.foo(), d2(), fn2`${0}${""}`, fn2`${""}${0}`, fn3`${3}`, fn3`${""}${3}${""}`, fn3`${5}${5}${5}`, fn3`${4}`, fn3`${""}${""}${""}`, fn3`${""}${""}${3}`, fn3``, fn4`${""}${3}`, fn4`${3}${""}`, fn4`${3}${void 0}`, fn4`${""}${null}`, fn4`${null}${null}`, fn4`${!0}${null}`, fn4`${null}${!0}`, fn5`${(n)=>n.toFixed()
|
||||
}`, fn5`${(n)=>n.substr(0)
|
||||
}`;
|
||||
|
@ -1,3 +1,3 @@
|
||||
(function(...rest) {})`${function(x) {
|
||||
x = "bad";
|
||||
"bad";
|
||||
}}`;
|
||||
|
@ -1,3 +1,3 @@
|
||||
(function(...rest) {})`${function(x) {
|
||||
x = "bad";
|
||||
"bad";
|
||||
}}`;
|
||||
|
@ -2122,17 +2122,6 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
fn visit_mut_super_prop_expr(&mut self, n: &mut SuperPropExpr) {
|
||||
if let SuperProp::Computed(c) = &mut n.prop {
|
||||
let ctx = Ctx {
|
||||
is_exact_lhs_of_assign: false,
|
||||
is_lhs_of_assign: false,
|
||||
..self.ctx
|
||||
};
|
||||
c.visit_mut_with(&mut *self.with_ctx(ctx));
|
||||
}
|
||||
}
|
||||
|
||||
fn visit_mut_module_items(&mut self, stmts: &mut Vec<ModuleItem>) {
|
||||
let ctx = Ctx {
|
||||
top_level: true,
|
||||
@ -2514,6 +2503,17 @@ where
|
||||
s.kind = Default::default()
|
||||
}
|
||||
|
||||
fn visit_mut_super_prop_expr(&mut self, n: &mut SuperPropExpr) {
|
||||
if let SuperProp::Computed(c) = &mut n.prop {
|
||||
let ctx = Ctx {
|
||||
is_exact_lhs_of_assign: false,
|
||||
is_lhs_of_assign: false,
|
||||
..self.ctx
|
||||
};
|
||||
c.visit_mut_with(&mut *self.with_ctx(ctx));
|
||||
}
|
||||
}
|
||||
|
||||
fn visit_mut_switch_cases(&mut self, n: &mut Vec<SwitchCase>) {
|
||||
n.visit_mut_children_with(self);
|
||||
|
||||
@ -2531,6 +2531,8 @@ where
|
||||
/// We don't optimize [Tpl] contained in [TaggedTpl].
|
||||
fn visit_mut_tagged_tpl(&mut self, n: &mut TaggedTpl) {
|
||||
n.tag.visit_mut_with(self);
|
||||
|
||||
n.tpl.exprs.visit_mut_with(self);
|
||||
}
|
||||
|
||||
fn visit_mut_throw_stmt(&mut self, n: &mut ThrowStmt) {
|
||||
|
@ -0,0 +1,6 @@
|
||||
export default function example(html) {
|
||||
const test = () => {
|
||||
return 'test';
|
||||
};
|
||||
return html`${test()}`
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
export default function example(html) {
|
||||
return html`${"test"}`;
|
||||
};
|
@ -1,6 +1,6 @@
|
||||
import { m } from "../index.f66dda46.js";
|
||||
const value$1 = "it works", value = "it works";
|
||||
function AliasOutside() {
|
||||
return m`<div><p>Inside: ${value}</p><p>Outside: ${value$1}</p></div>`;
|
||||
return m`<div><p>Inside: ${"it works"}</p><p>Outside: ${"it works"}</p></div>`;
|
||||
}
|
||||
export default AliasOutside;
|
||||
|
@ -10,7 +10,7 @@ const process = {
|
||||
}
|
||||
}, foo = 42;
|
||||
function Environment() {
|
||||
return m`<table><thead><tr><th>Name ${foo}</th><th>Value</th></tr></thead><tbody>${Object.keys(process.env).sort().map((key)=>{
|
||||
return m`<table><thead><tr><th>Name ${42}</th><th>Value</th></tr></thead><tbody>${Object.keys(process.env).sort().map((key)=>{
|
||||
return m`<tr key=${key}><td>${key}</td><td>${String(process.env[key])}</td></tr>`;
|
||||
})}</tbody></table>`;
|
||||
}
|
||||
|
@ -6,6 +6,6 @@ function About({ query , title , }) {
|
||||
return y(()=>(console.log("Mounted About: ", title), ()=>{
|
||||
console.log("Unmounting About: ", title);
|
||||
})
|
||||
, []), m`<section class=${styles.about}><h1>${title || "About"}</h1><p>My name is Jason.</p><pre>${JSON.stringify(query)}</pre></section>`;
|
||||
, []), m`<section class=${"about_migxty"}><h1>${title || "About"}</h1><p>My name is Jason.</p><pre>${JSON.stringify(query)}</pre></section>`;
|
||||
}
|
||||
export default About;
|
||||
|
Loading…
Reference in New Issue
Block a user