通过开发工具使用sourcemap插件,一直说未匹配到结果。通过程序循环了1000行,返回的都是null,到底是哪不对呢?看起来map文件内容蛮正常啊。
const fs = require('fs')
const { SourceMapConsumer } = require('source-map');
async function originalPositionFor(line, column) {
const sourceMapFilePath = 'C:\\Users\\Admin\\Desktop\\__FULL__\\pages\\index\\index.appservice.map.map'
const sourceMapConsumer = await new SourceMapConsumer(JSON.parse(fs.readFileSync(sourceMapFilePath, 'utf8')))
// console.log(sourceMapConsumer)
return sourceMapConsumer.originalPositionFor({
line,
column,
})
}
for (var n = 1; n < 1000; n++) {
originalPositionFor(n, 0).then((res) => {
console.log(res)
})
}
结果
{ source: null, line: null, column: null, name: null }
{ source: null, line: null, column: null, name: null }
。。。