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 renameTo not taking property shorthands into account #211

Merged
merged 4 commits into from Mar 7, 2018

Conversation

vitorbal
Copy link
Contributor

This fixes the renameTo helper method not properly renaming object properties that are shorthands.

Bug reproduction in AST Explorer: http://astexplorer.net/#/gist/0ad1434f08e1720089d7085fbdfe7ba0/6f6632f0bb6e2e3aa77d5e873d0ab05d6c3be0e3

The previous version of the code would rename the property's value correctly, but since shorthand was still set as true, the output result would still be the old variable as a shorthand
property.

Now, if an identifier to be renamed is of type Property and is a shorthand (but not a method), we flip the shorthand value to be false.

Added a test for this as well.

This fixes the `renameTo` helper method not properly renaming
object properties that are shorthands.

The previous version of the code would rename the property's
`value` correctly, but since `shorthand` was still set as `true`,
the output result would still be the old variable as a shorthand
property.

Now, if an identifier to be renamed is of type `Property` and
is a shorthand (but not a method), we flip the `shorthand` value
to be `false`.
@vitorbal
Copy link
Contributor Author

Hmm that failure looks unrelated to my changes 🤔

 FAIL  src/__tests__/Worker-test.js (17.716s)
  ● Worker API › custom parser › uses babylon if configured as such
    Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.
      
      at Timeout.callback [as _onTimeout] (node_modules/jsdom/lib/jsdom/browser/Window.js:523:19)
      at ontimeout (timers.js:488:11)
      at tryOnTimeout (timers.js:323:5)
      at Timer.listOnTimeout (timers.js:283:5)

@baopham
Copy link
Contributor

baopham commented Aug 19, 2017

🤔 what if I want to rename it like this though:

// Outputs:
var newFoo = 42;
var obj2 = {
  newFoo,
};

instead of:

// Outputs:
var newFoo = 42;
var obj2 = {
  foo: newFoo,
};

@vitorbal
Copy link
Contributor Author

@baopham I think that would be out of scope for this bug fix since you'd have to find all the places in the code that depend on obj2.foo.

@baopham
Copy link
Contributor

baopham commented Aug 21, 2017

Yeah, agree that it's out of scope.

@fkling fkling merged commit 99aaae5 into facebook:master Mar 7, 2018
@vitorbal vitorbal deleted the prop_shorthand_rename branch March 7, 2018 09:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants