MCPcopy Create free account
hub / github.com/ecomfe/tempad-dev / transform

Function transform

packages/extension/mcp/tools/code/variables.ts:35–70  ·  view source on GitHub ↗
(
  styles: Map<string, Record<string, string>>,
  { pluginCode, config }: TransformOptions
)

Source from the content-addressed store, hash-verified

33}
34
35export function transform(
36 styles: Map<string, Record<string, string>>,
37 { pluginCode, config }: TransformOptions
38): Promise<Set<string>> {
39 const { references, buckets } = collectRefs(styles)
40 if (!references.length) return Promise.resolve(new Set())
41
42 return runTransformVariableBatch(
43 references.map(({ code, name, value }) => ({ code, name, value })),
44 workerUnitOptions(config),
45 pluginCode
46 ).then((transformResults) => {
47 const replacements = transformResults.map((result) => {
48 const noFallback = stripFallback(result)
49 const canonicalName = canonicalizeVarName(noFallback)
50 return canonicalName ? toVarExpr(canonicalName) : noFallback
51 })
52 const usedNames = new Set<string>()
53 // Keep original reference names to handle transforms that inline literal values.
54 references.forEach(({ name }) => usedNames.add(`--${name}`))
55 replacements.forEach((repl) => extractVarNames(repl).forEach((n) => usedNames.add(n)))
56
57 for (const bucket of buckets.values()) {
58 const style = styles.get(bucket.nodeId)
59 if (!style) continue
60
61 let occurrence = 0
62 style[bucket.property] = replaceVarFunctions(bucket.value, ({ full }) => {
63 const refIndex = bucket.matchIndices[occurrence++]!
64 return replacements[refIndex] ?? full
65 })
66 }
67
68 return usedNames
69 })
70}
71
72export function collectRefs(styles: Map<string, Record<string, string>>) {
73 const references: VariableReferenceInternal[] = []

Callers 5

variables.test.tsFile · 0.90
renderMarkupFunction · 0.70
transformPxValueFunction · 0.50
serializeCSSFunction · 0.50
transformHTMLFunction · 0.50

Calls 9

workerUnitOptionsFunction · 0.90
stripFallbackFunction · 0.90
canonicalizeVarNameFunction · 0.90
toVarExprFunction · 0.90
extractVarNamesFunction · 0.90
replaceVarFunctionsFunction · 0.90
collectRefsFunction · 0.85
getMethod · 0.80

Tested by

no test coverage detected