feat(compiler): set sourcesContent for source map

This commit is contained in:
Evan You 2019-09-20 12:19:52 -04:00
parent 8a923f6a52
commit c78d47b788
2 changed files with 11 additions and 2 deletions

View File

@ -3,10 +3,16 @@ import { SourceMapConsumer, RawSourceMap } from 'source-map'
describe('compiler: codegen', () => {
test('basic source map support', async () => {
const ast = parse(`hello {{ world }}`)
const { code, map } = generate(ast)
const source = `hello {{ world }}`
const ast = parse(source)
const { code, map } = generate(ast, {
filename: `foo.vue`
})
expect(code).toBe(`["hello ", world]`)
expect(map!.sources).toEqual([`foo.vue`])
expect(map!.sourcesContent).toEqual([source])
const consumer = await new SourceMapConsumer(map as RawSourceMap)
const pos = consumer.originalPositionFor({
line: 1,

View File

@ -107,6 +107,9 @@ function createCodegenContext(
}
}
}
if (!__BROWSER__) {
context.map!.setSourceContent(filename, context.source)
}
return context
}