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'
99import { makeMap } from 'shared/util'
1010
1111const splitRE = / \r ? \n / g
12+ const emptyRE = / ^ (?: \/ \/ ) ? \s * $ /
1213const isSpecialTag = makeMap ( 'script,style,template' , true )
1314
1415type Attribute = {
@@ -68,7 +69,7 @@ export function parseComponent (
6869 function end ( ) {
6970 depth --
7071 if ( currentBlock && options && options . map ) {
71- addSourceMap ( currentBlock )
72+ addSourceMap ( currentBlock , options . map )
7273 }
7374 currentBlock = null
7475 }
@@ -95,8 +96,29 @@ export function parseComponent (
9596 return Array ( leadingContent . split ( splitRE ) . length ) . join ( padChar )
9697 }
9798
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 ( ) )
100122 }
101123
102124 parseHTML ( content , {
You can’t perform that action at this time.
0 commit comments