fix(@angular-devkit/build-optimizer): don't add pure comments inside arrow functions

Fixes #13768
This commit is contained in:
Alan 2019-03-11 14:54:11 +01:00 committed by vikerman
parent 1e3c6e3ca5
commit b32ad328cf
2 changed files with 34 additions and 0 deletions

View File

@ -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);

View File

@ -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}`);
});
});