MCPcopy
hub / github.com/vuejs/core / parse

Function parse

packages/compiler-sfc/src/parse.ts:107–299  ·  view source on GitHub ↗
(
  source: string,
  options: SFCParseOptions = {},
)

Source from the content-addressed store, hash-verified

105 | LRUCache<string, SFCParseResult> = createCache<SFCParseResult>()
106
107export function parse(
108 source: string,
109 options: SFCParseOptions = {},
110): SFCParseResult {
111 const sourceKey = genCacheKey(source, {
112 ...options,
113 compiler: { parse: options.compiler?.parse },
114 })
115 const cache = parseCache.get(sourceKey)
116 if (cache) {
117 return cache
118 }
119
120 const {
121 sourceMap = true,
122 filename = DEFAULT_FILENAME,
123 sourceRoot = '',
124 pad = false,
125 ignoreEmpty = true,
126 compiler = CompilerDOM,
127 templateParseOptions = {},
128 } = options
129
130 const descriptor: SFCDescriptor = {
131 filename,
132 source,
133 template: null,
134 script: null,
135 scriptSetup: null,
136 styles: [],
137 customBlocks: [],
138 cssVars: [],
139 slotted: false,
140 shouldForceReload: prevImports => hmrShouldReload(prevImports, descriptor),
141 }
142
143 const errors: (CompilerError | SyntaxError)[] = []
144 const ast = compiler.parse(source, {
145 parseMode: 'sfc',
146 prefixIdentifiers: true,
147 ...templateParseOptions,
148 onError: e => {
149 errors.push(e)
150 },
151 })
152 ast.children.forEach(node => {
153 if (node.type !== NodeTypes.ELEMENT) {
154 return
155 }
156 // we only want to keep the nodes that are not empty
157 // (when the tag is not a template)
158 if (
159 ignoreEmpty &&
160 node.tag !== 'template' &&
161 isEmpty(node) &&
162 !hasSrc(node)
163 ) {
164 return

Callers 8

parseFileFunction · 0.90
parse.spec.tsFile · 0.90
cssVars.spec.tsFile · 0.90
resolveFunction · 0.90
rewriteDefaultFunction · 0.70
constructorMethod · 0.50
compileSFCScriptFunction · 0.50

Calls 15

genCacheKeyFunction · 0.90
createRootFunction · 0.90
parseCssVarsFunction · 0.90
hmrShouldReloadFunction · 0.85
isEmptyFunction · 0.85
hasSrcFunction · 0.85
dedentFunction · 0.85
genMapFunction · 0.85
forEachMethod · 0.80
findMethod · 0.80
someMethod · 0.80

Tested by 2

resolveFunction · 0.72
compileSFCScriptFunction · 0.40