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

No need for parens for new expressions without args #3111

Merged
merged 4 commits into from
Dec 5, 2015
Merged

Conversation

amasad
Copy link
Member

@amasad amasad commented Nov 25, 2015

No description provided.

@codecov-io
Copy link

Current coverage is 89.11%

Merging #3111 into master will decrease coverage by -0.04% as of 752a77e

@@            master   #3111   diff @@
======================================
  Files          214     214       
  Stmts        15472   15473     +1
  Branches         0       0       
  Methods          0       0       
======================================
- Hit          13794   13788     -6
  Partial          0       0       
- Missed        1678    1685     +7

Review entire Coverage Diff as of 752a77e

Powered by Codecov. Updated on successful CI builds.

@hzoo
Copy link
Member

hzoo commented Nov 30, 2015

I would not of found those other edge cases - I wonder if there could be a tool that searches through codebases prints out the different types of AST to look for these. I guess you can also try to generate code from the spec but I would have even less idea about that?

@amasad
Copy link
Member Author

amasad commented Nov 30, 2015

One thing to do is to check how existing tools do this. I went through uglify's code and it seems like we're handling everything they're handling.

@hzoo
Copy link
Member

hzoo commented Nov 30, 2015

Ah yeah I guess that works as a baseline - unless they are messing up something as well.

I remember sebmck mentioning everything.js in an old issue (found it: https://phabricator.babeljs.io/T2191) which has some other forms - https://github.com/michaelficarra/everything.js/blob/9bdd8a0a9fd571ecca612d53d417890e5a9409d4/es5.js#L77-L80

@amasad
Copy link
Member Author

amasad commented Nov 30, 2015

Ah that's useful. I can do some more testing using that

@hzoo
Copy link
Member

hzoo commented Nov 30, 2015

Yeah don't need all of those but with

new X();
new Y()();
new F().z;

new x();
new new x()();
new x[0]();
new x.a();
new x[0].a();
new x.a[0]();

new x;
new new x;
new new x();
new new x().a;
new new x()[0];

I get

new X;new Y()();new F().z;
new x;new new x;new x[0];new x.a;new x[0].a;new x.a[0];
new x;new new x;new new x;new new x().a;new new x()[0];

@amasad
Copy link
Member Author

amasad commented Nov 30, 2015

looks correct?

@hzoo
Copy link
Member

hzoo commented Nov 30, 2015

Yeah looks good

@phantom10111
Copy link
Contributor

@amasad Some test cases that produce incorrect results:

new new x()(a);
new new x()()();
new new x()(a)();
new new x()()(a);
new new x()(a)(a);

Produces

new new x(a);new new x()();new new x(a)();new new x()(a);new new x(a)(a);

All those have empty parens first so it's possible they are all the same edge case.

@hzoo
Copy link
Member

hzoo commented Dec 5, 2015

Ok && !(t.isNewExpression(parent) && parent.arguments.length > 0) seems to fix it

@hzoo
Copy link
Member

hzoo commented Dec 5, 2015

new new x()();
new new x()(a);
new new x(a)();
new new x(a)(a);

new new x;new new x()(a);new new x(a);new new x(a)(a);

hzoo added a commit that referenced this pull request Dec 5, 2015
No need for parens for new expressions without args
@hzoo hzoo merged commit 8a1ad53 into babel:master Dec 5, 2015
@hzoo
Copy link
Member

hzoo commented Dec 5, 2015

Added the other commit in 21f7665

@hzoo
Copy link
Member

hzoo commented Dec 5, 2015

Actually I'm not sure how we would do this for multiple calls of new (my patch only works for new new but not new new new). I don't think we have a reference to the parent of the parent in this module - it's only export function NewExpression(node: Object, parent: Object) {.

Who would do even new new anyway?

Maybe it would be better to just not do anything for multiple nested NewExpression.

@hzoo
Copy link
Member

hzoo commented Dec 5, 2015

Talked with @amasad - just going to return if the parent of the NewExpression is a NewExpression

@lock lock bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Oct 8, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Oct 8, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated A closed issue/PR that is archived due to age. Recommended to make a new issue
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants