File tree Expand file tree Collapse file tree 1 file changed +25
-3
lines changed Expand file tree Collapse file tree 1 file changed +25
-3
lines changed Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ import { parseHTML } from './html-parser'
9
9
import { makeMap } from 'shared/util'
10
10
11
11
const splitRE = / \r ? \n / g
12
+ const emptyRE = / ^ (?: \/ \/ ) ? \s * $ /
12
13
const isSpecialTag = makeMap ( 'script,style,template' , true )
13
14
14
15
type Attribute = {
@@ -68,7 +69,7 @@ export function parseComponent (
68
69
function end ( ) {
69
70
depth --
70
71
if ( currentBlock && options && options . map ) {
71
- addSourceMap ( currentBlock )
72
+ addSourceMap ( currentBlock , options . map )
72
73
}
73
74
currentBlock = null
74
75
}
@@ -95,8 +96,29 @@ export function parseComponent (
95
96
return Array ( leadingContent . split ( splitRE ) . length ) . join ( padChar )
96
97
}
97
98
98
- function addSourceMap ( block : SFCBlock ) {
99
-
99
+ function addSourceMap ( block : SFCBlock , options : Object ) {
100
+ const filename = options . filename
101
+ if ( ! filename ) {
102
+ throw new Error ( 'Should provide original filename in the map option.' )
103
+ }
104
+ const map = new SourceMapGenerator ( )
105
+ map . setSourceContent ( filename , content )
106
+ block . content . split ( splitRE ) . forEach ( ( line , index ) => {
107
+ if ( ! emptyRE . test ( line ) ) {
108
+ map . addMapping ( {
109
+ source : filename ,
110
+ original : {
111
+ line : index + 1 ,
112
+ column : 0
113
+ } ,
114
+ generated : {
115
+ line : index + 1 ,
116
+ column : 0
117
+ }
118
+ } )
119
+ }
120
+ } )
121
+ block . map = JSON . parse ( map . toString ( ) )
100
122
}
101
123
102
124
parseHTML ( content , {
You can’t perform that action at this time.
0 commit comments