Skip to content
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

Remove folding Array.prototype.concat (fix #577) #578

Merged
merged 2 commits into from Jun 14, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -107,9 +107,6 @@ describe("constant-folding-plugin", () => {
it("should handle Array methods on array literals", () => {
const source = unpad(
`
[1, 2, 3].concat([4, 5, 6]);
[a, b, c].concat([d, e], f, g, [h]);
[1, 2, 3]["concat"]([4, 5, 6]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might want to test this with push since you’re removing it:

[1, 2, 3]["push"]([4, 5, 6])

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done 👍

[1, 2, 3].push([4, 5, 6]);

[1, 2, 3].join();
Expand Down Expand Up @@ -142,9 +139,6 @@ describe("constant-folding-plugin", () => {
);
const expected = unpad(
`
[1, 2, 3, 4, 5, 6];
[a, b, c, d, e, f, g, h];
[1, 2, 3, 4, 5, 6];
4;

"1,2,3";
Expand Down
Expand Up @@ -32,16 +32,6 @@ module.exports = ({ types: t }) => {
}
},
calls: {
concat(...args) {
return t.arrayExpression(
this.elements.concat(
...args.map(arg => {
if (t.isArrayExpression(arg)) return arg.elements;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be possible to check if any of these are variables instead of removing this entirely? For example, [a, b, c].concat([1, 2, 3]) is safe.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it really common to use constants here in concat ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess not.

return arg;
})
)
);
},
join(sep = t.stringLiteral(",")) {
if (!t.isStringLiteral(sep)) return;
let bad = false;
Expand Down