@@ -10,9 +10,23 @@ 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 !== null &&
20+ interpolation . charCodeAt ( 0 ) === code &&
21+ value . charCodeAt ( pos + 1 ) === openInterpolation
22+ ) ;
23+ }
24+
25+ function isCloseInterpolation ( code ) {
26+ return code === closeInterpolation ;
27+ }
28+
29+ module . exports = function ( input , options ) {
1630 var tokens = [ ] ;
1731 var value = input ;
1832
@@ -35,6 +49,15 @@ module.exports = function(input) {
3549 var before = "" ;
3650 var after = "" ;
3751
52+ options = options || { } ;
53+ var interpolationPrefix = null ;
54+ if (
55+ typeof options . interpolationPrefix !== "undefined" &&
56+ options . interpolationPrefix !== null
57+ ) {
58+ interpolationPrefix = options . interpolationPrefix ;
59+ }
60+
3861 while ( pos < max ) {
3962 // Whitespaces
4063 if ( code <= 32 ) {
@@ -46,7 +69,10 @@ module.exports = function(input) {
4669 token = value . slice ( pos , next ) ;
4770
4871 prev = tokens [ tokens . length - 1 ] ;
49- if ( code === closeParentheses && balanced ) {
72+ if (
73+ ( code === closeParentheses || isCloseInterpolation ( code ) ) &&
74+ balanced
75+ ) {
5076 after = token ;
5177 } else if ( prev && prev . type === "div" ) {
5278 prev . after = token ;
@@ -151,18 +177,22 @@ module.exports = function(input) {
151177 code = value . charCodeAt ( pos ) ;
152178
153179 // Open parentheses
154- } else if ( openParentheses === code ) {
180+ } else if (
181+ openParentheses === code ||
182+ isOpenInterpolation ( code , value , pos , interpolationPrefix )
183+ ) {
184+ var isFunction = openParentheses === code ;
155185 // Whitespaces after open parentheses
156- next = pos ;
186+ next = isFunction ? pos : pos + 1 ;
157187 do {
158188 next += 1 ;
159189 code = value . charCodeAt ( next ) ;
160190 } while ( code <= 32 ) ;
161- parenthesesOpenPos = pos ;
191+ parenthesesOpenPos = isFunction ? pos : pos + 1 ;
162192 token = {
163- type : "function" ,
193+ type : isFunction ? "function" : "interpolation ",
164194 sourceIndex : pos - name . length ,
165- value : name ,
195+ value : isFunction ? name : interpolationPrefix ,
166196 before : value . slice ( parenthesesOpenPos + 1 , next )
167197 } ;
168198 pos = next ;
@@ -230,7 +260,10 @@ module.exports = function(input) {
230260 name = "" ;
231261
232262 // Close parentheses
233- } else if ( closeParentheses === code && balanced ) {
263+ } else if (
264+ ( code === closeParentheses || isCloseInterpolation ( code ) ) &&
265+ balanced
266+ ) {
234267 pos += 1 ;
235268 code = value . charCodeAt ( pos ) ;
236269
@@ -260,19 +293,24 @@ module.exports = function(input) {
260293 code === colon ||
261294 code === slash ||
262295 code === openParentheses ||
296+ isOpenInterpolation ( code , value , pos , interpolationPrefix ) ||
263297 ( code === star &&
264298 parent &&
265299 parent . type === "function" &&
266300 parent . value === "calc" ) ||
267301 ( code === slash &&
268302 parent . type === "function" &&
269303 parent . value === "calc" ) ||
270- ( code === closeParentheses && balanced )
304+ ( ( code === closeParentheses || isCloseInterpolation ( code ) ) &&
305+ balanced )
271306 )
272307 ) ;
273308 token = value . slice ( pos , next ) ;
274309
275- if ( openParentheses === code ) {
310+ if (
311+ openParentheses === code ||
312+ isOpenInterpolation ( code , value , pos , interpolationPrefix )
313+ ) {
276314 name = token ;
277315 } else if (
278316 ( uLower === token . charCodeAt ( 0 ) || uUpper === token . charCodeAt ( 0 ) ) &&
0 commit comments