Skip to content

es/minifier: .join is not ignoring null values anymore #10936

@skearney414

Description

@skearney414

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

https://play.swc.rs/?version=1.13.2&code=H4sIAAAAAAAAA3WPTQuCQBRF94L%2FYXajENI6kYhWtbAW7cTFc2aIkXGezIcR2X9Ps4yC3vK%2Bcw9chto60oGRUCmxIljVgjnSE%2B2VIhm53dMwCAP2xFow0NghLcKADEcPhguT%2B6YSJqOLKXy7Eg4O1gl%2BkBdA%2B43n0uX4rwLTe8b36I0Gdbq2Yq44A9oCcxL1mG%2BRi%2BJLk%2FwQ5azb2aMRnRSXbDnayqRGqSNK43kpDg6F52jaG6cPnmfEwCUBAAA%3D&config=H4sIAAAAAAAAA32UO5LbMAxA%2Bz2FR3XapMgBtssZODQJytxQhIYAvdbs%2BO4BJfmTNaROwsOP%2BH29HQ7dB7nu9%2BFLPuVntIWg3P9FQlNmexFJx9MI5Eocuftxo0wNBZsIZtF1IR3b0gM3K6Cfq3qXEAlu6qtsiDmG6Tmgw2EsQPQkE6n4qwNkpv%2FtV1bwswEu9Vl%2BRExg8w4xlkzMDD0UzbHDlOxIYM62KF5aprZEQi1Eg5XBm7HgqPLsI0fMEvOVerDeOPSgoFjAcTyDZiaxxCyTPE95z4w9HGvfz03%2BZg1nm6plJSZc5pZItorXE0ZiE2rWSrjAjRoscC3ud8sYTAGuJb%2FafWDMGz35CyAVSJYo2wE0v7NGkHnasg67ljEHGVmeFC7zrb0yQy9FNTEGpbKtMlA4at0s4KuDVlmnpbPijfJR9GAgBJkVxTV9RnYnLWjbcgwKkP7aoE3VAsx9Czd4W4gd%2FC6vZH3AVo3B8mmb0jQcMe0EGIBP6HcUpBWM27jIlbiM27xmDzIa4FWVSjN4PQKyAIwmzcfyZTZkPcSj6RMeH2diVbjej%2FBgc%2F%2FY9%2BUOv60K3YC%2BznC98K2%2Fy13%2B1T2Ublf4nngX6c%2FNcg56%2FQckCXpSLQYAAA%3D%3D

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

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions