11var parse5 = require ( 'parse5' )
2- var parser = new parse5 . Parser ( null , { locationInfo : true } )
32var cache = require ( 'lru-cache' ) ( 100 )
43var SourceMapGenerator = require ( 'source-map' ) . SourceMapGenerator
54var hash = require ( 'hash-sum' )
@@ -22,14 +21,20 @@ module.exports = function (content, filename) {
2221 styleImports : [ ]
2322 }
2423
25- var fragment = parser . parseFragment ( content )
24+ var fragment = parse5 . parseFragment ( content , {
25+ locationInfo : true
26+ } )
2627
2728 fragment . childNodes . forEach ( function ( node ) {
2829 var type = node . tagName
2930 var lang = getAttribute ( node , 'lang' )
3031 var src = getAttribute ( node , 'src' )
3132 var scoped = getAttribute ( node , 'scoped' ) != null
3233
34+ if ( ! output [ type ] ) {
35+ return
36+ }
37+
3338 // node count check
3439 if (
3540 ( type === 'script' || type === 'template' ) &&
@@ -63,25 +68,19 @@ module.exports = function (content, filename) {
6368 return
6469 }
6570
66- if ( ! node . childNodes || ! node . childNodes . length ) {
71+ // skip empty script/style tags
72+ if ( type !== 'template' && ( ! node . childNodes || ! node . childNodes . length ) ) {
6773 return
6874 }
6975
70- if ( ! output [ type ] ) {
71- return
72- }
73-
74- // Work around changes in parse5 >= 1.2.0
75- if ( node . childNodes [ 0 ] . nodeName === '#document-fragment' ) {
76- node = node . childNodes [ 0 ]
77- if ( ! node . childNodes . length ) {
78- return
79- }
76+ // template content is nested inside the content fragment
77+ if ( type === 'template' ) {
78+ node = node . content
8079 }
8180
8281 // extract part
83- var start = node . childNodes [ 0 ] . __location . start
84- var end = node . childNodes [ node . childNodes . length - 1 ] . __location . end
82+ var start = node . childNodes [ 0 ] . __location . startOffset
83+ var end = node . childNodes [ node . childNodes . length - 1 ] . __location . endOffset
8584 var result
8685 var lineOffset
8786 if ( type === 'script' ) {
0 commit comments