未验证 提交 01a44dbb 编写于 作者: S skyler 提交者: GitHub

Merge pull request #34 from wechat-miniprogram/feat-skyler-update-rewrite-symbol-tool

update for new text and json symbols
...@@ -201,6 +201,14 @@ var symbolText = fs.readFileSync(process.argv[3], { encoding: "utf8" }); ...@@ -201,6 +201,14 @@ var symbolText = fs.readFileSync(process.argv[3], { encoding: "utf8" });
function parseSymbol(symbolText) { function parseSymbol(symbolText) {
var symbolMap = new Map(); var symbolMap = new Map();
try {
var symbols = JSON.parse(symbolText);
console.log("json symbols");
Object.entries(symbols).forEach(function (value) {
symbolMap.set(value[0], value[1]);
});
return symbolMap;
} catch (e) {}
var startLine = "var debugSymbols = {"; var startLine = "var debugSymbols = {";
var start = symbolText.indexOf(startLine); var start = symbolText.indexOf(startLine);
start += startLine.length; start += startLine.length;
...@@ -240,14 +248,16 @@ function replaceWithSymbol(src, symbolMap, regex) { ...@@ -240,14 +248,16 @@ function replaceWithSymbol(src, symbolMap, regex) {
// console.log("to replace symbol:", src, regex); // console.log("to replace symbol:", src, regex);
var output = ""; var output = "";
var start = 0; var start = 0;
var matched = false;
for (;;) { for (;;) {
var d = res.next(); var d = res.next();
if (d.value) { if (d.value) {
matched = true;
var s = symbolMap.get(d.value[1]); var s = symbolMap.get(d.value[1]);
// console.log("to replace:", d.value, s, start); // console.log("to replace:", d.value, s, start);
if (s) { if (s) {
output += src.substr(start, d.value.index - start); output += src.substr(start, d.value.index - start);
output += s + ":wasm-function[" + d.value[1] + "]"; output += s + " wasm-function[" + d.value[1] + "]";
} else { } else {
output += src.substr(start, d.value.index - start); output += src.substr(start, d.value.index - start);
output += d.value[0]; output += d.value[0];
...@@ -259,17 +269,26 @@ function replaceWithSymbol(src, symbolMap, regex) { ...@@ -259,17 +269,26 @@ function replaceWithSymbol(src, symbolMap, regex) {
break; break;
} }
} }
return output; return { output: output, matched: matched };
} }
var output = replaceWithSymbol( var res = replaceWithSymbol(
exceptionText, exceptionText,
symbolMap, symbolMap,
/j(\d+):wasm-function\[\d+]/g /j(\d+):wasm-function\[\d+]/g
); );
output = replaceWithSymbol( if (!res.matched) {
output, res = replaceWithSymbol(
symbolMap, exceptionText,
/<anonymous>:wasm-function\[(\d+)\]/g symbolMap,
); /j(\d+) \(wasm-function\[\d+]/g
console.log(output); );
}
if (!res.matched) {
res = replaceWithSymbol(
exceptionText,
symbolMap,
/<anonymous>:wasm-function\[(\d+)\]/g
);
}
console.log(res.output);
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册