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

Evaluate export default beforehand #1568

Closed
josteph opened this issue Apr 11, 2021 · 4 comments · Fixed by #1588
Closed

Evaluate export default beforehand #1568

josteph opened this issue Apr 11, 2021 · 4 comments · Fixed by #1588
Assignees
Labels
Milestone

Comments

@josteph
Copy link

josteph commented Apr 11, 2021

Describe the bug
Currently export should be evaluated beforehand to avoid undefined if bundled using webpack. Refer to this issue webpack/webpack#7767.

Input code

export default function get(key: string) {
  console.log(key);
}

Config

{
  jsc: {
    parser: {
      syntax: "typescript",
      tsx: false,
      decorators: false,
      dynamicImport: true
    },
    target: "es5",
    loose: true,
    externalHelpers: false
  },
  sourceMaps: true,
  minify: false,
  env: {
    mode: "entry",
    coreJs: 3
  },
  module: {
     type: "commonjs"
  }
}

Expected behavior
Babel sample output:

'use strict';

Object.defineProperty(exports, '__esModule', {
  value: true,
});

exports.default = get;

function get(key) {
  // code here
}

Version
The version of @swc/core: 1.2.51

Additional context
If we change the export this way, it would work normally as expected.

function get(key: string) {
  // code
}

export default get;

SWC output (changed the export as described above) (works):

'use strict';

Object.defineProperty(exports, '__esModule', {
  value: true,
});
exports.default = void 0;

function get(key) {
  // code here
}

var _default = get;
exports.default = _default;

Current SWC output (doesn't work):

'use strict';

Object.defineProperty(exports, '__esModule', {
  value: true,
});

function get(key) {
  // code here
}

exports.default = get;
@josteph josteph added the C-bug label Apr 11, 2021
@kdy1 kdy1 modified the milestones: v1.2.53, v1.2.54 Apr 14, 2021
@kdy1 kdy1 mentioned this issue Apr 17, 2021
6 tasks
@kdy1 kdy1 self-assigned this Apr 17, 2021
@kdy1
Copy link
Member

kdy1 commented Apr 17, 2021

How did you get the output of swc?
Your .swcrc does not contains module config, so I failed to reproduce it.

@kdy1
Copy link
Member

kdy1 commented Apr 17, 2021

I think I can fix it without reproduction.

I was wrong. I need more context.

kdy1 added a commit to kdy1/swc that referenced this issue Apr 17, 2021
kdy1 added a commit to kdy1/swc that referenced this issue Apr 17, 2021
kdy1 added a commit to kdy1/swc that referenced this issue Apr 17, 2021
@kdy1 kdy1 removed their assignment Apr 17, 2021
@kdy1 kdy1 modified the milestone: v1.2.54 Apr 17, 2021
@josteph
Copy link
Author

josteph commented Apr 17, 2021

Ah right, I forgot to put the module type. It should be "commonjs".

@kdy1 kdy1 self-assigned this Apr 18, 2021
kdy1 added a commit to kdy1/swc that referenced this issue Apr 18, 2021
kdy1 added a commit to kdy1/swc that referenced this issue Apr 18, 2021
kdy1 added a commit to kdy1/swc that referenced this issue Apr 18, 2021
@kdy1 kdy1 mentioned this issue Apr 18, 2021
3 tasks
kdy1 added a commit that referenced this issue Apr 18, 2021
swc_ecma_transforms_module:
 - Change the order of functions exported as default. (#1568)
 - Handle mixed imports correctly. (#1525)

swc:
 - Ensure that #1581 is fixed. (#1581)
@swc-bot
Copy link
Collaborator

swc-bot commented Oct 24, 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 24, 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.

3 participants