下载下来的sourcemap解析出来大约是这样的结果:
Mapping {
generatedLine: 508,
generatedColumn: 750,
lastGeneratedColumn: null,
source: 'game:///WeChatGoApp/src/netgame/game/internal/NewUserDetailPanel.ts',
originalLine: 23,
originalColumn: 11,
name: 'mask'
}
Mapping {
generatedLine: 508,
generatedColumn: 752,
lastGeneratedColumn: null,
source: 'game:///WeChatGoApp/src/netgame/game/internal/NewUserDetailPanel.ts',
originalLine: 23,
originalColumn: 16,
name: 'graphics'
}
Mapping {
generatedLine: 508,
generatedColumn: 761,
lastGeneratedColumn: null,
source: 'game:///WeChatGoApp/src/netgame/game/internal/NewUserDetailPanel.ts',
originalLine: 24,
originalColumn: 3,
name: 'g'
}
很明显generatedLine是不会那么大的。因为生成的wegame.js一共才1,2行。
我的在微信开发工具中的js文件本身是用ts写的,并带了souce map并且开启了inlineSources,也就是sourcemap中也带了ts的源代码。
不知道是不是因为这样,导致了你们生成的sourcemap不正常。
这是我用来解析的代码。你们也可以参考一下我写得对不对。
const { SourceMapConsumer } = require('source-map'); const fs = require('fs'); const content = fs.readFileSync('game.map.map',{encoding:'utf8'}); async function main() { let s = await new SourceMapConsumer(JSON.parse(content)); s.eachMapping(mapping=>{ console.log(mapping) }); //console.log(s); } main().catch(console.error);