@@ -24,11 +24,7 @@ let UNITLESS = {
2424}
2525
2626function atRule ( node ) {
27- if ( typeof node . nodes === 'undefined' ) {
28- return true
29- } else {
30- return process ( node )
31- }
27+ return node . nodes === undefined ? true : process ( node )
3228}
3329
3430// From https://github.com/hyperz111/fast-camelcase-css
@@ -43,32 +39,31 @@ function camelcase(property) {
4339
4440 // Microsoft vendor-prefixes are uniquely cased
4541 if ( property . startsWith ( '-ms-' ) ) {
46- property = property . substring ( 1 )
42+ property = property . slice ( 1 )
4743 index = property . indexOf ( '-' )
4844 }
4945
5046 let cursor = 0
5147 let result = ''
5248
5349 do {
54- result += property . substring ( cursor , index ) + property [ index + 1 ] . toUpperCase ( )
50+ result += property . slice ( cursor , index ) + property [ index + 1 ] . toUpperCase ( )
5551 cursor = index + 2
5652 index = property . indexOf ( '-' , cursor )
5753 } while ( index !== - 1 )
5854
59- return result + property . substring ( cursor )
55+ return result + property . slice ( cursor )
6056}
6157
6258function process ( node , options = { } ) {
6359 let name
6460 let result = { }
65- let { stringifyImportant } = options
6661
6762 node . each ( child => {
6863 if ( child . type === 'atrule' ) {
6964 name = '@' + child . name
7065 if ( child . params ) name += ' ' + child . params
71- if ( typeof result [ name ] === ' undefined' ) {
66+ if ( result [ name ] === undefined ) {
7267 result [ name ] = atRule ( child )
7368 } else if ( Array . isArray ( result [ name ] ) ) {
7469 result [ name ] . push ( atRule ( child ) )
@@ -81,7 +76,7 @@ function process(node, options = {}) {
8176 for ( let i in body ) {
8277 let object = result [ child . selector ]
8378 if (
84- stringifyImportant &&
79+ options . stringifyImportant &&
8580 typeof object [ i ] === 'string' &&
8681 object [ i ] . endsWith ( '!important' )
8782 ) {
@@ -96,19 +91,17 @@ function process(node, options = {}) {
9691 result [ child . selector ] = body
9792 }
9893 } else if ( child . type === 'decl' ) {
99- if ( child . prop [ 0 ] === '-' && child . prop [ 1 ] === '-' ) {
94+ if ( child . prop . startsWith ( '--' ) ) {
10095 name = child . prop
10196 } else if ( child . parent && child . parent . selector === ':export' ) {
10297 name = child . prop
10398 } else {
10499 name = camelcase ( child . prop )
105100 }
106101 let value = child . value
107- if ( ! isNaN ( child . value ) && UNITLESS [ name ] ) {
108- value = parseFloat ( child . value )
109- }
102+ if ( ! isNaN ( child . value ) && UNITLESS [ name ] ) value = parseFloat ( child . value )
110103 if ( child . important ) value += ' !important'
111- if ( typeof result [ name ] === ' undefined' ) {
104+ if ( result [ name ] === undefined ) {
112105 result [ name ] = value
113106 } else if ( Array . isArray ( result [ name ] ) ) {
114107 result [ name ] . push ( value )
0 commit comments