compileScript() — vue Function Reference
Architecture documentation for the compileScript() function in compileScript.ts from the vue codebase.
Entity Profile
Dependency Diagram
graph TD 6195696d_b4e9_b5d7_3dd5_1966a03d855f["compileScript()"] b9f12a63_b611_1b00_0717_3ff21d7ce156["compileScript.ts"] 6195696d_b4e9_b5d7_3dd5_1966a03d855f -->|defined in| b9f12a63_b611_1b00_0717_3ff21d7ce156 989e8fc5_57b3_7826_b914_70e76c9bcd53["analyzeScriptBindings()"] 6195696d_b4e9_b5d7_3dd5_1966a03d855f -->|calls| 989e8fc5_57b3_7826_b914_70e76c9bcd53 8933da81_7ce4_e6a6_daa5_f88a24e6be02["rewriteDefault()"] 6195696d_b4e9_b5d7_3dd5_1966a03d855f -->|calls| 8933da81_7ce4_e6a6_daa5_f88a24e6be02 ec134563_fe99_b34c_861f_267104e87086["genNormalScriptCssVarsCode()"] 6195696d_b4e9_b5d7_3dd5_1966a03d855f -->|calls| ec134563_fe99_b34c_861f_267104e87086 5b047687_7011_90aa_7925_63a1d469fe2b["isImportUsed()"] 6195696d_b4e9_b5d7_3dd5_1966a03d855f -->|calls| 5b047687_7011_90aa_7925_63a1d469fe2b 72aee498_7b56_2d69_75c1_073eba5bb101["isCallOf()"] 6195696d_b4e9_b5d7_3dd5_1966a03d855f -->|calls| 72aee498_7b56_2d69_75c1_073eba5bb101 6821e51e_382f_8ff8_ca9d_3b77f896018a["walkIdentifiers()"] 6195696d_b4e9_b5d7_3dd5_1966a03d855f -->|calls| 6821e51e_382f_8ff8_ca9d_3b77f896018a 257a9079_2101_e3b1_3a80_2666c0920143["toRuntimeTypeString()"] 6195696d_b4e9_b5d7_3dd5_1966a03d855f -->|calls| 257a9079_2101_e3b1_3a80_2666c0920143 b5dd2b92_1eb8_9be8_c96d_7d157359d180["walkDeclaration()"] 6195696d_b4e9_b5d7_3dd5_1966a03d855f -->|calls| b5dd2b92_1eb8_9be8_c96d_7d157359d180 6364246b_4ca9_9d10_2feb_edc16524fcfd["warnOnce()"] 6195696d_b4e9_b5d7_3dd5_1966a03d855f -->|calls| 6364246b_4ca9_9d10_2feb_edc16524fcfd 2da3a667_48eb_9608_1220_cf672cac17b7["isFunctionType()"] 6195696d_b4e9_b5d7_3dd5_1966a03d855f -->|calls| 2da3a667_48eb_9608_1220_cf672cac17b7 728798bd_d0a3_3f87_32eb_839c83a9e416["registerBinding()"] 6195696d_b4e9_b5d7_3dd5_1966a03d855f -->|calls| 728798bd_d0a3_3f87_32eb_839c83a9e416 b5bc0258_b738_f4bd_b2f8_86ad13c9824d["recordType()"] 6195696d_b4e9_b5d7_3dd5_1966a03d855f -->|calls| b5bc0258_b738_f4bd_b2f8_86ad13c9824d 055d772e_d763_3b26_fcda_751e2ef7f1ef["extractRuntimeProps()"] 6195696d_b4e9_b5d7_3dd5_1966a03d855f -->|calls| 055d772e_d763_3b26_fcda_751e2ef7f1ef style 6195696d_b4e9_b5d7_3dd5_1966a03d855f fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
packages/compiler-sfc/src/compileScript.ts lines 98–1273
export function compileScript(
sfc: SFCDescriptor,
options: SFCScriptCompileOptions = { id: '' }
): SFCScriptBlock {
let { filename, script, scriptSetup, source } = sfc
const isProd = !!options.isProd
const genSourceMap = options.sourceMap !== false
let refBindings: string[] | undefined
const cssVars = sfc.cssVars
const scopeId = options.id ? options.id.replace(/^data-v-/, '') : ''
const scriptLang = script && script.lang
const scriptSetupLang = scriptSetup && scriptSetup.lang
const isTS =
scriptLang === 'ts' ||
scriptLang === 'tsx' ||
scriptSetupLang === 'ts' ||
scriptSetupLang === 'tsx'
// resolve parser plugins
const plugins: ParserPlugin[] = []
if (!isTS || scriptLang === 'tsx' || scriptSetupLang === 'tsx') {
plugins.push('jsx')
} else {
// If don't match the case of adding jsx, should remove the jsx from the babelParserPlugins
if (options.babelParserPlugins)
options.babelParserPlugins = options.babelParserPlugins.filter(
n => n !== 'jsx'
)
}
if (options.babelParserPlugins) plugins.push(...options.babelParserPlugins)
if (isTS) {
plugins.push('typescript')
if (!plugins.includes('decorators')) {
plugins.push('decorators-legacy')
}
}
if (!scriptSetup) {
if (!script) {
throw new Error(`[@vue/compiler-sfc] SFC contains no <script> tags.`)
}
if (scriptLang && !isTS && scriptLang !== 'jsx') {
// do not process non js/ts script blocks
return script
}
try {
let content = script.content
let map = script.map
const scriptAst = _parse(content, {
plugins,
sourceType: 'module'
}).program
const bindings = analyzeScriptBindings(scriptAst.body)
if (cssVars.length) {
content = rewriteDefault(content, DEFAULT_VAR, plugins)
content += genNormalScriptCssVarsCode(
cssVars,
bindings,
scopeId,
isProd
)
content += `\nexport default ${DEFAULT_VAR}`
}
return {
...script,
content,
map,
bindings,
scriptAst: scriptAst.body
}
} catch (e: any) {
// silently fallback if parse fails since user may be using custom
// babel syntax
return script
}
}
if (script && scriptLang !== scriptSetupLang) {
throw new Error(
`[@vue/compiler-sfc] <script> and <script setup> must have the same ` +
Domain
Subdomains
Defined In
Calls
- analyzeScriptBindings()
- extractRuntimeEmits()
- extractRuntimeProps()
- genCssVarsCode()
- genNormalScriptCssVarsCode()
- genRuntimeEmits()
- getObjectOrArrayExpressionKeys()
- isCallOf()
- isFunctionType()
- isImportUsed()
- recordType()
- registerBinding()
- rewriteDefault()
- toRuntimeTypeString()
- walkDeclaration()
- walkIdentifiers()
- warnOnce()
Source
Frequently Asked Questions
What does compileScript() do?
compileScript() is a function in the vue codebase, defined in packages/compiler-sfc/src/compileScript.ts.
Where is compileScript() defined?
compileScript() is defined in packages/compiler-sfc/src/compileScript.ts at line 98.
What does compileScript() call?
compileScript() calls 17 function(s): analyzeScriptBindings, extractRuntimeEmits, extractRuntimeProps, genCssVarsCode, genNormalScriptCssVarsCode, genRuntimeEmits, getObjectOrArrayExpressionKeys, isCallOf, and 9 more.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free