fyk_loudspeaker_box/loaders/injectComponent/taro-inject-component-loader.cjs.production.min.js

3 lines
4.6 KiB
JavaScript
Raw Normal View History

2025-04-16 18:15:18 +08:00
"use strict";function e(e){return e&&"object"==typeof e&&"default"in e?e.default:e}Object.defineProperty(exports,"__esModule",{value:!0});var n=e(require("@babel/generator")),t=e(require("@babel/traverse")),o=e(require("@babel/types")),i=require("@babel/parser"),r=require("loader-utils"),a=require("schema-utils"),d={type:"object",properties:{importPath:{type:"string"},isPage:{instanceof:"Function"},componentName:{type:"string"}},additionalProperties:!1};function l(e){return o.jSXElement(o.jSXOpeningElement(o.jsxIdentifier(""+e),[],!0),null,[],!0)}function p(e,n,t){var i,r,a,d,p,c,s,u;"ReturnStatement"===(null==e?void 0:e.type)&&("createElement"!==(null==(i=e.argument)||null==(r=i.callee)||null==(a=r.property)?void 0:a.name)||t.importedComponent||(t.importedComponent=!0,e.argument.arguments.push((p=n,c=o.identifier("React"),s=o.identifier("createElement"),u=o.memberExpression(c,s),o.callExpression(u,[o.identifier(p)])))),"JSXElement"!==(null==(d=e.argument)?void 0:d.type)||t.importedComponent||(t.importedComponent=!0,e.argument.children.push(l(n)))),"JSXElement"!==e.type||t.importedComponent||(t.importedComponent=!0,e.children.push(l(n)))}function c(e){var n=e.replace(/\\/g,"/");return/(package-.+\/)?pages\/[A-Za-z0-9-]+\/index\.[tj]sx$/.test(n)}exports.default=function(e){var l=r.getOptions(this);a.validate(d,l,{name:"taro-inject-component-loader"});var s=l||{},u=s.importPath,m=void 0===u?"":u,y=s.componentName,f=void 0===y?"WebpackInjected":y,v=s.isPage,b=void 0===v?c:v,g=this.resourcePath;if("function"==typeof b&&b(g)){var h=i.parse(e,{sourceType:"module",plugins:["jsx","typescript","classProperties"]}),x=!1,D=new Map;if(t(h,{ImportDeclaration:function(e){e.node.source.value===m&&(x=!0)},ClassDeclaration:function(e){"Program"===e.parent.type&&D.set(e.node.id.name,e.node.type)},FunctionDeclaration:function(e){var n;if("Program"===e.parent.type){var t=null==(n=e.node.id)?void 0:n.name;t&&D.set(t,e.node.type)}},VariableDeclaration:function(e){"Program"===e.parent.type&&e.node.declarations.forEach((function(e){var n,t,o;if("ArrowFunctionExpression"===(null==(n=e.init)?void 0:n.type)){var i,r,a=null==(i=e.init)?void 0:i.type,d=null==(r=e.id)?void 0:r.name;D.set(d,a)}"FunctionExpression"===(null==(t=e.init)?void 0:t.type)&&D.set(e.id.name,e.init.type),"ClassExpression"===(null==(o=e.init)?void 0:o.type)&&D.set(e.id.name,e.init.type)}))}}),!x){var E={importedDeclaration:!1,importedComponent:!1};t(h,{ImportDeclaration:function(e){E.importedDeclaration||(E.importedDeclaration=!0,e.insertBefore(o.importDeclaration([o.importDefaultSpecifier(o.identifier(""+f))],o.stringLiteral(""+m))))},ExportDefaultDeclaration:function(e){if("FunctionDeclaration"===e.node.declaration.type){var n=e.node.declaration.body.body;p(n[n.length-1],""+f,E)}if("ArrowFunctionExpression"===e.node.declaration.type)if("BlockStatement"===e.node.declaration.body.type){var o=e.node.declaration.body.body;p(o[o.length-1],""+f,E)}else p(e.node.declaration.body,""+f,E);if("ClassDeclaration"===e.node.declaration.type&&t(e.node,{ClassMethod:function(e){if("render"!==e.node.key.name);else{var n=e.node.body.body||[];p(n[n.length-1],""+f,E)}}},e.scope,e),"Identifier"===e.node.declaration.type){var i=e.node.declaration.name,r=D.get(i);t(e.parent,{FunctionDeclaration:function(e){var n,t,o;if((null==(n=e.node.id)?void 0:n.name)===i){var r=null==(t=e.node)||null==(o=t.body)?void 0:o.body;p(r[r.length-1],""+f,E)}},ClassDeclaration:function(e){e.node.id.name===i&&t(e.node,{ClassMethod:function(e){var n;if("render"===(null==(n=e.node.key)?void 0:n.name)){var t=e.node.body.body||[];p(t[t.length-1],""+f,E)}}},e.scope,e)},VariableDeclarator:function(e){if("Identifier"===e.node.id.type&&e.node.id.name===i&&e.node.init&&e.node.init.type===r){if("FunctionExpression"===e.node.init.type){var n=e.node.init.body.body;p(n[n.length-1],""+f,E)}if("ClassExpression"===e.node.init.type&&t(e.node,{ClassMethod:function(e){if("render"===e.node.key.name){var n=e.node.body.body||[];p(n[n.length-1],""+f,E)}}},e.scope,e),"ArrowFunctionExpression"===e.node.init.type)if("BlockStatement"==e.node.init.b
//# sourceMappingURL=taro-inject-component-loader.cjs.production.min.js.map