Product
Introducing SSO
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
babel-plugin-transform-nullish-operator
Advanced tools
Readme
babel-plugin-transform-nullish-operator
This package is a babel
plugin which can be used to emulate the Coffeescript existence operator (a?
) in Babel using the new coalescing nullish operator (Stage 4 proposal).
This is completely non-standard, experimental and could break at any time.
In
var fooExists = object.foo ?? EXISTS;
Out
var _object$foo;
var fooExists = (_object$foo = object.foo) !== null && _object$foo !== void 0;
NOTE: We cannot use
!= null
here becausedocument.all == null
anddocument.all
has been deemed not "nullish".
npm install --save-dev babel-plugin-transform-nullish-operator
{
"plugins": ["babel-plugin-transform-nullish-operator"]
}
babel --plugins babel-plugin-transform-nullish-operator script.js
require("@babel/core").transform("code", {
plugins: ["babel-plugin-transform-nullish-operator"]
});
identifier
string
, defaults to EXISTS
.
Can be used to change the identifier which is used to trigger this alternative behavior of the nullish coalescing operator.
{"identifier": "DO_YOU_EXIST"}
In
var fooExists = object.foo ?? DO_YOU_EXIST;
Out
var _object$foo;
var fooExists = (_object$foo = object.foo) !== null && _object$foo !== void 0;
Your linter might EXISTS
as undefined (which is true, the symbol doesn't actually exists, it is only a placeholder), in that case you will need to explicitely add it in your config.
Example using eslint
:
{
...
"globals": {
"EXISTS": "readonly"
},
...
}
This is project is heavily based on Babel's @babel/plugin-proposal-nullish-coalescing-operator
(including code, tests, usage, etc).
MIT, Copyright (c) 2020-2020 Louis Brunner
FAQs
A Babel plugin which emulates the `a?` existence check from CoffeeScript using the `??` syntax
The npm package babel-plugin-transform-nullish-operator receives a total of 21 weekly downloads. As such, babel-plugin-transform-nullish-operator popularity was classified as not popular.
We found that babel-plugin-transform-nullish-operator demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.