Browse Source

KERNEL-14076 feat:把 base 里面的函数都加进来

es6
Treecat 2 years ago
parent
commit
175bbf178b
  1. 96
      es6.js

96
es6.js

@ -12,43 +12,43 @@ 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 = { const loader = {
G: { "@/core": { shortcut: true } }, G: { "@/core": { shortcut: true } },
async load(srcName, module) { async load(srcName, module) {
const G = loader.G; 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) { if (target.indexOf(module) >= 0) {
G["@/core"][module] = true; G["@/core"][module] = true;
@ -67,7 +67,6 @@ const loader = {
}, },
}; };
async function handleFile(srcName) { async function handleFile(srcName) {
const G = loader.G; const G = loader.G;
@ -83,8 +82,6 @@ async function handleFile(srcName) {
const superName = /inherit\(BI\.(.*?),/.exec(sourceCode)[1]; const superName = /inherit\(BI\.(.*?),/.exec(sourceCode)[1];
// const xtype = /BI.shortcut\(\"(.*?)\"/.exec(sourceCode)[1]; // const xtype = /BI.shortcut\(\"(.*?)\"/.exec(sourceCode)[1];
const collection = { const collection = {
@ -134,15 +131,17 @@ async function handleFile(srcName) {
collection.methods.forEach(el => { collection.methods.forEach(el => {
let f = `${el.toString().replace(/^function/, el.name)}\n`; let f = `${el.toString().replace(/^function/, el.name)}\n`;
// 换 BI.Button.superclass // 换 BI.Button.superclass,就说能不能跑吧
f = f.replace(`BI.${clzName}.superclass`, "super"); for (let i = 0; i < 100; i++) {
f = f.replace(`BI.${clzName}.superclass`, "super");
}
// 换 super._defaultConfig // 换 super._defaultConfig
f = f.replace( f = f.replace(
/super\._defaultConfig\.apply\(this,\sarguments\)/g, /super\._defaultConfig\.apply\(this,\sarguments\)/g,
"super._defaultConfig(arguments)" "super._defaultConfig(...arguments)"
); );
// 换 super.xxx.apply // 换 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); const f = /super\.(.*?)\.apply\(this,\sarguments\)/.exec(a);
return `super.${f[1]}(...arguments)`; return `super.${f[1]}(...arguments)`;
@ -167,9 +166,6 @@ async function handleFile(srcName) {
M += `${f}\n`; M += `${f}\n`;
}); });
Object.keys(G).forEach(moduleKey => { Object.keys(G).forEach(moduleKey => {
if (moduleKey === path.basename(srcName).replace(/.js$/g, "")) { if (moduleKey === path.basename(srcName).replace(/.js$/g, "")) {
return; return;
@ -181,7 +177,6 @@ async function handleFile(srcName) {
I += `import {${i}} from '${moduleKey}'\n`; I += `import {${i}} from '${moduleKey}'\n`;
}); });
const outputCode = ` const outputCode = `
${I} ${I}
@ -233,7 +228,18 @@ async function traverse(srcName) {
const srcName = process.argv[2]; const srcName = process.argv[2];
initDepts().then(() => { 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); traverse(srcName);
}); });

Loading…
Cancel
Save