11import { describe , it , expect } from 'vitest'
2- import { Parser } from './parse'
2+ import { parse } from './parse'
33import { SELECTOR_LIST , DECLARATION , IDENTIFIER } from './arena'
44
55describe ( 'Parser Options' , ( ) => {
66 const css = 'body { color: red; }'
77
88 describe ( 'Default behavior (all parsing enabled)' , ( ) => {
99 it ( 'should parse values and selectors by default' , ( ) => {
10- const parser = new Parser ( css )
11- const root = parser . parse ( )
10+ const root = parse ( css )
1211 const rule = root . first_child
1312
1413 // Check selector is parsed with detailed structure
@@ -27,8 +26,7 @@ describe('Parser Options', () => {
2726 } )
2827
2928 it ( 'should parse values and selectors with explicit options' , ( ) => {
30- const parser = new Parser ( css , { parse_values : true , parse_selectors : true } )
31- const root = parser . parse ( )
29+ const root = parse ( css , { parse_values : true , parse_selectors : true } )
3230 const rule = root . first_child
3331
3432 // Check selector is parsed
@@ -46,8 +44,7 @@ describe('Parser Options', () => {
4644
4745 describe ( 'parse_values disabled' , ( ) => {
4846 it ( 'should not parse value details when parse_values is false' , ( ) => {
49- const parser = new Parser ( css , { parse_values : false } )
50- const root = parser . parse ( )
47+ const root = parse ( css , { parse_values : false } )
5148 const rule = root . first_child
5249
5350 // Selector should still be parsed
@@ -67,8 +64,7 @@ describe('Parser Options', () => {
6764 } )
6865
6966 it ( 'should handle complex values without parsing' , ( ) => {
70- const parser = new Parser ( 'div { margin: 10px 20px; }' , { parse_values : false } )
71- const root = parser . parse ( )
67+ const root = parse ( 'div { margin: 10px 20px; }' , { parse_values : false } )
7268 const rule = root . first_child
7369 const selector = rule ?. first_child
7470 const block = selector ?. next_sibling
@@ -80,8 +76,7 @@ describe('Parser Options', () => {
8076 } )
8177
8278 it ( 'should handle function values without parsing' , ( ) => {
83- const parser = new Parser ( 'div { color: rgb(255, 0, 0); }' , { parse_values : false } )
84- const root = parser . parse ( )
79+ const root = parse ( 'div { color: rgb(255, 0, 0); }' , { parse_values : false } )
8580 const rule = root . first_child
8681 const selector = rule ?. first_child
8782 const block = selector ?. next_sibling
@@ -95,8 +90,7 @@ describe('Parser Options', () => {
9590
9691 describe ( 'parseSelectors disabled' , ( ) => {
9792 it ( 'should not parse selector details when parseSelectors is false' , ( ) => {
98- const parser = new Parser ( css , { parse_selectors : false } )
99- const root = parser . parse ( )
93+ const root = parse ( css , { parse_selectors : false } )
10094 const rule = root . first_child
10195
10296 // Selector should exist but be simple (just NODE_SELECTOR_LIST, no detailed structure)
@@ -114,8 +108,7 @@ describe('Parser Options', () => {
114108 } )
115109
116110 it ( 'should handle complex selectors without parsing' , ( ) => {
117- const parser = new Parser ( 'div.container#app { color: red; }' , { parse_selectors : false } )
118- const root = parser . parse ( )
111+ const root = parse ( 'div.container#app { color: red; }' , { parse_selectors : false } )
119112 const rule = root . first_child
120113 const selector = rule ?. first_child
121114
@@ -125,8 +118,7 @@ describe('Parser Options', () => {
125118 } )
126119
127120 it ( 'should handle selector lists without parsing' , ( ) => {
128- const parser = new Parser ( 'div, p, span { color: red; }' , { parse_selectors : false } )
129- const root = parser . parse ( )
121+ const root = parse ( 'div, p, span { color: red; }' , { parse_selectors : false } )
130122 const rule = root . first_child
131123 const selector = rule ?. first_child
132124
@@ -138,8 +130,7 @@ describe('Parser Options', () => {
138130
139131 describe ( 'Both parse_values and parseSelectors disabled' , ( ) => {
140132 it ( 'should not parse details for values or selectors' , ( ) => {
141- const parser = new Parser ( css , { parse_values : false , parse_selectors : false } )
142- const root = parser . parse ( )
133+ const root = parse ( css , { parse_values : false , parse_selectors : false } )
143134 const rule = root . first_child
144135
145136 // Selector should be simple
@@ -164,8 +155,7 @@ describe('Parser Options', () => {
164155 color: rgb(255, 0, 0);
165156 }
166157 `
167- const parser = new Parser ( css , { parse_values : false , parse_selectors : false } )
168- const root = parser . parse ( )
158+ const root = parse ( css , { parse_values : false , parse_selectors : false } )
169159 const rule = root . first_child
170160
171161 const selector = rule ?. first_child
@@ -194,8 +184,7 @@ describe('Parser Options', () => {
194184 margin: 10px 20px 30px 40px;
195185 }
196186 `
197- const parser = new Parser ( css , { parse_values : false } )
198- const root = parser . parse ( )
187+ const root = parse ( css , { parse_values : false } )
199188 const rule = root . first_child
200189 const selector = rule ?. first_child
201190
@@ -219,8 +208,7 @@ describe('Parser Options', () => {
219208 .another-complex[data-attr~="value"] { margin: 0; }
220209 #very-specific-id:not(.excluded) { padding: 10px; }
221210 `
222- const parser = new Parser ( css , { parse_selectors : false } )
223- const root = parser . parse ( )
211+ const root = parse ( css , { parse_selectors : false } )
224212
225213 // Can quickly count rules without parsing complex selectors
226214 let count = 0
@@ -236,8 +224,7 @@ describe('Parser Options', () => {
236224
237225 describe ( 'Options validation' , ( ) => {
238226 it ( 'should accept empty options object' , ( ) => {
239- const parser = new Parser ( css , { } )
240- const root = parser . parse ( )
227+ const root = parse ( css , { } )
241228 const rule = root . first_child
242229 const selector = rule ?. first_child
243230 const block = selector ?. next_sibling
@@ -249,8 +236,7 @@ describe('Parser Options', () => {
249236 } )
250237
251238 it ( 'should accept partial options' , ( ) => {
252- const parser = new Parser ( css , { parse_values : false } )
253- const root = parser . parse ( )
239+ const root = parse ( css , { parse_values : false } )
254240 const rule = root . first_child
255241 const selector = rule ?. first_child
256242 const block = selector ?. next_sibling
@@ -263,11 +249,10 @@ describe('Parser Options', () => {
263249 } )
264250
265251 it ( 'should accept skip_comments with parsing options' , ( ) => {
266- const parser = new Parser ( '/* test */ body { color: red; }' , {
252+ const root = parse ( '/* test */ body { color: red; }' , {
267253 skip_comments : true ,
268254 parse_values : false ,
269255 } )
270- const root = parser . parse ( )
271256 const rule = root . first_child
272257
273258 // Comment should be skipped
0 commit comments