From bda879d580613b74ed998f34d07e89332bc257ef Mon Sep 17 00:00:00 2001 From: Treecat Date: Tue, 10 Jan 2023 20:41:28 +0800 Subject: [PATCH] =?UTF-8?q?=E6=97=A0jira=20fix:es6=E8=84=9A=E6=9C=AC?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=B8=80=E4=BA=9B=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- es6.js | 52 ++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 36 insertions(+), 16 deletions(-) diff --git a/es6.js b/es6.js index 665270440..d2be104d0 100644 --- a/es6.js +++ b/es6.js @@ -11,17 +11,26 @@ const superName = /inherit\(BI\.(.*?),/.exec(sourceCode)[1]; // const xtype = /BI.shortcut\(\"(.*?)\"/.exec(sourceCode)[1]; const collection = { - static: {} + "static": {}, + attr: {}, }; const BI = { inherit(_, options) { - collection.methods = Object.keys(options).map((key) => options[key]); + collection.methods = Object.keys(options) + .filter(key => typeof options[key] === "function") + .map(key => options[key]); + Object.keys(options) + .filter(key => typeof options[key] !== "function") + .forEach(key => { + collection.attr[key] = options[key]; + }); + return collection.static; }, shortcut(xtype) { collection.xtype = xtype; - } + }, }; eval(sourceCode); @@ -29,24 +38,28 @@ eval(sourceCode); let M = ""; let E = ""; let I = ""; +let A = ""; const coreImport = { - shortcut: true + shortcut: true, }; if (superName === "Widget") { coreImport.Widget = true; } +Object.keys(collection.attr).forEach(key => { + A = `${key} = ${JSON.stringify(collection.attr[key])};`; +}); + // 静态方法 -Object.keys(collection.static).forEach((key) => { +Object.keys(collection.static).forEach(key => { E += `\tstatic ${key} = "${collection.static[key]}"\n`; }); // 对函数进行替换 -collection.methods.forEach((el) => { - let f = el.toString().replace(/^function/, el.name) + "\n"; - +collection.methods.forEach(el => { + let f = `${el.toString().replace(/^function/, el.name)}\n`; // 换 BI.Button.superclass f = f.replace(`BI.${clzName}.superclass`, "super"); @@ -56,8 +69,9 @@ collection.methods.forEach((el) => { "super._defaultConfig(arguments)" ); // 换 super.xxx.apply - f = f.replace(/super\.(.*?)\.apply\(this\,\sarguments\)/, (a) => { + f = f.replace(/super\.(.*?)\.apply\(this\,\sarguments\)/, a => { const f = /super\.(.*?)\.apply\(this\,\sarguments\)/.exec(a); + return `super.${f[1]}(...arguments)`; }); @@ -70,23 +84,26 @@ collection.methods.forEach((el) => { "extend", "isFunction", "isEmptyArray", - "isArray" + "isArray", + "Controller", + clzName, + "createWidget", + "Events", ]; - target.forEach((t) => { + target.forEach(t => { const arr = f.split(`BI.${t}`); // nodejs 低版本没有 replaceAll if (arr.length > 1) { - coreImport[t] = true; + if (t !== clzName) coreImport[t] = true; f = arr.join(t); } - }); - M += f; + M += `${f}\n`; }); -Object.keys(coreImport).forEach((el) => { +Object.keys(coreImport).forEach(el => { I += `${el},`; }); @@ -97,10 +114,13 @@ import {${I}} from "@/core" export class ${clzName} extends ${superName} { \tstatic xtype = "${collection.xtype}" +${A} + ${E} ${M} } `; -fs.writeFileSync(srcName + ".js", outputCode); +// fs.writeFileSync(`${srcName}.js.raw`, sourceCode); +fs.writeFileSync(srcName, outputCode);