Product
Introducing License Enforcement in Socket
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
@babel/plugin-syntax-do-expressions
Advanced tools
@babel/plugin-syntax-do-expressions is a Babel plugin that allows you to use the 'do' expression syntax in your JavaScript code. This syntax enables you to use block statements as expressions, which can be useful for complex logic that needs to return a value.
Basic do expression
This feature allows you to use a block statement as an expression. The block can contain multiple statements, and the value of the last statement is returned as the value of the 'do' expression.
const result = do {
if (x > 10) {
'greater';
} else {
'lesser';
}
};
Complex logic in do expression
This feature allows you to include more complex logic within the 'do' expression, such as variable declarations and multiple conditional statements.
const result = do {
let temp = x * 2;
if (temp > 20) {
'large';
} else {
'small';
}
};
This Babel plugin allows you to use the pipeline operator (|>) in your JavaScript code. The pipeline operator enables a more readable and functional approach to chaining functions. Unlike 'do' expressions, which are used for block statements, the pipeline operator is used for function composition.
This Babel plugin allows you to use optional chaining (?.) in your JavaScript code. Optional chaining provides a way to simplify accessing deeply nested properties without having to explicitly check for the existence of each level. While 'do' expressions are used for block statements, optional chaining is used for safely accessing object properties.
Allow parsing of do expressions
See our website @babel/plugin-syntax-do-expressions for more information.
Using npm:
npm install --save-dev @babel/plugin-syntax-do-expressions
or using yarn:
yarn add @babel/plugin-syntax-do-expressions --dev
v7.16.7 (2021-12-31)
babel-plugin-transform-runtime
, babel-runtime-corejs2
, babel-runtime-corejs3
, babel-runtime
babel-helpers
babel-helper-function-name
, babel-plugin-transform-function-name
babel-core
$schema
property in json config files (@The-x-Theorist)FAQs
Allow parsing of do expressions
The npm package @babel/plugin-syntax-do-expressions receives a total of 140,577 weekly downloads. As such, @babel/plugin-syntax-do-expressions popularity was classified as popular.
We found that @babel/plugin-syntax-do-expressions demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
Product
We're launching a new set of license analysis and compliance features for analyzing, managing, and complying with licenses across a range of supported languages and ecosystems.
Product
We're excited to introduce Socket Optimize, a powerful CLI command to secure open source dependencies with tested, optimized package overrides.