Skip to content
This repository has been archived by the owner on Feb 17, 2023. It is now read-only.

Commit

Permalink
fix: revert add sourcemap for temaplate block
Browse files Browse the repository at this point in the history
  • Loading branch information
underfin committed May 29, 2021
1 parent 97f2ca4 commit 6fa3cd0
Showing 1 changed file with 0 additions and 53 deletions.
53 changes: 0 additions & 53 deletions src/utils/descriptorCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, SFCDescriptor>()
const prevCache = new Map<string, SFCDescriptor | undefined>()
Expand All @@ -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)))
Expand Down Expand Up @@ -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())
}

0 comments on commit 6fa3cd0

Please sign in to comment.