1"use strict";(self.webpackChunk=self.webpackChunk||[]).push([["31714"],{17376:function(e,n,a){a.r(n),a.d(n,{metadata:function(){return t},default:function(){return p},frontMatter:function(){return s},contentTitle:function(){return u},toc:function(){return d},assets:function(){return c}});var t=JSON.parse('{"id":"babel-plugin-syntax-optional-chaining","title":"@babel/plugin-syntax-optional-chaining","description":"Syntax only","source":"@site/../docs/plugin-syntax-optional-chaining.md","sourceDirName":".","slug":"/babel-plugin-syntax-optional-chaining","permalink":"/docs/babel-plugin-syntax-optional-chaining","draft":false,"unlisted":false,"editUrl":"https://github.com/babel/website/edit/main/docs/../docs/plugin-syntax-optional-chaining.md","tags":[],"version":"current","frontMatter":{"id":"babel-plugin-syntax-optional-chaining","title":"@babel/plugin-syntax-optional-chaining","sidebar_label":"syntax-optional-chaining"}}'),i=a(62540),l=a(43023),r=a(77779),o=a(98263);let s={id:"babel-plugin-syntax-optional-chaining",title:"@babel/plugin-syntax-optional-chaining",sidebar_label:"syntax-optional-chaining"},u,c={},d=[{value:"Syntax only",id:"syntax-only",level:4},{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 CLI",id:"via-cli",level:3},{value:"Via Node API",id:"via-node-api",level:3}];function h(e){let n={a:"a",admonition:"admonition",code:"code",em:"em",h2:"h2",h3:"h3",h4:"h4",p:"p",pre:"pre",...(0,l.R)(),...e.components};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(n.admonition,{type:"note",children:[(0,i.jsx)(n.h4,{id:"syntax-only",children:"Syntax only"}),(0,i.jsxs)(n.p,{children:["It's unlikely you want to use this plugin directly as it only enables Babel to parse this syntax. Instead, use ",(0,i.jsx)(n.a,{href:"/docs/babel-plugin-transform-optional-chaining",children:"plugin-transform-optional-chaining"})," to ",(0,i.jsx)(n.em,{children:"both"})," parse and transform this syntax."]})]}),"\n",(0,i.jsx)(n.h2,{id:"installation",children:"Installation"}),"\n",(0,i.jsxs)(r.A,{groupId:"npm2yarn",children:[(0,i.jsx)(o.A,{value:"npm",children:(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-shell",children:"npm install --save-dev @babel/plugin-syntax-optional-chaining\n"})})}),(0,i.jsx)(o.A,{value:"yarn",label:"Yarn",children:(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-shell",children:"yarn add --dev @babel/plugin-syntax-optional-chaining\n"})})}),(0,i.jsx)(o.A,{value:"pnpm",label:"pnpm",children:(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-shell",children:"pnpm add --save-dev @babel/plugin-syntax-optional-chaining\n"})})}),(0,i.jsx)(o.A,{value:"bun",label:"Bun",children:(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-shell",children:"bun add --dev @babel/plugin-syntax-optional-chaining\n"})})})]}),"\n",(0,i.jsx)(n.h2,{id:"usage",children:"Usage"}),"\n",(0,i.jsx)(n.h3,{id:"with-a-configuration-file-recommended",children:"With a configuration file (Recommended)"}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-json",metastring:'title="babel.config.json"',children:'{\n "plugins": ["@babel/plugin-syntax-optional-chaining"]\n}\n'})}),"\n",(0,i.jsx)(n.h3,{id:"via-cli",children:"Via CLI"}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-sh",metastring:'title="Shell"',children:"babel --plugins @babel/plugin-syntax-optional-chaining script.js\n"})}),"\n",(0,i.jsx)(n.h3,{id:"via-node-api",children:"Via Node API"}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-js",metastring:'title="JavaScript"',children:'require("@babel/core").transformSync("code", {\n plugins: ["@babel/plugin-syntax-optional-chaining"]\n});\n'})})]})}function p(e={}){let{wrapper:n}={...(0,l.R)(),...e.components};return n?(0,i.jsx)(n,{...e,children:(0,i.jsx)(h,{...e})}):h(e)}},98263:function(e,n,a){a.d(n,{A:function(){return o}});var t=a(62540);a(63696);var i=a(11750),l=a(23865);function r({children:e,className:n,hidden:a}){return(0,t.jsx)("div",{role:"tabpanel",className:(0,i.A)("tabItem_wHwb",n),hidden:a,children:e})}function o({children:e,className:n,value:a}){let{selectedValue:i,lazy:s}=(0,l.uc)(),u=a===i;return!u&&s?null:(0,t.jsx)(r,{className:n,hidden:!u,children:e})}},77779:function(e,n,a){a.d(n,{A:function(){return h}});var t=a(62540);a(63696);var i=a(11750),l=a(46065),r=a(23865),o=a(45194),s=a(83029);function u({className:e}){let{selectedValue:n,selectValue:a,tabValues:l,block:s}=(0,r.uc)(),c=[],{blockElementScrollPositionUntilNextRender:d}
1=(0,o.a_)(),h=e=>{let t=e.currentTarget,i=l[c.indexOf(t)].value;i!==n&&(d(t),a(i))},p=e=>{let n=null;switch(e.key){case"Enter":h(e);break;case"ArrowRight":{let a=c.indexOf(e.currentTarget)+1;n=c[a]??c[0];break}case"ArrowLeft":{let a=c.indexOf(e.currentTarget)-1;n=c[a]??c[c.length-1]}}n?.focus()};return(0,t.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,i.A)("tabs",{"tabs--block":s},e),children:l.map(({value:e,label:a,attributes:l})=>(0,t.jsx)("li",{role:"tab",tabIndex:n===e?0:-1,"aria-selected":n===e,ref:e=>{c.push(e)},onKeyDown:p,onClick:h,...l,className:(0,i.A)("tabs__item","tabItem_l0OV",l?.className,{"tabs__item--active":n===e}),children:a??e},e))})}function c({children:e}){return(0,t.jsx)("div",{className:"margin-top--md",children:e})}function d({className:e,children:n}){return(0,t.jsxs)("div",{className:(0,i.A)(l.G.tabs.container,"tabs-container","tabList_J5MA"),children:[(0,t.jsx)(u,{className:e}),(0,t.jsx)(c,{children:n})]})}function h(e){let n=(0,s.A)(),a=(0,r.OC)(e);return(0,t.jsx)(r.O_,{value:a,children:(0,t.jsx)(d,{className:e.className,children:(0,r.vT)(e.children)})},String(n))}},23865:function(e,n,a){a.d(n,{OC:function(){return h},O_:function(){return b},uc:function(){return f},vT:function(){return c}});var t=a(62540),i=a(63696),l=a(49519),r=a(6743),o=a(88511),s=a(15396),u=a(89030);function c(e){return i.Children.toArray(e).filter(e=>"\n"!==e)}function d({value:e,tabValues:n}){return n.some(n=>n.value===e)}function h(e){let n,{defaultValue:a,queryString:t=!1,groupId:c}=e,h=function(e){let{values:n,children:a}=e;return(0,i.useMemo)(()=>{let e=n??i.Children.toArray(a).flatMap(e=>{if(!e)return[];if((0,i.isValidElement)(e)&&function(e){let{props:n}=e;return!!n&&"object"==typeof n&&"value"in n}(e))return[e];let 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:t}})=>({value:e,label:n,attributes:a,default:t})),t=(0,s.XI)(e,(e,n)=>e.value===n.value);if(t.length>0)throw Error(`Docusaurus error: Duplicate values "${t.map(e=>`'${e.value}'`).join(", ")}" found in <Tabs>. Every value needs to be unique.`);return e},[n,a])}(e),[p,f]=(0,i.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(!d({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:h})),[b,g]=function({queryString:e=!1,groupId:n}){let a=(0,l.W6)(),t=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,o.aZ)(t),(0,i.useCallback)(e=>{if(!t)return;let n=new URLSearchParams(a.location.search);n.set(t,e),a.replace({...a.location,search:n.toString()})},[t,a])]}({queryString:t,groupId:c}),[m,x]=function({groupId:e}){let n=e?`docusaurus.tab.${e}`:null,[a,t]=(0,u.Dv)(n);return[a,(0,i.useCallback)(e=>{n&&t.set(e)},[n,t])]}({groupId:c}),v=d({value:n=b??m,tabValues:h})?n:null;return(0,r.A)(()=>{v&&f(v)},[v]),{selectedValue:p,selectValue:(0,i.useCallback)(e=>{if(!d({value:e,tabValues:h}))throw Error(`Can't select invalid tab value=${e}`);f(e),g(e),x(e)},[g,x,h]),tabValues:h,lazy:e.lazy??!1,block:e.block??!1}}let p=(0,i.createContext)(null);function f(){let e=i.useContext(p);if(!e)throw Error("useTabsContext() must be used within a Tabs component");return e}function b(e){return(0,t.jsx)(p.Provider,{value:e.value,children:e.children})}},43023:function(e,n,a){a.d(n,{R:function(){return r},x:function(){return o}});var t=a(63696);let i={},l=t.createContext(i);function r(e){let n=t.useContext(l);return t.useMemo(function(){return"function"==typeof e?e(n):{...n,...e}},[n,e])}function o(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:r(e.components),t.createElement(l.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.