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: enums are not being wrapped any more #229

Closed

Description

@IgorMinar

Bug Report or Feature Request (mark with an x)

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

Area

- [x] devkit
- [ ] schematics

Versions

Repro steps

original TS:

export enum FormatWidth {
  Short,
  Medium,
  Long,
  Full
}

downleveled to js via tsickle:

/** @enum {number} */
const FormatWidth = {
    Short: 0,
    Medium: 1,
    Long: 2,
    Full: 3,
};
FormatWidth[FormatWidth.Short] = "Short";
FormatWidth[FormatWidth.Medium] = "Medium";
FormatWidth[FormatWidth.Long] = "Long";
FormatWidth[FormatWidth.Full] = "Full";

after build optimizer:

        /** @enum {number} */
        var FormatWidth = {
            Short: 0,
            Medium: 1,
            Long: 2,
            Full: 3
        };
        FormatWidth[FormatWidth.Short] = "Short";
        FormatWidth[FormatWidth.Medium] = "Medium";
        FormatWidth[FormatWidth.Long] = "Long";
        FormatWidth[FormatWidth.Full] = "Full";

Desired functionality

The enum should have been rewritten into:

var FormatWidth = /*@__PURE__*/ (function () {
        /** @enum {number} */
        var FormatWidth = {
            Short: 0,
            Medium: 1,
            Long: 2,
            Full: 3
        };
        FormatWidth[FormatWidth.Short] = "Short";
        FormatWidth[FormatWidth.Medium] = "Medium";
        FormatWidth[FormatWidth.Long] = "Long";
        FormatWidth[FormatWidth.Full] = "Full";
        return FormatWidth;
());

Mention any other details that might be useful

Angular CLI: 1.5.0-rc.2
Node: 6.9.5
OS: darwin x64
Angular: 5.0.0-rc.2
... animations, common, compiler, compiler-cli, core, forms
... http, platform-browser, platform-browser-dynamic
... platform-server, router

@angular/cdk: 2.0.0-beta.12
@angular/cli: 1.5.0-rc.2
@angular/material: 2.0.0-beta.12
@angular/service-worker: 1.0.0-beta.16
@angular-devkit/build-optimizer: 0.0.29
@angular-devkit/core: 0.0.20
@angular-devkit/schematics: 0.0.34
@ngtools/json-schema: 1.1.0
@schematics/angular: 0.0.48
typescript: 2.4.2
webpack: 3.7.1

Activity

  1. filipesilva commented on Oct 22, 2017

    @filipesilva
    Contributor

    This seems to be a new format for enums that we don't detect yet (we only detect 2.2 and 2.3 enums). Will have to add support for this format as well.

  2. self-assigned this
    on Oct 22, 2017
  3. IgorMinar commented on Oct 22, 2017

    @IgorMinar
    ContributorAuthor

    I believe that this downleveling format comes from tsickle. as far as I can tell typescript doesn't downlevel stuff in this way. but since all of our packages are downleveled with tsickle, we need to support this format as well.

  4. clydin commented on Oct 23, 2017

    @clydin
    Member

    In addition to the build optimizer change, would it make sense for tsickle to perform the IIFE wrapping during its enum downlevel processing? The enum is already being rewritten. Ideally TS could do the same and the build optimizer step could be simplified moving forward. However, would doing this break closure's handling of the enum? Also for safety, the PURE annotation should probably not be automatically added (unless all values are constants) as there are rare situations were an enum member initializer could have side effects.

  5. added a commit that references this issue on Oct 23, 2017
    18190d9
  6. IgorMinar commented on Oct 23, 2017

    @IgorMinar
    ContributorAuthor
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