Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Properly handle class members with decorators #31

Closed
bo4arovpavel1989 opened this issue Sep 20, 2022 · 2 comments
Closed

Properly handle class members with decorators #31

bo4arovpavel1989 opened this issue Sep 20, 2022 · 2 comments
Labels
bug Something isn't working

Comments

@bo4arovpavel1989
Copy link

bo4arovpavel1989 commented Sep 20, 2022

The goal of this package is to mangle renamed properties by minifiers like 'terser', but there is an issue, when using class members with decorators. When transformer renames decorated class member with prefix, this class member is mangled by minifier, but it can't handle connection of this class member and decorator function.
Ommiting implementation of __decorate fn, decorator transform has the following output

// input
class Foo {
  @foo private field = 1;
}

// output
class Foo {
    constructor() {
        this.field = 1;
    }
}
__decorate([
    foo
], Foo.prototype, "field", void 0);

If use ts-transformer-properties-rename package, it will be transformed to

// input
class Foo {
  @foo private _private_field = 1;
}

// output
class Foo {
    constructor() {
        this._private_field = 1;
    }
}
__decorate([
    foo
], Foo.prototype, "_private_field", void 0);

But after terser's mangling it will be smth like that

// input
class Foo {
  @foo private i = 1;
}

// output
class Foo {
    constructor() {
        this.i = 1;
    }
}
__decorate([
    foo
], Foo.prototype, "_private_field", void 0);

There is an issue in terser repo, where contributors assumed, that it could be solved by mangling string literals by same prefix as well, but according issue is still unresolved

@timocov timocov added the bug Something isn't working label Oct 22, 2022
timocov added a commit that referenced this issue Oct 22, 2022
@timocov
Copy link
Owner

timocov commented Oct 22, 2022

Not too sure about whether an option should be enabled by default (or whether this should should exist at all as I haven't worked with decorators close enough), but now at least it would be possible to disable renaming for decorated fields by enabling option ignoreDecorated, see 0c34883. Feel free to share feedback here or create another issue if you find anything else.

@timocov
Copy link
Owner

timocov commented Oct 22, 2022

The fix has been released in https://github.com/timocov/ts-transformer-properties-rename/releases/tag/v0.14.0 (please pay attention on breaking changes in this release).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants