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

fix(@angular-devkit/build-optimizer): don't add pure to super calls #168

Merged
merged 1 commit into from
Sep 26, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ export function findTopLevelFunctions(parentNode: ts.Node): ts.Node[] {
topLevelFunctions.push(node.parent);
} else if ((node.kind === ts.SyntaxKind.CallExpression
|| node.kind === ts.SyntaxKind.NewExpression)
&& !isSuperCall(node)
&& !hasPureComment(node)
) {
topLevelFunctions.push(node);
Expand Down Expand Up @@ -117,3 +118,9 @@ function hasPureComment(node: ts.Node) {

return leadingComment && leadingComment.some((comment) => comment.text === pureFunctionComment);
}

function isSuperCall(node: ts.Node) {
const callExpr = node as ts.CallExpression;

return callExpr.expression && callExpr.expression.kind === ts.SyntaxKind.SuperKeyword;
}
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ describe('prefix-functions', () => {
expect(oneLine`${transform(input)}`).toEqual(oneLine`${output}`);
});

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

expect(oneLine`${transform(input)}`).toEqual(oneLine`${output}`);
});

it('doesn\'t add comment to super calls', () => {
const input = oneLine`
class ExtendedClass extends BaseClass {
constructor(e) {
super(e);
}
}
`;
const output = stripIndent`
${emptyImportsComment}
${input}
`;

expect(oneLine`${transform(input)}`).toEqual(oneLine`${output}`);
});
});
});