Skip to content

Updated transform-react-display-name for createReactClass addon#5554

Merged
hzoo merged 3 commits intobabel:7.0from
bvaughn:react-create-class-addon
May 1, 2017
Merged

Updated transform-react-display-name for createReactClass addon#5554
hzoo merged 3 commits intobabel:7.0from
bvaughn:react-create-class-addon

Conversation

@bvaughn
Copy link
Contributor

@bvaughn bvaughn commented Mar 27, 2017

Q A
Patch: Bug Fix?
Major: Breaking Change?
Minor: New Feature? Yes
Deprecations?
Spec Compliancy?
Tests Added/Pass? Yes
Fixed Tickets
License MIT
Doc PR
Dependency Changes

The React team will be deprecating React.createClass soon (see facebook/react/pull/9232). This method will be moving to a new add-on package create-react-class (not yet released edit Released on Friday, April 7). We are in the process of creating a codemod now that will replace:

import React from 'react';

React.createClass({...})

with:

import createReactClass from 'create-react-class';

createReactClass({...})

This diff updates the transform-react-display-name plugin to handle the new naming convention (createReactClass) as well as the pre-existing use case (React.createClass) in order to remain backwards compatible with existing versions of React. The new check is a naive string comparison and so it's pretty weak- but hopefully this is sufficient given that createClass is deprecated going forward.

Caveat: It is possible that someone will manually write code using the new add-on that does not conform to the naming convention used by the codemod. This use case is not supported.

cc @acdlite

@mention-bot
Copy link

@bvaughn, thanks for your PR! By analyzing the history of the files in this pull request, we identified @hzoo, @existentialism and @loganfsmyth to be potential reviewers.

@existentialism existentialism added area: react PR: New Feature 🚀 A type of pull request used for our changelog categories labels Mar 27, 2017
@hzoo
Copy link
Member

hzoo commented Mar 28, 2017

@bvaughn yeah the only other relevant issue I remember is #4663 which we never merged

@bvaughn
Copy link
Contributor Author

bvaughn commented Mar 28, 2017

This PR is a bit more narrow-scope than that issue since it's only concerned with createClass usage. Functions/classes generally have a name attribute that React will already use instead of the displayName so I'm not sure how pressing the other request is. Maybe there are use cases I'm not thinking about (other than IE <= 11)?

Copy link
Member

@hzoo hzoo left a comment

Choose a reason for hiding this comment

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

lgtm! 🙂


