MCPcopy
hub / github.com/vercel/next.js / constructor

Function constructor

packages/next/src/compiled/babel-packages/packages-bundle.js:316–318  ·  view source on GitHub ↗
(e,r)

Source from the content-addressed store, hash-verified

314 ${c} = ${this.addHelper(i)}(${l})
315 )
316 `,...t.expressions]))},TemplateLiteral(e){if(e.parent.type==="TSLiteralType"){return}const r=[];const t=e.get("expressions");let s=0;for(const n of e.node.quasis){if(n.value.cooked){r.push(a.types.stringLiteral(n.value.cooked))}if(s<t.length){const e=t[s++];const n=e.node;if(!a.types.isStringLiteral(n,{value:""})){r.push(n)}}}if(!a.types.isStringLiteral(r[0])&&!(n&&a.types.isStringLiteral(r[1]))){r.unshift(a.types.stringLiteral(""))}let o=r[0];if(n){for(let e=1;e<r.length;e++){o=a.types.binaryExpression("+",o,r[e])}}else if(r.length>1){o=buildConcatCallExpressions(r)}e.replaceWith(o)}}}}))},4767:(e,r,t)=>{"use strict";Object.defineProperty(r,"__esModule",{value:true});r["default"]=void 0;var s=t(9045);var a=t(8304);var n=r["default"]=(0,s.declare)((e=>{e.assertVersion(7);return{name:"transform-typeof-symbol",visitor:{Scope({scope:e}){if(!e.getBinding("Symbol")){return}e.rename("Symbol")},UnaryExpression(e){const{node:r,parent:t}=e;if(r.operator!=="typeof")return;if(e.parentPath.isBinaryExpression()&&a.types.EQUALITY_BINARY_OPERATORS.includes(t.operator)){const r=e.getOpposite();if(r.isStringLiteral()&&r.node.value!=="symbol"&&r.node.value!=="object"){return}}let s=e.findParent((e=>{if(e.isFunctionDeclaration()){var r;return((r=e.get("body.directives.0"))==null?void 0:r.node.value.value)==="@babel/helpers - typeof"}}));if(s)return;const n=this.addHelper("typeof");{s=e.findParent((e=>e.isVariableDeclarator()&&e.node.id===n||e.isFunctionDeclaration()&&e.node.id&&e.node.id.name===n.name));if(s){return}}const o=a.types.callExpression(n,[r.argument]);const i=e.get("argument");if(i.isIdentifier()&&!e.scope.hasBinding(i.node.name,true)){const t=a.types.unaryExpression("typeof",a.types.cloneNode(r.argument));e.replaceWith(a.types.conditionalExpression(a.types.binaryExpression("===",t,a.types.stringLiteral("undefined")),a.types.stringLiteral("undefined"),o))}else{e.replaceWith(o)}}}}}))},7077:(e,r,t)=>{"use strict";Object.defineProperty(r,"__esModule",{value:true});r.EXPORTED_CONST_ENUMS_IN_NAMESPACE=void 0;r["default"]=transpileConstEnum;var s=t(5886);const a=r.EXPORTED_CONST_ENUMS_IN_NAMESPACE=new WeakSet;function transpileConstEnum(e,r){const{name:t}=e.node.id;const n=e.parentPath.isExportNamedDeclaration();let o=n;if(!o&&r.isProgram(e.parent)){o=e.parent.body.some((e=>r.isExportNamedDeclaration(e)&&e.exportKind!=="type"&&!e.source&&e.specifiers.some((e=>r.isExportSpecifier(e)&&e.exportKind!=="type"&&e.local.name===t))))}const{enumValues:i}=(0,s.translateEnumValues)(e,r);if(o||a.has(e.node)){const s=r.objectExpression(i.map((([e,t])=>r.objectProperty(r.isValidIdentifier(e)?r.identifier(e):r.stringLiteral(e),t))));if(e.scope.hasOwnBinding(t)){(n?e.parentPath:e).replaceWith(r.expressionStatement(r.callExpression(r.memberExpression(r.identifier("Object"),r.identifier("assign")),[e.node.id,s])))}else{e.replaceWith(r.variableDeclaration("var",[r.variableDeclarator(e.node.id,s)]));e.scope.registerDeclaration(e)}return}const l=new Map(i);e.scope.path.traverse({Scope(e){if(e.scope.hasOwnBinding(t))e.skip()},MemberExpression(e){if(!r.isIdentifier(e.node.object,{name:t}))return;let s;if(e.node.computed){if(r.isStringLiteral(e.node.property)){s=e.node.property.value}else{return}}else if(r.isIdentifier(e.node.property)){s=e.node.property.name}else{return}if(!l.has(s))return;e.replaceWith(r.cloneNode(l.get(s)))}});e.remove()}},5886:(e,r,t)=>{"use strict";Object.defineProperty(r,"__esModule",{value:true});r["default"]=transpileEnum;r.isSyntacticallyString=isSyntacticallyString;r.translateEnumValues=translateEnumValues;var s=t(8304);var a=t(9491);var n=t(344);var o=t(9102);const i=new WeakMap;const l=s.template.expression(`\n (function (ID) {\n ASSIGNMENTS;\n return ID;\n })(INIT)\n `);function transpileEnum(e,r){const{node:t,parentPath:s}=e;if(t.declare){e.remove();return}const a=t.id.name;const{fill:o,data:c,isPure:d}=enumFill(e,r,t.id);switch(s.type){case"BlockStatement":case"ExportNamedDeclaration":case"Program":{const u=r.isProgram(e.parent);const p=seen(s);let f=r.objectExpression([]);if(p||u){f=r.logicalExpression("||",r.cloneNode(o.ID),f)}const y=l(Object.assign({},o,{INIT:f}));if(d)(0,n.default)(y);if(p){const a=s.isExportDeclaration()?s:e;a.replaceWith(r.expressionStatement(r.assignmentExpression("=",r.cloneNode(t.id),y)))}else{e.scope.registerDeclaration(e.replaceWith(r.variableDeclaration(u?"var":"let",[r.variableDeclarator(t.id,y)]))[0])}i.set(e.scope.getBindingIdentifier(a),c);break}default:throw new Error(`Unexpected enum parent '${e.parent.type}`)}function seen(e){if(e.isExportDeclaration()){return seen(e.parentPath)}if(e.getData(a)){return true}else{e.setData(a,true);return false}}}const c=s.template.statement(`\n ENUM["NAME"] = VALUE;\n`);const d=s.template.statement(`\n ENUM[ENUM["NAME"] = VALUE] = "NAME";\n`);const buildEnumMember=(e,r)=>(e?c:d)(r);function enumFill(e,r,t){const{enumValues:s,data:a,isPure:n}=translateEnumValues(e,r);const o=e.get("members");const i=[];for(let e=0;e<o.length;e++){const[a,n]=s[e];i.push(r.inheritsComments(buildEnumMember(isSyntacticallyString(n),{ENUM:r.cloneNode(t),NAME:a,VALUE:n}),o[e].node))}return{fill:{ID:r.cloneNode(t),ASSIGNMENTS:i},data:a,isPure:n}}function isSyntacticallyString(e){e=(0,o.skipTransparentExprWrapperNodes)(e);switch(e.type){case"BinaryExpression":{const r=e.left;const t=e.right;return e.operator==="+"&&(isSyntacticallyString(r)||isSyntacticallyString(t))}case"TemplateLiteral":case"StringLiteral":return true}return false}function ReferencedIdentifier(e,r){const{seen:t,path:s,t:a}=r;const n=e.node.name;if(t.has(n)){{for(let r=e.scope;r!==s.scope;r=r.parent){if(r.hasOwnBinding(n)){return}}}e.replaceWith(a.memberExpression(a.cloneNode(s.node.id),a.cloneNode(e.node)));e.skip()}}const u={ReferencedIdentifier:ReferencedIdentifier};function translateEnumValues(e,r){var t;const s=e.scope.getBindingIdentifier(e.node.id.name);const n=(t=i.get(s))!=null?t:new Map;let o=-1;let l;let c=true;const d=e.get("members");const p=d.map((t=>{const s=t.node;const i=r.isIdentifier(s.id)?s.id.name:s.id.value;const d=t.get("initializer");const p=s.initializer;let f;if(p){o=computeConstantValue(d,n);if(o!==undefined){n.set(i,o);a(typeof o==="number"||typeof o==="string");if(o===Infinity||Number.isNaN(o)){f=r.identifier(String(o))}else if(o===-Infinity){f=r.unaryExpression("-",r.identifier("Infinity"))}else{f=r.valueToNode(o)}}else{c&&(c=d.isPure());if(d.isReferencedIdentifier()){ReferencedIdentifier(d,{t:r,seen:n,path:e})}else{d.traverse(u,{t:r,seen:n,path:e})}f=d.node;n.set(i,undefined)}}else if(typeof o==="number"){o+=1;f=r.numericLiteral(o);n.set(i,o)}else if(typeof o==="string"){throw e.buildCodeFrameError("Enum member must have initializer.")}else{const t=r.memberExpression(r.cloneNode(e.node.id),r.stringLiteral(l),true);f=r.binaryExpression("+",r.numericLiteral(1),t);n.set(i,undefined)}l=i;return[i,f]}));return{isPure:c,data:n,enumValues:p}}function computeConstantValue(e,r,t=new Set){return evaluate(e);function evaluate(e){const s=e.node;switch(s.type){case"MemberExpression":return evaluateRef(e,r,t);case"StringLiteral":return s.value;case"UnaryExpression":return evalUnaryExpression(e);case"BinaryExpression":return evalBinaryExpression(e);case"NumericLiteral":return s.value;case"ParenthesizedExpression":return evaluate(e.get("expression"));case"Identifier":return evaluateRef(e,r,t);case"TemplateLiteral":{if(s.quasis.length===1){return s.quasis[0].value.cooked}const a=e.get("expressions");const n=s.quasis;let o="";for(let e=0;e<n.length;e++){o+=n[e].value.cooked;if(e+1<n.length){const s=evaluateRef(a[e],r,t);if(s===undefined)return undefined;o+=s}}return o}default:return undefined}}function evaluateRef(e,r,t){if(e.isMemberExpression()){const r=e.node;const t=r.object;const a=r.property;if(!s.types.isIdentifier(t)||(r.computed?!s.types.isStringLiteral(a):!s.types.isIdentifier(a))){return}const n=e.scope.getBindingIdentifier(t.name);const o=i.get(n);if(!o)return;return o.get(a.computed?a.value:a.name)}else if(e.isIdentifier()){const s=e.node.name;if(["Infinity","NaN"].includes(s)){return Number(s)}let a=r==null?void 0:r.get(s);if(a!==undefined){return a}if(r!=null&&r.has(s)){return undefined}if(t.has(e.node))return;t.add(e.node);a=computeConstantValue(e.resolve(),r,t);return a}}function evalUnaryExpression(e){const r=evaluate(e.get("argument"));if(r===undefined){return undefined}switch(e.node.operator){case"+":return r;case"-":return-r;case"~":return~r;default:return undefined}}function evalBinaryExpression(e){const r=evaluate(e.get("left"));if(r===undefined){return undefined}const t=evaluate(e.get("right"));if(t===undefined){return undefined}switch(e.node.operator){case"|":return r|t;case"&":return r&t;case">>":return r>>t;case">>>":return r>>>t;case"<<":return r<<t;case"^":return r^t;case"*":return r*t;case"/":return r/t;case"+":return r+t;case"-":return r-t;case"%":return r%t;case"**":return Math.pow(r,t);default:return undefined}}}},9878:(e,r)=>{"use strict";Object.defineProperty(r,"__esModule",{value:true});r.GLOBAL_TYPES=void 0;r.isGlobalType=isGlobalType;r.registerGlobalType=registerGlobalType;const t=r.GLOBAL_TYPES=new WeakMap;function isGlobalType({scope:e},r){if(e.hasBinding(r))return false;if(t.get(e).has(r))return true;console.warn(`The exported identifier "${r}" is not declared in Babel's scope tracker\n`+`as a JavaScript value binding, and "@babel/plugin-transform-typescript"\n`+`never encountered it as a TypeScript type declaration.\n`+`It will be treated as a JavaScript value.\n\n`+`This problem is likely caused by another plugin injecting\n`+`"${r}" without registering it in the scope tracker. If you are the author\n`+` of that plugin, please use "scope.registerDeclaration(declarationPath)".`);return false}function registerGlobalType(e,r){t.get(e).add(r)}},7687:(e,r,t)=>{"use strict";Object.defineProperty(r,"__esModule",{value:true});r["default"]=void 0;var s=t(9045);var a=t(8184);var n=t(3713);var o=t(7077);var i=t(5886);var l=t(9878);var c=t(723);function isInType(e){switch(e.parent.type){case"TSTypeReference":case"TSExpressionWithTypeArguments":case"TSExpressionWithTypeArguments":case"TSTypeQuery":return true;case"TSQualifiedName":return e.parentPath.findParent((e=>e.type!=="TSQualifiedName")).type!=="TSImportEqualsDeclaration";case"ExportSpecifier":return e.parent.exportKind==="type"||e.parentPath.parent.exportKind==="type";default:return false}}const d=new WeakMap;const u=new WeakSet;function safeRemove(e){const r=e.getBindingIdentifiers();for(const t of Object.keys(r)){const s=e.scope.getBinding(t);if(s&&s.identifier===r[t]){s.scope.removeBinding(t)}}e.opts.noScope=true;e.remove();e.opts.noScope=false}function assertCjsTransformEnabled(e,r,t,s,a=""){if(r.file.get("@babel/plugin-transform-modules-*")!=="commonjs"){throw e.buildCodeFrameError(`\`${t}\` is only supported when compiling modules to CommonJS.\n`+`Please consider using \`${s}\`${a}, or add `+`@babel/plugin-transform-modules-commonjs to your Babel config.`)}}var p=r["default"]=(0,s.declare)(((e,r)=>{const{types:t,template:s}=e;e.assertVersion(7);const p=/\*?\s*@jsx((?:Frag)?)\s+(\S+)/;const{allowNamespaces:f=true,jsxPragma:y="React.createElement",jsxPragmaFrag:g="React.Fragment",onlyRemoveTypeImports:h=false,optimizeConstEnums:b=false}=r;{var{allowDeclareFields:x=false}=r}const v={field(e){const{node:r}=e;{if(!x&&r.declare){throw e.buildCodeFrameError(`The 'declare' modifier is only allowed when the 'allowDeclareFields' option of `+`@babel/plugin-transform-typescript or @babel/preset-typescript is enabled.`)}}if(r.declare){if(r.value){throw e.buildCodeFrameError(`Fields with the 'declare' modifier cannot be initialized here, but only in the constructor`)}if(!r.decorators){e.remove()}}else if(r.definite){if(r.value){throw e.buildCodeFrameError(`Definitely assigned fields cannot be initialized here, but only in the constructor`)}{if(!x&&!r.decorators&&!t.isClassPrivateProperty(r)){e.remove()}}}else if(r.abstract){e.remove()}else{if(!x&&!r.value&&!r.decorators&&!t.isClassPrivateProperty(r)){e.remove()}}if(r.accessibility)r.accessibility=null;if(r.abstract)r.abstract=null;if(r.readonly)r.readonly=null;if(r.optional)r.optional=null;if(r.typeAnnotation)r.typeAnnotation=null;if(r.definite)r.definite=null;if(r.declare)r.declare=null;if(r.override)r.override=null},method({node:e}){if(e.accessibility)e.accessibility=null;if(e.abstract)e.abstract=null;if(e.optional)e.optional=null;if(e.override)e.override=null},constructor(e,r){if(e.node.accessibility)e.node.accessibility=null;const a=[];const{scope:o}=e;for(const r of e.get("params")){const e=r.node;if(e.type==="TSParameterProperty"){const n=e.parameter;if(u.has(n))continue;u.add(n);let i;if(t.isIdentifier(n)){i=n}else if(t.isAssignmentPattern(n)&&t.isIdentifier(n.left)){i=n.left}else{throw r.buildCodeFrameError("Parameter properties can not be destructuring patterns.")}a.push(s.statement.ast`
317 this.${t.cloneNode(i)} = ${t.cloneNode(i)}
318 `);r.replaceWith(r.get("parameter"));o.registerBinding("param",r)}}(0,n.injectInitialization)(r,e,a)}};return{name:"transform-typescript",inherits:a.default,visitor:{Pattern:visitPattern,Identifier:visitPattern,RestElement:visitPattern,Program:{enter(e,r){const{file:t}=r;let s=null;let a=null;const n=e.scope;if(!l.GLOBAL_TYPES.has(n)){l.GLOBAL_TYPES.set(n,new Set)}if(t.ast.comments){for(const e of t.ast.comments){const r=p.exec(e.value);if(r){if(r[1]){a=r[2]}else{s=r[2]}}}}let o=s||y;if(o){[o]=o.split(".")}let i=a||g;if(i){[i]=i.split(".")}for(let t of e.get("body")){if(t.isImportDeclaration()){if(!d.has(r.file.ast.program)){d.set(r.file.ast.program,true)}if(t.node.importKind==="type"){for(const e of t.node.specifiers){(0,l.registerGlobalType)(n,e.local.name)}t.remove();continue}const s=new Set;const a=t.node.specifiers.length;const isAllSpecifiersElided=()=>a>0&&a===s.size;for(const e of t.node.specifiers){if(e.type==="ImportSpecifier"&&e.importKind==="type"){(0,l.registerGlobalType)(n,e.local.name);const r=t.scope.getBinding(e.local.name);if(r){s.add(r.path)}}}if(h){d.set(e.node,false)}else{if(t.node.specifiers.length===0){d.set(e.node,false);continue}for(const r of t.node.specifiers){const a=t.scope.getBinding(r.local.name);if(a&&!s.has(a.path)){if(isImportTypeOnly({binding:a,programPath:e,pragmaImportName:o,pragmaFragImportName:i})){s.add(a.path)}else{d.set(e.node,false)}}}}if(isAllSpecifiersElided()&&!h){t.remove()}else{for(const e of s){e.remove()}}continue}if(!h&&t.isTSImportEqualsDeclaration()){const{id:r}=t.node;const s=t.scope.getBinding(r.name);if(s&&!t.node.isExport&&isImportTypeOnly({binding:s,programPath:e,pragmaImportName:o,pragmaFragImportName:i})){t.remove();continue}}if(t.isExportDeclaration()){t=t.get("declaration")}if(t.isVariableDeclaration({declare:true})){for(const e of Object.keys(t.getBindingIdentifiers())){(0,l.registerGlobalType)(n,e)}}else if(t.isTSTypeAliasDeclaration()||t.isTSDeclareFunction()&&t.get("id").isIdentifier()||t.isTSInterfaceDeclaration()||t.isClassDeclaration({declare:true})||t.isTSEnumDeclaration({declare:true})||t.isTSModuleDeclaration({declare:true})&&t.get("id").isIdentifier()){(0,l.registerGlobalType)(n,t.node.id.name)}}},exit(e){if(e.node.sourceType==="module"&&d.get(e.node)){e.pushContainer("body",t.exportNamedDeclaration())}}},ExportNamedDeclaration(e,r){if(!d.has(r.file.ast.program)){d.set(r.file.ast.program,true)}if(e.node.exportKind==="type"){e.remove();return}if(e.node.source&&e.node.specifiers.length>0&&e.node.specifiers.every((e=>e.type==="ExportSpecifier"&&e.exportKind==="type"))){e.remove();return}if(!e.node.source&&e.node.specifiers.length>0&&e.node.specifiers.every((r=>t.isExportSpecifier(r)&&(0,l.isGlobalType)(e,r.local.name)))){e.remove();return}if(t.isTSModuleDeclaration(e.node.declaration)){const r=e.node.declaration;if(!t.isStringLiteral(r.id)){const s=(0,c.getFirstIdentifier)(r.id);if(e.scope.hasOwnBinding(s.name)){e.replaceWith(r)}else{const[a]=e.replaceWithMultiple([t.exportNamedDeclaration(t.variableDeclaration("let",[t.variableDeclarator(t.cloneNode(s))])),r]);e.scope.registerDeclaration(a)}}}d.set(r.file.ast.program,false)},ExportAllDeclaration(e){if(e.node.exportKind==="type")e.remove()},ExportSpecifier(e){const r=e.parent;if(!r.source&&(0,l.isGlobalType)(e,e.node.local.name)||e.node.exportKind==="type"){e.remove()}},ExportDefaultDeclaration(e,r){if(!d.has(r.file.ast.program)){d.set(r.file.ast.program,true)}if(t.isIdentifier(e.node.declaration)&&(0,l.isGlobalType)(e,e.node.declaration.name)){e.remove();return}d.set(r.file.ast.program,false)},TSDeclareFunction(e){safeRemove(e)},TSDeclareMethod(e){safeRemove(e)},VariableDeclaration(e){if(e.node.declare){safeRemove(e)}},VariableDeclarator({node:e}){if(e.definite)e.definite=null},TSIndexSignature(e){e.remove()},ClassDeclaration(e){const{node:r}=e;if(r.declare){safeRemove(e)}},Class(e){const{node:r}=e;if(r.typeParameters)r.typeParameters=null;{if(r.superTypeParameters)r.superTypeParameters=null}if(r.implements)r.implements=null;if(r.abstract)r.abstract=null;e.get("body.body").forEach((r=>{if(r.isClassMethod()||r.isClassPrivateMethod()){if(r.node.kind==="constructor"){v.constructor(r,e)}else{v.method(r)}}else if(r.isClassProperty()||r.isClassPrivateProperty()||r.isClassAccessorProperty()){v.field(r)}}))},Function(e){const{node:r}=e;if(r.typeParameters)r.typeParameters=null;if(r.returnType)r.returnType=null;const s=r.params;if(s.length>0&&t.isIdentifier(s[0],{name:"this"})){s.shift()}},TSModuleDeclaration(e){(0,c.default)(e,f)},TSInterfaceDeclaration(e){e.remove()},TSTypeAliasDeclaration(e){e.remove()},TSEnumDeclaration(e){if(b&&e.node.const){(0,o.default)(e,t)}else{(0,i.default)(e,t)}},TSImportEqualsDeclaration(e,r){const{id:s,moduleReference:a}=e.node;let n;let o;if(t.isTSExternalModuleReference(a)){assertCjsTransformEnabled(e,r,`import ${s.name} = require(...);`,`import ${s.name} from '...';`," alongside Typescript's --allowSyntheticDefaultImports option");n=t.callExpression(t.identifier("require"),[a.expression]);o="const"}else{n=entityNameToExpr(a);o="var"}const i=t.variableDeclaration(o,[t.variableDeclarator(s,n)]);{e.replaceWith(e.node.isExport?t.exportNamedDeclaration(i):i)}e.scope.registerDeclaration(e)},TSExportAssignment(e,r){assertCjsTransformEnabled(e,r,`export = <value>;`,`export default <value>;`);e.replaceWith(s.statement.ast`module.exports = ${e.node.expression}`)},TSTypeAssertion(e){e.replaceWith(e.node.expression)},[`TSAsExpression${t.tsSatisfiesExpression?"|TSSatisfiesExpression":""}`](e){let{node:r}=e;do{r=r.expression}while(t.isTSAsExpression(r)||t.isTSSatisfiesExpression!=null&&t.isTSSatisfiesExpression(r));e.replaceWith(r)},[e.types.tsInstantiationExpression?"TSNonNullExpression|TSInstantiationExpression":"TSNonNullExpression"](e){e.replaceWith(e.node.expression)},CallExpression(e){{e.node.typeParameters=null}},OptionalCallExpression(e){{e.node.typeParameters=null}},NewExpression(e){{e.node.typeParameters=null}},JSXOpeningElement(e){{e.node.typeParameters=null}},TaggedTemplateExpression(e){{e.node.typeParameters=null}}}};function entityNameToExpr(e){if(t.isTSQualifiedName(e)){return t.memberExpression(entityNameToExpr(e.left),e.right)}return e}function visitPattern({node:e}){if(e.typeAnnotation)e.typeAnnotation=null;if(t.isIdentifier(e)&&e.optional)e.optional=null}function isImportTypeOnly({binding:e,programPath:r,pragmaImportName:t,pragmaFragImportName:s}){for(const r of e.referencePaths){if(!isInType(r)){return false}}if(e.identifier.name!==t&&e.identifier.name!==s){return true}let a=false;r.traverse({"JSXElement|JSXFragment"(e){a=true;e.stop()}});return!a}}))},723:(e,r,t)=>{"use strict";Object.defineProperty(r,"__esModule",{value:true});r["default"]=transpileNamespace;r.getFirstIdentifier=getFirstIdentifier;var s=t(8304);var a=t(9878);var n=t(7077);function getFirstIdentifier(e){if(s.types.isIdentifier(e)){return e}return getFirstIdentifier(e.left)}function transpileNamespace(e,r){if(e.node.declare||e.node.id.type==="StringLiteral"){e.remove();return}if(!r){throw e.get("id").buildCodeFrameError("Namespace not marked type-only declare."+" Non-declarative namespaces are only supported experimentally in Babel."+" To enable and review caveats see:"+" https://babeljs.io/docs/en/babel-plugin-transform-typescript")}const t=getFirstIdentifier(e.node.id).name;const s=handleNested(e,e.node);if(s===null){const r=e.findParent((e=>e.isProgram()));(0,a.registerGlobalType)(r.scope,t);e.remove()}else if(e.scope.hasOwnBinding(t)){e.replaceWith(s)}else{e.scope.registerDeclaration(e.replaceWithMultiple([getDeclaration(t),s])[0])}}function getDeclaration(e){return s.types.variableDeclaration("let",[s.types.variableDeclarator(s.types.identifier(e))])}function getMemberExpression(e,r){return s.types.memberExpression(s.types.identifier(e),s.types.identifier(r))}function handleVariableDeclaration(e,r,t){if(e.kind!=="const"){throw t.file.buildCodeFrameError(e,"Namespaces exporting non-const are not supported by Babel."+" Change to const or see:"+" https://babeljs.io/docs/en/babel-plugin-transform-typescript")}const{declarations:a}=e;if(a.every((e=>s.types.isIdentifier(e.id)))){for(const e of a){e.init=s.types.assignmentExpression("=",getMemberExpression(r,e.id.name),e.init)}return[e]}const n=s.types.getBindingIdentifiers(e);const o=[];for(const e in n){o.push(s.types.assignmentExpression("=",getMemberExpression(r,e),s.types.cloneNode(n[e])))}return[e,s.types.expressionStatement(s.types.sequenceExpression(o))]}function buildNestedAmbientModuleError(e,r){return e.hub.buildError(r,"Ambient modules cannot be nested in other modules or namespaces.",Error)}function handleNested(e,r,t){const a=new Set;const o=r.id;const i=e.scope.generateUid(o.name);const l=r.body;let c=r.id;let d;{d=s.types.isTSModuleBlock(l)?l.body:[s.types.exportNamedDeclaration(l)]}let u=true;for(let r=0;r<d.length;r++){const t=d[r];switch(t.type){case"TSModuleDeclaration":{if(!s.types.isIdentifier(t.id)){throw buildNestedAmbientModuleError(e,t)}const n=handleNested(e,t);if(n!==null){u=false;const e=t.id.name;if(a.has(e)){d[r]=n}else{a.add(e);d.splice(r++,1,getDeclaration(e),n)}}continue}case"TSEnumDeclaration":case"FunctionDeclaration":case"ClassDeclaration":u=false;a.add(t.id.name);continue;case"VariableDeclaration":{u=false;for(const e in s.types.getBindingIdentifiers(t)){a.add(e)}continue}default:u&&(u=s.types.isTypeScript(t));continue;case"ExportNamedDeclaration":}if("declare"in t.declaration&&t.declaration.declare){continue}switch(t.declaration.type){case"TSEnumDeclaration":n.EXPORTED_CONST_ENUMS_IN_NAMESPACE.add(t.declaration);case"FunctionDeclaration":case"ClassDeclaration":{u=false;const e=t.declaration.id.name;a.add(e);d.splice(r++,1,t.declaration,s.types.expressionStatement(s.types.assignmentExpression("=",getMemberExpression(i,e),s.types.identifier(e))));break}case"VariableDeclaration":{u=false;const s=handleVariableDeclaration(t.declaration,i,e.hub);d.splice(r,s.length,...s);r+=s.length-1;break}case"TSModuleDeclaration":{if(!s.types.isIdentifier(t.declaration.id)){throw buildNestedAmbientModuleError(e,t.declaration)}const n=handleNested(e,t.declaration,s.types.identifier(i));if(n!==null){u=false;const e=t.declaration.id.name;if(a.has(e)){d[r]=n}else{a.add(e);d.splice(r++,1,getDeclaration(e),n)}}else{d.splice(r,1);r--}}}}if(u)return null;let p=s.types.objectExpression([]);if(t){const e=s.types.memberExpression(t,o);p=s.template.expression.ast`
319 ${s.types.cloneNode(e)} ||
320 (${s.types.cloneNode(e)} = ${p})
321 `}return s.template.statement.ast`

Callers

nothing calls this directly

Calls 8

isIdentifierMethod · 0.80
replaceWithMethod · 0.80
registerBindingMethod · 0.80
getMethod · 0.65
pushMethod · 0.65
hasMethod · 0.45
addMethod · 0.45
buildCodeFrameErrorMethod · 0.45

Tested by

no test coverage detected