-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Description
Describe the bug
Since #10758 the compiler has broken certain cases of array.join. It no longer ignores null values
Input code
const variable: object | null = {};
const params = [
'OrderNumber=',
variable.data?.orderNumber,
'|AuditNo=',
variable.data?.auditNo,
'|JournalType=',
transactionTypeCode[variable.data.transactionType],
'|IsPreview=0',
].join('');
console.log(params);
Config
{
"jsc": {
"parser": {
"syntax": "typescript",
"tsx": false
},
"target": "es5",
"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
},
"mangle": false
}
},
"module": {
"type": "es6"
},
"minify": false,
"isModule": true
}
Link to the code that reproduces this issue
SWC Info output
No response
Expected behavior
In 1.12.7 this was compressed to var _variable_data, _variable_data1, variable = {};
console.log([
'OrderNumber=',
null == (_variable_data = variable.data) ? void 0 : _variable_data.orderNumber,
'|AuditNo=',
null == (_variable_data1 = variable.data) ? void 0 : _variable_data1.auditNo,
'|JournalType=',
transactionTypeCode[variable.data.transactionType],
'|IsPreview=0'
].join('')); which handled null values correctly
Actual behavior
var _variable_data, _variable_data1, variable = {};
console.log("OrderNumber=" + (null == (_variable_data = variable.data) ? void 0 : _variable_data.orderNumber) + "|AuditNo=" + (null == (_variable_data1 = variable.data) ? void 0 : _variable_data1.auditNo) + "|JournalType=" + transactionTypeCode[variable.data.transactionType] + "|IsPreview=0");
Version
1.13.2
Additional context
No response