Skip to content

Commit

Permalink
fix(@angular-devkit/build-optimizer): don't add pure comments inside …
Browse files Browse the repository at this point in the history
…arrow functions

Fixes #13768
  • Loading branch information
Alan authored and vikerman committed Mar 11, 2019
1 parent 44085ec commit 9ad9c9d
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
Expand Up @@ -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);
Expand Down
Expand Up @@ -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}`);
});
});

0 comments on commit 9ad9c9d

Please sign in to comment.