@@ -10,9 +10,22 @@ var star = "*".charCodeAt(0);
1010var uLower = "u" . charCodeAt ( 0 ) ;
1111var uUpper = "U" . charCodeAt ( 0 ) ;
1212var plus = "+" . charCodeAt ( 0 ) ;
13+ var openInterpolation = "{" . charCodeAt ( 0 ) ;
14+ var closeInterpolation = "}" . charCodeAt ( 0 ) ;
1315var isUnicodeRange = / ^ [ a - f 0 - 9 ? - ] + $ / i;
1416
15- module . exports = function ( input ) {
17+ function isOpenInterpolation ( code , value , pos , interpolation ) {
18+ return (
19+ interpolation . charCodeAt ( 0 ) === code &&
20+ value . charCodeAt ( pos + 1 ) === openInterpolation
21+ ) ;
22+ }
23+
24+ function isCloseInterpolation ( code ) {
25+ return code === closeInterpolation ;
26+ }
27+
28+ module . exports = function ( input , options ) {
1629 var tokens = [ ] ;
1730 var value = input ;
1831
@@ -35,6 +48,9 @@ module.exports = function(input) {
3548 var before = "" ;
3649 var after = "" ;
3750
51+ options = options || { } ;
52+ var interpolationPrefix = options . interpolationPrefix || "" ;
53+
3854 while ( pos < max ) {
3955 // Whitespaces
4056 if ( code <= 32 ) {
@@ -46,7 +62,10 @@ module.exports = function(input) {
4662 token = value . slice ( pos , next ) ;
4763
4864 prev = tokens [ tokens . length - 1 ] ;
49- if ( code === closeParentheses && balanced ) {
65+ if (
66+ ( code === closeParentheses || isCloseInterpolation ( code ) ) &&
67+ balanced
68+ ) {
5069 after = token ;
5170 } else if ( prev && prev . type === "div" ) {
5271 prev . after = token ;
@@ -151,18 +170,22 @@ module.exports = function(input) {
151170 code = value . charCodeAt ( pos ) ;
152171
153172 // Open parentheses
154- } else if ( openParentheses === code ) {
173+ } else if (
174+ openParentheses === code ||
175+ isOpenInterpolation ( code , value , pos , interpolationPrefix )
176+ ) {
177+ var isFunction = openParentheses === code ;
155178 // Whitespaces after open parentheses
156- next = pos ;
179+ next = isFunction ? pos : pos + 1 ;
157180 do {
158181 next += 1 ;
159182 code = value . charCodeAt ( next ) ;
160183 } while ( code <= 32 ) ;
161- parenthesesOpenPos = pos ;
184+ parenthesesOpenPos = isFunction ? pos : pos + 1 ;
162185 token = {
163- type : "function" ,
186+ type : isFunction ? "function" : "interpolation ",
164187 sourceIndex : pos - name . length ,
165- value : name ,
188+ value : isFunction ? name : interpolationPrefix ,
166189 before : value . slice ( parenthesesOpenPos + 1 , next )
167190 } ;
168191 pos = next ;
@@ -230,7 +253,10 @@ module.exports = function(input) {
230253 name = "" ;
231254
232255 // Close parentheses
233- } else if ( closeParentheses === code && balanced ) {
256+ } else if (
257+ ( code === closeParentheses || isCloseInterpolation ( code ) ) &&
258+ balanced
259+ ) {
234260 pos += 1 ;
235261 code = value . charCodeAt ( pos ) ;
236262
@@ -260,19 +286,24 @@ module.exports = function(input) {
260286 code === colon ||
261287 code === slash ||
262288 code === openParentheses ||
289+ isOpenInterpolation ( code , value , pos , interpolationPrefix ) ||
263290 ( code === star &&
264291 parent &&
265292 parent . type === "function" &&
266293 parent . value === "calc" ) ||
267294 ( code === slash &&
268295 parent . type === "function" &&
269296 parent . value === "calc" ) ||
270- ( code === closeParentheses && balanced )
297+ ( ( code === closeParentheses || isCloseInterpolation ( code ) ) &&
298+ balanced )
271299 )
272300 ) ;
273301 token = value . slice ( pos , next ) ;
274302
275- if ( openParentheses === code ) {
303+ if (
304+ openParentheses === code ||
305+ isOpenInterpolation ( code , value , pos , interpolationPrefix )
306+ ) {
276307 name = token ;
277308 } else if (
278309 ( uLower === token . charCodeAt ( 0 ) || uUpper === token . charCodeAt ( 0 ) ) &&
0 commit comments