Skip to content

Commit

Permalink
fix(@angular-devkit/build-optimizer): update ɵsetClassMetadata call f…
Browse files Browse the repository at this point in the history
…ormat

It's in a IIFE after angular/angular#33337 lands.
  • Loading branch information
filipesilva authored and vikerman committed Nov 20, 2019
1 parent ec563b8 commit 3e14634
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
Expand Up @@ -303,7 +303,35 @@ function isAssignmentExpressionTo(exprStmt: ts.ExpressionStatement, name: string
}

function isIvyPrivateCallExpression(exprStmt: ts.ExpressionStatement) {
const callExpr = exprStmt.expression;
// Each Ivy private call expression is inside an IIFE as single statements, so we must go down it.
const expression = exprStmt.expression;
if (!expression || !ts.isCallExpression(expression) || expression.arguments.length !== 0) {
return null;
}

const parenExpr = expression;
if (!ts.isParenthesizedExpression(parenExpr.expression)) {
return null;
}

const funExpr = parenExpr.expression.expression;
if (!ts.isFunctionExpression(funExpr)) {
return null;
}

const innerStmts = funExpr.body.statements;
if (innerStmts.length !== 1) {
return null;
}

const innerExprStmt = innerStmts[0];
if (!ts.isExpressionStatement(innerExprStmt)) {
return null;
}

// Now we're in the IIFE and have the inner expression statement. We can check if it matches
// a private Ivy call.
const callExpr = innerExprStmt.expression;
if (!ts.isCallExpression(callExpr)) {
return false;
}
Expand Down
Expand Up @@ -722,14 +722,14 @@ describe('scrub-file', () => {
`;
const input = tags.stripIndent`
${output}
/*@__PURE__*/ i0.ɵsetClassMetadata(Clazz, [{
/*@__PURE__*/ (function () { i0.ɵsetClassMetadata(Clazz, [{
type: Component,
args: [{
selector: 'app-lazy',
template: 'very lazy',
styles: []
}]
}], null, null);
}], null, null); })();
`;

expect(testScrubFile(input)).toBeTruthy();
Expand Down

0 comments on commit 3e14634

Please sign in to comment.