fix(ngcc): handle UMD re-exports (#34254)

In TS we can re-export imports using statements of the form:

```
export * from 'some-import';
```

This is downleveled in UMD to:

```
function factory(exports, someImport) {
  function __export(m) {
    for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
  }
  __export(someImport);
}
```

This commit adds support for this.

PR Close #34254
This commit is contained in:
Pete Bacon Darwin
2019-12-18 14:03:05 +00:00
committed by Kara Erickson
parent 9ca5faab47
commit 84a7d8a4e4
4 changed files with 129 additions and 27 deletions

View File

@ -11,7 +11,7 @@ import {absoluteFrom} from '../../../src/ngtsc/file_system';
import {Declaration, Import} from '../../../src/ngtsc/reflection';
import {Logger} from '../logging/logger';
import {BundleProgram} from '../packages/bundle_program';
import {isDefined} from '../utils';
import {isDefined, stripExtension} from '../utils';
import {Esm5ReflectionHost} from './esm5_host';
import {NgccClassSymbol} from './ngcc_host';
@ -152,12 +152,12 @@ export class CommonJsReflectionHost extends Esm5ReflectionHost {
return [];
}
const viaModule = stripExtension(importedFile.fileName);
const importedExports = this.getExportsOfModule(importedFile);
if (importedExports === null) {
return [];
}
const viaModule = stripExtension(importedFile.fileName);
const reexports: CommonJsExportDeclaration[] = [];
importedExports.forEach((decl, name) => {
if (decl.node !== null) {
@ -259,10 +259,6 @@ function isReexportStatement(statement: ts.Statement): statement is ReexportStat
statement.expression.arguments.length === 1;
}
function stripExtension(fileName: string): string {
return fileName.replace(/\..+$/, '');
}
function getOrDefault<K, V>(map: Map<K, V>, key: K, factory: (key: K) => V): V {
if (!map.has(key)) {
map.set(key, factory(key));