Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 067ae54

Browse filesBrowse files
gkalpakthePunderWoman
authored andcommitted
fix(ngcc): support alternate UMD layout when adding new imports (#43931)
In #43879, `UmdReflectionHost` was updated to deal with the new UMD format used by Rollup, where the parenthesis is around the wrapper function and not the wrapper function call. For reference, this caused failures in the `ngcc-validation` repo ([example 1][1], [example 2][2]). This commit updates `UmdRenderingFormatter` to also handle both UMD formats. In order to validate the change, this commit also updates the `UmdRenderingFormatter` tests to run against both UMD formats. [1]: https://circleci.com/gh/angular/ngcc-validation/65916 [2]: https://circleci.com/gh/angular/ngcc-validation/65758 PR Close #43931
1 parent 7817892 commit 067ae54
Copy full SHA for 067ae54

File tree

Expand file treeCollapse file tree

2 files changed

+570
-511
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+570
-511
lines changed

‎packages/compiler-cli/ngcc/src/rendering/umd_rendering_formatter.ts

Copy file name to clipboardExpand all lines: packages/compiler-cli/ngcc/src/rendering/umd_rendering_formatter.ts
+6-19Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,13 @@ export class UmdRenderingFormatter extends Esm5RenderingFormatter {
6161
return;
6262
}
6363

64-
const wrapperFunction = umdModule.wrapperFn;
64+
const {wrapperFn, factoryFn} = umdModule;
6565

6666
// We need to add new `require()` calls for each import in the CommonJS initializer
67-
renderCommonJsDependencies(output, wrapperFunction, imports);
68-
renderAmdDependencies(output, wrapperFunction, imports);
69-
renderGlobalDependencies(output, wrapperFunction, imports);
70-
renderFactoryParameters(output, wrapperFunction, imports);
67+
renderCommonJsDependencies(output, wrapperFn, imports);
68+
renderAmdDependencies(output, wrapperFn, imports);
69+
renderGlobalDependencies(output, wrapperFn, imports);
70+
renderFactoryParameters(output, factoryFn, imports);
7171
}
7272

7373
/**
@@ -210,20 +210,7 @@ function renderGlobalDependencies(
210210
* Add dependency parameters to the UMD factory function.
211211
*/
212212
function renderFactoryParameters(
213-
output: MagicString, wrapperFunction: ts.FunctionExpression, imports: Import[]) {
214-
const wrapperCall = wrapperFunction.parent as ts.CallExpression;
215-
const secondArgument = wrapperCall.arguments[1];
216-
if (!secondArgument) {
217-
return;
218-
}
219-
220-
// Be resilient to the factory being inside parentheses
221-
const factoryFunction =
222-
ts.isParenthesizedExpression(secondArgument) ? secondArgument.expression : secondArgument;
223-
if (!ts.isFunctionExpression(factoryFunction)) {
224-
return;
225-
}
226-
213+
output: MagicString, factoryFunction: ts.FunctionExpression, imports: Import[]) {
227214
const parameters = factoryFunction.parameters;
228215
const parameterString = imports.map(i => i.qualifier.text).join(',');
229216
if (parameters.length > 0) {

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.