Skip to content
This repository has been archived by the owner on Apr 9, 2022. It is now read-only.

Commit

Permalink
fix(@angular-devkit/build-optimizer): don't search for pure top-level…
Browse files Browse the repository at this point in the history
… functions inside classes

Partially address #816.

Supersedes #237
  • Loading branch information
filipesilva authored and hansl committed May 30, 2018
1 parent ae72a14 commit 40cc440
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,11 @@ export function findTopLevelFunctions(parentNode: ts.Node): Set<ts.Node> {
const topLevelFunctions = new Set<ts.Node>();

function cb(node: ts.Node) {
// Stop recursing into this branch if it's a function expression or declaration
if (ts.isFunctionDeclaration(node) || ts.isFunctionExpression(node)) {
// Stop recursing into this branch if it's a function expression or declaration, or a class.
if (ts.isFunctionDeclaration(node)
|| ts.isFunctionExpression(node)
|| ts.isClassDeclaration(node)
) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,5 +124,24 @@ describe('prefix-functions', () => {

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

it('doesn\'t add comment when inside class', () => {
const input = tags.stripIndent`
class Foo {
constructor(e) {
super(e);
}
method() {
var newClazz = new Clazz();
}
}
`;
const output = tags.stripIndent`
${emptyImportsComment}
${input}
`;

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

0 comments on commit 40cc440

Please sign in to comment.