fix(ngcc): do not add trailing commas in UMD imports (#34545)

Previously, if `UmdRenderingFormatter#addImports()` was called with an
empty list of imports to add (i.e. no new imports were needed), it would
add trailing commas in several locations (arrays, function arguments,
function parameters), thus making the code imcompatible with legacy
browsers such as IE11.

This commit fixes it by ensuring that no trailing commas are added if
`addImports()` is called with an empty list of imports.
This is a follow-up to #34353.

Fixes #34525

PR Close #34545
This commit is contained in:
George Kalpakas
2019-12-23 16:07:34 +02:00
committed by Alex Rickabaugh
parent 4f42de9704
commit 10e29355db
8 changed files with 74 additions and 1 deletions

View File

@ -125,6 +125,21 @@ assertSucceeded "Expected 'ngcc' to log 'Compiling'."
assertSucceeded "Expected '@angular/cdk/a11y' (umd) to actually have decorators via static properties."
# Did it transform imports in UMD correctly?
# (E.g. no trailing commas, so that it remains compatible with legacy browsers, such as IE11.)
grep "factory(exports, require('rxjs'), require('rxjs/operators'))" node_modules/@angular/core/bundles/core.umd.js
assertSucceeded "Expected 'ngcc' to not add trailing commas to CommonJS block in UMD."
grep "define('@angular/core', \['exports', 'rxjs', 'rxjs/operators'], factory)" node_modules/@angular/core/bundles/core.umd.js
assertSucceeded "Expected 'ngcc' to not add trailing commas to AMD block in UMD."
grep "factory((global.ng = global.ng || {}, global.ng.core = {}), global.rxjs, global.rxjs.operators)" node_modules/@angular/core/bundles/core.umd.js
assertSucceeded "Expected 'ngcc' to not add trailing commas to globals block in UMD."
grep "(this, (function (exports, rxjs, operators) {" node_modules/@angular/core/bundles/core.umd.js
assertSucceeded "Expected 'ngcc' to not add trailing commas to factory function parameters in UMD."
# Can it be safely run again (as a noop)?
# And check that it logged skipping compilation as expected
ngcc -l debug | grep 'Skipping'