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

Doesn't export the default value when interopRequireDefault is applied #1790

Closed
Tracked by #2228
merceyz opened this issue Jun 4, 2021 · 2 comments · Fixed by #1829
Closed
Tracked by #2228

Doesn't export the default value when interopRequireDefault is applied #1790

merceyz opened this issue Jun 4, 2021 · 2 comments · Fixed by #1829
Labels
Milestone

Comments

@merceyz
Copy link

merceyz commented Jun 4, 2021

Describe the bug

swc exports the incorrect value when the interopRequireDefault helper is applied to a separate import from the same library

Input code

Reproducible using the API

const swc = require(`@swc/wasm`);
console.log(swc.transformSync(`
import semver from 'semver';

export {SemVer} from 'semver';

export function foo() {
  return new semver.SemVer('');
}
`, {
  module: {type: `commonjs`},
  jsc: {
    externalHelpers: true,
  },
}).code);

The output exports _semver.SemVer instead of _semver.default.SemVer

"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
exports.foo = foo;
var swcHelpers = require("@swc/helpers");
var _semver = swcHelpers.interopRequireDefault(require("semver"));
Object.defineProperty(exports, "SemVer", {
    enumerable: true,
    get: function() {
        return _semver.SemVer;
    }
});
function foo() {
    return new _semver.default.SemVer('');
}

Config
n/a

Expected behavior

diff --git a/out.js b/out.js
index 3b5596341..8b5e63f09 100644
--- a/out.js
+++ b/out.js
@@ -8,7 +8,7 @@ var _semver = swcHelpers.interopRequireDefault(require("semver"));
 Object.defineProperty(exports, "SemVer", {
     enumerable: true,
     get: function() {
-        return _semver.SemVer;
+        return _semver.default.SemVer;
     }
 });
 function foo() {

Version
The version of @swc/wasm: 1.2.58

Additional context
yarnpkg/berry#2228

@merceyz merceyz added the C-bug label Jun 4, 2021
@kdy1 kdy1 modified the milestones: v1.2.60, v1.2.61 Jun 5, 2021
@kdy1 kdy1 modified the milestones: v1.2.61, v1.2.62 Jun 16, 2021
@cspotcode
Copy link
Contributor

I think we may need to revise the description of this issue. The exported value should actually be require('semver').SemVer, at least according to TypeScript's behavior:

https://www.typescriptlang.org/play?#code/JYWwDg9gTgLgBAZwKYgG5KnAZlCI4DkyaGBA3ALABQ1SAHpLHAN4DKKAahgL7a75EU6KOWq0G0eFgCuAOwDGMYBFnYIEABQBKFtThwoSGNKirZSAO6IhGAHTsQXKBoIEtlKtyA

I believe this issue may be fixed by #1829

@swc-bot
Copy link
Collaborator

swc-bot commented Oct 23, 2022

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 Oct 23, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

Successfully merging a pull request may close this issue.

4 participants