Skip to content
This repository has been archived by the owner on Apr 9, 2022. It is now read-only.

No __PURE_ for component #211

Closed
WiseBird opened this issue Oct 17, 2017 · 5 comments
Closed

No __PURE_ for component #211

WiseBird opened this issue Oct 17, 2017 · 5 comments

Comments

@WiseBird
Copy link

Bug Report or Feature Request (mark with an x)

- [x] bug report -> please search issues before submitting
- [ ] feature request

Area

- [x] devkit
- [ ] schematics

Versions

node - v7.6.0
npm - 4.1.2
ts - 2.5.3
angular - 4.4.5
devkit - 0.0.27

Repro steps

I have a loader that uses build optimizer:

const BuildOptimizer = require('@angular-devkit/build-optimizer').buildOptimizer;

module.exports = function (source) {
    let result = BuildOptimizer({
        content: source,
        emitSourceMap: true,
    });

    return result.content || source;
};

and a simple component:

import {Component} from '@angular/core';

enum Modes { Option1, Option2 }

@Component({
               selector: 'app-root',
               templateUrl: './app.component.html',
           })
export class AppComponent  {
    title = 'app component!';
    mode: Modes;
}

When built it result in

var __decorate = /*@__PURE__*/ __webpack_require__(0).__decorate;
Object.defineProperty(exports, "__esModule", { value: true });
var core_1 = __webpack_require__(2);
var Modes = /*@__PURE__*/ (function () {
    var Modes = {};
    Modes[Modes["Option1"] = 0] = "Option1";
    Modes[Modes["Option2"] = 1] = "Option2";
    return Modes;
})();
var AppComponent = (function () {
    function AppComponent() {
        this.title = 'app component!';
    }
    AppComponent = __decorate([
        core_1.Component({
            selector: 'app-root',
            template: __webpack_require__(47),
        })
    ], AppComponent);
    return AppComponent;
}());
exports.AppComponent = AppComponent;

Repo: https://github.com/WiseBird/ng_devkit_test

Desired functionality

If I understand correctly comopnent class should also be marked as pure: var AppComponent = /*@__PURE__*/ (function () {

@filipesilva
Copy link
Contributor

It should, yes. Thank you for the report and repro. Will investigate.

@filipesilva
Copy link
Contributor

Ok I know what's going on. The transform that adds that pure comment is prefix-functions.

But we only apply it to libraries we know are safe: https://github.com/angular/devkit/blob/master/packages/angular_devkit/build_optimizer/src/build-optimizer/build-optimizer.ts#L80-L92

So your user code does not get it. Perhaps we should have a flag to force it...

@clydin
Copy link
Member

clydin commented Oct 19, 2017

Something else to note is that the annotation is only relevant if the component is never used within the application.

@hansl
Copy link
Contributor

hansl commented Oct 19, 2017

@clydin @filipesilva Was this fixed by my fix from yesterday?

@filipesilva
Copy link
Contributor

@hansl no, this is different. It needs a forced flag. I'm putting up a PR for it soon.

@hansl hansl closed this as completed in f34b43a Oct 24, 2017
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants