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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: commonjs lazy transform produces invalid output with multiple ns imports for same module #15939

Closed
1 task done
nicolo-ribaudo opened this issue Sep 6, 2023 · 1 comment 路 Fixed by #15941
Closed
1 task done
Labels
i: bug outdated A closed issue/PR that is archived due to age. Recommended to make a new issue

Comments

@nicolo-ribaudo
Copy link
Member

馃捇

  • Would you like to work on a fix?

How are you using Babel?

Programmatic API (babel.transform, babel.parse)

Input code

import * as a from "mod";
import * as b from "mod";

later(() => [a, b])

Configuration file name

No response

Configuration

const out = transformSync(input, {
  configFile: false,
  plugins: [[await load(`transform-modules-commonjs`), { lazy: true }]],
});

Current and expected behavior

Current:

"use strict";

function a() {
  const data = _interopRequireWildcard(require("mod"));
  a = function () {
    return data;
  };
  return data;
}
var b = a();
function _getRequireWildcardCache(nodeInterop) { ... }
later(() => [a(), b()]);

Expected (note the b declaration):

"use strict";

function a() {
  const data = _interopRequireWildcard(require("mod"));
  a = function () {
    return data;
  };
  return data;
}
var b = a;
function _getRequireWildcardCache(nodeInterop) { ... }
later(() => [a(), b()]);

Environment

Current main

Possible solution

No response

Additional context

No response

@nicolo-ribaudo
Copy link
Member Author

nicolo-ribaudo commented Sep 6, 2023

Still happens with #15878, also with import defer.

This bug blocks #15878 and #15898.

@github-actions github-actions bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Dec 8, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 8, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
i: bug outdated A closed issue/PR that is archived due to age. Recommended to make a new issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants