HaxeFoundation / HaxeFoundation/haxe

[js] Top-level mutation of every class prevents tree-shaking

Open
#12,409 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
Haxe
Stars
6.9k
Forks
715
Avg merge
2d 2h
Merged PRs (30d)
11

Description

I am working on a library written in Haxe and compiled to JS. I have everything working pretty well but have run into this. The generated code for a class (even in ES6 mode) always looks like:

```
class Thing {
}
Thing.__name__ = "Thing";
Object.assign(Thing.prototype, {
__class__: Thing
,thing: null
});
```

This top-level mutation prevents tree shaking of the class no matter how I set up my imports. removing these lines after the class fixes it for me but of course I'm not sure that safe to do. It seems like this should be equivalent to:

```
class Thing {
static __name__ = "Thing";
__class__ = Thing;
thing = null;
}
```

perhaps ES6 mode could generate this modern syntax instead?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.