Skip to content
This repository was archived by the owner on Apr 4, 2025. It is now read-only.

Commit 69225e5

Browse files
committed
fix(@angular-devkit/build-optimizer): don't add pure to super calls
Fix angular/angular-cli#7799
1 parent 6168620 commit 69225e5

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

packages/angular_devkit/build_optimizer/src/transforms/prefix-functions.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ export function findTopLevelFunctions(parentNode: ts.Node): ts.Node[] {
7070
topLevelFunctions.push(node.parent);
7171
} else if ((node.kind === ts.SyntaxKind.CallExpression
7272
|| node.kind === ts.SyntaxKind.NewExpression)
73+
&& !isSuperCall(node)
7374
&& !hasPureComment(node)
7475
) {
7576
topLevelFunctions.push(node);
@@ -117,3 +118,9 @@ function hasPureComment(node: ts.Node) {
117118

118119
return leadingComment && leadingComment.some((comment) => comment.text === pureFunctionComment);
119120
}
121+
122+
function isSuperCall(node: ts.Node) {
123+
const callExpr = node as ts.CallExpression;
124+
125+
return callExpr.expression && callExpr.expression.kind === ts.SyntaxKind.SuperKeyword;
126+
}

packages/angular_devkit/build_optimizer/src/transforms/prefix-functions_spec.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ describe('prefix-functions', () => {
8383
expect(oneLine`${transform(input)}`).toEqual(oneLine`${output}`);
8484
});
8585

86-
it('doesn\'t adds comment when inside function declarations or expressions', () => {
86+
it('doesn\'t add comment when inside function declarations or expressions', () => {
8787
const input = stripIndent`
8888
function funcDecl() {
8989
var newClazz = Clazz();
@@ -102,5 +102,21 @@ describe('prefix-functions', () => {
102102

103103
expect(oneLine`${transform(input)}`).toEqual(oneLine`${output}`);
104104
});
105+
106+
it('doesn\'t add comment to super calls', () => {
107+
const input = oneLine`
108+
class ExtendedClass extends BaseClass {
109+
constructor(e) {
110+
super(e);
111+
}
112+
}
113+
`;
114+
const output = stripIndent`
115+
${emptyImportsComment}
116+
${input}
117+
`;
118+
119+
expect(oneLine`${transform(input)}`).toEqual(oneLine`${output}`);
120+
});
105121
});
106122
});

0 commit comments

Comments
 (0)