Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference between babel-preset-stage-0, babel-preset-stage-1 etc?

My question is : What's the difference between babel-preset-stage-0,babel-preset-stage-1,babel-preset-stage-2 and babel-preset-stage-3, and what's the best choice when we develop with ES6?

like image 689
flyingzl Avatar asked Oct 10 '22 03:10

flyingzl


People also ask

What are Babel stages?

Stage 1 - Proposal: this is worth working on. Stage 2 - Draft: initial spec. Stage 3 - Candidate: complete spec and initial browser implementations. Stage 4 - Finished: will be added to the next yearly release.

What are Babel presets?

@babel/preset-env is a smart preset that allows you to use the latest JavaScript without needing to micromanage which syntax transforms (and optionally, browser polyfills) are needed by your target environment(s). This both makes your life easier and JavaScript bundles smaller!

What are presets in react?

A preset is a set of plugins used to support particular language features. The two presets Babel uses by default: es2015: Adds support for ES2015 (or ES6) JavaScript. react: Adds support for JSX.

What is a Babelrc file?

The . babelrc file is your local configuration for your code in your project. Generally you would put it in the root of your application repo. It will affect all files that Babel processes that are in the same directory or in sibling directories of the . babelrc .


2 Answers

Babel's stage presets equate to the TC39 Process and the different states of each proposal for a potential language change. They include implementations and polyfills for all of the proposed changes in that stage.

Anything currently in Stage-0 is Strawman, not ES6. It is future Javascript and absolutely not certain that it will ever make it into any official ECMAScript specification.

Please do not just set to stage-0 so it will work without understanding the consequences this will have.

The Babel Preset which contains only ES6 features is preset-es2015

like image 102
CodingIntrigue Avatar answered Oct 11 '22 17:10

CodingIntrigue


As mostly elaborated by other answers. Stage 4 is most Stable and Stage 0, the most dangerous. Here is a bit of a breakdown at a high level for the 5 stages from the previous answers and the documentation. I'm adding this because when I came to this I was expecting a more high-level break down of what each stage is:


Stage 4: Finished

Ready for inclusion in ECMAScript Standard, has passed testing and will be part of the next revision


Stage 3: Candidate

Includes a full spec text and includes plugins that have mostly been tested and provided with feedback. Solution is complete and all further changes are based on implementation experience.


Stage 2: Draft

Further support for plugins completed as much as possible. Requirements for these are met mostly with only incremental changes on the way. Semantics and api is expected to be complete. It will most likely become part of the spec.


Stage 1: Proposal A concept that has been discovered and selected to be examined at this phase mostly poly-fills and demos are expected.


Stage 0: Strawman This name made me chuckle according to the TC-39 it kind of doesn't have any sort of bound but given the context it is the category for concepts that have not been selected to be followed up on or examined.

Each level is inclusive whereas 4 includes 3 includes 2 and so on... I hope that this summation helps someone in the future.

like image 59
Callat Avatar answered Oct 11 '22 17:10

Callat