]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
test: move source map test to compile.spec.ts
authorEvan You <yyx990803@gmail.com>
Wed, 25 Sep 2019 03:01:57 +0000 (23:01 -0400)
committerEvan You <yyx990803@gmail.com>
Wed, 25 Sep 2019 03:01:57 +0000 (23:01 -0400)
packages/compiler-core/__tests__/codegen.spec.ts
packages/compiler-core/__tests__/compile.spec.ts

index 43d5d0b43cb5a79db60ba865317e53b2ff427990..42c73c2b98f1bcd24f7b7d540c7d5620507b3c46 100644 (file)
@@ -1,5 +1,4 @@
 import {
-  parse,
   generate,
   NodeTypes,
   RootNode,
@@ -13,7 +12,6 @@ import {
   createArrayExpression,
   ElementNode
 } from '../src'
-import { SourceMapConsumer, RawSourceMap } from 'source-map'
 import { CREATE_VNODE, COMMENT, TO_STRING } from '../src/runtimeConstants'
 
 const mockLoc: SourceLocation = {
@@ -452,36 +450,4 @@ describe('compiler: codegen', () => {
     ])`)
     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
-    })
-  })
 })
index b8c736c09596212aa1c05187b88cef66cb029903..ad28e5653fa2829b65070bf9f43a9eb9e61954a0 100644 (file)
@@ -1,2 +1,36 @@
+import { compile } from '../src'
+import { SourceMapConsumer, RawSourceMap } from 'source-map'
+
 // 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
+  })
+})