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

Function processTokens

packages/extension/mcp/tools/code/tokens/process.ts:38–131  ·  view source on GitHub ↗
({
  code: inputCode,
  variableIds,
  usedCandidateIds,
  variableCache,
  styles,
  textSegments,
  svgs,
  config,
  pluginCode,
  resolveTokens,
  stamp,
  now
}: ProcessTokensInput)

Source from the content-addressed store, hash-verified

36}
37
38export async function processTokens({
39 code: inputCode,
40 variableIds,
41 usedCandidateIds,
42 variableCache,
43 styles,
44 textSegments,
45 svgs,
46 config,
47 pluginCode,
48 resolveTokens,
49 stamp,
50 now
51}: ProcessTokensInput): Promise<ProcessTokensResult> {
52 const clock = now ?? (() => Date.now())
53 let code = stripFallback(inputCode)
54
55 const candidateIds = usedCandidateIds.size
56 ? new Set<string>([...variableIds, ...usedCandidateIds])
57 : variableIds
58 const sourceIndex = buildSourceNameIndex(candidateIds, variableCache)
59 const sourceNames = new Set(sourceIndex.keys())
60 const emptyResult = () => ({
61 code,
62 tokensByCanonical: {},
63 sourceIndex
64 })
65 if (!sourceNames.size) {
66 return emptyResult()
67 }
68
69 let t = clock()
70 const usedNamesRaw = extractTokenNames(code, sourceNames)
71 if (stamp) stamp('tokens:detect', t)
72 if (!usedNamesRaw.size) {
73 return emptyResult()
74 }
75
76 t = clock()
77 const { rewriteMap, finalBridge } = await applyPluginTransformToNames(
78 usedNamesRaw,
79 sourceIndex,
80 pluginCode,
81 config
82 )
83
84 const hasRenames = rewriteMap.size > 0
85
86 if (hasRenames) {
87 code = rewriteTokenNamesInCode(code, rewriteMap)
88 }
89
90 let usedNamesFinal = usedNamesRaw
91 if (hasRenames) {
92 const remapped = new Set<string>()
93 usedNamesRaw.forEach((name) => {
94 remapped.add(rewriteMap.get(name) ?? name)
95 })

Callers 2

process.test.tsFile · 0.90
finalizeRenderedOutputFunction · 0.90

Calls 12

stripFallbackFunction · 0.90
buildSourceNameIndexFunction · 0.90
extractTokenNamesFunction · 0.90
rewriteTokenNamesInCodeFunction · 0.90
filterBridgeFunction · 0.90
buildUsedTokensFunction · 0.90
createTokenMatcherFunction · 0.90
emptyResultFunction · 0.85
stampFunction · 0.85
collectResolveNodeIdsFunction · 0.85
getMethod · 0.80

Tested by

no test coverage detected