/** * A Vue / Svelte / Astro file is one file node holding the component it is, * and the component holds its script: each symbol has one parent, and a * component never contains its own file. What a per-instance script does at * its top level — ` `); const file = r.nodes.find((n) => n.kind === 'file')!; const component = componentOf(r); expect(file).toMatchObject({ id: 'file:pages/index.vue', startLine: 1, endLine: 9 }); const p = parents(r); expect(p.get(component.id)).toEqual([file.id]); expect(p.get(file.id)).toBeUndefined(); const load = r.nodes.find((n) => n.name === 'load')!; expect(p.get(load.id)).toEqual([component.id]); for (const [, list] of p) expect(list).toHaveLength(1); }); it('gives a `); expect(from(r, 'useFetch').filter((id) => id.startsWith('component:'))).toHaveLength(1); expect(r.unresolvedReferences.filter((ref) => ref.referenceKind === 'imports').every((ref) => ref.fromNodeId === 'file:pages/index.vue')).toBe(true); }); it('leaves a plain `); expect(from(r, 'registerWidget')).toEqual(['file:src/Widget.vue']); }); it('gives a Svelte instance script to the component, and a module script to the file', () => { const r = extractFromSource('src/routes/+page.svelte', `
items
`); const component = componentOf(r).id; expect(from(r, 'onMount')).toEqual([component]); expect(from(r, 'preload')).toEqual(['file:src/routes/+page.svelte']); expect(from(r, 'register')).toEqual(['file:src/routes/+page.svelte']); }); it('gives Astro frontmatter to the component, and makes a file node for a file without one', () => { const r = extractFromSource('src/pages/blog.astro', `--- const posts = await getCollection('blog'); ---about
\n`); expect(bare.nodes.map((n) => n.kind).sort()).toEqual(['component', 'file']); }); });