mirror of
https://github.com/swc-project/swc.git
synced 2024-12-25 06:36:08 +03:00
fix(es/codegen): Preserve parens for new
in optional chaining (#6484)
This commit is contained in:
parent
66b4966d60
commit
1ca281a6cf
72
crates/swc/tests/fixture/issues-6xxx/6438/input/.swcrc
Normal file
72
crates/swc/tests/fixture/issues-6xxx/6438/input/.swcrc
Normal file
@ -0,0 +1,72 @@
|
||||
{
|
||||
"jsc": {
|
||||
"parser": {
|
||||
"syntax": "typescript",
|
||||
"tsx": true
|
||||
},
|
||||
"transform": {
|
||||
"react": {
|
||||
"runtime": "automatic",
|
||||
"importSource": "preact",
|
||||
"development": true
|
||||
}
|
||||
},
|
||||
"target": "es2022",
|
||||
"loose": false,
|
||||
"minify": {
|
||||
"compress": {
|
||||
"arguments": false,
|
||||
"arrows": true,
|
||||
"booleans": true,
|
||||
"booleans_as_integers": false,
|
||||
"collapse_vars": true,
|
||||
"comparisons": true,
|
||||
"computed_props": true,
|
||||
"conditionals": true,
|
||||
"dead_code": true,
|
||||
"directives": true,
|
||||
"drop_console": false,
|
||||
"drop_debugger": true,
|
||||
"evaluate": true,
|
||||
"expression": false,
|
||||
"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": false,
|
||||
"side_effects": true,
|
||||
"switches": true,
|
||||
"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,
|
||||
"const_to_let": true,
|
||||
"pristine_globals": true,
|
||||
"passes": 2
|
||||
},
|
||||
"mangle": false
|
||||
}
|
||||
},
|
||||
"module": {
|
||||
"type": "es6"
|
||||
},
|
||||
"minify": true,
|
||||
"isModule": true
|
||||
}
|
1
crates/swc/tests/fixture/issues-6xxx/6438/input/index.js
Normal file
1
crates/swc/tests/fixture/issues-6xxx/6438/input/index.js
Normal file
@ -0,0 +1 @@
|
||||
new Date()?.toLocaleDateString()
|
@ -0,0 +1 @@
|
||||
new Date()?.toLocaleDateString();
|
@ -810,7 +810,11 @@ where
|
||||
|
||||
match n.base {
|
||||
OptChainBase::Member(ref e) => {
|
||||
emit!(e.obj);
|
||||
if let Expr::New(new) = &*e.obj {
|
||||
self.emit_new(new, false)?;
|
||||
} else {
|
||||
emit!(e.obj);
|
||||
}
|
||||
punct!("?.");
|
||||
|
||||
match &e.prop {
|
||||
@ -820,11 +824,8 @@ where
|
||||
}
|
||||
}
|
||||
OptChainBase::Call(ref e) => {
|
||||
if let Expr::New(new) = &*e.callee {
|
||||
self.emit_new(new, false)?;
|
||||
} else {
|
||||
emit!(e.callee);
|
||||
}
|
||||
debug_assert!(!e.callee.is_new());
|
||||
emit!(e.callee);
|
||||
punct!("?.");
|
||||
|
||||
punct!("(");
|
||||
|
Loading…
Reference in New Issue
Block a user