-
Notifications
You must be signed in to change notification settings - Fork 905
Support for JSX #497
Comments
Is JSX significantly different syntactically from E4X? |
There are some differences, but JSX is a dialect of XML, according to Facebook. However, its usually just in the code as a return argument like this:
or inside parens:
|
Do you have a description of the rules that describe when a The following JS, not JSX, var a = 3;
var disabled, href, foo;
var x = 1
<a
href="foo"
disabled>
foo || alert(1) is equivalent by virtue of semicolon insertion to var a = 3;
var disabled, href, foo;
var x = 1 < a;
href = "foo";
if (!(disabled > foo)) {
alert(1);
} but, if you replace newlines with spaces, that script contains |
Not really, either you return some JSX or you enclose it in parens. The Babel JSX transformer plugin identifies the JSX and converts it into a function that is used by frameworks to create the actual markup. But that's only after running a build script. So in your file you would have like my previous examples. The general practice is to enclose JSX in parens. By the way, here are links to Facebooks documentation on JSX: https://facebook.github.io/react/docs/introducing-jsx.html, https://facebook.github.io/react/docs/jsx-in-depth.html |
Here's the coverage report for a JSX file. Generated by Code is covered by this test file (everything is run through Babel): import React from 'react';
import { shallow } from 'enzyme';
import Example from '../../../../src/common/Example';
describe('Example', () => {
it('renders without error', () => {
const wrapper = shallow(<Example />);
console.log(wrapper.html());
});
}); ...its console output shows that it rendered this HTML: <div class="plain">Free text</div> There a few issues with the way code-prettify reports on Example.js:
Further reading on JSX: |
Here is some relevant discussion in the acorn-jsx repo that begins with an example very similar to yours: acornjs/acorn-jsx#78. In this comment @RReverser draws an analogy to parsing regular expression literals with respect to ASI (emphasis mine):
The JSX repo has some additional discussion here: facebook/jsx#87. Finally, I don't have the expertise to tell if this is useful, but FWIW the draft JSX specification says:
PrimaryExpression is defined as:
In other words, a PrimaryExpression is anything we'd informally call an "expression" in JavaScript, and a JSX element or fragment ( I hope that's helpful. |
I've used prettify for years. But know, with the prevalence of JSX in code, I need it to highlight properly online. Prettify currently breaks badly with JSX. The React/Preact/Inferno community is huge. And Angularjs and Vuejs developers can also use JSX. It's everywhere now. I'm hoping this can be added soon.
The text was updated successfully, but these errors were encountered: