Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions oxide/crates/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -433,9 +433,9 @@ fn read_all_files_sync(changed_content: Vec<ChangedContent>) -> Vec<Vec<u8>> {

changed_content
.into_iter()
.map(|c| match (c.file, c.content) {
(Some(file), None) => std::fs::read(file).unwrap(),
(None, Some(content)) => content.into_bytes(),
.filter_map(|c| match (c.file, c.content) {
(Some(file), None) => std::fs::read(file).ok(),
(None, Some(content)) => Some(content.into_bytes()),
_ => Default::default(),
})
.collect()
Expand Down
5 changes: 3 additions & 2 deletions packages/@tailwindcss-cli/src/commands/build/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ export async function handle(args: Result<ReturnType<typeof options>>) {
)

// Compile the input
let result = compile(input, candidates)
let { build } = compile(input)
let result = build(candidates)

// Optimize the output
if (args['--minify'] || args['--optimize']) {
Expand Down Expand Up @@ -193,7 +194,7 @@ export async function handle(args: Result<ReturnType<typeof options>>) {
}

// Compile the input
let result = compile(input, candidates)
result = compile(input).build(candidates)

// Optimize the output
if (args['--minify'] || args['--optimize']) {
Expand Down
4 changes: 2 additions & 2 deletions packages/@tailwindcss-postcss/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ function tailwindcss(opts: PluginOptions = {}): AcceptedPlugin {

// No `@tailwind` means we don't have to look for candidates
if (!hasTailwind) {
replaceCss(compile(root.toString(), []))
replaceCss(compile(root.toString()).build([]))
return
}

Expand Down Expand Up @@ -83,7 +83,7 @@ function tailwindcss(opts: PluginOptions = {}): AcceptedPlugin {
})
}

replaceCss(compile(root.toString(), candidates))
replaceCss(compile(root.toString()).build(candidates))
},
],
}
Expand Down
2 changes: 1 addition & 1 deletion packages/@tailwindcss-vite/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export default function tailwindcss(): Plugin[] {
}

function generateCss(css: string) {
return compile(css, Array.from(candidates))
return compile(css).build(Array.from(candidates))
}

function generateOptimizedCss(css: string) {
Expand Down
7 changes: 7 additions & 0 deletions packages/tailwindcss/src/ast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,13 @@ export function toCss(ast: AstNode[]) {
return css
}

if (node.selector === '@tailwind utilities') {
for (let child of node.nodes) {
css += stringify(child, depth)
}
return css
}

// Print at-rules without nodes with a `;` instead of an empty block.
//
// E.g.:
Expand Down
9 changes: 2 additions & 7 deletions packages/tailwindcss/src/candidate.bench.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { scanDir } from '@tailwindcss/oxide'
import { bench } from 'vitest'
import { parseCandidate, parseVariant } from './candidate'
import { parseCandidate } from './candidate'
import { buildDesignSystem } from './design-system'
import { Theme } from './theme'
import { DefaultMap } from './utils/default-map'

// FOLDER=path/to/folder vitest bench
const root = process.env.FOLDER || process.cwd()
Expand All @@ -15,10 +14,6 @@ const designSystem = buildDesignSystem(new Theme())

bench('parseCandidate', () => {
for (let candidate of result.candidates) {
parseCandidate(
candidate,
designSystem.utilities,
new DefaultMap((variant, map) => parseVariant(variant, designSystem.variants, map)),
)
parseCandidate(candidate, designSystem)
}
})
13 changes: 7 additions & 6 deletions packages/tailwindcss/src/candidate.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expect, it } from 'vitest'
import { parseCandidate, parseVariant } from './candidate'
import { buildDesignSystem } from './design-system'
import { Theme } from './theme'
import { Utilities } from './utilities'
import { DefaultMap } from './utils/default-map'
import { Variants } from './variants'

function run(
Expand All @@ -11,11 +11,12 @@ function run(
utilities ??= new Utilities()
variants ??= new Variants()

let parsedVariants = new DefaultMap((variant, map) => {
return parseVariant(variant, variants!, map)
})
let designSystem = buildDesignSystem(new Theme())

return parseCandidate(candidate, utilities, parsedVariants)
designSystem.utilities = utilities
designSystem.variants = variants

return designSystem.parseCandidate(candidate)
}

it('should skip unknown utilities', () => {
Expand Down
42 changes: 14 additions & 28 deletions packages/tailwindcss/src/candidate.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { DesignSystem } from './design-system'
import { decodeArbitraryValue } from './utils/decode-arbitrary-value'
import { segment } from './utils/segment'

Expand Down Expand Up @@ -206,14 +207,7 @@ export type Candidate =
important: boolean
}

export function parseCandidate(
input: string,
utilities: {
has: (value: string) => boolean
kind: (root: string) => Omit<Candidate['kind'], 'arbitrary'>
},
parsedVariants: { get: (value: string) => Variant | null },
): Candidate | null {
export function parseCandidate(input: string, designSystem: DesignSystem): Candidate | null {
// hover:focus:underline
// ^^^^^ ^^^^^^ -> Variants
// ^^^^^^^^^ -> Base
Expand All @@ -228,7 +222,7 @@ export function parseCandidate(
let parsedCandidateVariants: Variant[] = []

for (let variant of rawVariants) {
let parsedVariant = parsedVariants.get(variant)
let parsedVariant = designSystem.parseVariant(variant)
if (parsedVariant === null) return null

// Variants are applied left-to-right meaning that any representing pseudo-
Expand Down Expand Up @@ -320,7 +314,7 @@ export function parseCandidate(
base = base.slice(1)
}

let [root, value] = findRoot(base, utilities)
let [root, value] = findRoot(base, designSystem.utilities)

let modifierSegment: string | null = null

Expand All @@ -335,13 +329,13 @@ export function parseCandidate(
modifierSegment = rootModifierSegment

// Try to find the root and value, without the modifier present
;[root, value] = findRoot(rootWithoutModifier, utilities)
;[root, value] = findRoot(rootWithoutModifier, designSystem.utilities)
}

// If there's no root, the candidate isn't a valid class and can be discarded.
if (root === null) return null

let kind = utilities.kind(root)
let kind = designSystem.utilities.kind(root)

if (kind === 'static') {
if (value !== null) return null
Expand Down Expand Up @@ -475,15 +469,7 @@ function parseModifier(modifier: string): CandidateModifier {
}
}

export function parseVariant(
variant: string,
variants: {
has: (value: string) => boolean
kind: (root: string) => Omit<Variant['kind'], 'arbitrary'>
compounds: (root: string) => boolean
},
parsedVariants: { get: (value: string) => Variant | null },
): Variant | null {
export function parseVariant(variant: string, designSystem: DesignSystem): Variant | null {
// Arbitrary variants
if (variant[0] === '[' && variant[variant.length - 1] === ']') {
/**
Expand Down Expand Up @@ -535,20 +521,20 @@ export function parseVariant(
// - `group-hover/foo/bar`
if (additionalModifier) return null

let [root, value] = findRoot(variantWithoutModifier, variants)
let [root, value] = findRoot(variantWithoutModifier, designSystem.variants)

// Variant is invalid, therefore the candidate is invalid and we can skip
// continue parsing it.
if (root === null) return null

switch (variants.kind(root)) {
switch (designSystem.variants.kind(root)) {
case 'static': {
if (value !== null) return null

return {
kind: 'static',
root,
compounds: variants.compounds(root),
compounds: designSystem.variants.compounds(root),
}
}

Expand All @@ -564,7 +550,7 @@ export function parseVariant(
kind: 'arbitrary',
value: decodeArbitraryValue(value.slice(1, -1)),
},
compounds: variants.compounds(root),
compounds: designSystem.variants.compounds(root),
}
}

Expand All @@ -573,14 +559,14 @@ export function parseVariant(
root,
modifier: modifier === null ? null : parseModifier(modifier),
value: { kind: 'named', value },
compounds: variants.compounds(root),
compounds: designSystem.variants.compounds(root),
}
}

case 'compound': {
if (value === null) return null

let subVariant = parsedVariants.get(value)
let subVariant = designSystem.parseVariant(value)
if (subVariant === null) return null
if (subVariant.compounds === false) return null

Expand All @@ -589,7 +575,7 @@ export function parseVariant(
root,
modifier: modifier === null ? null : { kind: 'named', value: modifier },
variant: subVariant,
compounds: variants.compounds(root),
compounds: designSystem.variants.compounds(root),
}
}
}
Expand Down
Loading