@@ -35,25 +35,9 @@ function parseThemeOptions(selector: string) {
35
35
return { isReference, isInline }
36
36
}
37
37
38
- export async function compile (
39
- css : string ,
40
- { loadPlugin = throwOnPlugin } : CompileOptions = { } ,
41
- ) : Promise < {
42
- globs : string [ ]
43
- build ( candidates : string [ ] ) : string
44
- } > {
38
+ async function parseCss ( css : string , { loadPlugin = throwOnPlugin } : CompileOptions = { } ) {
45
39
let ast = CSS . parse ( css )
46
40
47
- if ( process . env . NODE_ENV !== 'test' ) {
48
- ast . unshift ( comment ( `! tailwindcss v${ version } | MIT License | https://tailwindcss.com ` ) )
49
- }
50
-
51
- // Track all invalid candidates
52
- let invalidCandidates = new Set < string > ( )
53
- function onInvalidCandidate ( candidate : string ) {
54
- invalidCandidates . add ( candidate )
55
- }
56
-
57
41
// Find all `@theme` declarations
58
42
let theme = new Theme ( )
59
43
let pluginLoaders : Promise < Plugin > [ ] = [ ]
@@ -301,21 +285,6 @@ export async function compile(
301
285
302
286
await Promise . all ( pluginLoaders . map ( ( loader ) => loader . then ( ( plugin ) => plugin ( pluginApi ) ) ) )
303
287
304
- let tailwindUtilitiesNode : Rule | null = null
305
-
306
- // Find `@tailwind utilities` so that we can later replace it with the actual
307
- // generated utility class CSS.
308
- walk ( ast , ( node ) => {
309
- if ( node . kind === 'rule' && node . selector === '@tailwind utilities' ) {
310
- tailwindUtilitiesNode = node
311
-
312
- // Stop walking after finding `@tailwind utilities` to avoid walking all
313
- // of the generated CSS. This means `@tailwind utilities` can only appear
314
- // once per file but that's the intended usage at this point in time.
315
- return WalkAction . Stop
316
- }
317
- } )
318
-
319
288
// Replace `@apply` rules with the actual utility classes.
320
289
if ( css . includes ( '@apply' ) ) {
321
290
substituteAtApply ( ast , designSystem )
@@ -335,6 +304,47 @@ export async function compile(
335
304
return WalkAction . Skip
336
305
} )
337
306
307
+ return {
308
+ designSystem,
309
+ ast,
310
+ globs,
311
+ }
312
+ }
313
+
314
+ export async function compile (
315
+ css : string ,
316
+ opts : CompileOptions = { } ,
317
+ ) : Promise < {
318
+ globs : string [ ]
319
+ build ( candidates : string [ ] ) : string
320
+ } > {
321
+ let { designSystem, ast, globs } = await parseCss ( css , opts )
322
+
323
+ let tailwindUtilitiesNode : Rule | null = null
324
+
325
+ // Find `@tailwind utilities` so that we can later replace it with the actual
326
+ // generated utility class CSS.
327
+ walk ( ast , ( node ) => {
328
+ if ( node . kind === 'rule' && node . selector === '@tailwind utilities' ) {
329
+ tailwindUtilitiesNode = node
330
+
331
+ // Stop walking after finding `@tailwind utilities` to avoid walking all
332
+ // of the generated CSS. This means `@tailwind utilities` can only appear
333
+ // once per file but that's the intended usage at this point in time.
334
+ return WalkAction . Stop
335
+ }
336
+ } )
337
+
338
+ if ( process . env . NODE_ENV !== 'test' ) {
339
+ ast . unshift ( comment ( `! tailwindcss v${ version } | MIT License | https://tailwindcss.com ` ) )
340
+ }
341
+
342
+ // Track all invalid candidates
343
+ let invalidCandidates = new Set < string > ( )
344
+ function onInvalidCandidate ( candidate : string ) {
345
+ invalidCandidates . add ( candidate )
346
+ }
347
+
338
348
// Track all valid candidates, these are the incoming `rawCandidate` that
339
349
// resulted in a generated AST Node. All the other `rawCandidates` are invalid
340
350
// and should be ignored.
@@ -385,24 +395,7 @@ export async function compile(
385
395
}
386
396
}
387
397
388
- export function __unstable__loadDesignSystem ( css : string ) {
389
- // Find all `@theme` declarations
390
- let theme = new Theme ( )
391
- let ast = CSS . parse ( css )
392
-
393
- walk ( ast , ( node ) => {
394
- if ( node . kind !== 'rule' ) return
395
- if ( node . selector !== '@theme' && ! node . selector . startsWith ( '@theme ' ) ) return
396
- let { isReference, isInline } = parseThemeOptions ( node . selector )
397
-
398
- // Record all custom properties in the `@theme` declaration
399
- walk ( [ node ] , ( node ) => {
400
- if ( node . kind !== 'declaration' ) return
401
- if ( ! node . property . startsWith ( '--' ) ) return
402
-
403
- theme . add ( node . property , node . value , { isReference, isInline } )
404
- } )
405
- } )
406
-
407
- return buildDesignSystem ( theme )
398
+ export async function __unstable__loadDesignSystem ( css : string , opts : CompileOptions = { } ) {
399
+ let result = await parseCss ( css , opts )
400
+ return result . designSystem
408
401
}
0 commit comments