mirror of
https://github.com/angular/angular-cli.git
synced 2025-05-14 17:43:52 +08:00
fix(@angular-devkit/build-optimizer): don't add pure comments inside arrow functions
Fixes #13768
This commit is contained in:
parent
1e3c6e3ca5
commit
b32ad328cf
@ -64,6 +64,14 @@ export function findTopLevelFunctions(parentNode: ts.Node): Set<ts.Node> {
|
||||
return;
|
||||
}
|
||||
|
||||
if ((ts.isFunctionExpression(innerNode) || ts.isArrowFunction(innerNode))
|
||||
&& ts.isParenthesizedExpression(node)) {
|
||||
// pure functions can be wrapped in parentizes
|
||||
// we should not add pure comments to this sort of syntax.
|
||||
// example var foo = (() => x)
|
||||
return;
|
||||
}
|
||||
|
||||
if (noPureComment) {
|
||||
if (ts.isNewExpression(innerNode)) {
|
||||
topLevelFunctions.add(node);
|
||||
|
@ -141,4 +141,30 @@ describe('prefix-functions', () => {
|
||||
expect(tags.oneLine`${transform(input)}`).toEqual(tags.oneLine`${output}`);
|
||||
});
|
||||
});
|
||||
|
||||
it('doesn\'t add comment to downlevel arrow function', () => {
|
||||
const input = tags.stripIndent`
|
||||
var populate = (function (props, rawData, entity) {
|
||||
props.forEach(function (prop) { });
|
||||
});
|
||||
`;
|
||||
const output = tags.stripIndent`
|
||||
${input}
|
||||
`;
|
||||
|
||||
expect(tags.oneLine`${transform(input)}`).toEqual(tags.oneLine`${output}`);
|
||||
});
|
||||
|
||||
it('doesn\'t add comment inside arrow function', () => {
|
||||
const input = tags.stripIndent`
|
||||
const populate = ((props, rawData, entity) => {
|
||||
props.forEach(x => x);
|
||||
});
|
||||
`;
|
||||
const output = tags.stripIndent`
|
||||
${input}
|
||||
`;
|
||||
|
||||
expect(tags.oneLine`${transform(input)}`).toEqual(tags.oneLine`${output}`);
|
||||
});
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user