PageSourceSearch

https://babeljs.io/assets/js/0f9e9104.6fd082a7.js

js babeljs.io collected 2026-09-24 06:56:25 UTC 11,327 bytes, 2 lines download raw bytes

1"use strict";(self.webpackChunk=self.webpackChunk||[]).push([["33382"],{14678:function(e,n,a){a.r(n),a.d(n,{metadata:function(){return i},default:function(){return h},frontMatter:function(){return o},contentTitle:function(){return c},toc:function(){return p},assets:function(){return u}});var i=JSON.parse('{"id":"babel-plugin-proposal-optional-chaining-assign","title":"@babel/plugin-proposal-optional-chaining-assign","description":"Transform optional chaining on the left-hand side of assignment expressions.","source":"@site/../docs/plugin-proposal-optional-chaining-assign.md","sourceDirName":".","slug":"/babel-plugin-proposal-optional-chaining-assign","permalink":"/docs/babel-plugin-proposal-optional-chaining-assign","draft":false,"unlisted":false,"editUrl":"https://github.com/babel/website/edit/main/docs/../docs/plugin-proposal-optional-chaining-assign.md","tags":[],"version":"current","frontMatter":{"id":"babel-plugin-proposal-optional-chaining-assign","title":"@babel/plugin-proposal-optional-chaining-assign","sidebar_label":"optional-chaining-assign"},"sidebar":"plugins","previous":{"title":"import-defer","permalink":"/docs/babel-plugin-proposal-import-defer"},"next":{"title":"partial-application","permalink":"/docs/babel-plugin-proposal-partial-application"}}'),l=a(62540),t=a(43023),r=a(77779),s=a(98263);let o={id:"babel-plugin-proposal-optional-chaining-assign",title:"@babel/plugin-proposal-optional-chaining-assign",sidebar_label:"optional-chaining-assign"},c,u={},p=[{value:"Example",id:"example",level:2},{value:"Installation",id:"installation",level:2},{value:"Usage",id:"usage",level:2},{value:"With a configuration file (Recommended)",id:"with-a-configuration-file-recommended",level:3},{value:"Via Node API",id:"via-node-api",level:3},{value:"Options",id:"options",level:2},{value:"Assumptions",id:"assumptions",level:3},{value:"<code>version</code>",id:"version",level:3},{value:"References",id:"references",level:2}];function d(e){let n={a:"a",code:"code",h2:"h2",h3:"h3",li:"li",p:"p",pre:"pre",ul:"ul",...(0,t.R)(),...e.components};return(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(n.p,{children:"Transform optional chaining on the left-hand side of assignment expressions."}),"\n",(0,l.jsx)(n.h2,{id:"example",children:"Example"}),"\n",(0,l.jsx)(n.pre,{children:(0,l.jsx)(n.code,{className:"language-js",metastring:'title="input.js"',children:"function doSomething(maybeOptions) {\n  maybeOptions?.retries = 5;\n}\n"})}),"\n",(0,l.jsx)(n.p,{children:"will be transformed to"}),"\n",(0,l.jsx)(n.pre,{children:(0,l.jsx)(n.code,{className:"language-js",metastring:'title="output.js"',children:"function doSomething(maybeOptions) {\n  maybeOptions !== null && maybeOptions !== void 0 && maybeOptions.retries = 5;\n}\n"})}),"\n",(0,l.jsx)(n.h2,{id:"installation",children:"Installation"}),"\n",(0,l.jsxs)(r.A,{groupId:"npm2yarn",children:[(0,l.jsx)(s.A,{value:"npm",children:(0,l.jsx)(n.pre,{children:(0,l.jsx)(n.code,{className:"language-shell",children:"npm install --save-dev @babel/plugin-proposal-optional-chaining-assign\n"})})}),(0,l.jsx)(s.A,{value:"yarn",label:"Yarn",children:(0,l.jsx)(n.pre,{children:(0,l.jsx)(n.code,{className:"language-shell",children:"yarn add --dev @babel/plugin-proposal-optional-chaining-assign\n"})})}),(0,l.jsx)(s.A,{value:"pnpm",label:"pnpm",children:(0,l.jsx)(n.pre,{children:(0,l.jsx)(n.code,{className:"language-shell",children:"pnpm add --save-dev @babel/plugin-proposal-optional-chaining-assign\n"})})}),(0,l.jsx)(s.A,{value:"bun",label:"Bun",children:(0,l.jsx)(n.pre,{children:(0,l.jsx)(n.code,{className:"language-shell",children:"bun add --dev @babel/plugin-proposal-optional-chaining-assign\n"})})})]}),"\n",(0,l.jsx)(n.h2,{id:"usage",children:"Usage"}),"\n",(0,l.jsx)(n.h3,{id:"with-a-configuration-file-recommended",children:"With a configuration file (Recommended)"}),"\n",(0,l.jsx)(n.pre,{children:(0,l.jsx)(n.code,{className:"language-json",metastring:'title="babel.config.json"',children:'{\n  "plugins": [\n    [\n      "@babel/plugin-proposal-optional-chaining-assign",\n      {\n        "version": "2023-07"\n      }\n    ]\n  ]\n}\n'})}),"\n",(0,l.jsx)(n.h3,{id:"via-node-api",children:"Via Node API"}),"\n",(0,l.jsx)(n.pre,{children:(0,l.jsx)(n.code,{className:"language-js",metastring:'title="JavaScript"',children:'require("@babel/core").transformSync("code", {\n  plugins: [["@babel/plugin-proposal-optional-chaining-assign", {\n      "version": "2023-07"\n    }]],\n});\n'})}),"\n",(0,l.jsx)(n.h2,{id:"options",children:"Options"}),"\n",(0,l.jsx)(n.h3,{id:"assumptions",children:"Assumptions"}),"\n",(0,l.jsxs)(n.p,{children:["This plugin is affected by the ",(0,l.jsx)(n.a,{href:"/docs/assumptions#nodocumentall",children:(0,l.jsx)(n.code,{children:"noDocumentAll"})})," assumption."]}),"\n",(0,l.jsx)(n.h3,{id:"version",children:(0,l.jsx)(n.code,{children:"version"})}),"\n",(0,l.jsx)(n.p,{children:"Required."}),"\n",(0,l.jsx)(n.p,{children:(0,l.jsx)(n.code,{children:'"2023-07"'})}),"\n",(0,l.jsx)(n.p,{children:"Selects the proposal to use:"}),"\n",(0,l.jsxs)(n.ul,{children:["\n",(0,l.jsxs)(n.li,{children:[(0,l.jsx)(n.code,{children:'"2023-07"'}),": The stage 1 proposal as defined at ",(0,l.jsx)(n.a,{href:"https://github.com/tc39/proposal-optional-chaining-assignment/commit/e7b48795b66a8196b1abcab2e52e2049d055c44b",children:(0,l.jsx)(n.code,{children:"tc39/proposal-optional-chaining-assignment@49d055c44b"})}),", presented in the July 2023 TC39 meeting."]}),"\n"]}),"\n",(0,l.jsx)(n.h2,{id:"references",children:"References"}),"\n",(0,l.jsxs)(n.ul,{children:["\n",(0,l.jsx)(n.li,{children:(0,l.jsx)(n.a,{href:"https://github.com/tc39/proposal-optional-chaining-assignment",children:"Proposal: Optional Chaining Assignment"})}),"\n"]})]})}function h(e={}){let{wrapper:n}={...(0,t.R)(),...e.components};return n?(0,l.jsx)(n,{...e,children:(0,l.jsx)(d,{...e})}):d(e)}},98263:function(e,n,a){a.d(n,{A:function(){return s}});var i=a(62540);a(63696);var l=a(11750),t=a(23865);function r({children:e,className:n,hidden:a}){return(0,i.jsx)("div",{role:"tabpanel",className:(0,l.A)("tabItem_wHwb",n),hidden:a,children:e})}function s({children:e,className:n,value:a}){let{selectedValue:l,lazy:o}=(0,t.uc)(),c=a===l;return!c&&o?null:(0,i.jsx)(r,{className:n,hidden:!c,children:e})}},77779:function(e,n,a){a.d(n,{A:function(){return d}});var i=a(62540);a(63696);var l=a(11750),t=a(46065),r=a(23865),s=a(45194),o=a(83029);function c({className:e}){let{selectedValue:n,selectValue:a,tabValues:t,block:o}=(0,r.uc)(),u=[],{blockElementScrollPositionUntilNextRender:p}=(0,s.a_)(),d=e=>{let i=e.currentTarget,l=t[u.indexOf(i)].value;l!==n&&(p(i),a(l))},h=e=>{let n=null;switch(e.key){case"Enter":d(e);break;case"ArrowRight":{let a=u.indexOf(e.currentTarget)+1;n=u[a]??u[0];break}case"ArrowLeft":{let a=u.indexOf(e.currentTarget)-1;n=u[a]??u[u.length-1]}}n?.focus()};return(0,i.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,l.A)("tabs",{"tabs--block":o},e),children:t.map(({value:e,label:a,attributes:t})=>(0,i.jsx)("li",{role:"tab",tabIndex:n===e?0:-1,"aria-selected":n===e,ref:e=>{u.push(e)},onKeyDown:h,onClick:d,...t,className:(0,l.A)("tabs__item","tabItem_l0OV",t?.className,{"tabs__item--active":n===e}),children:a??e},e))})}function u({children:e}){return(0,i.jsx)("div",{className:"margin-top--md",children:e})}function p({className:e,children:n}){return(0,i.jsxs)("div",{className:(0,l.A)(t.G.tabs.container,"tabs-container","tabList_J5MA"),children:[(0,i.jsx)(c,{className:e}),(0,i.jsx)(u,{children:n})]})}function d(e){let n=(0,o.A)(),a=(0,r.OC)(e);return(0,i.jsx)(r.O_,{value:a,children:(0,i.jsx)(p,{className:e.className,children:(0,r.vT)(e.children)})},String(n))}},23865:function(e,n,a){a.d(n,{OC:function(){return d},O_:function(){return f},uc:function(){return g},vT:function(){return u}});var i=a(62540),l=a(63696),t=a(49519),r=a(6743),s=a(88511),o=a(15396),c=a(89030);function u(e){return l.Children.toArray(e).filter(e=>"\n"!==e)}function p({value:e,tabValues:n}){return n.some(n=>n.value===e)}function d(e){let n,{defaultValue:a,queryString:i=!1,groupId:u}=e,d=function(e){let{values:n,children:a}=e;return(0,l.useMemo)(()=>{let e=n??l.Children.toArray(a).flatMap(e=>{if(!e)return[];if((0,l.isValidElement)(e)&&function(e){let{props:n}=e;return!!n&&"object"==typeof n&&"value"in n}(e))return[e];
1let n="string"==typeof e.type?e.type:e.type.name;throw Error(`Docusaurus error: Bad <Tabs> child <${n}>: all children of the <Tabs> component should be <TabItem>, and every <TabItem> should have a unique "value" prop.
2If you do not want to pass on a "value" prop to the direct children of <Tabs>, you can also pass an explicit <Tabs values={...}> prop.`)}).map(({props:{value:e,label:n,attributes:a,default:i}})=>({value:e,label:n,attributes:a,default:i})),i=(0,o.XI)(e,(e,n)=>e.value===n.value);if(i.length>0)throw Error(`Docusaurus error: Duplicate values "${i.map(e=>`'${e.value}'`).join(", ")}" found in <Tabs>. Every value needs to be unique.`);return e},[n,a])}(e),[h,g]=(0,l.useState)(()=>(function({defaultValue:e,tabValues:n}){if(0===n.length)throw Error("Docusaurus error: the <Tabs> component requires at least one <TabItem> children component");if(e){if(!p({value:e,tabValues:n}))throw Error(`Docusaurus error: The <Tabs> has a defaultValue "${e}" but none of its children has the corresponding value. Available values are: ${n.map(e=>e.value).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return e}let a=n.find(e=>e.default)??n[0];if(!a)throw Error("Unexpected error: 0 tabValues");return a.value})({defaultValue:a,tabValues:d})),[f,m]=function({queryString:e=!1,groupId:n}){let a=(0,t.W6)(),i=function({queryString:e=!1,groupId:n}){if("string"==typeof e)return e;if(!1===e)return null;if(!0===e&&!n)throw Error('Docusaurus error: The <Tabs> component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return n??null}({queryString:e,groupId:n});return[(0,s.aZ)(i),(0,l.useCallback)(e=>{if(!i)return;let n=new URLSearchParams(a.location.search);n.set(i,e),a.replace({...a.location,search:n.toString()})},[i,a])]}({queryString:i,groupId:u}),[b,v]=function({groupId:e}){let n=e?`docusaurus.tab.${e}`:null,[a,i]=(0,c.Dv)(n);return[a,(0,l.useCallback)(e=>{n&&i.set(e)},[n,i])]}({groupId:u}),x=p({value:n=f??b,tabValues:d})?n:null;return(0,r.A)(()=>{x&&g(x)},[x]),{selectedValue:h,selectValue:(0,l.useCallback)(e=>{if(!p({value:e,tabValues:d}))throw Error(`Can't select invalid tab value=${e}`);g(e),m(e),v(e)},[m,v,d]),tabValues:d,lazy:e.lazy??!1,block:e.block??!1}}let h=(0,l.createContext)(null);function g(){let e=l.useContext(h);if(!e)throw Error("useTabsContext() must be used within a Tabs component");return e}function f(e){return(0,i.jsx)(h.Provider,{value:e.value,children:e.children})}},43023:function(e,n,a){a.d(n,{R:function(){return r},x:function(){return s}});var i=a(63696);let l={},t=i.createContext(l);function r(e){let n=i.useContext(t);return i.useMemo(function(){return"function"==typeof e?e(n):{...n,...e}},[n,e])}function s(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(l):e.components||l:r(e.components),i.createElement(t.Provider,{value:n},e.children)}}}]);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.