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

Fix collapse with circular reference #523

Merged
merged 2 commits into from
May 8, 2017
Merged

Conversation

jhen0409
Copy link
Contributor

@jhen0409 jhen0409 commented May 5, 2017

This PR fix the bug for:

var foo = {};
foo.bar = foo;

var foo2 = [];
foo2[2] = foo2;

var foo3 = new Set([])
foo3.add(foo3)

Will convert to:

var foo = {bar:foo};

var foo2 = [,,foo2];

var foo3 = new Set([foo3])

It will get undefined for var, a ReferenceError for let and const.

I catched the problem with prop-types module.

@codecov
Copy link

codecov bot commented May 5, 2017

Codecov Report

Merging #523 into master will increase coverage by 0.19%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #523      +/-   ##
==========================================
+ Coverage   83.06%   83.26%   +0.19%     
==========================================
  Files          34       34              
  Lines        2539     2539              
  Branches      907      908       +1     
==========================================
+ Hits         2109     2114       +5     
+ Misses        257      254       -3     
+ Partials      173      171       -2
Impacted Files Coverage Δ
...gin-transform-inline-consecutive-adds/src/index.js 79.79% <100%> (ø) ⬆️
...sform-inline-consecutive-adds/src/set-collapser.js 83.78% <100%> (+5.4%) ⬆️
packages/babel-plugin-minify-simplify/src/index.js 80.74% <0%> (+0.12%) ⬆️
...e-consecutive-adds/src/array-property-collapser.js 82.6% <0%> (+4.34%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9a5bf2a...201a8a8. Read the comment docs.

@boopathi boopathi added the Tag: Bug Fix Pull Request fixes a bug label May 6, 2017
obj.isIdentifier() &&
right.isIdentifier() &&
obj.node.name === right.node.name
) {
Copy link
Member

Choose a reason for hiding this comment

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

Good catch. But, this check should go into the checkReference call which is used above so it applies the fix for all collapsers.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right! I'll do it to checkReference.

@jhen0409 jhen0409 changed the title Fix collapse computed properties with circular reference Fix collapse with circular reference May 6, 2017
@@ -44,7 +44,7 @@ class SetCollapser extends Collapser {
if (args.length !== 1) {
return false;
}
if (checkReference(args)) {
if (checkReference(args[0])) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

It should not expect an array (as Line 44), so I change to args[0] made Set works with this PR.

@@ -142,7 +142,7 @@ function getContiguousStatementsAndExpressions(

function getReferenceChecker(references) {
// returns a function s.t. given an expr, returns true iff expr is an ancestor of a reference
return expr => references.some(r => r.isDescendant(expr));
return expr => references.some(r => r.isDescendant(expr) || r === expr);
Copy link
Member

Choose a reason for hiding this comment

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

Isn't it better to place r === expr first for early exit ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Tag: Bug Fix Pull Request fixes a bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants