Browse Source

无jira fix:es6脚本修复一些问题

es6
Treecat 2 years ago
parent
commit
bda879d580
  1. 52
      es6.js

52
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);

Loading…
Cancel
Save