```js
var foo = React.createClass({});
var foo = React.createClass({}); // React <= 15
Copy link
Member

Choose a reason for hiding this comment

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

dono if we want to modify > Add displayName to React.createClass calls above this too

Copy link
Member

Choose a reason for hiding this comment

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

We should definitely update the docs after the codemod/package are published

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure thing fellas. Sorry it took me a bit to circle back here. Got pulled away on some react-native stuff. Wording has been updated.

@acdlite
Copy link

acdlite commented Mar 28, 2017

Let's use createReactClass instead Never mind, don't have ownership of the package (yet?). ReactCreateClass is fine.

@bvaughn bvaughn force-pushed the react-create-class-addon branch from ac8a31a to 463d995 Compare March 30, 2017 20:40
@bvaughn bvaughn changed the title Updated transform-react-display-name for ReactCreateClass addon Updated transform-react-display-name for createReactClass addon Mar 30, 2017
@bvaughn
Copy link
Contributor Author

bvaughn commented Mar 30, 2017

Sounds like we have decided to go with createReactClass instead of ReactCreateClass~ so I've made one last update to this transform. Sorry for the churn!

@acdlite
Copy link

acdlite commented Mar 30, 2017

Let's maybe wait to merge this until 15.5 is released, just in case

@hzoo
Copy link
Member

hzoo commented Mar 30, 2017

FYI this will be targeting 7.0 anyway unless you also do a backport to 6.x

@hzoo
Copy link
Member

hzoo commented Mar 30, 2017

Also adding both of you to a "react" team on babel (just read access atm) so that we can assign people if that's cool (who else should I add). doing the same for flow

going to use the area: react label

@acdlite
Copy link

acdlite commented Mar 30, 2017

Dan is already added I think. The rest of the team is sebmarkbage, spicyj, trueadm, and flarnie.

@hzoo
Copy link
Member

hzoo commented Mar 30, 2017

the flow I was thinking of

issues: in an updated version of the issue template maybe can specify a place for a user to auto label an issue.
pr: the babel-bot can read if the files touch affect packages/babel-plugin-*-react-* and then @ mention the relevant team. Or just modify mention-bot to do it (easier).

@timdorr
Copy link

timdorr commented Apr 10, 2017

/poke

Looks like I borked a release on react-router 3.x, since we use createClass in that version. Would love to get this out and backported to 6.x. Let me know if I can help!

@bvaughn bvaughn mentioned this pull request Apr 10, 2017
10 tasks
@immortal-tofu
Copy link

LGTM

@hzoo
Copy link
Member

hzoo commented May 1, 2017

@timdorr yeah feel free to do the backport pr

@hzoo hzoo merged commit 526a7d2 into babel:7.0 May 1, 2017
hulkish added a commit to hulkish/babel that referenced this pull request May 2, 2017
* 'master' of github.com:hulkish/babel: (190 commits)
  Fix incorrect property ordering with obj rest spread on nested (babel#5685)
  Fix PathHoister hoisting before a same-scope variable declaration.
  Updated transform-react-display-name for createReactClass addon (babel#5554)
  Fix PathHoister error attaching after export declarations.
  add .mjs to list of well known extensions
  Remove babel-helper-builder-conditional-assignment-operator-visitor, unused in babel [skip ci] (babel#5676)
  use find-cache-dir for babel-register cache (babel#5669)
  Fix operator processing in object super.
  -> parsedAst
  string -> sourceCode, ast -> generatedCode
  back to babylon
  Switch to pirates for babel-register. (babel#3670)
  [skip ci] babylon -> babel, ast -> parsedAst
  [readme] change code -> string
  Add support for object type spread (babel#5525)
  Fix object destructuring in param arrays (babel#5650)
  Remove merge helper and add more type declarations. (babel#5649)
  Typecheck much more of the config loading process (babel#5642)
  update to alpha.9 (babel#5639)
  v7.0.0-alpha.9
  ...
hulkish added a commit to hulkish/babel that referenced this pull request May 2, 2017
* '7.0' of https://github.com/babel/babel: (190 commits)
  Fix incorrect property ordering with obj rest spread on nested (babel#5685)
  Fix PathHoister hoisting before a same-scope variable declaration.
  Updated transform-react-display-name for createReactClass addon (babel#5554)
  Fix PathHoister error attaching after export declarations.
  add .mjs to list of well known extensions
  Remove babel-helper-builder-conditional-assignment-operator-visitor, unused in babel [skip ci] (babel#5676)
  use find-cache-dir for babel-register cache (babel#5669)
  Fix operator processing in object super.
  -> parsedAst
  string -> sourceCode, ast -> generatedCode
  back to babylon
  Switch to pirates for babel-register. (babel#3670)
  [skip ci] babylon -> babel, ast -> parsedAst
  [readme] change code -> string
  Add support for object type spread (babel#5525)
  Fix object destructuring in param arrays (babel#5650)
  Remove merge helper and add more type declarations. (babel#5649)
  Typecheck much more of the config loading process (babel#5642)
  update to alpha.9 (babel#5639)
  v7.0.0-alpha.9
  ...
@itkach
Copy link

itkach commented May 5, 2017

Any chance to have this backported to babel 6?

@bvaughn bvaughn deleted the react-create-class-addon branch May 5, 2017 22:11
@bvaughn
Copy link
Contributor Author

bvaughn commented May 5, 2017

@timdorr: Looks like I borked a release on react-router 3.x, since we use createClass in that version. Would love to get this out and backported to 6.x. Let me know if I can help!

@hzoo: @timdorr yeah feel free to do the backport pr

@itkach Seems like someone would just need to submit a PR

kentor pushed a commit to kentor/babel that referenced this pull request May 26, 2017
…l#5554)

* Updated transform-react-display-name for ReactCreateClass addon

* Tweaked description for transform-react-display-name plugin

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

Labels

area: react outdated A closed issue/PR that is archived due to age. Recommended to make a new issue PR: New Feature 🚀 A type of pull request used for our changelog categories

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants