MCPcopy Create free account
hub / github.com/chakra-ui/panda / createParser

Function createParser

packages/parser/src/parser.ts:25–345  ·  view source on GitHub ↗
(context: ParserOptions)

Source from the content-addressed store, hash-verified

23}
24
25export function createParser(context: ParserOptions) {
26 const { jsx, imports, recipes, config } = context
27 const syntax = config.syntax
28
29 return function parse(
30 sourceFile: SourceFile | undefined,
31 encoder?: Generator['encoder'],
32 options?: ParserResultConfigureOptions & Partial<JsxFactoryResultTransform>,
33 ) {
34 if (!sourceFile) return
35
36 const importDeclarations: ImportResult[] = getImportDeclarations(context, sourceFile)
37
38 const file = imports.file(importDeclarations)
39
40 const filePath = sourceFile.getFilePath()
41
42 logger.debug(
43 'ast:import',
44 !file.isEmpty() ? `Found import { ${file.toString()} } in ${filePath}` : `No import found in ${filePath}`,
45 )
46
47 const parserResult = new ParserResult(context, encoder)
48
49 if (file.isEmpty() && !jsx.isEnabled) {
50 return parserResult
51 }
52
53 const extractResultByName = extract({
54 ast: sourceFile,
55 tokens: context.tokens
56 ? {
57 view: context.tokens.view,
58 isTokenFn: (fnName) => file.isTokenAlias(fnName),
59 }
60 : undefined,
61 components: jsx.isEnabled
62 ? {
63 matchTag: (prop) => {
64 if (options?.matchTag) {
65 // If the user has a custom matchTag function,
66 // we're not going to match every uppercased tag
67 const isPandaComponent = file.isPandaComponent(prop.tagName)
68 const matchTagMode = options.matchTagMode ?? 'extend'
69 const isCustomMatch = options.matchTag(prop.tagName, isPandaComponent)
70
71 if (matchTagMode === 'override') {
72 return isCustomMatch
73 }
74
75 return isPandaComponent || isCustomMatch
76 }
77
78 return !!file.matchTag(prop.tagName)
79 },
80 matchProp: (prop) => {
81 const isPandaProp = file.matchTagProp(prop.tagName, prop.propName)
82

Callers 1

constructorMethod · 0.90

Calls 15

setMethod · 0.95
setTokenMethod · 0.95
setPatternMethod · 0.95
setRecipeMethod · 0.95
setCvaMethod · 0.95
setJsxMethod · 0.95
getImportDeclarationsFunction · 0.90
extractFunction · 0.90
unboxFunction · 0.90
astishFunction · 0.90
matchFunction · 0.85
combineResultFunction · 0.85

Tested by

no test coverage detected