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

Difference between Babel and SWC compilation #8664

Closed
Kahor opened this issue Feb 26, 2024 · 2 comments
Closed

Difference between Babel and SWC compilation #8664

Kahor opened this issue Feb 26, 2024 · 2 comments
Labels

Comments

@Kahor
Copy link

Kahor commented Feb 26, 2024

Describe the bug

Export functions only generate the getter for said function in transpiled SWC code, which is different than what is output by Babel, this is an issue for us as we are using the jasmine spyOn method which is not compatible with the SWC compiled code (see expected behavior)

Input code

export function getSelectorByName(
    selectorName,
) {
    return selectorName;
}

Config

{
  "jsc": {
    "parser": {
      "syntax": "typescript",
      "tsx": false
    },
    "target": "es5",
    "loose": false,
    "minify": {
      "compress": false,
      "mangle": false
    }
  },
  "module": {
    "type": "commonjs"
  },
  "minify": false,
  "isModule": true
}

Playground link (or link to the minimal reproduction)

https://play.swc.rs/?version=1.3.100&code=H4sIAAAAAAAAA0utKMgvKlFIK81LLsnMz1NITy0JTs1JTS7JL3Kq9EvMTdXgUgCCYqgYSESHS1OhGixalFpSWpSHImnNVQsAzfJPSVMAAAA%3D&config=H4sIAAAAAAAAA1WPSw7DMAhE9z6FxbrbbnqHHsJySeTIPwGRakW5e%2B3UTpsdzAw82JTWsLCFh95qWZtsiJHOvipcoph3VUBKRrbkssBtuMLNmoxnPKT964AYmlHaFPK9x8GnxDjiXQsuuqn8A20KmZD5GmxRE2ePV5zqSAjptR5mf6Qd2%2FB1W0hxYfglB%2FHcDo6fY1xoRbV%2FALu7P%2BkZAQAA

SWC Info output

Operating System:
    Platform: darwin
    Arch: x64
    Machine Type: x86_64
    Version: Darwin Kernel Version 23.3.0: Wed Dec 20 21:28:58 PST 2023; root:xnu-10002.81.5~7/RELEASE_X86_64
    CPU: (12 cores)
        Models: Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz

Binaries:
    Node: 20.11.0
    npm: 10.2.4
    Yarn: N/A
    pnpm: N/A

Relevant Packages:
    @swc/core: 1.4.2
    @swc/helpers: 0.5.6
    @swc/types: 0.1.5
    

SWC Config:
    output: N/A
    .swcrc path: N/A

Next.js info:
    output: N/A

Expected behavior

Babel return the following transpiled code.

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.getSelectorByName = getSelectorByName;
function getSelectorByName(selectorName) {
  return selectorName;
}

Which is working fine with jasmine SpyOn method:
spyOn(<moduleName>, "getSelectorByName")
which is not the code with the SWC transpile code which return the following error:
getSelectorByName is not declared writable or has no setter

Actual behavior

"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
Object.defineProperty(exports, "getSelectorByName", {
    enumerable: true,
    get: function() {
        return getSelectorByName;
    }
});
function getSelectorByName(selectorName) {
    return selectorName;
}

Version

1.3.100

Additional context

No response

@Kahor Kahor added the C-bug label Feb 26, 2024
@kdy1
Copy link
Member

kdy1 commented Feb 26, 2024

#7435

@kdy1 kdy1 closed this as not planned Won't fix, can't repro, duplicate, stale Feb 26, 2024
@swc-bot
Copy link
Collaborator

swc-bot commented Mar 28, 2024

This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@swc-project swc-project locked as resolved and limited conversation to collaborators Mar 28, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

No branches or pull requests

3 participants