feat: wcc,wcsc编译器template解析支持

This commit is contained in:
msojocs 2022-04-24 11:24:22 +08:00
parent c9fcf1d8c8
commit 7ee2b2818d
16 changed files with 4719 additions and 143 deletions

View File

@ -1,5 +1,7 @@
# 1.05.2204180-1 / 2022- # 1.05.2204180-1 / 2022-
- update: devtools 1.05.2204180 - update: devtools 1.05.2204180
- update: 跟进更新 wcc,wcsc node模块逻辑
- feat: wcc,wcsc编译器template解析支持
# 1.05.2203070-10 / 2022-04-22 # 1.05.2203070-10 / 2022-04-22
- fix: 修正命令行入口 - fix: 修正命令行入口

View File

@ -1,6 +1,6 @@
#!/usr/bin/env node #!/usr/bin/env node
// wcc.exe md5 = "dbb9ed8bdee6654460dafc618f9622f3" // wcc.exe md5 = "0634f39da88890439a92351ce102efd9"
const version = "20220310"; const version = "20220424";
const { spawn } = require("child_process"); const { spawn } = require("child_process");
const path = require("path"); const path = require("path");
const fs = require("fs"); const fs = require("fs");
@ -16,7 +16,7 @@ const FUNC_PREFIX = `=function(_,_v,_n,_p,_s,_wp,_wl,$gwn,$gwl,$gwh,wh,$gstack,$
function parseDeps(source, x, pageConfig){ function parseDeps(source, x, pageConfig){
// 插入引用信息 // 插入引用信息
let dep_x = `var x=['`; let dep_x = `var x=[`;
let dep_gz = ""; let dep_gz = "";
let dep_d_ = ""; let dep_d_ = "";
let t_x = []; let t_x = [];
@ -92,7 +92,8 @@ function parseDeps(source, x, pageConfig){
) + "\n"; ) + "\n";
i++; i++;
} }
dep_x += `${t_x.join("','")}'];`; dep_x += t_x.length > 0 ? `'${t_x.join("','")}'` : '';
dep_x += `];`;
return { return {
dep_x, dep_x,
dep_gz, dep_gz,
@ -109,6 +110,13 @@ function genFunctionContent_LLW(wxmlName, config = {}, source, x) {
"var cs = cs || [];" + "var cs = cs || [];" +
cs[1].replace(new RegExp(`\\${funcName}`, "g"), config.funcName); cs[1].replace(new RegExp(`\\${funcName}`, "g"), config.funcName);
// template 检测 模板处理位于二者之间: d_[x[index]]={} ---{template}-- var m0; x[index]中index为wxml在x数组中的索引, m0中数字为当前函数代码
const templateReg = source.match(new RegExp(`d_\\[x\\[${x.indexOf(`./${wxmlName}.wxml`)}\\]\\]=\\{\\}\n([\\s\\S]*?)\nvar m${config.num}=`))
if(templateReg)
DEBUG_OUTPUT && process.stderr.write(templateReg[1] + '\n------\n')
else
DEBUG_OUTPUT && process.stderr.write('无匹配\n------\n')
// gz函数 // gz函数
const exp = `function gz\\${funcName}_${ const exp = `function gz\\${funcName}_${
config.num + 1 config.num + 1
@ -152,6 +160,10 @@ function genFunctionContent_LLW(wxmlName, config = {}, source, x) {
} }
} }
content += `];d_[x[0]]={}\u000a`; content += `];d_[x[0]]={}\u000a`;
templateReg && (content += templateReg[1].replace(
new RegExp(`\\${funcName}\\_\\d+`, "g"),
`${config.funcName}_1`
) + '\n')
m0_str = m0_str.replace(new RegExp(`x\\[${config.num}\\]`, "g"), "x[0]"); m0_str = m0_str.replace(new RegExp(`x\\[${config.num}\\]`, "g"), "x[0]");
content += m0_str.replace( content += m0_str.replace(
new RegExp(`\\${funcName}\\_\\d+`, "g"), new RegExp(`\\${funcName}\\_\\d+`, "g"),
@ -221,9 +233,17 @@ function genFunctionContent_LLA(wxmlName, config = {}, source, x) {
"var cs = cs || [];" + "var cs = cs || [];" +
cs[1].replace(new RegExp(`\\${funcName}`, "g"), config.funcName); cs[1].replace(new RegExp(`\\${funcName}`, "g"), config.funcName);
// template 检测 模板处理位于二者之间: d_[x[index]]={} ---{template}-- var m0; x[index]中index为wxml在x数组中的索引, m0中数字为当前函数代码
const templateReg = source.match(new RegExp(`d_\\[x\\[${x.indexOf(`./${wxmlName}.wxml`)}\\]\\]=\\{\\}\n([\\s\\S]*?)\nvar m${config.num}=`))
if(templateReg)
DEBUG_OUTPUT && process.stderr.write(templateReg[1] + '\n------\n')
else
DEBUG_OUTPUT && process.stderr.write('无匹配\n------\n')
DEBUG_OUTPUT && process.stderr.write(`wxmlName: ${wxmlName} debugWXS: ${!!debugWXS}, hasDeps: ${!!hasDeps}, templateReg: ${!!templateReg}\n${JSON.stringify(x)} ${JSON.stringify(config)}\n\n`)
// gz函数 // gz函数
let gz; let gz;
if (!debugWXS && !hasDeps) { if (!debugWXS && !hasDeps && !templateReg) {
const exp = `function gz\\${funcName}_${ const exp = `function gz\\${funcName}_${
config.num + 1 config.num + 1
}\\(\\)\\{[\\s\\S]*?\\)\\}`; }\\(\\)\\{[\\s\\S]*?\\)\\}`;
@ -262,7 +282,7 @@ function genFunctionContent_LLA(wxmlName, config = {}, source, x) {
// m0 --- m{num} // m0 --- m{num}
content += `var x=['./${wxmlName}.wxml'`; content += `var x=['./${wxmlName}.wxml'`;
if (!debugWXS && !hasDeps) { if (!debugWXS && !hasDeps && !templateReg) {
content += `];d_[x[0]]={}\u000a`; content += `];d_[x[0]]={}\u000a`;
content += `var m0=function(e,s,r,gg){\u000avar z=gz${config.funcName}_1()\u000areturn r\u000a}\u000ae_[x[0]]=e_[x[0]]||{f:m0,j:[],i:[],ti:[],ic:[]}`; content += `var m0=function(e,s,r,gg){\u000avar z=gz${config.funcName}_1()\u000areturn r\u000a}\u000ae_[x[0]]=e_[x[0]]||{f:m0,j:[],i:[],ti:[],ic:[]}`;
} else { } else {
@ -284,10 +304,14 @@ function genFunctionContent_LLA(wxmlName, config = {}, source, x) {
} }
} }
content += `];d_[x[0]]={}\u000a`; content += `];d_[x[0]]={}\u000a`;
templateReg && (content += templateReg[1].replace(
new RegExp(`\\${funcName}\\_\\d+`, "g"),
`${config.funcName}_1`
) + '\n')
m0_str = m0_str.replace( m0_str = m0_str.replace(
new RegExp(`x\\[${config.num}\\]`, "g"), new RegExp(`x\\[${config.num}\\]`, "g"),
"x[0]" "x[0]"
); ).replace('={f', '=e_[x[0]]||{f');
content += m0_str.replace( content += m0_str.replace(
new RegExp(`\\${funcName}\\_\\d+`, "g"), new RegExp(`\\${funcName}\\_\\d+`, "g"),
`${config.funcName}_1` `${config.funcName}_1`

View File

@ -1,6 +1,6 @@
#!/usr/bin/env node #!/usr/bin/env node
// wcsc.exe md5 = "3999c590c57c764b152bc6db3b3288c4" // wcsc.exe md5 = "d45f45f109afa238cd83c8ad1d0e2a5e"
const version = "20220308"; const version = "20220423";
const { spawn } = require("child_process"); const { spawn } = require("child_process");
const fs = require("fs"); const fs = require("fs");
const path = require("path"); const path = require("path");

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,39 @@
d_[x[0]]["odd"]=function(e,s,r,gg){
var z=gz$gwx_1()
var b=x[0]+':odd'
r.wxVkey=b
gg.f=$gdc(f_["./pages/index/index.wxml"],"",1)
if(p_[b]){_wl(b,x[0]);return}
p_[b]=true
try{
}catch(err){
p_[b]=false
throw err
}
p_[b]=false
return r
}
d_[x[0]]["even"]=function(e,s,r,gg){
var z=gz$gwx_1()
var b=x[0]+':even'
r.wxVkey=b
gg.f=$gdc(f_["./pages/index/index.wxml"],"",1)
if(p_[b]){_wl(b,x[0]);return}
p_[b]=true
try{
}catch(err){
p_[b]=false
throw err
}
p_[b]=false
return r
}
------
wxmlName: pages/index/index debugWXS: false, hasDeps: false, templateReg: true
["./pages/index/index.wxml","./pages/logs/logs.wxml"] {"funcName":"$gwx_XC_0","num":0,"deps":[]}
------
wxmlName: pages/logs/logs debugWXS: false, hasDeps: false, templateReg: false
["./pages/index/index.wxml","./pages/logs/logs.wxml"] {"funcName":"$gwx_XC_1","num":1,"deps":[]}

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,118 @@
#!/usr/bin/env node
const { spawn, spawnSync } = require("child_process");
const path = require("path");
const fs = require("fs");
const { exit } = require("process");
const projectPath = "/home/msojocs/Documents/we1";
const config = ["-d","--split",">_<2460","-xc","2>_<2460./pages/index/index.wxml>_<24600>_<2460./pages/logs/logs.wxml>_<24600","-lla","./pages/index/index>_<2460./pages/logs/logs","./pages/index/index.wxml","./pages/logs/logs.wxml","-gn","$gwx"]
const id = 5;
const test_wine = () => {
const wine = spawn(
path.resolve(__dirname, "../../../../package.nw/js/vendor/wcc.exe"),
config,
{
cwd: projectPath,
}
);
const spwanData = [],
errData = [];
wine.stdout.on("data", (e) => {
spwanData.push(e);
});
wine.stderr.on("data", (e) => {
errData.push(e);
});
return new Promise((resolve, reject) => {
wine.on("close", (n) => {
console.log("wine n: ", n);
if (0 === n) {
let result = Buffer.concat(spwanData).toString();
result = JSON.parse(result);
// result = result.generateFunctionContent["__COMMON__"];
// delete result.generateFunctionContent["__COMMON__"];
result = JSON.stringify(result, null, 4);
fs.writeFileSync(
path.resolve(__dirname, `./${id}/wine_output.json`),
result
);
// process.stdout.write(result);
resolve(result);
} else {
process.stderr.write(
"wine error:",
Buffer.concat(errData).toString()
);
// process.stderr.write(Buffer.concat(spwanData).toString());
reject(n);
}
});
});
};
const test_node = () => {
const node_exec = spawn(
path.resolve(__dirname, "../../../nodejs/wcc"),
config,
{
cwd: projectPath,
env: {
WX_DEBUG_COMPILER_OUTPUT: path.resolve(__dirname, "./" + id),
},
// stdio: 'inherit'
}
);
const spwanData = [],
errData = [];
node_exec.stdout.on("data", (e) => {
spwanData.push(e);
// console.log(e.toString())
});
node_exec.stderr.on("data", (e) => {
errData.push(e);
// console.log(e.toString())
});
return new Promise((resolve, reject) => {
node_exec.on("close", (n) => {
console.log("node n: ", n);
if (0 === n) {
let result = Buffer.concat(spwanData).toString();
// require('fs').writeFileSync('/mnt/disk2/wechat-web-devtools-linux/tmp/llw2.json', result)
// process.stdout.write(result);
result = JSON.parse(result);
// fs.writeFileSync(
// path.resolve(__dirname, "./4/node_output1.json"),
// JSON.stringify(result, null, 4)
// );
// result = result.generateFunctionContent["__COMMON__"];
// delete result.generateFunctionContent["__COMMON__"];
result = JSON.stringify(result, null, 4);
fs.writeFileSync(
path.resolve(__dirname, `./${id}/node_output.json`),
result
);
fs.writeFileSync(
path.resolve(__dirname, `./${id}/node_stderr.json`),
Buffer.concat(errData)
);
resolve(result);
} else {
process.stderr.write(Buffer.concat(errData).toString());
// process.stderr.write(Buffer.concat(spwanData).toString());
reject(n);
}
});
});
};
const test = async () => {
try {
const node_result = await test_node();
const wine_result = await test_wine();
console.log("结果是否一致:", wine_result.trim() === node_result);
} catch (err) {
console.error("错误:", err);
}
};
test();

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,45 @@
d_[x[0]]["odd"]=function(e,s,r,gg){
var z=gz$gwx_1()
var b=x[0]+':odd'
r.wxVkey=b
gg.f=$gdc(f_["./pages/index/index.wxml"],"",1)
if(p_[b]){_wl(b,x[0]);return}
p_[b]=true
try{
cs.push("./pages/index/index.wxml:view:4:6")
var oB=_n('view')
var xC=_oz(z,2,e,s,gg)
_(oB,xC)
cs.pop()
_(r,oB)
}catch(err){
p_[b]=false
throw err
}
p_[b]=false
return r
}
d_[x[0]]["even"]=function(e,s,r,gg){
var z=gz$gwx_1()
var b=x[0]+':even'
r.wxVkey=b
gg.f=$gdc(f_["./pages/index/index.wxml"],"",1)
if(p_[b]){_wl(b,x[0]);return}
p_[b]=true
try{
cs.push("./pages/index/index.wxml:view:7:6")
var oB=_n('view')
var xC=_oz(z,4,e,s,gg)
_(oB,xC)
cs.pop()
_(r,oB)
}catch(err){
p_[b]=false
throw err
}
p_[b]=false
return r
}
------
------

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,114 @@
#!/usr/bin/env node
const { spawn, spawnSync } = require("child_process");
const path = require("path");
const fs = require("fs");
const { exit } = require("process");
const projectPath = "/home/msojocs/Documents/we1";
const config = ["-d","--split",">_<7271","-cc","2>_<7271./pages/index/index.wxml>_<72710>_<7271./pages/logs/logs.wxml>_<72710","-llw","./pages/index/index>_<7271./pages/logs/logs","./pages/index/index.wxml","./pages/logs/logs.wxml","-gn","$gwx"];
const id = 5;
const test_wine = () => {
const wine = spawn(
path.resolve(__dirname, "../../../../package.nw/js/vendor/wcc.exe"),
config,
{
cwd: projectPath,
}
);
const spwanData = [],
errData = [];
wine.stdout.on("data", (e) => {
spwanData.push(e);
});
wine.stderr.on("data", (e) => {
errData.push(e);
});
return new Promise((resolve, reject) => {
wine.on("close", (n) => {
console.log("wine n: ", n);
if (0 === n) {
let result = Buffer.concat(spwanData).toString();
result = JSON.parse(result);
// delete result.generateFunctionContent["__COMMON__"];
result = JSON.stringify(result, null, 4);
// result = result.generateFunctionContent["__COMMON__"];
fs.writeFileSync(
path.resolve(__dirname, `./${id}/wine_output.json`),
result
);
// process.stdout.write(result);
resolve(result);
} else {
process.stderr.write(
"wine error:",
Buffer.concat(errData).toString()
);
// process.stderr.write(Buffer.concat(spwanData).toString());
reject(n);
}
});
});
};
const test_node = () => {
const node_exec = spawn(
path.resolve(__dirname, "../../../nodejs/wcc"),
config,
{
cwd: projectPath,
env: {
WX_DEBUG_COMPILER_OUTPUT: path.resolve(__dirname, "./" + id),
},
// stdio: 'inherit'
}
);
const spwanData = [],
errData = [];
node_exec.stdout.on("data", (e) => {
spwanData.push(e);
// console.log(e.toString())
});
node_exec.stderr.on("data", (e) => {
errData.push(e);
// console.log(e.toString())
});
return new Promise((resolve, reject) => {
node_exec.on("close", (n) => {
console.log("node n: ", n);
if (0 === n) {
let result = Buffer.concat(spwanData).toString();
// require('fs').writeFileSync('/mnt/disk2/wechat-web-devtools-linux/tmp/llw2.json', result)
// process.stdout.write(result);
result = JSON.parse(result);
// delete result.generateFunctionContent["__COMMON__"];
result = JSON.stringify(result, null, 4);
// result = result.generateFunctionContent["__COMMON__"];
fs.writeFileSync(
path.resolve(__dirname, `./${id}/node_output.json`),
result
);
fs.writeFileSync(
path.resolve(__dirname, `./${id}/node_stderr.json`),
Buffer.concat(errData)
);
resolve(result);
} else {
process.stderr.write(Buffer.concat(errData).toString());
// process.stderr.write(Buffer.concat(spwanData).toString());
reject(n);
}
});
});
};
const test = async () => {
try {
const node_result = await test_node();
const wine_result = await test_wine();
console.log("结果是否一致:", wine_result.trim() === node_result);
} catch (err) {
console.error("错误:", err);
}
};
test();