feat(compiler): set sourcesContent for source map
This commit is contained in:
parent
8a923f6a52
commit
c78d47b788
@ -3,10 +3,16 @@ import { SourceMapConsumer, RawSourceMap } from 'source-map'
|
|||||||
|
|
||||||
describe('compiler: codegen', () => {
|
describe('compiler: codegen', () => {
|
||||||
test('basic source map support', async () => {
|
test('basic source map support', async () => {
|
||||||
const ast = parse(`hello {{ world }}`)
|
const source = `hello {{ world }}`
|
||||||
const { code, map } = generate(ast)
|
const ast = parse(source)
|
||||||
|
const { code, map } = generate(ast, {
|
||||||
|
filename: `foo.vue`
|
||||||
|
})
|
||||||
expect(code).toBe(`["hello ", world]`)
|
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 consumer = await new SourceMapConsumer(map as RawSourceMap)
|
||||||
const pos = consumer.originalPositionFor({
|
const pos = consumer.originalPositionFor({
|
||||||
line: 1,
|
line: 1,
|
||||||
|
@ -107,6 +107,9 @@ function createCodegenContext(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (!__BROWSER__) {
|
||||||
|
context.map!.setSourceContent(filename, context.source)
|
||||||
|
}
|
||||||
return context
|
return context
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user