From 6fa3cd0beae76e5415fb7509681e76b98b4c4417 Mon Sep 17 00:00:00 2001 From: underfin <2218301630@qq.com> Date: Sat, 29 May 2021 18:26:10 +0800 Subject: [PATCH] fix: revert add sourcemap for temaplate block --- src/utils/descriptorCache.ts | 53 ------------------------------------ 1 file changed, 53 deletions(-) diff --git a/src/utils/descriptorCache.ts b/src/utils/descriptorCache.ts index ccc2ff4..bcc9597 100644 --- a/src/utils/descriptorCache.ts +++ b/src/utils/descriptorCache.ts @@ -4,7 +4,6 @@ import hash from 'hash-sum' import { parse, SFCDescriptor } from '@vue/component-compiler-utils' import * as vueTemplateCompiler from 'vue-template-compiler' import { ResolvedOptions } from '../index' -import { RawSourceMap, SourceMapGenerator } from 'source-map' const cache = new Map() const prevCache = new Map() @@ -22,24 +21,6 @@ export function createDescriptor( needMap: true, }) // v2 hasn't generate template and customBlocks map - if (descriptor.template && !descriptor.template.src) { - descriptor.template.map = generateSourceMap( - filename, - source, - descriptor.template.content, - root - ) - } - if (descriptor.customBlocks) { - descriptor.customBlocks.forEach((customBlock) => { - customBlock.map = generateSourceMap( - filename, - source, - customBlock.content, - root - ) - }) - } // ensure the path is normalized in a way that is consistent inside // project (relative to root) and on different systems. const normalizedPath = slash(path.normalize(path.relative(root, filename))) @@ -72,37 +53,3 @@ export function getDescriptor(filename: string, errorOnMissing = true) { export function setDescriptor(filename: string, entry: SFCDescriptor) { cache.set(filename, entry) } - -const splitRE = /\r?\n/g -const emptyRE = /^(?:\/\/)?\s*$/ - -function generateSourceMap( - filename: string, - source: string, - generated: string, - sourceRoot: string -): RawSourceMap { - const map = new SourceMapGenerator({ - file: filename.replace(/\\/g, '/'), - sourceRoot: sourceRoot.replace(/\\/g, '/'), - }) - const offset = source.split(generated).shift()!.split(splitRE).length - 1 - - map.setSourceContent(filename, source) - generated.split(splitRE).forEach((line, index) => { - if (!emptyRE.test(line)) { - map.addMapping({ - source: filename, - original: { - line: index + 1 + offset, - column: 0, - }, - generated: { - line: index + 1, - column: 0, - }, - }) - } - }) - return JSON.parse(map.toString()) -}