From 175bbf178b98dc54273487b40febd91ff6fd91b2 Mon Sep 17 00:00:00 2001 From: Treecat Date: Wed, 11 Jan 2023 16:58:20 +0800 Subject: [PATCH] =?UTF-8?q?KERNEL-14076=20feat:=E6=8A=8A=20base=20?= =?UTF-8?q?=E9=87=8C=E9=9D=A2=E7=9A=84=E5=87=BD=E6=95=B0=E9=83=BD=E5=8A=A0?= =?UTF-8?q?=E8=BF=9B=E6=9D=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- es6.js | 102 ++++++++++++++++++++++++++++++--------------------------- 1 file changed, 54 insertions(+), 48 deletions(-) diff --git a/es6.js b/es6.js index 560f26f7d..c1f9d79ad 100644 --- a/es6.js +++ b/es6.js @@ -12,49 +12,49 @@ async function fix(path) { }); } +const target = [ + "isNull", + "toPix", + "isKey", + "isObject", + "map", + "extend", + "isFunction", + "isEmptyArray", + "isArray", + "Controller", + "createWidget", + "Events", + "emptyFn", + "nextTick", + "bind", + "i18nText", + "isNotNull", + "isString", + "isNumber", + "isEmpty", + "isEmptyString", + "any", + "deepContains", + "isNotEmptyString", + "each", + "contains", + "remove", + "createItems", + "makeArrayByArray", +]; + // 加载模块 const loader = { G: { "@/core": { shortcut: true } }, async load(srcName, module) { const G = loader.G; - const target = [ - "isNull", - "toPix", - "isKey", - "isObject", - "map", - "extend", - "isFunction", - "isEmptyArray", - "isArray", - "Controller", - "createWidget", - "Events", - "emptyFn", - "nextTick", - "bind", - "i18nText", - "isNotNull", - "isString", - "isNumber", - "isEmpty", - "isEmptyString", - "any", - "deepContains", - "isNotEmptyString", - "each", - "contains", - "remove", - "createItems", - "makeArrayByArray", - ]; - console.log(module); if (target.indexOf(module) >= 0) { G["@/core"][module] = true; - + return true; } - + const key = search(srcName, module); if (key) { if (!G[key]) { @@ -67,7 +67,6 @@ const loader = { }, }; - async function handleFile(srcName) { const G = loader.G; @@ -83,8 +82,6 @@ async function handleFile(srcName) { const superName = /inherit\(BI\.(.*?),/.exec(sourceCode)[1]; - - // const xtype = /BI.shortcut\(\"(.*?)\"/.exec(sourceCode)[1]; const collection = { @@ -134,15 +131,17 @@ async function handleFile(srcName) { collection.methods.forEach(el => { let f = `${el.toString().replace(/^function/, el.name)}\n`; - // 换 BI.Button.superclass - f = f.replace(`BI.${clzName}.superclass`, "super"); + // 换 BI.Button.superclass,就说能不能跑吧 + for (let i = 0; i < 100; i++) { + f = f.replace(`BI.${clzName}.superclass`, "super"); + } // 换 super._defaultConfig f = f.replace( /super\._defaultConfig\.apply\(this,\sarguments\)/g, - "super._defaultConfig(arguments)" + "super._defaultConfig(...arguments)" ); // 换 super.xxx.apply - f = f.replace(/super\.(.*?)\.apply\(this,\sarguments\)/, a => { + f = f.replace(/super\.(.*?)\.apply\(this,\sarguments\)/g, a => { const f = /super\.(.*?)\.apply\(this,\sarguments\)/.exec(a); return `super.${f[1]}(...arguments)`; @@ -159,7 +158,7 @@ async function handleFile(srcName) { return target + end; } else { console.log(`加载 ${target}失败`); - + return matchedSentence; } }); @@ -167,9 +166,6 @@ async function handleFile(srcName) { M += `${f}\n`; }); - - - Object.keys(G).forEach(moduleKey => { if (moduleKey === path.basename(srcName).replace(/.js$/g, "")) { return; @@ -181,7 +177,6 @@ async function handleFile(srcName) { I += `import {${i}} from '${moduleKey}'\n`; }); - const outputCode = ` ${I} @@ -233,7 +228,18 @@ async function traverse(srcName) { const srcName = process.argv[2]; initDepts().then(() => { + const content = fs.readFileSync("src/core/2.base.js").toString(); + + let result = content.match(/export function (.*?)\(/g); + target.push( + ...result.map(el => + el.replace("export function ", "").replace("(", "") + ) + ); + result = content.match(/export const (.*?) =/g); + target.push( + ...result.map(el => el.replace("export const ", "").replace(" =", "")) + ); + traverse(srcName); }); - -