构建后,部分代码未被压缩。

huangapple go评论57阅读模式
英文:

After build some parts of code aren't minified

问题

以下是翻译好的部分:

原始代码中的部分:

I have this Angular service:

class MyService extends BaseService  {
    constructor(
        private translationService: TranslationService, 
        private authService: AuthService) {
        super()
    }

    getActiveLang() {
        return this.translationService.getActiveLang()
    }

    getUserMail() {
        const user = this.authService.currentUser();
        return user  ? user .email : null
    }          
}

编译后的代码中的部分:

class u extends w.PV {
    constructor(_, t) {
        super(),
        this.translationService = _,
        this.authService = t
    }
    getActiveLang() {
        return this.translationService.getActiveLang()
    }
    getUserMail() {
        const _ = this.authService.currentUser();
        return _ ? _.email : null
    }          
}

注:由于您要求只返回翻译好的部分,我已省略问题内容。如果您有其他需要,请随时提出。

英文:

I have this Angular service:

class MyService extends BaseService  {
    constructor(
        private translationService: TranslationService, 
        private authService: AuthService) {
        super()
    }

    getActiveLang() {
        return this.translationService.getActiveLang()
    }

    getUserMail() {
        const user = this.authService.currentUser();
        return user  ? user .email : null
    }          
}

After build the code becomes:

class u extends w.PV {
    constructor(_, t) {
        super(),
        this.translationService = _,
        this.authService = t
    }
    getActiveLang() {
        return this.translationService.getActiveLang()
    }
    getUserMail() {
        const _ = this.authService.currentUser();
        return _ ? _.email : null
    }          
}

Why aren't the properties (translationService, authService) and methods (getActiveLang, getUserMail) of injected services minified?

答案1

得分: 0

我回答我自己。

实例属性可能会泄漏到几乎任何地方,只要混淆器不能保证应用一致的混淆。

例如

window.svc = new MyService();

然后一些全局脚本使用 window.svc.translationService 以便可用。私有标记不会阻止这一点;它只是 TypeScript 中的一个关键字,混淆器不会注意到。

一些优化器能够进行这种混淆,比如使用高级优化的 Closure 编译器,但你必须遵循它的严格规则以使一切都按照这种方式工作。不过,Angular 不集成/支持 Closure 编译器。

英文:

I answer my self.

Instance properties can leak into basically anywhere, where the minifier is not guaranteed to have applied a consistent minification.

Eg

window.svc = new MyService();

and then some global script uses window.svc.translationService to be available. The private marker does not prevent this; it is a TypeScript only keyword that minifiers don't see.

Some optimizers are capable of this minification, like Closure Compiler using Advanced optimizations, but you have to follow its strict rules to make everything work that way. Angular does not integrate/support Closure Compiler though.

huangapple
  • 本文由 发表于 2023年5月22日 23:59:44
  • 转载请务必保留本文链接:https://go.coder-hub.com/76307990.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定