Skip to content

Add block if parent is non-block statement for remove-console/debugger#3583

Merged
loganfsmyth merged 2 commits intobabel:masterfrom
jhen0409:patch-3
Jul 19, 2016
Merged

Add block if parent is non-block statement for remove-console/debugger#3583
loganfsmyth merged 2 commits intobabel:masterfrom
jhen0409:patch-3

Conversation

@jhen0409
Copy link
Copy Markdown
Contributor

@jhen0409 jhen0409 commented Jul 17, 2016

This PR is re-work for #3453. Fixes the error if we use no block statement (e.g. if (blah) console.log(blah)) :

Property consequent of IfStatement expected node to be of a type ["Statement"] but instead got null

Transform

if (blah) console.log(blah);
for (;;) console.log(blah);
while (blah) console.log(blah);

to

if (blah) {}
for (;;) {}
while (blah) {}

@jhen0409 jhen0409 force-pushed the patch-3 branch 2 times, most recently from 8447699 to a57d2d4 Compare July 17, 2016 19:18
@codecov-io
Copy link
Copy Markdown

codecov-io commented Jul 17, 2016

Current coverage is 87.70%

Merging #3583 into master will increase coverage by 0.15%

@@             master      #3583   diff @@
==========================================
  Files           193        194     +1   
  Lines          9285       9430   +145   
  Methods        1048       1069    +21   
  Messages          0          0          
  Branches       2100       2154    +54   
==========================================
+ Hits           8129       8271   +142   
- Misses         1156       1159     +3   
  Partials          0          0          

Powered by Codecov. Last updated by ab47b43...6cb3e5e

visitor: {
CallExpression(path) {
if (path.get("callee").matchesPattern("console", true)) {
const statementPath = path.parentPath.parentPath;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Does path.parentPath always exist? I assume even when the script is just debugger, the parent would be program or file. I just want to make sure that we never get "can't get property parentPath on undefined"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@danez It looks path.parentPath.parentPath gets problem in top-level case for remove-console, and I just used path.parentPath for remove-debugger.

Anyway, @loganfsmyth's recommend will be better, I'll change it. :)

@jhen0409 jhen0409 force-pushed the patch-3 branch 5 times, most recently from 15a007e to 6574722 Compare July 18, 2016 00:46
@@ -0,0 +1,3 @@
if (blah) console.log(blah);
for (;;) console.log(blah);
while (blah) console.log(blah);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

do arrow functions work?

var a = (blah) => console.log(blah);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It looks done in this step of removal-hooks, it will transform to var a = (blah) => void 0;, should we add the case to expression fixture?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ah I see, no I think this is fine now.

@danez
Copy link
Copy Markdown
Member

danez commented Jul 18, 2016

👍

@danez danez added the PR: Bug Fix 🐛 A type of pull request used for our changelog categories label Jul 18, 2016
@danez danez added this to the Next Patch milestone Jul 18, 2016

function (self, parent) {
if (
(self.key === 'consequent' || self.key === 'alternate') && parent.isIfStatement() ||
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Seems like we should check the parent type first to be consistent with the rest of these, and to help readability. I'd also be in favor of adding more parens around these && vs || groups since I never remember their precedence.

@loganfsmyth loganfsmyth merged commit 40ec299 into babel:master Jul 19, 2016
@loganfsmyth
Copy link
Copy Markdown
Member

Thanks!

@danez danez modified the milestone: Next Patch Jul 20, 2016
@lock lock bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Oct 7, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Oct 7, 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 PR: Bug Fix 🐛 A type of pull request used for our changelog categories

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants