Angular-cli: `const enum` breaks when running production build/serve

Created on 7 Mar 2019  路  4Comments  路  Source: angular/angular-cli

馃悶 Bug report

Command (mark with an x)


- [ ] new
- [x] build
- [x] serve
- [ ] test
- [ ] e2e
- [ ] generate
- [ ] add
- [ ] update
- [ ] lint
- [ ] xi18n
- [ ] run
- [ ] config
- [ ] help
- [ ] version
- [ ] doc

Is this a regression?


Not sure about this. This seems to be a reappearance of #9571.

Description

For a const enum of type number, like const enum TestEnum { DESC = 2, }, usage of this kind TestEnum.DESC.toString(10) breaks on ng serve/build --prod.

馃敩 Minimal Reproduction


My global environments:
node --version // v11.10.1
npm --version // 6.9.0
npm list -g --depth=0 | grep angular // @angular/[email protected]

  1. On Desktop, run ng new prod-build-test-proj;
    1.1 ? Would you like to add Angular routing? No
    1.2 ? Which stylesheet format would you like to use? CSS (.css )
  2. cd prod-build-test-proj/;
  3. Add following code to the bottom of file src/app/app.component.ts:
const enum TestBuildProd {
  OPT1 = 1,
  OPT2 = 2,
}

console.log(TestBuildProd.OPT1.toString(10));
  1. Run npx ng build, success;
  2. Run npx ng build --prod, fail;

馃敟 Exception or Error




ERROR in ./src/app/app.component.ts 8:25
Module parse failed: Unexpected token (8:25)
You may need an appropriate loader to handle this file type.
| }());
| export { AppComponent };
> console.log(1 /* OPT1 */..toString(10));
| 

馃實 Your Environment




Angular CLI: 7.3.5
Node: 11.10.1
OS: darwin x64
Angular: 
... 

Package                      Version
------------------------------------------------------
@angular-devkit/architect    0.13.5
@angular-devkit/core         7.3.5
@angular-devkit/schematics   7.3.5
@schematics/angular          7.3.5
@schematics/update           0.13.5
rxjs                         6.3.3
typescript                   3.2.4

Anything else relevant?


If the code was appended to main.ts then everything works normally, this error only occurs when it was appended to *.service.ts or *.component.ts;

devkibuild-optimizer medium broken bufix

All 4 comments

Hi, I am sorry but this is not caused by Angular CLI, the issue here is a bug in TypeScript.

Build Optimizer use TypeScript to transform source files, and unfortunately when TypeScript encounters 1 /* OPT1 */.toString(10); it will add an addition dot.

This issue should be resolved with TypeScript 3.3.X.

Thanks for your quick reply, I just used template string as a workaround until TS 3.3 is supported.

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._

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ericel picture ericel  路  3Comments

gotschmarcel picture gotschmarcel  路  3Comments

hartjo picture hartjo  路  3Comments

rajjejosefsson picture rajjejosefsson  路  3Comments

MateenKadwaikar picture MateenKadwaikar  路  3Comments