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

[build-optimizer] Ivy code is not full tree shaken / marked @PURE #11796

Closed
hansl opened this issue Aug 7, 2018 · 4 comments · Fixed by #13613
Closed

[build-optimizer] Ivy code is not full tree shaken / marked @PURE #11796

hansl opened this issue Aug 7, 2018 · 4 comments · Fixed by #13613

Comments

@hansl
Copy link
Contributor

hansl commented Aug 7, 2018

Building an app with Ivy and optimizations on, I see the following code still there:

Before Uglify:

var NgModuleFactory$1 = /** @class */ (function (_super) {
    __extends(NgModuleFactory$$1, _super);
    function NgModuleFactory$$1(moduleType) {
        var _this = _super.call(this) || this;
        _this.moduleType = moduleType;
        return _this;
    }
    NgModuleFactory$$1.prototype.create = function (parentInjector) {
        return new NgModuleRef$1(this.moduleType, parentInjector);
    };
    return NgModuleFactory$$1;
}(NgModuleFactory));

After Uglify (with mangle off):

        !function(_super) {
            function NgModuleFactory$$1(moduleType) {
                var _this = _super.call(this) || this;
                return _this.moduleType = moduleType,
                _this
            }
            __extends(NgModuleFactory$$1, _super),
            NgModuleFactory$$1.prototype.create = function(parentInjector) {
                return new NgModuleRef$1(this.moduleType,parentInjector)
            }
        }(function() {}),

We would expect the first snippet to have a @PURE annotation on it following the @class, and the function not to be there at all after uglify.

@hansl
Copy link
Contributor Author

hansl commented Aug 7, 2018

Seems like we don't use the @class annotation as hint to add @PURE, which we should.

@kzc
Copy link

kzc commented Aug 9, 2018

On a hunch I searched for __extends in the repo. It may be due to the \w+ in this regex:

\w+ doesn't match the $ character in the bundler renamed NgModuleFactory$$1.

$ node -p '/\w*\.?__extends\(\w+, _super\);/.test("__extends(NgModuleFactory$$1, _super);")'
false

Possible alternatives: \S+ or [A-Za-z_$][A-Za-z0-9_$]*.

$ node -p '/\w*\.?__extends\(\S+, _super\);/.test("__extends(NgModuleFactory$$1, _super);")'
true

$ node -p '/\w*\.?__extends\([A-Za-z_$][A-Za-z0-9_$]*, _super\);/.test("__extends(NgModuleFactory$$1, _super);")'
true

@filipesilva
Copy link
Contributor

Yeah I think this was the renamed class. 07ceb05 fixed a similar thing.

The "gatekeeper" regex didn't correctly identify it though, for the reasons highlighted by @kzc. #13613 should fix it.

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 9, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants