Skip to content

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

@singpolyma

Description

@singpolyma

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions