mirror of
https://github.com/swc-project/swc.git
synced 2024-11-28 02:29:04 +03:00
fix(es/minifier): Fix handling of optional chaining when hoist_props
is enabled (#7246)
**Related issue:** - Closes https://github.com/swc-project/swc/issues/7228.
This commit is contained in:
parent
dd56100585
commit
a44fea1ec8
64
crates/swc/tests/fixture/issues-7xxx/7228/input/.swcrc
Normal file
64
crates/swc/tests/fixture/issues-7xxx/7228/input/.swcrc
Normal file
@ -0,0 +1,64 @@
|
||||
{
|
||||
"jsc": {
|
||||
"parser": {
|
||||
"syntax": "ecmascript",
|
||||
"jsx": false
|
||||
},
|
||||
"target": "es2022",
|
||||
"loose": false,
|
||||
"minify": {
|
||||
"compress": {
|
||||
"arguments": false,
|
||||
"arrows": false,
|
||||
"booleans": false,
|
||||
"booleans_as_integers": false,
|
||||
"collapse_vars": false,
|
||||
"comparisons": false,
|
||||
"computed_props": false,
|
||||
"conditionals": false,
|
||||
"dead_code": false,
|
||||
"directives": false,
|
||||
"drop_console": false,
|
||||
"drop_debugger": false,
|
||||
"evaluate": false,
|
||||
"expression": false,
|
||||
"hoist_funs": false,
|
||||
"hoist_props": true,
|
||||
"hoist_vars": false,
|
||||
"if_return": false,
|
||||
"join_vars": false,
|
||||
"keep_classnames": false,
|
||||
"keep_fargs": false,
|
||||
"keep_fnames": false,
|
||||
"keep_infinity": false,
|
||||
"loops": false,
|
||||
"negate_iife": false,
|
||||
"properties": false,
|
||||
"reduce_funcs": false,
|
||||
"reduce_vars": false,
|
||||
"side_effects": false,
|
||||
"switches": false,
|
||||
"typeofs": false,
|
||||
"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": false,
|
||||
"const_to_let": false,
|
||||
"pristine_globals": false
|
||||
},
|
||||
"mangle": false
|
||||
}
|
||||
},
|
||||
"module": {
|
||||
"type": "es6"
|
||||
},
|
||||
"minify": false,
|
||||
"isModule": true
|
||||
}
|
4
crates/swc/tests/fixture/issues-7xxx/7228/input/input.js
Normal file
4
crates/swc/tests/fixture/issues-7xxx/7228/input/input.js
Normal file
@ -0,0 +1,4 @@
|
||||
function f() {
|
||||
const foos = something.getFoos();
|
||||
return foos?.[0];
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
function f() {
|
||||
return something.getFoos()?.[0];
|
||||
}
|
@ -195,6 +195,10 @@ where
|
||||
pub(super) fn replace_props(&mut self, e: &mut Expr) {
|
||||
let member = match e {
|
||||
Expr::Member(m) => m,
|
||||
Expr::OptChain(m) => match &mut *m.base {
|
||||
OptChainBase::Member(m) => m,
|
||||
_ => return,
|
||||
},
|
||||
_ => return,
|
||||
};
|
||||
if let Expr::Ident(obj) = &*member.obj {
|
||||
|
@ -0,0 +1,47 @@
|
||||
{
|
||||
"arguments": false,
|
||||
"arrows": false,
|
||||
"booleans": false,
|
||||
"booleans_as_integers": false,
|
||||
"collapse_vars": false,
|
||||
"comparisons": false,
|
||||
"computed_props": false,
|
||||
"conditionals": false,
|
||||
"dead_code": false,
|
||||
"directives": false,
|
||||
"drop_console": false,
|
||||
"drop_debugger": false,
|
||||
"evaluate": false,
|
||||
"expression": false,
|
||||
"hoist_funs": false,
|
||||
"hoist_props": true,
|
||||
"hoist_vars": false,
|
||||
"if_return": false,
|
||||
"join_vars": false,
|
||||
"keep_classnames": false,
|
||||
"keep_fargs": false,
|
||||
"keep_fnames": false,
|
||||
"keep_infinity": false,
|
||||
"loops": false,
|
||||
"negate_iife": false,
|
||||
"properties": false,
|
||||
"reduce_funcs": false,
|
||||
"reduce_vars": false,
|
||||
"side_effects": false,
|
||||
"switches": false,
|
||||
"typeofs": false,
|
||||
"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": false,
|
||||
"const_to_let": false,
|
||||
"pristine_globals": false,
|
||||
"defaults": true
|
||||
}
|
@ -0,0 +1,4 @@
|
||||
export function f() {
|
||||
const foos = something.getFoos();
|
||||
return foos?.[0];
|
||||
}
|
@ -0,0 +1,4 @@
|
||||
export function f() {
|
||||
const foos = something.getFoos();
|
||||
return foos?.[0];
|
||||
}
|
Loading…
Reference in New Issue
Block a user