@@ -50,6 +50,7 @@ module.exports = function(input) {
5050 after = token ;
5151 } else if ( prev && prev . type === "div" ) {
5252 prev . after = token ;
53+ prev . sourceEndIndex += token . length ;
5354 } else if (
5455 code === comma ||
5556 code === colon ||
@@ -63,6 +64,7 @@ module.exports = function(input) {
6364 tokens . push ( {
6465 type : "space" ,
6566 sourceIndex : pos ,
67+ sourceEndIndex : next ,
6668 value : token
6769 } ) ;
6870 }
@@ -94,22 +96,25 @@ module.exports = function(input) {
9496 }
9597 } while ( escape ) ;
9698 token . value = value . slice ( pos + 1 , next ) ;
97-
99+ token . sourceEndIndex = token . unclosed ? next : next + 1 ;
98100 tokens . push ( token ) ;
99101 pos = next + 1 ;
100102 code = value . charCodeAt ( pos ) ;
101103
102104 // Comments
103105 } else if ( code === slash && value . charCodeAt ( pos + 1 ) === star ) {
106+ next = value . indexOf ( "*/" , pos ) ;
107+
104108 token = {
105109 type : "comment" ,
106- sourceIndex : pos
110+ sourceIndex : pos ,
111+ sourceEndIndex : next + 2
107112 } ;
108113
109- next = value . indexOf ( "*/" , pos ) ;
110114 if ( next === - 1 ) {
111115 token . unclosed = true ;
112116 next = value . length ;
117+ token . sourceEndIndex = next ;
113118 }
114119
115120 token . value = value . slice ( pos + 2 , next ) ;
@@ -129,6 +134,7 @@ module.exports = function(input) {
129134 tokens . push ( {
130135 type : "word" ,
131136 sourceIndex : pos - before . length ,
137+ sourceEndIndex : pos + token . length ,
132138 value : token
133139 } ) ;
134140 pos += 1 ;
@@ -141,6 +147,7 @@ module.exports = function(input) {
141147 tokens . push ( {
142148 type : "div" ,
143149 sourceIndex : pos - before . length ,
150+ sourceEndIndex : pos + token . length ,
144151 value : token ,
145152 before : before ,
146153 after : ""
@@ -196,6 +203,7 @@ module.exports = function(input) {
196203 {
197204 type : "word" ,
198205 sourceIndex : pos ,
206+ sourceEndIndex : whitespacePos + 1 ,
199207 value : value . slice ( pos , whitespacePos + 1 )
200208 }
201209 ] ;
@@ -207,21 +215,25 @@ module.exports = function(input) {
207215 token . nodes . push ( {
208216 type : "space" ,
209217 sourceIndex : whitespacePos + 1 ,
218+ sourceEndIndex : next ,
210219 value : value . slice ( whitespacePos + 1 , next )
211220 } ) ;
212221 } else {
213222 token . after = value . slice ( whitespacePos + 1 , next ) ;
223+ token . sourceEndIndex = next ;
214224 }
215225 } else {
216226 token . after = "" ;
217227 token . nodes = [ ] ;
218228 }
219229 pos = next + 1 ;
230+ token . sourceEndIndex = token . unclosed ? next : pos ;
220231 code = value . charCodeAt ( pos ) ;
221232 tokens . push ( token ) ;
222233 } else {
223234 balanced += 1 ;
224235 token . after = "" ;
236+ token . sourceEndIndex = pos + 1 ;
225237 tokens . push ( token ) ;
226238 stack . push ( token ) ;
227239 tokens = token . nodes = [ ] ;
@@ -235,8 +247,10 @@ module.exports = function(input) {
235247 code = value . charCodeAt ( pos ) ;
236248
237249 parent . after = after ;
250+ parent . sourceEndIndex += after . length ;
238251 after = "" ;
239252 balanced -= 1 ;
253+ stack [ stack . length - 1 ] . sourceEndIndex = pos ;
240254 stack . pop ( ) ;
241255 parent = stack [ balanced ] ;
242256 tokens = parent . nodes ;
@@ -282,12 +296,14 @@ module.exports = function(input) {
282296 tokens . push ( {
283297 type : "unicode-range" ,
284298 sourceIndex : pos ,
299+ sourceEndIndex : next ,
285300 value : token
286301 } ) ;
287302 } else {
288303 tokens . push ( {
289304 type : "word" ,
290305 sourceIndex : pos ,
306+ sourceEndIndex : next ,
291307 value : token
292308 } ) ;
293309 }
@@ -298,6 +314,7 @@ module.exports = function(input) {
298314
299315 for ( pos = stack . length - 1 ; pos ; pos -= 1 ) {
300316 stack [ pos ] . unclosed = true ;
317+ stack [ pos ] . sourceEndIndex = value . length ;
301318 }
302319
303320 return stack [ 0 ] . nodes ;
0 commit comments