
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
@babel/plugin-syntax-optional-chaining
Advanced tools
The @babel/plugin-syntax-optional-chaining package allows Babel to parse and understand the optional chaining syntax. Optional chaining (`?.`) permits reading the value of a property located deep within a chain of connected objects without having to expressly validate that each reference in the chain is valid. The `?.` operator functions similarly to the `.` chaining operator, except that instead of causing an error if a reference is nullish (`null` or `undefined`), the expression short-circuits with a return value of `undefined`. This simplifies accessing values through connected objects when there's a possibility that a reference may be missing.
Optional Property Access
This feature allows safe access to nested object properties without having to check each level of the object to ensure it exists. If any reference is nullish, the expression evaluates to `undefined` instead of throwing an error.
const streetName = user?.address?.street;
Optional Method Calls
Enables calling a method on an object only if the object exists; otherwise, it returns `undefined`. This is useful for calling methods on objects that may not be initialized.
const length = users?.length;
Optional Bracket Notation
Similar to optional property access, but with the ability to access properties using bracket notation. This is useful when property names are dynamically determined.
const lastName = user?.['name']?.['last'];
While not exclusively focused on optional chaining, @babel/preset-env includes support for it among other JavaScript features. This preset allows you to use the latest JavaScript without needing to micromanage which syntax transforms (or polyfills) are needed by your target environment(s). It's more comprehensive but heavier than using a specific plugin for optional chaining.
TypeScript, a superset of JavaScript, includes support for optional chaining natively. When compiling TypeScript code to JavaScript, the TypeScript compiler can transform optional chaining syntax into equivalent JavaScript that works in environments not supporting the syntax natively. This offers a broader solution for adopting modern JavaScript features, including but not limited to optional chaining.
Allow parsing of optional properties
See our website @babel/plugin-syntax-optional-chaining for more information.
Using npm:
npm install --save-dev @babel/plugin-syntax-optional-chaining
or using yarn:
yarn add @babel/plugin-syntax-optional-chaining --dev
FAQs
Allow parsing of optional properties
The npm package @babel/plugin-syntax-optional-chaining receives a total of 10,045,913 weekly downloads. As such, @babel/plugin-syntax-optional-chaining popularity was classified as popular.
We found that @babel/plugin-syntax-optional-chaining demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 6 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.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.