Skip to content

Commit abec0eb

Browse files
filipesilvavikerman
authored andcommitted
fix(@angular-devkit/build-optimizer): update ɵsetClassMetadata call format
It's in a IIFE after angular/angular#33337 lands.
1 parent 77b3981 commit abec0eb

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed

packages/angular_devkit/build_optimizer/src/transforms/scrub-file.ts

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,35 @@ function isAssignmentExpressionTo(exprStmt: ts.ExpressionStatement, name: string
303303
}
304304

305305
function isIvyPrivateCallExpression(exprStmt: ts.ExpressionStatement) {
306-
const callExpr = exprStmt.expression;
306+
// Each Ivy private call expression is inside an IIFE as single statements, so we must go down it.
307+
const expression = exprStmt.expression;
308+
if (!expression || !ts.isCallExpression(expression) || expression.arguments.length !== 0) {
309+
return null;
310+
}
311+
312+
const parenExpr = expression;
313+
if (!ts.isParenthesizedExpression(parenExpr.expression)) {
314+
return null;
315+
}
316+
317+
const funExpr = parenExpr.expression.expression;
318+
if (!ts.isFunctionExpression(funExpr)) {
319+
return null;
320+
}
321+
322+
const innerStmts = funExpr.body.statements;
323+
if (innerStmts.length !== 1) {
324+
return null;
325+
}
326+
327+
const innerExprStmt = innerStmts[0];
328+
if (!ts.isExpressionStatement(innerExprStmt)) {
329+
return null;
330+
}
331+
332+
// Now we're in the IIFE and have the inner expression statement. We can check if it matches
333+
// a private Ivy call.
334+
const callExpr = innerExprStmt.expression;
307335
if (!ts.isCallExpression(callExpr)) {
308336
return false;
309337
}

packages/angular_devkit/build_optimizer/src/transforms/scrub-file_spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -722,14 +722,14 @@ describe('scrub-file', () => {
722722
`;
723723
const input = tags.stripIndent`
724724
${output}
725-
/*@__PURE__*/ i0.ɵsetClassMetadata(Clazz, [{
725+
/*@__PURE__*/ (function () { i0.ɵsetClassMetadata(Clazz, [{
726726
type: Component,
727727
args: [{
728728
selector: 'app-lazy',
729729
template: 'very lazy',
730730
styles: []
731731
}]
732-
}], null, null);
732+
}], null, null); })();
733733
`;
734734

735735
expect(testScrubFile(input)).toBeTruthy();

0 commit comments

Comments
 (0)