-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
Added jsx-self babel transform plugin #3540
Conversation
also cc @sebmarkbage |
If you mean default to the react-preset yeah, actually already some code there that was commented out (due to http://phabricator.babeljs.io/T2994) doing a similar thing https://github.com/babel/babel/blob/master/packages/babel-preset-react/index.js |
Current coverage is 88.04%@@ master #3540 diff @@
==========================================
Files 193 194 +1
Lines 10072 9746 -326
Methods 1553 1510 -43
Messages 0 0
Branches 2199 2106 -93
==========================================
- Hits 8875 8581 -294
+ Misses 1197 1165 -32
Partials 0 0
|
@jimfb Also if you want, you can just push commits and we can squash into 1 commit at the end. |
@hzoo The CI appears to be failing with |
I see, it's because those tests are using the preset which now has the new module and I don't think lerna 1.x accounts for that. Not sure we can do anything other than switching to lerna 2.x which (I think) fixes it (#3509) or of course releasing/publishing it |
JSXOpeningElement(node) { | ||
const id = t.jSXIdentifier(TRACE_ID); | ||
const trace = t.identifier("this"); | ||
node.container.openingElement.attributes.push(t.jSXAttribute(id, t.jSXExpressionContainer(trace))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also is it ok that there's no check for an existing __self
attribute?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be. The JSX transform will just output a object with multiple __self
properties which is fine.
@jimfb Ohh.. I checked the PR out locally and was still confused - it's because we need to add the plugin to the package.json not just the babelrc file haha. |
@@ -0,0 +1,18 @@ | |||
{ | |||
"name": "babel-plugin-transform-react-jsx-self", | |||
"version": "6.0.14", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if this matters but I would change this to be the current version so 6.0.14
Added in 93299d9 |
Didn't we decide last time against including dev-specific stuff in the dev environment for the preset because most people don't set BABEL_ENV (or NODE_ENV) properly during build time? |
Yea, this should not go into any preset that the source transform isn't in. |
Ah sorry should of checked with someone else? I don't remember if we decided on that but I found http://phabricator.babeljs.io/T2994 which was regarding purerendermixin (although not sure how relevant since it's only in dev? Hmm it must be because it defaults to dev and like mentioned people don't set the env to prod. Made #3552 to remove it from the preset |
@hzoo decided is a strong word, but there was some discussion about it (not between maintainers) starting here: #2963 (comment). I'm not sure I'm convinced that people are going to be oblivious to setting |
I don't remember that being the decision. We backed out the __source transform from the default dev ENV because it broke the older versions of React which didn't have __source whitelisted yet. This change doesn't have the same concern since __self was whitelisted a long time ago, so it is "safer". We could probably also turn on the __source transform at this point. Anyway, that was my recollection, but maybe I'm mistaken, it was a long time ago. |
I agree that people probably usually set NODE_ENV properly for runtime, but the question here is what NODE_ENV is when Babel is run, and I don't think most people set that. I know I usually don't. |
I'm not sure about the details of why
I don't know if there's any way to get a meaningful amount of information about this kind of usage, but I would guess that a lot of people are compiling with Babel as part of bundling with Browserify or Webpack and setting Can you help me out with some context and summarize how you're utilizing Babel when you're not setting If we need to we can do more in the docs about guiding people to specify the environment. |
In webpack, you would typically use |
@spicyj Well, I realize there are a lot of work flows and tools I don't know about, that's why I wanted to better understand your scenario. I often use Babel with Browserify via Babelify, doing something like this for example:
If I'm bundling React with Browserify, If a user is just compiling some stuff with Babel and they don't have custom per-env configuration setup, I could see how they'd overlook setting the env or not realize it'd make a difference in that case (which maybe it hasn't up til now). Like I mentioned, if it is important (e.g. if stuff in Babel core is going to behave differently per-env) we could do more with the docs to educate people about that.
The way that's illustrated makes it seem static -- in that scenario doesn't the user still need to dynamically set the I don't know if your question was rhetorical, but if we want more perspective on Webpack usage I think @loganfsmyth, for one, knows way more about it than I do. Or I could ask on Slack -- I think a lot of Babel users use Webpack. Here's one example I found (Redux) where they're doing this (interestingly setting both
And passing that value to Webpack:
(Granted, people working on Redux have sophisticated development skills.) |
This adds a new transform which appends the
__self
prop to jsx elements. The transform is needed by one of the React warnings that is being introduced, so users should enable it when running React in DEV mode.