Babel preset for stage 0 plugins that enables experimental JavaScript language features
npx @tessl/cli install tessl/npm-babel-preset-stage-0@6.24.0babel-preset-stage-0 is a Babel preset that enables experimental JavaScript language features in stage 0 of the TC39 proposal process. This preset provides access to the most cutting-edge JavaScript syntax and constructs that are still in early development stages, making it ideal for experimental projects and early adopters who want to leverage the latest language innovations.
npm install --save-dev babel-preset-stage-0babel-preset-stage-0 is used as a preset configuration in Babel, not imported directly in code. The package's main entry point is lib/index.js (compiled from src/index.js), but users reference it by name in Babel configuration files.
For programmatic usage (requiring the preset directly):
// CommonJS - accessing the compiled preset object
const stage0Preset = require("babel-preset-stage-0");
// Returns: { presets: [...], plugins: [...] }
// Using with babel-core transform
const babel = require("babel-core");
const result = babel.transform(code, {
presets: [stage0Preset]
});For Babel configuration files:
.babelrc:
{
"presets": ["stage-0"]
}babel.config.js:
module.exports = {
presets: ["babel-preset-stage-0"]
};Create a .babelrc file in your project root:
{
"presets": ["stage-0"]
}babel script.js --presets stage-0const babel = require("babel-core");
const result = babel.transform(code, {
presets: ["stage-0"]
});babel-preset-stage-0 follows Babel's preset hierarchy system:
The preset follows Babel's standard build process:
src/index.jslib/index.jsexports.default + module.exports) for maximum compatibilityes2015 preset and custom export pluginlib/ directory contains the actual code consumed by users via npmThe main export of babel-preset-stage-0 is a Babel preset configuration object that tells Babel which transformations to apply.
/**
* Main preset export (CommonJS format - compiled from ES6 source)
* This is the actual structure published to npm as lib/index.js
*/
module.exports = {
/** Array of child presets - includes babel-preset-stage-1 which inherits stage-2 and stage-3 */
presets: [require("babel-preset-stage-1")],
/** Array of plugins specific to stage-0 experimental features */
plugins: [
require("babel-plugin-transform-do-expressions"),
require("babel-plugin-transform-function-bind")
]
};
/**
* Source code structure (ES6 modules in src/index.js)
* This gets compiled to the CommonJS format above
*/
import presetStage1 from "babel-preset-stage-1";
import transformDoExpressions from "babel-plugin-transform-do-expressions";
import transformFunctionBind from "babel-plugin-transform-function-bind";
export default {
presets: [presetStage1],
plugins: [transformDoExpressions, transformFunctionBind]
};/**
* Babel Preset Configuration Object
* Structure returned by babel-preset-stage-0
*/
interface BabelPresetConfig {
/** Array of child presets to include in transformation chain */
presets: BabelPreset[];
/** Array of transform plugins to apply */
plugins: BabelPlugin[];
}
/**
* Individual preset or plugin references
* Can be plugin functions, preset objects, or string names
*/
type BabelPreset = Function | Object | string;
type BabelPlugin = Function | Object | string;
/**
* The actual exported object structure
*/
const presetStage0: BabelPresetConfig = {
presets: [
/* babel-preset-stage-1 (includes stage-2 and stage-3) */
],
plugins: [
/* babel-plugin-transform-do-expressions */,
/* babel-plugin-transform-function-bind */
]
};babel-preset-stage-0 provides two experimental language features:
Enables do expressions that return values from statement blocks.
Plugin: babel-plugin-transform-do-expressions
Syntax Example:
// Before transformation
const result = do {
if (condition) {
'success'
} else {
'failure'
}
};
// Allows statement blocks to return values like expressionsEnables the function bind operator (::) for method binding.
Plugin: babel-plugin-transform-function-bind
Syntax Example:
// Before transformation
const boundMethod = obj::method;
const result = obj::method(arg);
// Equivalent to:
const boundMethod = method.bind(obj);
const result = method.call(obj, arg);Through babel-preset-stage-1@^6.24.1, this preset includes all features from:
babel-plugin-transform-class-constructor-call@^6.24.1babel-plugin-transform-export-extensions@^6.22.0babel-preset-stage-2@^6.24.1babel-preset-stage-0 accepts no configuration options - it provides a fixed set of transformations. To customize behavior, configure individual plugins instead:
// Custom configuration bypassing the preset
module.exports = {
plugins: [
"babel-plugin-transform-do-expressions",
"babel-plugin-transform-function-bind",
// ... other stage-1/2/3 plugins
]
};This preset is part of Babel 6's stage preset system, which was deprecated in Babel 7. For modern projects:
@babel/plugin-proposal-do-expressions and @babel/plugin-proposal-function-bind@babel/preset-env with appropriate targetsThe preset internally depends on (exact versions from package.json):
babel-plugin-transform-do-expressions@^6.22.0 - Enables do-expression syntaxbabel-plugin-transform-function-bind@^6.22.0 - Enables function bind operator (::)babel-preset-stage-1@^6.24.1 - Includes all stage-1, stage-2, and stage-3 featuresThrough the stage hierarchy, this preset inherits:
babel-plugin-transform-class-constructor-call, babel-plugin-transform-export-extensions