|
|
@@ -1,15 +1,10 @@
|
|
|
/* @flow */
|
|
|
|
|
|
-// this file is used in the vue-template-compiler npm package
|
|
|
-// and assumes its dependencies and a Node/CommonJS environment
|
|
|
-import deindent from 'de-indent'
|
|
|
-import { SourceMapGenerator } from 'source-map'
|
|
|
-
|
|
|
-import { parseHTML } from './html-parser'
|
|
|
+import deindent from './deindent'
|
|
|
+import { parseHTML } from 'compiler/parser/html-parser'
|
|
|
import { makeMap } from 'shared/util'
|
|
|
|
|
|
const splitRE = /\r?\n/g
|
|
|
-const emptyRE = /^(?:\/\/)?\s*$/
|
|
|
const isSpecialTag = makeMap('script,style,template', true)
|
|
|
|
|
|
type Attribute = {
|
|
|
@@ -82,50 +77,17 @@ export function parseComponent (
|
|
|
text = padContent(currentBlock) + text
|
|
|
}
|
|
|
currentBlock.content = text
|
|
|
- if (options.map && !currentBlock.src) {
|
|
|
- addSourceMap(currentBlock)
|
|
|
- }
|
|
|
currentBlock = null
|
|
|
}
|
|
|
depth--
|
|
|
}
|
|
|
|
|
|
function padContent (block: SFCBlock) {
|
|
|
+ const offset = content.slice(0, block.start).split(splitRE).length
|
|
|
const padChar = block.type === 'script' && !block.lang
|
|
|
? '//\n'
|
|
|
: '\n'
|
|
|
- return Array(getPaddingOffset(block) + 1).join(padChar)
|
|
|
- }
|
|
|
-
|
|
|
- function getPaddingOffset (block: SFCBlock) {
|
|
|
- return content.slice(0, block.start).split(splitRE).length - 1
|
|
|
- }
|
|
|
-
|
|
|
- function addSourceMap (block: SFCBlock) {
|
|
|
- const filename = options.map.filename
|
|
|
- /* istanbul ignore if */
|
|
|
- if (!filename) {
|
|
|
- throw new Error('Should provide original filename in the map option.')
|
|
|
- }
|
|
|
- const offset = options.pad ? 0 : getPaddingOffset(block)
|
|
|
- const map = new SourceMapGenerator()
|
|
|
- map.setSourceContent(filename, content)
|
|
|
- block.content.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
|
|
|
- }
|
|
|
- })
|
|
|
- }
|
|
|
- })
|
|
|
- block.map = JSON.parse(map.toString())
|
|
|
+ return Array(offset).join(padChar)
|
|
|
}
|
|
|
|
|
|
parseHTML(content, {
|