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

Function processNormalScript

packages/compiler-sfc/src/script/normalScript.ts:10–53  ·  view source on GitHub ↗
(
  ctx: ScriptCompileContext,
  scopeId: string,
)

Source from the content-addressed store, hash-verified

8export const normalScriptDefaultVar = `__default__`
9
10export function processNormalScript(
11 ctx: ScriptCompileContext,
12 scopeId: string,
13): SFCScriptBlock {
14 const script = ctx.descriptor.script!
15 try {
16 let content = script.content
17 let map = script.map
18 const scriptAst = ctx.scriptAst!
19 const bindings = analyzeScriptBindings(scriptAst.body)
20 const { cssVars } = ctx.descriptor
21 const { genDefaultAs, isProd } = ctx.options
22
23 if (cssVars.length || genDefaultAs) {
24 const defaultVar = genDefaultAs || normalScriptDefaultVar
25 const s = new MagicString(content)
26 rewriteDefaultAST(scriptAst.body, s, defaultVar)
27 content = s.toString()
28 if (cssVars.length && !ctx.options.templateOptions?.ssr) {
29 content += genNormalScriptCssVarsCode(
30 cssVars,
31 bindings,
32 scopeId,
33 !!isProd,
34 defaultVar,
35 )
36 }
37 if (!genDefaultAs) {
38 content += `\nexport default ${defaultVar}`
39 }
40 }
41 return {
42 ...script,
43 content,
44 map,
45 bindings,
46 scriptAst: scriptAst.body,
47 }
48 } catch (e: any) {
49 // silently fallback if parse fails since user may be using custom
50 // babel syntax
51 return script
52 }
53}

Callers 1

compileScriptFunction · 0.90

Calls 4

analyzeScriptBindingsFunction · 0.90
rewriteDefaultASTFunction · 0.90
toStringMethod · 0.80

Tested by

no test coverage detected