fix(es/minifier): Fix join_vars (#2494)

swc_ecma_minifier:
 - Don't join `let`/`const` into narrower scope.
This commit is contained in:
Donny/강동윤 2021-10-20 14:17:14 +09:00 committed by GitHub
parent b62dc60c5d
commit cef2c8666e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 55 additions and 14 deletions

View File

@ -1,4 +1,4 @@
format_strings = true
merge_imports = true
imports_granularity = "Crate"
use_field_init_shorthand = true
wrap_comments = true

16
Cargo.lock generated
View File

@ -2503,7 +2503,7 @@ dependencies = [
[[package]]
name = "swc_css"
version = "0.21.0"
version = "0.22.0"
dependencies = [
"swc_css_ast",
"swc_css_codegen",
@ -2514,7 +2514,7 @@ dependencies = [
[[package]]
name = "swc_css_ast"
version = "0.19.0"
version = "0.20.0"
dependencies = [
"is-macro",
"serde",
@ -2525,7 +2525,7 @@ dependencies = [
[[package]]
name = "swc_css_codegen"
version = "0.19.0"
version = "0.20.0"
dependencies = [
"auto_impl",
"bitflags",
@ -2551,7 +2551,7 @@ dependencies = [
[[package]]
name = "swc_css_parser"
version = "0.21.0"
version = "0.22.0"
dependencies = [
"bitflags",
"lexical",
@ -2567,7 +2567,7 @@ dependencies = [
[[package]]
name = "swc_css_utils"
version = "0.16.0"
version = "0.17.0"
dependencies = [
"swc_atoms 0.2.9",
"swc_common",
@ -2577,7 +2577,7 @@ dependencies = [
[[package]]
name = "swc_css_visit"
version = "0.18.0"
version = "0.19.0"
dependencies = [
"swc_atoms 0.2.9",
"swc_common",
@ -2678,7 +2678,7 @@ dependencies = [
[[package]]
name = "swc_ecma_minifier"
version = "0.44.2"
version = "0.44.3"
dependencies = [
"ansi_term 0.12.1",
"anyhow",
@ -3148,7 +3148,7 @@ dependencies = [
[[package]]
name = "swc_stylis"
version = "0.18.0"
version = "0.19.0"
dependencies = [
"swc_atoms 0.2.9",
"swc_common",

View File

@ -7,7 +7,7 @@ include = ["Cargo.toml", "src/**/*.rs", "src/lists/*.json"]
license = "Apache-2.0/MIT"
name = "swc_ecma_minifier"
repository = "https://github.com/swc-project/swc.git"
version = "0.44.2"
version = "0.44.3"
[features]
debug = ["backtrace"]

View File

@ -78,7 +78,14 @@ where
}
},
Stmt::For(mut stmt) => match &mut stmt.init {
Some(VarDeclOrExpr::VarDecl(var)) => match &mut cur {
Some(VarDeclOrExpr::VarDecl(
var
@
VarDecl {
kind: VarDeclKind::Var,
..
},
)) => match &mut cur {
Some(cur) if cur.kind == var.kind => {
// Merge
cur.decls.append(&mut var.decls);
@ -94,7 +101,11 @@ where
new.push(T::from_stmt(Stmt::For(stmt)))
}
},
None => {
None if cur
.as_ref()
.map(|v| v.kind == VarDeclKind::Var)
.unwrap_or(true) =>
{
stmt.init = cur.take().map(VarDeclOrExpr::VarDecl);
new.push(T::from_stmt(Stmt::For(stmt)))

View File

@ -1,4 +1,5 @@
for(let rerenderQueue = [
let rerenderQueue = [
1
], queue; rerenderQueue.length > 0;)queue = rerenderQueue.sort(), rerenderQueue = [], queue.forEach((c)=>console.log(c)
], queue;
for(; rerenderQueue.length > 0;)queue = rerenderQueue.sort(), rerenderQueue = [], queue.forEach((c)=>console.log(c)
);

View File

@ -0,0 +1,17 @@
export function treeSubTree(tree, pathObj) {
// TODO: Require pathObj to be Path?
let path = pathObj instanceof Path ? pathObj : new Path(pathObj);
let child = tree,
next = pathGetFront(path);
while (next !== null) {
const childNode = safeGet(child.node.children, next) || {
children: {},
childCount: 0
};
child = new Tree(next, child, childNode);
path = pathPopFront(path);
next = pathGetFront(path);
}
return child;
}

View File

@ -0,0 +1,12 @@
export function treeSubTree(tree, pathObj) {
let path = pathObj instanceof Path ? pathObj : new Path(pathObj), child = tree, next = pathGetFront(path);
for(; null !== next;){
const childNode = safeGet(child.node.children, next) || {
children: {
},
childCount: 0
};
child = new Tree(next, child, childNode), next = pathGetFront(path = pathPopFront(path));
}
return child;
}