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 () => {
|
|
|
|
const ast = parse(`hello {{ world }}`)
|
2019-09-20 12:12:37 +08:00
|
|
|
const { code, map } = generate(ast)
|
2019-09-20 11:05:51 +08:00
|
|
|
expect(code).toBe(`["hello ", world]`)
|
|
|
|
|
|
|
|
const consumer = await new SourceMapConsumer(map as RawSourceMap)
|
|
|
|
const pos = consumer.originalPositionFor({
|
|
|
|
line: 1,
|
|
|
|
column: 11
|
|
|
|
})
|
|
|
|
expect(pos).toMatchObject({
|
|
|
|
line: 1,
|
|
|
|
column: 6
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|