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

Change bin/jsx default file extension to .jsx #832

Closed
andrewdavey opened this issue Jan 7, 2014 · 14 comments
Closed

Change bin/jsx default file extension to .jsx #832

andrewdavey opened this issue Jan 7, 2014 · 14 comments

Comments

@andrewdavey
Copy link
Contributor

Currently, bin/jsx defaults to looking for .js files to which contain jsx content to compile. Whilst it's possible to override this using jsx -x jsx ..., I think that since jsx content is not valid JavaScript, using the .js extension by default isn't ideal.

Could we change bin/jsx to look for .jsx files instead?

Another advantage to this is that the generated .js files can live the same directory as the source .jsx. This simplifies the generation of source maps files as well, because the path to the .jsx is trivially relative to the generated .js

For example, given foo.jsx, running jsx . . would result in:

$ ls
foo.jsx
foo.js
foo.js.map
@zpao
Copy link
Member

zpao commented Jan 7, 2014

This is probably reasonable, though it'll break some people's current expectations. I do like that it would leave .js files alone by default. @benjamn?

@sophiebits
Copy link
Collaborator

+1, we can then get rid of the docblock.

@benjamn
Copy link
Contributor

benjamn commented Jan 7, 2014

I really wish we'd done this from the beginning. My only concern is for backwards compatibility. Maybe target this for the next minor version bump and make a big deal of it in the release notes?

@andrewdavey
Copy link
Contributor Author

+1 for breaking change at next minor version bump. You're still < 1.0, so semver-wise it's acceptable - as long as it's well documented ;)

Anyone who wanted to keep using .js can switch to using jsx -x js ...

@jokeyrhyme
Copy link

Urgh. I just got caught out by this big time. Spent 30 minutes trying to figure this out before I realised that jsx ignores *.jsx files by default. Felt really stupid when I realised that the tutorial files are all *.js. :P

@turadg
Copy link

turadg commented Nov 20, 2014

Agreed on all points above. I'll add that using .jsx instead of .js tips off your editor to highlight correctly.

@koistya
Copy link
Contributor

koistya commented Jan 24, 2015

As far as I understand, if you choose to use .jsx extension for your React components, you will be forced to explicitly specify this extension in every require() statement throughout your code base (e.g. require('../TextEditor.jsx') instead of just require('../TextEditor')) in order to be able to navigate between files with CTR+Click (aka "navigate to source"). That's the primary reason why .js is currently used by default in React.js Starter Kit.

@gaearon
Copy link
Collaborator

gaearon commented Jan 24, 2015

@koistya This depends on the bundler you're using. In Webpack, extensions can be configured explicitly in resolve.extensions; pretty sure Browserify allows something similar.

@gaearon
Copy link
Collaborator

gaearon commented Jan 24, 2015

Oh, I get your point now. I don't really use an IDE.

Regardless, I think such issues should be filed against IDEs themselves. If you use JSX, IDE already has to have some knowledge about it (e.g. how to parse it), so it's not too much to expect it to also follow JSX requires IMO.

@jokeyrhyme
Copy link

Feels suspiciously like the user agent string conundrum. JSX is distinctly not JavaScript, but we put it in *.js files anyway because the tools we use don't conveniently look at *.jsx. We propagate a lie for convenience.

@brigand
Copy link
Contributor

brigand commented Jan 25, 2015

though it'll break some people's current expectations

It could give an error when no files are found, and the extension isn't explicitly set. I say error, as in non-zero exit code, so any CI servers that install the latest version implicitly will fail.

Something like this,

JSX found 0 .jsx files.

The default extension was changed from .js to .jsx.  To restore the old behavior add 
the following to your command: -x js

To suppress this error, explicitly set the extension: -x jsx

For more information see http://fb.me/react-updates-0-13

@rickbeerendonk
Copy link
Contributor

Related: #2943

@sdiaz
Copy link

sdiaz commented Feb 4, 2015

IDEs like Webstorm recognize JSX inside a .js, just configure JSX Harmony when the IDE detects JSX and prompt to use it instead of ECMAScript 5.1

@zpao
Copy link
Member

zpao commented Jul 28, 2015

We're deprecating react-tools so closing out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests