2019-09-20 11:05:51 +08:00
|
|
|
import { parse, generate } from '../src'
|
|
|
|
import { SourceMapConsumer, RawSourceMap } from 'source-map'
|
|
|
|
|
|
|
|
describe('compiler: codegen', () => {
|
|
|
|
test('basic source map support', async () => {
|
2019-09-21 00:19:52 +08:00
|
|
|
const source = `hello {{ world }}`
|
|
|
|
const ast = parse(source)
|
|
|
|
const { code, map } = generate(ast, {
|
|
|
|
filename: `foo.vue`
|
|
|
|
})
|
2019-09-20 11:05:51 +08:00
|
|
|
expect(code).toBe(`["hello ", world]`)
|
|
|
|
|
2019-09-21 00:19:52 +08:00
|
|
|
expect(map!.sources).toEqual([`foo.vue`])
|
|
|
|
expect(map!.sourcesContent).toEqual([source])
|
|
|
|
|
2019-09-20 11:05:51 +08:00
|
|
|
const consumer = await new SourceMapConsumer(map as RawSourceMap)
|
|
|
|
const pos = consumer.originalPositionFor({
|
|
|
|
line: 1,
|
|
|
|
column: 11
|
|
|
|
})
|
|
|
|
expect(pos).toMatchObject({
|
|
|
|
line: 1,
|
|
|
|
column: 6
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|