Repository: tailwindlabs/tailwindcss
File: packages/tailwindcss/src/compile.ts (TypeScript)

Code before:
    return (
      // Sort by lowest property index first
      (aSorting.properties.order[offset] ?? Infinity) -
        (zSorting.properties.order[offset] ?? Infinity) ||
      // Sort by most properties first, then by least properties
      zSorting.properties.count - aSorting.properties.count ||
      // Sort alphabetically
      compare(aSorting.candidate, zSorting.candidate)
    )
  })

  return {
    astNodes,
    nodeSorting,
  }
}

export function compileAstNodes(
  candidate: Candidate,
  designSystem: DesignSystem,
  flags: CompileAstFlags,
) {
  let asts = compileBaseUtility(candidate, designSystem)
  if (asts.length === 0) return []

  let respectImportant = Boolean(flags & CompileAstFlags.RespectImportant)

  let rules: {
    node: AstNode
    propertySort: {
      order: number[]
      count: number
    }
  }[] = []

  let selector = `.${escape(candidate.raw)}`

  for (let nodes of asts) {
    let propertySort = getPropertySort(nodes)

    // If the candidate itself is important then we want to always mark
    // the utility as important. However, at a design system level we want
    // to be able to opt-out when using things like `@apply`
    if (candidate.important || (designSystem.important && respectImportant)) {
      applyImportant(nodes)
    }

    let node: StyleRule = {
      kind: 'rule',
      selector,
      nodes,

Review comment (suggestion):
If we move the `designSystem.important` check here, then we don't need to recompute the `designSystem.import && respectImportant` in the loop below.

Bonus points: it would short-circuit and not even bother with the flags checking when not using the `important` flag on the import.

```suggestion
  let respectImportant = designSystem.important && Boolean(flags & CompileAstFlags.RespectImportant)
```

Code after:
    return (
      // Sort by lowest property index first
      (aSorting.properties.order[offset] ?? Infinity) -
        (zSorting.properties.order[offset] ?? Infinity) ||
      // Sort by most properties first, then by least properties
      zSorting.properties.count - aSorting.properties.count ||
      // Sort alphabetically
      compare(aSorting.candidate, zSorting.candidate)
    )
  })

  return {
    astNodes,
    nodeSorting,
  }
}

export function compileAstNodes(
  candidate: Candidate,
  designSystem: DesignSystem,
  flags: CompileAstFlags,
) {
  let asts = compileBaseUtility(candidate, designSystem)
  if (asts.length === 0) return []

  let respectImportant = designSystem.important && Boolean(flags & CompileAstFlags.RespectImportant)

  let rules: {
    node: AstNode
    propertySort: {
      order: number[]
      count: number
    }
  }[] = []

  let selector = `.${escape(candidate.raw)}`

  for (let nodes of asts) {
    let propertySort = getPropertySort(nodes)

    // If the candidate itself is important then we want to always mark
    // the utility as important. However, at a design system level we want
    // to be able to opt-out when using things like `@apply`
    if (candidate.important || respectImportant) {
      applyImportant(nodes)
    }

    let node: StyleRule = {
      kind: 'rule',
      selector,
      nodes,