Skip to content

Commit 9ad9c9d

Browse files
Alanvikerman
Alan
authored and
vikerman
committed
fix(@angular-devkit/build-optimizer): don't add pure comments inside arrow functions
Fixes #13768
1 parent 44085ec commit 9ad9c9d

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

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

+8
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,14 @@ export function findTopLevelFunctions(parentNode: ts.Node): Set<ts.Node> {
6464
return;
6565
}
6666

67+
if ((ts.isFunctionExpression(innerNode) || ts.isArrowFunction(innerNode))
68+
&& ts.isParenthesizedExpression(node)) {
69+
// pure functions can be wrapped in parentizes
70+
// we should not add pure comments to this sort of syntax.
71+
// example var foo = (() => x)
72+
return;
73+
}
74+
6775
if (noPureComment) {
6876
if (ts.isNewExpression(innerNode)) {
6977
topLevelFunctions.add(node);

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

+26
Original file line numberDiff line numberDiff line change
@@ -141,4 +141,30 @@ describe('prefix-functions', () => {
141141
expect(tags.oneLine`${transform(input)}`).toEqual(tags.oneLine`${output}`);
142142
});
143143
});
144+
145+
it('doesn\'t add comment to downlevel arrow function', () => {
146+
const input = tags.stripIndent`
147+
var populate = (function (props, rawData, entity) {
148+
props.forEach(function (prop) { });
149+
});
150+
`;
151+
const output = tags.stripIndent`
152+
${input}
153+
`;
154+
155+
expect(tags.oneLine`${transform(input)}`).toEqual(tags.oneLine`${output}`);
156+
});
157+
158+
it('doesn\'t add comment inside arrow function', () => {
159+
const input = tags.stripIndent`
160+
const populate = ((props, rawData, entity) => {
161+
props.forEach(x => x);
162+
});
163+
`;
164+
const output = tags.stripIndent`
165+
${input}
166+
`;
167+
168+
expect(tags.oneLine`${transform(input)}`).toEqual(tags.oneLine`${output}`);
169+
});
144170
});

0 commit comments

Comments
 (0)