PageSourceSearch

https://babeljs.io/assets/js/89dd7445.5694f033.js

js babeljs.io collected 2026-09-24 06:54:43 UTC 9,723 bytes, 2 lines download raw bytes

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