MCPcopy
hub / github.com/nuxt/nuxt / handler

Function handler

packages/nuxt/src/components/plugins/component-names.ts:28–65  ·  view source on GitHub ↗
(code, id)

Source from the content-addressed store, hash-verified

26 id: { include: FILENAME_RE },
27 },
28 handler (code, id) {
29 const filename = id.match(FILENAME_RE)?.[1]
30 if (!filename) {
31 return
32 }
33 const component = options.getComponents().find(c => c.filePath === id)
34
35 if (!component) {
36 return
37 }
38
39 const NAME_RE = new RegExp(`__name:\\s*['"]${filename}['"]`)
40 const s = new MagicString(code)
41 s.replace(NAME_RE, `__name: ${JSON.stringify(component.pascalName)}`)
42
43 // Without setup function, vue compiler does not generate __name
44 if (!s.hasChanged()) {
45 parseAndWalk(code, id, function (node) {
46 if (node.type !== 'ExportDefaultDeclaration') {
47 return
48 }
49
50 const { start, end } = node.declaration
51 s.overwrite(start, end, `Object.assign(${code.slice(start, end)}, { __name: ${JSON.stringify(component.pascalName)} })`)
52 this.skip()
53 })
54 }
55
56 if (s.hasChanged()) {
57 return {
58 code: s.toString(),
59 map: options.sourcemap
60 /* v8 ignore next */
61 ? s.generateMap({ hires: true })
62 : undefined,
63 }
64 }
65 },
66 },
67 }
68})

Callers

nothing calls this directly

Calls 2

toStringMethod · 0.80
getComponentsMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…