Why say Babel will drive JavaScript development

Source: Internet
Author: User
Tags closure

Babel is a conversion compiler that converts ES6 to code that can be run in a browser. Babel was created by developer Sebastian McKenzie from Australia. His goal is to enable Babel to handle all the new syntax for ES6 and to have built-in react jsx extensions and flow type annotation support.

According to Codemix founder Charles Pick, Babel is the most compatible with ES6 specifications in all ES6 conversion compilers, even surpassing Google's long-established traceur compilers. Babel allows developers to use all of the new features of ES6 without compromising compatibility with older versions of the browser. In addition, it supports many different build & test systems, making it easy for developers to integrate it into their toolchain.

Charles believes that Babel is fundamentally a platform, which is the biggest difference between it and Compile-to-js language Coffeescript and typescript. Babel's plug-in system allows developers to customize the code converters and insert them into the compilation process. These converters receive an abstract syntax tree and manipulate the code before it is translated into executable JavaScript. Codemix has tried to develop plugins such as static & runtime type checking, closure cancellation, JAVASCRIPT health macros (hygienic macros).

Babel not only tracks the progress of ES6, but also the ES7 or ES2016 test site. For example, it already supports async/await, making it easier for developers to write asynchronous JavaScript code, and the code is simpler and easier to understand than using callbacks or promises. While it may take several years for mainstream browsers to support this asynchronous JavaScript code, Babel allows developers to use it now. This is thanks to the high level of consistency between Babel and the JavaScript Technical Committee (TC39), which provides developers with real-world implementations prior to the standardization of ECMAScript new features. At the same time, this also facilitates JavaScript's further development, as its team can get feedback from the real world before the ECMAScript specification is finalized.

Babel also increases the speed of JavaScript execution. Because the slow loading and execution of JavaScript files can severely affect the user experience, JIT does not have time to perform all technically feasible optimizations at runtime. In contrast, Babel is run at compile time, and there is no such a strict timing limit. With powerful scope tracking and type inference capabilities and plug-in systems, developers can build converters to perform such optimizations, such as the closure elimination mentioned above, which translates closures into normal functions. The Babel itself has some optimizations built in, such as constant merge/constant propagation through the utility.deadcodeelimination converter. In the next few months, we are also expected to see the following plugins:

    • arbitrary function Inline: the function is inline to the call point, maximizing performance, avoiding polymorphism and function call overhead;
    • Function replication: In JavaScript, polymorphism is a common cause of slow code execution. Therefore, in a place where the function cannot be inline, a copy of the function should be generated to ensure that the function remains a single state;
    • In-Loop invariant code extrapolation: Move the unchanged code in the loop body outside the loop body;
    • Loop unfold: If the number of cycles n is fixed, the loop is removed and the loop body is copied n copies.

Codemix will post several plugins that perform such optimizations, and interested readers can contact them or follow their Twitter. There are several different optimizations that can be made about the JavaScript engine, which can be viewed here. Babel plug-ins are also limited to performance improvements, such as the following: i18n/Translator: Translate a specific string and replace it;

Custom Logging System: Set the log level through environment variables, control the granularity of log;

Compile-time converters for optional templating systems (such as mustache or handlebars): Convert label template strings directly to JavaScript code;

 

Document Builder: Generate documents with Flow type annotations and type inference.

Part of the above plugin has been implemented. In short, Charles believes that Babel is an excellent software that will become part of every web Developer toolkit, and as ECMAScript's proving ground, it is likely to be a major driver of ES6 and esnext applications and development in the near future.

Thank you for your continued attention, the following will also provide you with more recent and most popular industry trends and technical content.

Interested friends are welcome to join our Technical discussion community: Sound Community "Thank you for your support Oh ~

This article transferred from HTML5 China

Why say Babel will drive JavaScript development

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.