@@ -142,17 +142,9 @@ const hasCalcFunc = (val) => {
142142 *
143143 * @param {string } val - The CSS string to parse.
144144 * @param {object } opt - The options for parsing.
145- * @param {boolean } [toObject=false] - Whether to return a plain object.
146- * @returns {object } The AST or a plain object.
145+ * @returns {object } The AST.
147146 */
148- const parseCSS = ( val , opt , toObject = false ) => {
149- val = prepareValue ( val ) ;
150- const ast = cssTree . parse ( val , opt ) ;
151- if ( toObject ) {
152- return cssTree . toPlainObject ( ast ) ;
153- }
154- return ast ;
155- } ;
147+ const parseCSS = ( val , opt ) => cssTree . parse ( prepareValue ( val ) , opt ) ;
156148
157149/**
158150 * Checks if the value is a valid property value.
@@ -212,13 +204,12 @@ const resolveCalc = (val, opt = { format: "specifiedValue" }) => {
212204 if ( typeof cachedValue === "string" ) {
213205 return cachedValue ;
214206 }
215- const obj = parseCSS ( val , { context : "value" } , true ) ;
216- if ( ! obj ?. children ) {
207+ const ast = parseCSS ( val , { context : "value" } ) ;
208+ if ( ! ast ?. children ) {
217209 return ;
218210 }
219- const { children : items } = obj ;
220211 const values = [ ] ;
221- for ( const item of items ) {
212+ for ( const item of ast . children ) {
222213 const { type : itemType , name : itemName , value : itemValue } = item ;
223214 if ( itemType === AST_TYPES . FUNCTION ) {
224215 const value = cssTree
@@ -301,8 +292,8 @@ const parsePropertyValue = (prop, val, opt = {}) => {
301292 if ( error || ! matched ) {
302293 parsedValue = false ;
303294 } else {
304- const obj = cssTree . toPlainObject ( ast ) ;
305- const items = obj . children ;
295+ const items = ast . children ;
296+ const itemCount = items . size ;
306297 const values = [ ] ;
307298 for ( const item of items ) {
308299 const { children, name, type, value, unit } = item ;
@@ -320,12 +311,12 @@ const parsePropertyValue = (prop, val, opt = {}) => {
320311 . generate ( item )
321312 . replace ( / \) (? ! \) | \s | , ) / g, ") " )
322313 . trim ( ) ;
323- const raw = items . length === 1 ? val : css ;
314+ const raw = itemCount === 1 ? val : css ;
324315 // Remove "${name}(" from the start and ")" from the end
325316 const itemValue = raw . slice ( name . length + 1 , - 1 ) . trim ( ) ;
326317 if ( name === "calc" ) {
327- if ( children . length === 1 ) {
328- const [ child ] = children ;
318+ if ( children . size === 1 ) {
319+ const child = children . first ;
329320 if ( child . type === AST_TYPES . NUMBER ) {
330321 values . push ( {
331322 type : AST_TYPES . CALC ,
0 commit comments