Skip to content

swc compress bug #10473

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
littleprincewdk opened this issue May 16, 2025 · 2 comments
Open

swc compress bug #10473

littleprincewdk opened this issue May 16, 2025 · 2 comments
Assignees
Labels
Milestone

Comments

@littleprincewdk
Copy link

Describe the bug

Code run error after swc compress:
Expected:

In fact:

Input code

"use strict";

function _typeof(e) {
    return (_typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(e) {
        return typeof e
    } : function(e) {
        return e && "function" == typeof Symbol && e.constructor === Symbol && e !== Symbol.prototype ? "symbol" : typeof e
    })(e)
}

function ownKeys(t, e) {
    var o, r = Object.keys(t);
    return Object.getOwnPropertySymbols && (o = Object.getOwnPropertySymbols(t), e && (o = o.filter(function(e) {
        return Object.getOwnPropertyDescriptor(t, e).enumerable
    })), r.push.apply(r, o)), r
}

function _objectSpread(t) {
    for (var e = 1; e < arguments.length; e++) {
        var o = null != arguments[e] ? arguments[e] : {};
        e % 2 ? ownKeys(Object(o), !0).forEach(function(e) {
            _defineProperty(t, e, o[e])
        }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(t, Object.getOwnPropertyDescriptors(o)) : ownKeys(Object(o)).forEach(function(e) {
            Object.defineProperty(t, e, Object.getOwnPropertyDescriptor(o, e))
        })
    }
    return t
}

function _defineProperty(e, t, o) {
    return (t = _toPropertyKey(t)) in e ? Object.defineProperty(e, t, {
        value: o,
        enumerable: !0,
        configurable: !0,
        writable: !0
    }) : e[t] = o, e
}

function _toPropertyKey(e) {
    e = _toPrimitive(e, "string");
    return "symbol" == _typeof(e) ? e : e + ""
}

function _toPrimitive(e, t) {
    if ("object" != _typeof(e) || !e) return e;
    var o = e[Symbol.toPrimitive];
    if (void 0 === o) return ("string" === t ? String : Number)(e);
    o = o.call(e, t || "default");
    if ("object" != _typeof(o)) return o;
    throw new TypeError("@@toPrimitive must return a primitive value.")
}
Object.defineProperty(exports, "__esModule", {
    value: !0
}), exports.config = void 0;
var systemInfo = tt.getSystemInfoSync(),
    //  Douyin
    appName = systemInfo.appName,
    douyin = {
        name: "douyin",
    },
    toutiao = {
        name: "toutiao",
    },
    cmConfig = (cmConfig = {
        isToutiao: "Toutiao" === appName,
        appid: "xxx",
        version: "5.8.20",
    }).isToutiao ? _objectSpread(_objectSpread({}, cmConfig), toutiao) : _objectSpread(_objectSpread({}, cmConfig), douyin),
    // config should equal { ...cmConfig, ...douyin }
    config = exports.config = cmConfig;

Config

{
  "jsc": {
    "parser": {
      "syntax": "ecmascript",
      "jsx": false
    },
    "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
    },
    "externalHelpers": false
  },
  "module": {
    "type": "es6"
  },
  "minify": false,
  "isModule": true,
  "env": {
    
  }
}

Link to the code that reproduces this issue

https://play.swc.rs/?version=1.11.24&code=H4sIAAAAAAAAA5VV227bOBB991dMCGwhIQabLbDAwm7QAts%2BFMW2C7hvQ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2F4n%2FzNRSpf8pyZhDT%2Blxh%2F3R%2BnGSaNoWvD389fiIpc9TPohmi2yjUrwP9c1cA9cM5TzNR%2FdNzHPZfn%2FkgIKWb%2BP8SsHfZHCQAA&config=H4sIAAAAAAAAA32UwZLbMAiG73mKjM8999AH6PTSZ9AoFnKUSsIjUDaenbx7sWM72Q32zebjBwkQn4fjsblQ2%2Fw6fsqn%2FPS2EJT1Xyw0ZLY3sTTQJkttCT03PxZ6oRF5Gwkm0%2F1BmohIsJDZlkIOfniN3WLqCxC92MRqS1cTZKav%2BpkV%2FBgBl%2FpqPyFGsHmHGEsmZIYOiha4xRhtT2CutihRxpPaEgi1FCOsDM70BXuVZxc4YJac79SBdaZFBwoKBVoOV9BkkktkmeR6yn0m7OBUu27q5zc1XG2slpWccJtaIqdVop4xEBtfs1bCB9yowQPOxf2uDN4U4Fryu%2B6CIW%2F05B%2BAVCBaomwTaHEnDy%2FztKX2u8qQvYwsDwqX%2BdZumaGTopoQvFLZsTJQOGjdLOBqC2NlW%2B04M94oHwUHBryXWVFC00fg9qwl5aEH9AqQ%2FlqvTdUDmPUVbvDxQezg33JL1gds9kiWz9uUhnTCuJMgAZ%2FR7ThIKxi3cZEtceu3ec0OZDTAqS6VJvC%2BBOQBMJoIrM2GPA%2BJaLqIp%2BeamB3u675NNnfP9%2F5l5cKNociK%2BQOxf9lxh9mjSejqJJ1X%2Fdj9aa3Tz%2BbptOzo9VpNoL%2BLcjl0A%2Fm6Bhq1h%2Ft%2F5JlPJEsGAAA%3D

SWC Info output

No response

Expected behavior

Actual behavior

Version

1.11.24

Additional context

No response

@kdy1 kdy1 added this to the Planned milestone May 16, 2025
@kdy1 kdy1 self-assigned this May 16, 2025
@CodeMan62
Copy link
Contributor

@kdy1 if you want can i investigate in this. and propose a fix?

@kdy1 kdy1 assigned CodeMan62 and unassigned kdy1 May 20, 2025
@kdy1
Copy link
Member

kdy1 commented May 20, 2025

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

3 participants