Skip to content
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

Prevent transpiling of swc helpers (cont.) #9584

Open
bert-mccutchen opened this issue Sep 24, 2024 · 0 comments
Open

Prevent transpiling of swc helpers (cont.) #9584

bert-mccutchen opened this issue Sep 24, 2024 · 0 comments
Labels

Comments

@bert-mccutchen
Copy link

Describe the bug

A past issue has re-appeared (#3201) under a different helper: _instanceof

When using SWC in a bundler that also transpiles node_modules and externalHelpers is enabled, the instanceof object expression in the _instanceof helper:

} else return left instanceof right;

is transpiled to call the _instanceof helper, leading to infinite recursion:

// node_modules/@swc/helpers/esm/_instanceof.js
function _instanceof1(left, right) {
  if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
    return !!right[Symbol.hasInstance](left);
  } else return _instanceof1(left, right);
}
var init_instanceof = __esm({
  "node_modules/@swc/helpers/esm/_instanceof.js": function() {
    init_instanceof();
  }
});

Input code

function _instanceof(left, right) {
    if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
        return !!right[Symbol.hasInstance](left);
    } else return left instanceof right;
}
export { _instanceof as _ };

Config

{
  "jsc": {
    "parser": {
      "syntax": "ecmascript",
      "jsx": false
    },
    "target": "es5",
    "externalHelpers": true,
    "loose": false,
    "minify": {
      "compress": false,
      "mangle": false
    }
  },
  "module": {
    "type": "es6"
  },
  "minify": false,
  "isModule": true
}

Playground link (or link to the minimal reproduction)

https://play.swc.rs/?version=1.7.28&code=H4sIAAAAAAAAA3VPQQqDMBC8%2B4rRQ1Eo%2FYD4gJ57LEWsbmog3UiygYr492qstJfOcWdmZ0YFbkVbRq3ZS8MtWZUbUnKE049eCkwJFmiFPB6QVuBgDA4HyDgsclzG592ahaiQBe5IaaYuWwXRcd34U9%2F48yfjtr9d4UiCY6TpX3UsVJTRMYOMp920Evg23wLLZE7oNVgnmH53ofGoMZdvX8z%2B4PQAAAA%3D&config=H4sIAAAAAAAAA1WPPQ6DMAyFd06BPHdth56gSw9hpQYF5U%2B2kUCIuzdAQstmv%2B%2FZfl6atoVBDDzbJZe5SchCfPZZkTkoTlkBMh7FsE0Kt0oH2VCHTmiX1oOAIvek%2B5Tcix1oUuKA7kUuEUumyiMV6GIUqruK5m2w3fyfxkSfmESuxs2KoXd0zdKUPODjZ9xh%2BVLnREe2B%2FxM9di5GKy86%2BSWtFm%2FmL2vqjEBAAA%3D

SWC Info output

No response

Expected behavior

No infinite recursion

Actual behavior

Infinite recursion of _instanceof1

Version

1.7.28

Additional context

No response

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

1 participant