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.

No __PURE_ for component #211

Closed
Closed

Description

@WiseBird

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 () {

Activity

  1. filipesilva commented on Oct 17, 2017

    @filipesilva
    Contributor

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

  2. self-assigned this
    on Oct 17, 2017
  3. filipesilva commented on Oct 17, 2017

    @filipesilva
    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...

  4. clydin commented on Oct 19, 2017

    @clydin
    Member

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

  5. hansl commented on Oct 19, 2017

    @hansl
    Contributor

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

  6. filipesilva commented on Oct 24, 2017

    @filipesilva
    Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions