fix(es/minifier): Fix inlining of uninitialized variables (#4292)

This commit is contained in:
Donny/강동윤 2022-04-09 18:15:40 +09:00 committed by GitHub
parent 1fb456c630
commit b990b19ed1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 85 additions and 3 deletions

View File

@ -0,0 +1,68 @@
{
"jsc": {
"parser": {
"syntax": "ecmascript",
"jsx": false
},
"target": "es2015",
"loose": false,
"minify": {
"compress": {
"arguments": false,
"arrows": true,
"booleans": true,
"booleans_as_integers": false,
"collapse_vars": true,
"comparisons": true,
"computed_props": false,
"conditionals": false,
"dead_code": false,
"directives": false,
"drop_console": false,
"drop_debugger": true,
"evaluate": true,
"expression": true,
"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": true,
"side_effects": true,
"switches": false,
"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
},
"mangle": {
"toplevel": true,
"keep_classnames": false,
"keep_fnames": false,
"keep_private_props": false,
"ie8": false,
"safari10": false
}
}
},
"module": {
"type": "es6"
},
"minify": true
}

View File

@ -0,0 +1,7 @@
const foo = 'foo-';
console.log(foo)
const A = `${foo}bar`;
const B = `${foo}bar2`;
console.log("test", foo, A, B)

View File

@ -0,0 +1 @@
const a="foo-";console.log(a);const b=`${a}bar`,c=`${a}bar2`;console.log("test",a,b,c)

View File

@ -129,13 +129,19 @@ where
.data
.vars
.get(&i.to_id())
.map(|v| v.assign_count == 0 && !v.declared_as_fn_param)
.map(|v| {
v.declared
&& !v.var_initialized
&& !v.cond_init
&& v.assign_count == 0
&& !v.declared_as_fn_param
})
.unwrap_or(false)
{
self.changed = true;
tracing::debug!(
"strings: Converting a reference ({}{:?}) into `undefined` (in string \
context)",
"strings: Converting an unresolved reference ({}{:?}) into `undefined` \
(in string context)",
i.sym,
i.span.ctxt
);