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

Surprising output order of imported core-js #421

Closed
danr opened this issue Oct 2, 2020 · 2 comments
Closed

Surprising output order of imported core-js #421

danr opened this issue Oct 2, 2020 · 2 comments

Comments

@danr
Copy link
Contributor

danr commented Oct 2, 2020

Setup

main.ts:

import "core-js/features/array/flat-map"
import {thing} from "./import"

console.log(thing())

import.ts:

const x = [].flatMap(i => i)

export function thing() { return x }

Observed output

$ esbuild main.ts --bundle
[ ... ]
  // node_modules/core-js/es/array/flat-map.js
  var require_flat_map = __commonJS((exports, module) => {
    require_es_array_flat_map();
    require_es_array_unscopables_flat_map();
    var entryUnbind = require_entry_unbind();
    module.exports = entryUnbind("Array", "flatMap");
  });

  // node_modules/core-js/features/array/flat-map.js
  var require_flat_map2 = __commonJS((exports, module) => {
    var parent = require_flat_map();
    module.exports = parent;
  });

  // import.ts
  const x = [].flatMap((i) => i);
  function thing() {
    return x;
  }

  // main.ts
  const flat_map = __toModule(require_flat_map2());
  console.log(thing());
})();

We see that flatMap is called before the __toModule of core-js's flat-map.

Expected output

I am expecting to see the module to be instantiated before flatMap is called, like this:

$ esbuild main.ts --bundle
[ ... ]
  // main.ts
  const flat_map = __toModule(require_flat_map2());

  // import.ts
  const x = [].flatMap((i) => i);
  function thing() {
    return x;
  }

  // main.ts, continued
  console.log(thing());
})();
@evanw evanw closed this as completed in 9522ed1 Oct 3, 2020
@evanw
Copy link
Owner

evanw commented Oct 3, 2020

Thank you very much for reporting this issue. This is similar to #399 and comes from a misunderstanding I had about how ES6 import statements are ordered. I believe I have fixed this ordering issue in the latest release.

@danr
Copy link
Contributor Author

danr commented Oct 5, 2020

I can confirm that 0.7.9 now makes the expected output :) Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants