MCPcopy
hub / github.com/tailwindlabs/tailwindcss / build

Function build

packages/tailwindcss/src/index.ts:750–814  ·  packages/tailwindcss/src/index.ts::build
(newRawCandidates: string[])

Source from the content-addressed store, hash-verified

748 root,
749 features,
750 build(newRawCandidates: string[]) {
751 if (features === Features.None) {
752 return input
753 }
754
755 if (!utilitiesNode) {
756 compiled ??= optimizeAst(ast, designSystem, opts.polyfills)
757 return compiled
758 }
759
760 let didChange = defaultDidChange
761 let didAddExternalVariable = false
762 defaultDidChange = false
763
764 class="cm">// Add all new candidates unless we know that they are invalid.
765 let prevSize = allValidCandidates.size
766 for (let candidate of newRawCandidates) {
767 if (!designSystem.invalidCandidates.has(candidate)) {
768 if (candidate[0] === class="st">'-' && candidate[1] === class="st">'-') {
769 let didMarkVariableAsUsed = designSystem.theme.markUsedVariable(candidate)
770 didChange ||= didMarkVariableAsUsed
771 didAddExternalVariable ||= didMarkVariableAsUsed
772 } else {
773 allValidCandidates.add(candidate)
774 didChange ||= allValidCandidates.size !== prevSize
775 }
776 }
777 }
778
779 class="cm">// If no new candidates were added, we can return the original CSS. This
780 class="cm">// currently assumes that we only add new candidates and never remove any.
781 if (!didChange) {
782 compiled ??= optimizeAst(ast, designSystem, opts.polyfills)
783 return compiled
784 }
785
786 let newNodes = compileCandidates(allValidCandidates, designSystem, {
787 onInvalidCandidate,
788 }).astNodes
789
790 if (opts.from) {
791 walk(newNodes, (node) => {
792 class="cm">// We do this conditionally to preserve source locations from both
793 class="cm">// `@utility` and `@custom-variant`. Even though generated nodes are
794 class="cm">// cached this should be fine because `utilitiesNode.src` should not
795 class="cm">// change without a full rebuild which destroys the cache.
796 node.src ??= utilitiesNode.src
797 })
798 }
799
800 class="cm">// If no new ast nodes were generated, then we can return the original
801 class="cm">// CSS. This currently assumes that we only add new ast nodes and never
802 class="cm">// remove any.
803 if (!didAddExternalVariable && previousAstNodeCount === newNodes.length) {
804 compiled ??= optimizeAst(ast, designSystem, opts.polyfills)
805 return compiled
806 }
807

Callers 3

index.bench.tsFile · 0.70
runFunction · 0.50
renderFunction · 0.50

Calls 7

optimizeAstFunction · 0.90
compileCandidatesFunction · 0.90
walkFunction · 0.90
toCssFunction · 0.90
markUsedVariableMethod · 0.80
hasMethod · 0.45
addMethod · 0.45

Tested by 1

renderFunction · 0.40