Faster Babel 7 compiler debuts for JavaScript, TypeScript
Babel 7, an upgrade to the JavaScript compiler two years in the making, is now available, with speed improvements and TypeScript support.
The faster Babel should reduce build times. Changes have been made to optimize code. Patches have been accepted from Google’s V8 JavaScript engine team.
Also, Babel now ships with TypeScript support. You parse type syntax using @babel/preset-typescript
, similar to how Babel has handled the Flow static type checker. But Babel does not do type-checking on TypeScript code; it only transforms the code and will compile regardless of which type errors might be present. Babel does transform the latest JavaScript features to older runtimes and browsers.
Other capabilities in Babel 7 include:
- The
babel-upgrade
tool, for automatically dealing with breaking changes. The tool has dependencies inpackage.json
andbabelrc
config. The Babel team recommends running it directly on a Git repo withnpx babel-upgrade
, or you can installed it directly withnpm i babel-upgrade –g
. - For JavaScript configuration files, there is now
babel.js.config
. These files are common in the JavaScript ecosystem. - Selective configurations are enabled via
overrides
, for specifying different configs per glob. - Changes have been made to the
loose
option of some plugins, while new options have been added to others. But using these options opts the developer into non-spec-compliant behavior. This can become an issue when switching off of compiling to use the syntax natively. - Automatic polyfilling is featured, in an experimental fashion. Polyfills are needed for features such as
Promise
andsymbol
in environments that do not support them. This is important when differentiating between what Babel does as a compiler vs. a polyfill. - The
caller
option has been added to@babel/core
so tools can pass metadata to presets and plugins.
Babel 7 does break several existing capabilities:
- It drops support for unmaintained Node Versions 0.10, 0.12, 4, 5.
- It introduces the
peerDependency
on@babel/core
for certain user-facing packages, such asbabel-loader
andbabel-cli
. - It moves to the
@babel
namespace by switching to “scoped” packages. This helps differentiate official packages sobabel-core
becomes@babel/core
. - JSX Fragment support is available, as it has been since beta 31.
Planned features for future versions include:
- Plugin ordering.
- Better validation and error messages.
- Asynchronous use of Babel.
source computerworld