vue3-yuanma/packages/compiler-core/__tests__/codegen.spec.ts

36 lines
798 B
TypeScript
Raw Normal View History

import { parse, generate } from '../src'
import { SourceMapConsumer, RawSourceMap } from 'source-map'
describe('compiler: codegen', () => {
test('basic source map support', async () => {
const source = `hello {{ world }}`
const ast = parse(source)
const { code, map } = generate(ast, {
filename: `foo.vue`
})
2019-09-23 04:50:57 +08:00
expect(code).toBe(
`return function render() {
with (this) {
return [
"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({
2019-09-23 04:50:57 +08:00
line: 5,
column: 6
})
expect(pos).toMatchObject({
line: 1,
column: 6
})
})
})