test: move source map test to compile.spec.ts
This commit is contained in:
parent
af585081b1
commit
61be769ce6
@ -1,5 +1,4 @@
|
|||||||
import {
|
import {
|
||||||
parse,
|
|
||||||
generate,
|
generate,
|
||||||
NodeTypes,
|
NodeTypes,
|
||||||
RootNode,
|
RootNode,
|
||||||
@ -13,7 +12,6 @@ import {
|
|||||||
createArrayExpression,
|
createArrayExpression,
|
||||||
ElementNode
|
ElementNode
|
||||||
} from '../src'
|
} from '../src'
|
||||||
import { SourceMapConsumer, RawSourceMap } from 'source-map'
|
|
||||||
import { CREATE_VNODE, COMMENT, TO_STRING } from '../src/runtimeConstants'
|
import { CREATE_VNODE, COMMENT, TO_STRING } from '../src/runtimeConstants'
|
||||||
|
|
||||||
const mockLoc: SourceLocation = {
|
const mockLoc: SourceLocation = {
|
||||||
@ -452,36 +450,4 @@ describe('compiler: codegen', () => {
|
|||||||
])`)
|
])`)
|
||||||
expect(code).toMatchSnapshot()
|
expect(code).toMatchSnapshot()
|
||||||
})
|
})
|
||||||
|
|
||||||
test('basic source map support', async () => {
|
|
||||||
const source = `hello {{ world }}`
|
|
||||||
const ast = parse(source)
|
|
||||||
const { code, map } = generate(ast, {
|
|
||||||
sourceMap: true,
|
|
||||||
filename: `foo.vue`
|
|
||||||
})
|
|
||||||
expect(code).toMatch(
|
|
||||||
`return function render() {
|
|
||||||
with (this) {
|
|
||||||
return [
|
|
||||||
"hello ",
|
|
||||||
toString(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: 5,
|
|
||||||
column: 15
|
|
||||||
})
|
|
||||||
expect(pos).toMatchObject({
|
|
||||||
line: 1,
|
|
||||||
column: 6
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
|
@ -1,2 +1,36 @@
|
|||||||
|
import { compile } from '../src'
|
||||||
|
import { SourceMapConsumer, RawSourceMap } from 'source-map'
|
||||||
|
|
||||||
// Integration tests for parser + transform + codegen
|
// Integration tests for parser + transform + codegen
|
||||||
test.todo('compile')
|
test('basic source map support', async () => {
|
||||||
|
const source = `hello {{ world }}`
|
||||||
|
const { code, map } = compile(source, {
|
||||||
|
sourceMap: true,
|
||||||
|
filename: `foo.vue`
|
||||||
|
})
|
||||||
|
expect(code).toMatch(
|
||||||
|
`const { toString } = Vue
|
||||||
|
|
||||||
|
return function render() {
|
||||||
|
with (this) {
|
||||||
|
return [
|
||||||
|
"hello ",
|
||||||
|
toString(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: 7,
|
||||||
|
column: 16
|
||||||
|
})
|
||||||
|
expect(pos).toMatchObject({
|
||||||
|
line: 1,
|
||||||
|
column: 6
|
||||||
|
})
|
||||||
|
})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user