Home / Function/ next() — tailwindcss Function Reference

next() — tailwindcss Function Reference

Architecture documentation for the next() function in candidate_machine.rs from the tailwindcss codebase.

Entity Profile

Dependency Diagram

graph TD
  72559c5d_4bb9_6910_9b2a_e40485083ef5["next()"]
  77d62df5_fc2d_7aca_6445_23866d7db6db["candidate_machine.rs"]
  72559c5d_4bb9_6910_9b2a_e40485083ef5 -->|defined in| 77d62df5_fc2d_7aca_6445_23866d7db6db
  f222032f_1888_f50c_eee2_2eec75873336["reset()"]
  72559c5d_4bb9_6910_9b2a_e40485083ef5 -->|calls| f222032f_1888_f50c_eee2_2eec75873336
  2e4bab61_4088_e78b_82ff_81de38e001d3["done_span()"]
  72559c5d_4bb9_6910_9b2a_e40485083ef5 -->|calls| 2e4bab61_4088_e78b_82ff_81de38e001d3
  style 72559c5d_4bb9_6910_9b2a_e40485083ef5 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

crates/oxide/src/extractor/candidate_machine.rs lines 29–169

    fn next(&mut self, cursor: &mut cursor::Cursor<'_>) -> MachineState {
        let len = cursor.input.len();

        while cursor.pos < len {
            // Skip ahead for known characters that will never be part of a candidate. No need to
            // run any sub-machines.
            if cursor.curr.is_ascii_whitespace() {
                self.reset();
                cursor.advance();
                continue;
            }

            // Candidates don't start with these characters, so we can skip ahead.
            if matches!(cursor.curr, b':' | b'"' | b'\'' | b'`') {
                self.reset();
                cursor.advance();
                continue;
            }

            // Jump ahead if the character is known to be an invalid boundary and we should start
            // at the next boundary even though "valid" candidates can exist.
            //
            // E.g.: `<div class="">`
            //         ^^^            Valid candidate
            //        ^               But this character makes it invalid
            //             ^          Therefore we jump here
            //
            // E.g.: `Some Class`
            //        ^    ^       Invalid, we can jump ahead to the next boundary
            //
            if matches!(cursor.curr, b'<' | b'A'..=b'Z') {
                if let Some(offset) = cursor.input[cursor.pos..]
                    .iter()
                    .position(|&c| is_valid_before_boundary(&c))
                {
                    self.reset();
                    cursor.advance_by(offset + 1);
                } else {
                    return self.restart();
                }

                continue;
            }

            let mut variant_cursor = cursor.clone();
            let variant_machine_state = self.variant_machine.next(&mut variant_cursor);

            let mut utility_cursor = cursor.clone();
            let utility_machine_state = self.utility_machine.next(&mut utility_cursor);

            match (variant_machine_state, utility_machine_state) {
                // No variant, but the utility machine completed
                (MachineState::Idle, MachineState::Done(utility_span)) => {
                    cursor.move_to(utility_cursor.pos + 1);

                    let span = match self.last_variant_end_pos {
                        Some(end_pos) => {
                            // Verify that the utility is touching the last variant
                            if end_pos + 1 != utility_span.start {
                                return self.restart();
                            }

                            Span::new(self.start_pos, utility_span.end)
                        }
                        None => utility_span,
                    };

                    // Ensure the span has valid boundary characters before and after
                    if !has_valid_boundaries(&span, cursor.input) {
                        return self.restart();
                    }

                    return self.done_span(span);
                }

                // Both variant and utility machines are done
                // E.g.: `hover:flex`
                //        ^^^^^^      Variant
                //        ^^^^^       Utility
                //
                (MachineState::Done(variant_span), MachineState::Done(utility_span)) => {

Domain

Subdomains

Frequently Asked Questions

What does next() do?
next() is a function in the tailwindcss codebase, defined in crates/oxide/src/extractor/candidate_machine.rs.
Where is next() defined?
next() is defined in crates/oxide/src/extractor/candidate_machine.rs at line 29.
What does next() call?
next() calls 2 function(s): done_span, reset.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free