Skip to content

fix(@angular-devkit/build-optimizer): don't add pure comments inside … #13871

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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}`);
});
});