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

Function checkInvalidScopeReference

packages/compiler-sfc/src/compileScript.ts:282–297  ·  view source on GitHub ↗
(node: Node | undefined, method: string)

Source from the content-addressed store, hash-verified

280 }
281
282 function checkInvalidScopeReference(node: Node | undefined, method: string) {
283 if (!node) return
284 walkIdentifiers(node, id => {
285 const binding = setupBindings[id.name]
286 if (binding && binding !== BindingTypes.LITERAL_CONST) {
287 ctx.error(
288 `\`${method}()\` in <script setup> cannot reference locally ` +
289 `declared variables because it will be hoisted outside of the ` +
290 `setup() function. If your component options require initialization ` +
291 `in the module scope, use a separate normal <script> to export ` +
292 `the options instead.`,
293 id,
294 )
295 }
296 })
297 }
298
299 const scriptAst = ctx.scriptAst
300 const scriptSetupAst = ctx.scriptSetupAst!

Callers 1

compileScriptFunction · 0.85

Calls 2

walkIdentifiersFunction · 0.85
errorMethod · 0.80

Tested by

no test coverage detected