timocov / ts-transformer-minify-privates

A TypeScript custom transformer which renames private class members
MIT License
52 stars 5 forks source link

Bugs when using decorators with private props/methods #17

Closed bo4arovpavel1989 closed 3 years ago

bo4arovpavel1989 commented 3 years ago

There is a problem, when using decorators with private class members. This package is meant to be used with terser minify properties option, but for now terser isn't able to work with class members decorators (issue here). Seems, that can be fixed, when add additional check for decorators here. That would be smth like:

return (isClassMember(x) && !hasDecorators(x) || isConstructorParameter(x)) && isPrivateNonStatic(x);

where hasDecorators fn impl:

function hasDecorators(node: ts.Node): boolean {
    return !!node.decorators;
}

seems, this solution would fit for all cases now, since props or methods with decorators can't be minified anyway? If any thoughts, i would be glad to contribute

timocov commented 3 years ago

Hi there,

yeah, looks legit for me.

Btw, did you see kind of the next generation of this project https://github.com/timocov/ts-transformer-properties-rename? It could do even more than just rename privates in classes, so probably you might find this helpful.

bo4arovpavel1989 commented 3 years ago

Hi there,

yeah, looks legit for me.

Btw, did you see kind of the next generation of this project https://github.com/timocov/ts-transformer-properties-rename? It could do even more than just rename privates in classes, so probably you might find this helpful.

oh, thanks, i didn't. Sure, will have a look