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

Function doCompileTemplate

packages/compiler-sfc/src/compileTemplate.ts:162–275  ·  view source on GitHub ↗
({
  filename,
  id,
  scoped,
  slotted,
  inMap,
  source,
  ast: inAST,
  ssr = false,
  ssrCssVars,
  isProd = false,
  compiler,
  compilerOptions = {},
  transformAssetUrls,
}: SFCTemplateCompileOptions)

Source from the content-addressed store, hash-verified

160}
161
162function doCompileTemplate({
163 filename,
164 id,
165 scoped,
166 slotted,
167 inMap,
168 source,
169 ast: inAST,
170 ssr = false,
171 ssrCssVars,
172 isProd = false,
173 compiler,
174 compilerOptions = {},
175 transformAssetUrls,
176}: SFCTemplateCompileOptions): SFCTemplateCompileResults {
177 const errors: CompilerError[] = []
178 const warnings: CompilerError[] = []
179
180 let nodeTransforms: NodeTransform[] = []
181 if (isObject(transformAssetUrls)) {
182 const assetOptions = normalizeOptions(transformAssetUrls)
183 nodeTransforms = [
184 createAssetUrlTransformWithOptions(assetOptions),
185 createSrcsetTransformWithOptions(assetOptions),
186 ]
187 } else if (transformAssetUrls !== false) {
188 nodeTransforms = [transformAssetUrl, transformSrcset]
189 }
190
191 if (ssr && !ssrCssVars) {
192 warnOnce(
193 `compileTemplate is called with \`ssr: true\` but no ` +
194 `corresponding \`cssVars\` option.`,
195 )
196 }
197 if (!id) {
198 warnOnce(`compileTemplate now requires the \`id\` option.`)
199 id = ''
200 }
201
202 const shortId = id.replace(/^data-v-/, '')
203 const longId = `data-v-${shortId}`
204
205 const defaultCompiler = ssr ? (CompilerSSR as TemplateCompiler) : CompilerDOM
206 compiler = compiler || defaultCompiler
207
208 if (compiler !== defaultCompiler) {
209 // user using custom compiler, this means we cannot reuse the AST from
210 // the descriptor as they might be different.
211 inAST = undefined
212 }
213
214 if (inAST?.transformed) {
215 // If input AST has already been transformed, then it cannot be reused.
216 // We need to parse a fresh one. Can't just use `source` here since we need
217 // the AST location info to be relative to the entire SFC.
218 const newAST = (ssr ? CompilerDOM : compiler).parse(inAST.source, {
219 prefixIdentifiers: true,

Callers 1

compileTemplateFunction · 0.85

Calls 15

isObjectFunction · 0.90
normalizeOptionsFunction · 0.90
warnOnceFunction · 0.90
createRootFunction · 0.90
genCssVarsFromListFunction · 0.90
generateCodeFrameFunction · 0.90
mapLinesFunction · 0.85
patchErrorsFunction · 0.85
findMethod · 0.80
compileMethod · 0.80

Tested by

no test coverage detected