简体   繁体   English

JSX vs ES6 / ES2015

[英]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. 在我的项目中,我使用的是React和Babel,因此我使用了一些ES6功能,但主要是React使用的功能。 Webstorm gives me the option to mark my syntax either as ES6 or JSX Harmony and I got confused. Webstorm让我可以选择将我的语法标记为ES6或JSX Harmony,我感到困惑。

I think I know what ES6/ES2015 is and how to use it with a compiler, eg. 我想我知道ES6 / ES2015是什么以及如何在编译器中使用它,例如。 Babel. 巴贝尔。

The hard part id JSX/JSX Harmony. 难题部分是JSX / JSX Harmony。 I know that React uses "JSX" but: 我知道React使用“JSX”但是:

  1. Is this the same JSX as here ? 这和这里的 JSX一样吗? If not, which JSX is meant by JSX Harmony option in Webstorm? 如果不是,WebXorm中的JSX Harmony选项意味着哪个JSX?

  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? 我已经看到了这里提到的兼容性页面并且知道JSX Transformer仅支持ES6的一小部分,但显然Babel支持JSX作为ES6支持的补充,因此JSX似乎不仅仅是ES6子集...如果是这样,那么什么功能JSX React或JSX Harmony不是ES6规范的一部分?

EDIT: 编辑:

As for question 1 I'm getting sure, these are two completely different things. 至于问题1,我确定,这是两个完全不同的事情。 But what is JSX Harmony then? 但是什么是JSX Harmony呢?

EDIT 2: 编辑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. 为了回答我自己的问题,Webstorm JSX Harmony最有可能提到React JSX Compiler支持的语法 - 带有--harmony flag - 增加了一点ES6支持。

  1. No, it's not the JSX you've mentioned. 不,这不是你提到的JSX。 It's this one . 就是这个

    JSX is a XML-like syntax extension to ECMAScript without any defined semantics. JSX是ECMAScript的类似XML的语法扩展,没有任何定义的语义。 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. JSX并不打算将ES6功能转换为ES5,因此,它只实现了一些最有用的功能来帮助模板化代码。

    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. 如果您今天要使用ES6,则必须使用Babel (首选)或Traceur将代码转换为ES5,然后您可以使用已有的大部分功能。 If you want an even more powerful transpiler, that also has type definitions, you can take a look at Typescript . 如果你想要一个更强大的转换器,它也有类型定义,你可以看一下Typescript

No, it's not the same jsx. 不,这不是jsx。 There are two languages called JSX that I know of: 我知道有两种叫做JSX的语言:

  1. The templating language for React.js React.js的模板语言

  2. A statically typed programming language that compiles down to javascript. 一种静态类型的编程语言,可编译为javascript。

The two languages are as different as XML and C++. 这两种语言与XML和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 您正在寻找的JSX来自: https//github.com/facebook/react ,可以从这里通过npm安装: https ://www.npmjs.com/package/react-tools

The JSX programming language will not compile React JSX templates. JSX编程语言不会编译React JSX模板。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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