Bug in build-optimizer or uglify-es (AOT output bug)
See original GitHub issueAs per @trotyl on https://github.com/angular/angular/issues/25800 I post this here:
Bug Report or Feature Request (mark with an x
)
- [ X] bug report -> please search issues before submitting
- [ ] feature request
Command (mark with an x
)
- [ ] new
- [ X] build
- [ ] serve
- [ ] test
- [ ] e2e
- [ ] generate
- [ ] add
- [ ] update
- [ ] lint
- [ ] xi18n
- [ ] run
- [ ] config
- [ ] help
- [ ] version
- [ ] doc
Versions
Angular CLI: 6.0.8 Node: 10.4.0 OS: darwin x64 Angular: 6.1.6
Repro steps
Current behavior
The following Typescript code:
let table1 = [null, "hello"];
let table2 = [null, "world"];
let i = -1;
for (const row of table1) {
i++;
if (!row) {
continue;
}
console.log(row, table2[i])
}
when compiled with AOT in an Angular project (ng build --prod --build-optimizer --vendor-chunk=true --aot
), produces the following “compiled” code:
for (var l = [null, "world"], n = -1, u = 0, a = [null, "hello"]; u < a.length; u++) {
var o = a[u];
o && console.log(o, l[++n])
}
The compiled code checks for null first before it increments i
, the written Typescript codes increments i
before the null check.
When run in a browser the AOT code prints hello null
Expected behavior
The AOT compiled code in a browser should print hello world
Minimal reproduction of the problem with instructions
Copy above Typescript snipped into a newly created Angular project and build it with AOT.
What is the motivation / use case for changing the behavior?
We expect AOT compiled code to do exactly what the code intends to do
Issue Analytics
- State:
- Created 5 years ago
- Comments:8 (2 by maintainers)
Top Results From Across the Web
angular/angular-cli - Gitter
I think I found a bug in the NamedLazyChunksPlugin in Angular CLI ... production --aot=true --build-optimizer=true --output-hashing=none --named-chunks=true.
Read more >"Unexpected token: punc ())" when building for production
Refactoring the .js file's code to ES5 fixed the problem. I used ng build --prod --aot to check if the error was gone....
Read more >CHANGELOG.md
`uglifyjs` was replaced with the newer `uglifyes`, which supports ES2015. ### Bug Fixes * **aot:** normalize paths to fix path issues on windows ......
Read more >node_modules/@ionic/app-scripts/CHANGELOG.md ... - GitLab
Bug Fixes. AoT: properly check for ngmodule declaration errors from the AoT build (a47f120); template: fix bug with using dollar sign within templates ......
Read more >Angular CLI - Tutorial - Vskills
Install a previous version, maybe because of a bug in the latest version. For example to get 7.0.2: ... The syntax is: –aot;...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I guess this is the same problem with pure_getters: true that is already discussed in issue 11439
Thank you for re-opening the issue.
These type of changes are very dangerous for your users; We have more than 100k lines of code since Angular 2. We don’t see these type of issues in tests as the they only appear in the AOT compilation. We have to “read” the code to find out where else this problem might occur.
On Tue, Sep 4, 2018, 19:04 Alan Agius notifications@github.com wrote: