|
1 | 1 | /* @flow */
|
2 | 2 |
|
3 |
| -// this file is used in the vue-template-compiler npm package |
4 |
| -// and assumes its dependencies and a Node/CommonJS environment |
5 |
| -import deindent from 'de-indent' |
6 |
| -import { SourceMapGenerator } from 'source-map' |
7 |
| - |
8 |
| -import { parseHTML } from './html-parser' |
| 3 | +import deindent from './deindent' |
| 4 | +import { parseHTML } from 'compiler/parser/html-parser' |
9 | 5 | import { makeMap } from 'shared/util'
|
10 | 6 |
|
11 | 7 | const splitRE = /\r?\n/g
|
12 |
| -const emptyRE = /^(?:\/\/)?\s*$/ |
13 | 8 | const isSpecialTag = makeMap('script,style,template', true)
|
14 | 9 |
|
15 | 10 | type Attribute = {
|
@@ -82,50 +77,17 @@ export function parseComponent (
|
82 | 77 | text = padContent(currentBlock) + text
|
83 | 78 | }
|
84 | 79 | currentBlock.content = text
|
85 |
| - if (options.map && !currentBlock.src) { |
86 |
| - addSourceMap(currentBlock) |
87 |
| - } |
88 | 80 | currentBlock = null
|
89 | 81 | }
|
90 | 82 | depth--
|
91 | 83 | }
|
92 | 84 |
|
93 | 85 | function padContent (block: SFCBlock) {
|
| 86 | + const offset = content.slice(0, block.start).split(splitRE).length |
94 | 87 | const padChar = block.type === 'script' && !block.lang
|
95 | 88 | ? '//\n'
|
96 | 89 | : '\n'
|
97 |
| - return Array(getPaddingOffset(block) + 1).join(padChar) |
98 |
| - } |
99 |
| - |
100 |
| - function getPaddingOffset (block: SFCBlock) { |
101 |
| - return content.slice(0, block.start).split(splitRE).length - 1 |
102 |
| - } |
103 |
| - |
104 |
| - function addSourceMap (block: SFCBlock) { |
105 |
| - const filename = options.map.filename |
106 |
| - /* istanbul ignore if */ |
107 |
| - if (!filename) { |
108 |
| - throw new Error('Should provide original filename in the map option.') |
109 |
| - } |
110 |
| - const offset = options.pad ? 0 : getPaddingOffset(block) |
111 |
| - const map = new SourceMapGenerator() |
112 |
| - map.setSourceContent(filename, content) |
113 |
| - block.content.split(splitRE).forEach((line, index) => { |
114 |
| - if (!emptyRE.test(line)) { |
115 |
| - map.addMapping({ |
116 |
| - source: filename, |
117 |
| - original: { |
118 |
| - line: index + 1 + offset, |
119 |
| - column: 0 |
120 |
| - }, |
121 |
| - generated: { |
122 |
| - line: index + 1, |
123 |
| - column: 0 |
124 |
| - } |
125 |
| - }) |
126 |
| - } |
127 |
| - }) |
128 |
| - block.map = JSON.parse(map.toString()) |
| 90 | + return Array(offset).join(padChar) |
129 | 91 | }
|
130 | 92 |
|
131 | 93 | parseHTML(content, {
|
|
0 commit comments