@@ -9,6 +9,36 @@ module.exports = function(css, options){
9
9
var lineno = 1 ;
10
10
var column = 1 ;
11
11
12
+ /**
13
+ * Shim-wrapper for trim. Will use native trim if supported, otherwise the trim
14
+ * found at https://github.com/kriskowal/es5-shim/blob/master/es5-shim.js
15
+ * at commit 32ff9747d5baaa446d5a49d0078ed38fcff93ab0
16
+ *
17
+ * Modified a bit to not pollute String prototype.
18
+ */
19
+
20
+ function trim ( str ) {
21
+ if ( str === void 0 || str === null ) {
22
+ throw new TypeError ( 'trim called on null or undefined' ) ;
23
+ }
24
+
25
+ var ws = '\x09\x0A\x0B\x0C\x0D\x20\xA0\u1680\u180E\u2000\u2001\u2002\u2003' +
26
+ '\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u202F\u205F\u3000\u2028' +
27
+ '\u2029\uFEFF' ;
28
+
29
+ if ( ! String . prototype . trim || ws . trim ( ) ) {
30
+ // http://blog.stevenlevithan.com/archives/faster-trim-javascript
31
+ // http://perfectionkills.com/whitespace-deviations/
32
+ ws = "[" + ws + "]" ;
33
+ var trimBeginRegexp = new RegExp ( "^" + ws + ws + "*" ) ;
34
+ var trimEndRegexp = new RegExp ( ws + ws + "*$" ) ;
35
+
36
+ return String ( str ) . replace ( trimBeginRegexp , "" ) . replace ( trimEndRegexp , "" ) ;
37
+ }
38
+
39
+ return String ( str ) . trim ( ) ;
40
+ }
41
+
12
42
/**
13
43
* Update lineno and column based on `str`.
14
44
*/
@@ -168,7 +198,7 @@ module.exports = function(css, options){
168
198
function selector ( ) {
169
199
var m = match ( / ^ ( [ ^ { ] + ) / ) ;
170
200
if ( ! m ) return ;
171
- return m [ 0 ] . trim ( ) . split ( / \s * , \s * / ) ;
201
+ return trim ( m [ 0 ] ) . split ( / \s * , \s * / ) ;
172
202
}
173
203
174
204
/**
@@ -193,7 +223,7 @@ module.exports = function(css, options){
193
223
var ret = pos ( {
194
224
type : 'declaration' ,
195
225
property : prop ,
196
- value : val [ 0 ] . trim ( )
226
+ value : trim ( val [ 0 ] )
197
227
} ) ;
198
228
199
229
// ;
@@ -290,7 +320,7 @@ module.exports = function(css, options){
290
320
var m = match ( / ^ @ s u p p o r t s * ( [ ^ { ] + ) / ) ;
291
321
292
322
if ( ! m ) return ;
293
- var supports = m [ 1 ] . trim ( ) ;
323
+ var supports = trim ( m [ 1 ] ) ;
294
324
295
325
if ( ! open ( ) ) return error ( "@supports missing '{'" ) ;
296
326
@@ -314,7 +344,7 @@ module.exports = function(css, options){
314
344
var m = match ( / ^ @ m e d i a * ( [ ^ { ] + ) / ) ;
315
345
316
346
if ( ! m ) return ;
317
- var media = m [ 1 ] . trim ( ) ;
347
+ var media = trim ( m [ 1 ] ) ;
318
348
319
349
if ( ! open ( ) ) return error ( "@media missing '{'" ) ;
320
350
@@ -368,8 +398,8 @@ module.exports = function(css, options){
368
398
var m = match ( / ^ @ ( [ - \w ] + ) ? d o c u m e n t * ( [ ^ { ] + ) / ) ;
369
399
if ( ! m ) return ;
370
400
371
- var vendor = ( m [ 1 ] || '' ) . trim ( ) ;
372
- var doc = m [ 2 ] . trim ( ) ;
401
+ var vendor = trim ( m [ 1 ] || '' ) ;
402
+ var doc = trim ( m [ 2 ] ) ;
373
403
374
404
if ( ! open ( ) ) return error ( "@document missing '{'" ) ;
375
405
@@ -418,7 +448,7 @@ module.exports = function(css, options){
418
448
var m = match ( new RegExp ( '^@' + name + ' *([^;\\n]+);' ) ) ;
419
449
if ( ! m ) return ;
420
450
var ret = { type : name } ;
421
- ret [ name ] = m [ 1 ] . trim ( ) ;
451
+ ret [ name ] = trim ( m [ 1 ] ) ;
422
452
return pos ( ret ) ;
423
453
}
424
454
0 commit comments