Skip to content
This repository was archived by the owner on Apr 4, 2025. It is now read-only.
This repository was archived by the owner on Apr 4, 2025. It is now read-only.

Build optimizer incorrect code for enum #155

@IgorMinar

Description

@IgorMinar

(resubmitting from angular/angular#19137 by @achimha)

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[X] Bug report  
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question

Current behavior

Using --build-optimizer on @angular/cli 1.4.1 generates incorrect code for a module of @ng-bootstrap

The enum ModalDismissReasons is not correctly referenced, it evaluates to undefined when accessed via o.ModalDismissReasons. Instead of referencing to it as a, it is still referenced as ModalDismissReasons. The source code is here

https://github.com/ng-bootstrap/ng-bootstrap/blob/0c03671c52500f13387deeaf31f815372d364c26/src/modal/modal-window.ts#L45

AVYa: function(t, e, n) {
        "use strict";
        n.d(e, "a", function() {
            return i
        });
        var r = n("/oeL")
          , o = n("zGKh")
          , i = (n.n(o),
        function() {
            function t(t, e) {
                this._elRef = t,
                this._renderer = e,
                this.backdrop = !0,
                this.keyboard = !0,
                this.dismissEvent = new r.EventEmitter
            }
            return t.prototype.backdropClick = function(t) {
                !0 === this.backdrop && this._elRef.nativeElement === t.target && this.dismiss(o.ModalDismissReasons.BACKDROP_CLICK)
            }
            ,
            t.prototype.escKey = function(t) {
                this.keyboard && !t.defaultPrevented && this.dismiss(o.ModalDismissReasons.ESC)
            }
            ,
            t.prototype.dismiss = function(t) {
                this.dismissEvent.emit(t)
            }
            ,
            t.prototype.ngOnInit = function() {
                this._elWithFocus = document.activeElement,
                this._renderer.addClass(document.body, "modal-open")
            }
            ,
            t.prototype.ngAfterViewInit = function() {
                this._elRef.nativeElement.contains(document.activeElement) || this._elRef.nativeElement.focus.apply(this._elRef.nativeElement, [])
            }
            ,
            t.prototype.ngOnDestroy = function() {
                var t, e = document.body, n = this._elWithFocus;
                t = n && n.focus && e.contains(n) ? n : e,
                t.focus.apply(t, []),
                this._elWithFocus = null,
                this._renderer.removeClass(e, "modal-open")
            }
            ,
            t
        }())
    },

Expected behavior

Without --build-optimizer, the generated code looks like this:

AVYa: function(t, e, n) {
        "use strict";
        n.d(e, "a", function() {
            return i
        });
        var r = n("/oeL")
          , o = n("zGKh")
          , i = function() {
            function t(t, e) {
                this._elRef = t,
                this._renderer = e,
                this.backdrop = !0,
                this.keyboard = !0,
                this.dismissEvent = new r.EventEmitter
            }
            return t.prototype.backdropClick = function(t) {
                !0 === this.backdrop && this._elRef.nativeElement === t.target && this.dismiss(o.a.BACKDROP_CLICK)
            }
            ,
            t.prototype.escKey = function(t) {
                this.keyboard && !t.defaultPrevented && this.dismiss(o.a.ESC)
            }
            ,
            t.prototype.dismiss = function(t) {
                this.dismissEvent.emit(t)
            }
            ,
            t.prototype.ngOnInit = function() {
                this._elWithFocus = document.activeElement,
                this._renderer.addClass(document.body, "modal-open")
            }
            ,
            t.prototype.ngAfterViewInit = function() {
                this._elRef.nativeElement.contains(document.activeElement) || this._elRef.nativeElement.focus.apply(this._elRef.nativeElement, [])
            }
            ,
            t.prototype.ngOnDestroy = function() {
                var t, e = document.body, n = this._elWithFocus;
                t = n && n.focus && e.contains(n) ? n : e,
                t.focus.apply(t, []),
                this._elWithFocus = null,
                this._renderer.removeClass(e, "modal-open")
            }
            ,
            t
        }();
        i.decorators = [{
            type: r.Component,
            args: [{
                selector: "ngb-modal-window",
                host: {
                    "[class]": '"modal fade show" + (windowClass ? " " + windowClass : "")',
                    role: "dialog",
                    tabindex: "-1",
                    style: "display: block;",
                    "(keyup.esc)": "escKey($event)",
                    "(click)": "backdropClick($event)"
                },
                template: "\n    <div [class]=\"'modal-dialog' + (size ? ' modal-' + size : '')\" role=\"document\">\n        <div class=\"modal-content\"><ng-content></ng-content></div>\n    </div>\n    "
            }]
        }],
        i.ctorParameters = function() {
            return [{
                type: r.ElementRef
            }, {
                type: r.Renderer2
            }]
        }
        ,
        i.propDecorators = {
            backdrop: [{
                type: r.Input
            }],
            keyboard: [{
                type: r.Input
            }],
            size: [{
                type: r.Input
            }],
            windowClass: [{
                type: r.Input
            }],
            dismissEvent: [{
                type: r.Output,
                args: ["dismiss"]
            }]
        }
    },

It seems that the build optimizer is responsible for the enum lookup using the original Typescript identifier instead of the generated enum function.

This could be a TS bug of course. Using Typescript 2.5.2.

Environment


Angular version: 4.3.6

Angular CLI 1.4.1
TypeScript 2.5.2
 

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