简体   繁体   中英

JSX vs ES6/ES2015

In my project I'm using React and Babel so I use some ES6 features but mainly those used by React. Webstorm gives me the option to mark my syntax either as ES6 or JSX Harmony and I got confused.

I think I know what ES6/ES2015 is and how to use it with a compiler, eg. Babel.

The hard part id JSX/JSX Harmony. I know that React uses "JSX" but:

  1. Is this the same JSX as here ? If not, which JSX is meant by JSX Harmony option in Webstorm?

  2. I've seen the compatibility page mentioned here and know that JSX Transformer supports only small part of ES6 but also that apparently Babel supports JSX as an addition to ES6 support so JSX seems to be more than ES6 subset... If so, what features of JSX React or JSX Harmony are not part of ES6 specs?

EDIT:

As for question 1 I'm getting sure, these are two completely different things. But what is JSX Harmony then?

EDIT 2:

To answer my own question, Webstorm JSX Harmony refers most probably to the syntax supported by React JSX Compiler with --harmony flag on - adding a bit of ES6 support.

  1. No, it's not the JSX you've mentioned. It's this one .

    JSX is a XML-like syntax extension to ECMAScript without any defined semantics. It's NOT intended to be implemented by engines or browsers.

  2. JSX doesn't intend to transpile the ES6 features to ES5, so, it only implements some of the most useful features to help with the templating code.

    If you want to use ES6 today, you must use Babel (preferred) or Traceur to transpile your code to ES5, and then you can use most of the features already available. If you want an even more powerful transpiler, that also has type definitions, you can take a look at Typescript .

No, it's not the same jsx. There are two languages called JSX that I know of:

  1. The templating language for React.js

  2. A statically typed programming language that compiles down to javascript.

The two languages are as different as XML and C++.

The JSX you're looking for is from here: https://github.com/facebook/react and can be installed via npm from here: https://www.npmjs.com/package/react-tools

The JSX programming language will not compile React JSX templates.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM