swc-project / swc-loader

Moved to https://github.com/swc-project/pkgs
MIT License
394 stars 29 forks source link

Unexpected result in code execution order between ts-loader and swc-loader #40

Closed JerryChan31 closed 2 years ago

JerryChan31 commented 2 years ago

Problem context

Hi! I'm trying to replace ts-loader with swc-loader in my app to speed up building. And I found that the replacement cause unexpected result in code execution order. Here's the reproduction repository: https://github.com/JerryChan31/swc-loader-context

Reproduction steps:

  1. run pnpm install on branch main.
  2. run git checkout ts-loader
  3. run npm run reproduce
  4. run git checkout swc-loader
  5. run npm run reproduce

And you can see the output of the first npm run reproduce is:

a.js entry
d.js constructor
d.js init
a.js before B
B.js exec

and the second one:

d.js constructor
a.js entry
d.js init
a.js before B
B.js exec

It would be grateful to know what cause the difference. Thank you!

kdy1 commented 2 years ago

Imports should be hoisted according to es specification.

JerryChan31 commented 2 years ago

Thank you so much for the speedy reply. I'll follow up the clue. Appreciate your work on swc ! 👍