]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
refactor(compiler): downgrade to source-map v6 for sync API
authorEvan You <yyx990803@gmail.com>
Fri, 13 Dec 2019 17:56:25 +0000 (12:56 -0500)
committerEvan You <yyx990803@gmail.com>
Fri, 13 Dec 2019 17:56:31 +0000 (12:56 -0500)
packages/compiler-core/__tests__/compile.spec.ts
packages/compiler-core/package.json
packages/compiler-core/src/codegen.ts
packages/compiler-sfc/__tests__/__snapshots__/compileTemplate.spec.ts.snap
packages/compiler-sfc/package.json
yarn.lock

index 668519511868020bcc2b8ac42cf716ed1aa9a542..33766f71b3b18e143fbbbe60c6d67fb41bcbf376 100644 (file)
@@ -44,7 +44,7 @@ describe('compiler: integration tests', () => {
     return res
   }
 
-  test('function mode', async () => {
+  test('function mode', () => {
     const { code, map } = compile(source, {
       sourceMap: true,
       filename: `foo.vue`
@@ -54,7 +54,7 @@ describe('compiler: integration tests', () => {
     expect(map!.sources).toEqual([`foo.vue`])
     expect(map!.sourcesContent).toEqual([source])
 
-    const consumer = await new SourceMapConsumer(map as RawSourceMap)
+    const consumer = new SourceMapConsumer(map as RawSourceMap)
 
     expect(
       consumer.originalPositionFor(getPositionInCode(code, `id`))
@@ -109,7 +109,7 @@ describe('compiler: integration tests', () => {
     ).toMatchObject(getPositionInCode(source, `value + index`))
   })
 
-  test('function mode w/ prefixIdentifiers: true', async () => {
+  test('function mode w/ prefixIdentifiers: true', () => {
     const { code, map } = compile(source, {
       sourceMap: true,
       filename: `foo.vue`,
@@ -120,7 +120,7 @@ describe('compiler: integration tests', () => {
     expect(map!.sources).toEqual([`foo.vue`])
     expect(map!.sourcesContent).toEqual([source])
 
-    const consumer = await new SourceMapConsumer(map as RawSourceMap)
+    const consumer = new SourceMapConsumer(map as RawSourceMap)
 
     expect(
       consumer.originalPositionFor(getPositionInCode(code, `id`))
@@ -184,7 +184,7 @@ describe('compiler: integration tests', () => {
     ).toMatchObject(getPositionInCode(source, `value + index`))
   })
 
-  test('module mode', async () => {
+  test('module mode', () => {
     const { code, map } = compile(source, {
       mode: 'module',
       sourceMap: true,
@@ -195,7 +195,7 @@ describe('compiler: integration tests', () => {
     expect(map!.sources).toEqual([`foo.vue`])
     expect(map!.sourcesContent).toEqual([source])
 
-    const consumer = await new SourceMapConsumer(map as RawSourceMap)
+    const consumer = new SourceMapConsumer(map as RawSourceMap)
 
     expect(
       consumer.originalPositionFor(getPositionInCode(code, `id`))
index 4af472bb1d21ce7fed8177e06a3909bd458c99be..5f6311730aa75724b4ee4527e79f1e608046ae19 100644 (file)
@@ -31,6 +31,6 @@
   "dependencies": {
     "acorn": "^7.1.0",
     "estree-walker": "^0.8.1",
-    "source-map": "^0.7.3"
+    "source-map": "^0.6.1"
   }
 }
index fed615196100558c399c658b7a19f09a49ae1afb..939a07f8eb5eb12440303b42d977a039d72f2f20 100644 (file)
@@ -10,7 +10,6 @@ import {
   CallExpression,
   ArrayExpression,
   ObjectExpression,
-  SourceLocation,
   Position,
   InterpolationNode,
   CompoundExpressionNode,
@@ -18,7 +17,8 @@ import {
   FunctionExpression,
   SequenceExpression,
   ConditionalExpression,
-  CacheExpression
+  CacheExpression,
+  locStub
 } from './ast'
 import { SourceMapGenerator, RawSourceMap } from 'source-map'
 import {
@@ -58,8 +58,7 @@ export interface CodegenContext extends Required<CodegenOptions> {
   indentLevel: number
   map?: SourceMapGenerator
   helper(key: symbol): string
-  push(code: string, node?: CodegenNode, openOnly?: boolean): void
-  resetMapping(loc: SourceLocation): void
+  push(code: string, node?: CodegenNode): void
   indent(): void
   deindent(withoutNewLine?: boolean): void
   newline(): void
@@ -96,7 +95,7 @@ function createCodegenContext(
       const name = helperNameMap[key]
       return prefixIdentifiers ? name : `_${name}`
     },
-    push(code, node, openOnly) {
+    push(code, node) {
       context.code += code
       if (!__BROWSER__ && context.map) {
         if (node) {
@@ -110,16 +109,11 @@ function createCodegenContext(
           addMapping(node.loc.start, name)
         }
         advancePositionWithMutation(context, code)
-        if (node && !openOnly) {
+        if (node && node.loc !== locStub) {
           addMapping(node.loc.end)
         }
       }
     },
-    resetMapping(loc: SourceLocation) {
-      if (!__BROWSER__ && context.map) {
-        addMapping(loc.start)
-      }
-    },
     indent() {
       newline(++context.indentLevel)
     },
@@ -279,7 +273,8 @@ export function generate(
   return {
     ast,
     code: context.code,
-    map: context.map ? context.map.toJSON() : undefined
+    // SourceMapGenerator does have toJSON() method but it's not in the types
+    map: context.map ? (context.map as any).toJSON() : undefined
   }
 }
 
@@ -510,13 +505,13 @@ function genCallExpression(node: CallExpression, context: CodegenContext) {
   const callee = isString(node.callee)
     ? node.callee
     : context.helper(node.callee)
-  context.push(callee + `(`, node, true)
+  context.push(callee + `(`, node)
   genNodeList(node.arguments, context)
   context.push(`)`)
 }
 
 function genObjectExpression(node: ObjectExpression, context: CodegenContext) {
-  const { push, indent, deindent, newline, resetMapping } = context
+  const { push, indent, deindent, newline } = context
   const { properties } = node
   if (!properties.length) {
     push(`{}`, node)
@@ -529,8 +524,7 @@ function genObjectExpression(node: ObjectExpression, context: CodegenContext) {
   push(multilines ? `{` : `{ `)
   multilines && indent()
   for (let i = 0; i < properties.length; i++) {
-    const { key, value, loc } = properties[i]
-    resetMapping(loc) // reset source mapping for every property.
+    const { key, value } = properties[i]
     // key
     genExpressionAsPropertyKey(key, context)
     push(`: `)
index 8cb28f25ea304874714f603dbfa58677c6cd1fe8..d5ef08a12119838eaa8189549f8f2ca417edf780 100644 (file)
@@ -2,7 +2,7 @@
 
 exports[`source map 1`] = `
 Object {
-  "mappings": ";;;;UAAA,aACE;IAAK,gCAAMA,WAAM",
+  "mappings": ";;;;UAAA,aACE,YAA8B;IAAzB,YAAmB,oBAAbA,WAAM",
   "names": Array [
     "render",
   ],
index aa16a9ca4e902ba63dc895417d51d769df2b23ef..e6762b4bb60d4cad679a133c12fe0f37f037a44f 100644 (file)
@@ -35,7 +35,7 @@
     "merge-source-map": "^1.1.0",
     "postcss": "^7.0.21",
     "postcss-selector-parser": "^6.0.2",
-    "source-map": "^0.7.3"
+    "source-map": "^0.6.1"
   },
   "devDependencies": {
     "@types/consolidate": "^0.14.0",
index 784174a25be150ac80ebbc2404a33d7214c2d33d..a7a1e88f4ac5461f8d949666260313e640c95950 100644 (file)
--- a/yarn.lock
+++ b/yarn.lock
@@ -4990,11 +4990,6 @@ source-map@^0.6.0, source-map@^0.6.1, source-map@~0.6.0, source-map@~0.6.1:
   resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.6.1.tgz#74722af32e9614e9c287a8d0bbde48b5e2f1a263"
   integrity sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==
 
-source-map@^0.7.3:
-  version "0.7.3"
-  resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.7.3.tgz#5302f8169031735226544092e64981f751750383"
-  integrity sha512-CkCj6giN3S+n9qrYiBTX5gystlENnRW5jZeNLHpe6aue+SrHcG5VYwujhW9s4dY31mEGsxBDrHR6oI69fTXsaQ==
-
 sourcemap-codec@^1.4.4:
   version "1.4.6"
   resolved "https://registry.yarnpkg.com/sourcemap-codec/-/sourcemap-codec-1.4.6.tgz#e30a74f0402bad09807640d39e971090a08ce1e9"