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

Commit 40cc440

Browse files
filipesilvahansl
authored andcommitted
fix(@angular-devkit/build-optimizer): don't search for pure top-level functions inside classes
Partially address #816. Supersedes #237
1 parent ae72a14 commit 40cc440

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

Diff for: packages/angular_devkit/build_optimizer/src/transforms/prefix-functions.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,11 @@ export function findTopLevelFunctions(parentNode: ts.Node): Set<ts.Node> {
5353
const topLevelFunctions = new Set<ts.Node>();
5454

5555
function cb(node: ts.Node) {
56-
// Stop recursing into this branch if it's a function expression or declaration
57-
if (ts.isFunctionDeclaration(node) || ts.isFunctionExpression(node)) {
56+
// Stop recursing into this branch if it's a function expression or declaration, or a class.
57+
if (ts.isFunctionDeclaration(node)
58+
|| ts.isFunctionExpression(node)
59+
|| ts.isClassDeclaration(node)
60+
) {
5861
return;
5962
}
6063

Diff for: packages/angular_devkit/build_optimizer/src/transforms/prefix-functions_spec.ts

+19
Original file line numberDiff line numberDiff line change
@@ -124,5 +124,24 @@ describe('prefix-functions', () => {
124124

125125
expect(tags.oneLine`${transform(input)}`).toEqual(tags.oneLine`${output}`);
126126
});
127+
128+
it('doesn\'t add comment when inside class', () => {
129+
const input = tags.stripIndent`
130+
class Foo {
131+
constructor(e) {
132+
super(e);
133+
}
134+
method() {
135+
var newClazz = new Clazz();
136+
}
137+
}
138+
`;
139+
const output = tags.stripIndent`
140+
${emptyImportsComment}
141+
${input}
142+
`;
143+
144+
expect(tags.oneLine`${transform(input)}`).toEqual(tags.oneLine`${output}`);
145+
});
127146
});
128147
});

0 commit comments

Comments
 (0)