Skip to content
This repository has been archived by the owner on Nov 4, 2024. It is now read-only.

3.0.37+ breaks behavior of new keyword when accessing class under import #437

Closed
kherock opened this issue May 28, 2018 · 3 comments
Closed
Labels

Comments

@kherock
Copy link

kherock commented May 28, 2018

In a module that imports myExport from another module that has a class MyClass as a property, attempting to instantiate MyClass with

new myExport.MyClass()

can sometimes result it the error

[Error] TypeError: _d7e‍.t is not a constructor

It seems like this kind of transformation lost a set of parentheses and attempts to call the .t as a constructor.

in 3.0.36:

new (_6c5‍.t("myExport",myExport)).MyClass()

in 3.0.37:

new _e8e‍.t("myExport",myExport).MyClass()

I was really struggling to consistently reproduce this since there seems to be some caching happening that I'm not fully aware of. Sometimes the transformed result would remain as new myExport.MyClass(), but after resetting my shell session, it changes to be one of the above without even touching the source files.

Anyway, here's a pretty minimal reproduction that should help explain:

// index.js
import { myExport } from './module';

// the affected transformation only seems to happen with circular dependencies?
export default 'foo';

const fn = () => {
  new myExport.MyClass()
}

console.log(fn.toString());
// module.js
import foo from './index';
export const myExport = {
  MyClass: class MyClass { }
}
@kherock kherock changed the title 3.0.37+ breaks behavior of new keyword with class under export 3.0.37+ breaks behavior of new keyword when accessing class under import May 28, 2018
@jdalton
Copy link
Member

jdalton commented May 29, 2018

Thanks @specialkk!

I've been tweaking the TDZ instrumentation and this got regressed.

@jdalton jdalton added the bug label May 29, 2018
@kherock
Copy link
Author

kherock commented May 29, 2018

I find it seriously impressive with how dedicated you are at keeping that issue counter down at 0. Do you ever find time to sleep?

Thanks for fixing these!

@jdalton
Copy link
Member

jdalton commented May 29, 2018

v3.0.39 is released 🎉

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

No branches or pull requests

2 participants