Fix svelte component types

pull/8452/head
Puru Vijay 3 years ago
parent 2cfcdc7a49
commit 181b541b63

@ -222,3 +222,7 @@ Events can be cancelable by passing a third parameter to the dispatch function.
}
</script>
```
## Types
> TYPES: svelte

@ -319,6 +319,63 @@ const bundled_types = await get_bundled_types();
modules.sort((a, b) => (a.name < b.name ? -1 : 1));
// Fix the duplicate/messed up types
// !NOTE: This relies on mutation of `modules`
$: {
const module_with_SvelteComponent = modules.find((m) =>
m.types.filter((t) => t.name === 'SvelteComponent')
);
if (!module_with_SvelteComponent) break $;
const svelte_comp_part = module_with_SvelteComponent?.types.filter(
(t) => t.name === 'SvelteComponent'
);
if (svelte_comp_part?.[1]) {
// Take the comment from [0], and insert into [1]. Then delete [0]
svelte_comp_part[1].comment = svelte_comp_part?.[0].comment;
delete svelte_comp_part[0];
svelte_comp_part.reverse();
svelte_comp_part.length = 1;
module_with_SvelteComponent.types = module_with_SvelteComponent?.types.filter(
(t) => t.name !== 'SvelteComponent'
);
module_with_SvelteComponent.types.push(svelte_comp_part[0]);
module_with_SvelteComponent.types.sort((a, b) => (a.name < b.name ? -1 : 1));
}
}
// Fix the duplicate/messed up types
// !NOTE: This relies on mutation of `modules`
$: {
const module_with_SvelteComponentTyped = modules.find((m) =>
m.types.filter((t) => t.name === 'SvelteComponentTyped')
);
if (!module_with_SvelteComponentTyped) break $;
const svelte_comp_typed_part = module_with_SvelteComponentTyped?.types.filter(
(t) => t.name === 'SvelteComponentTyped'
);
if (svelte_comp_typed_part?.[1]) {
// Take the comment from [1], and insert into [0]. Then delete [1]
svelte_comp_typed_part[0].comment = svelte_comp_typed_part?.[1].comment;
delete svelte_comp_typed_part[1];
svelte_comp_typed_part.length = 1;
module_with_SvelteComponentTyped.types = module_with_SvelteComponentTyped?.types.filter(
(t) => t.name !== 'SvelteComponentTyped'
);
module_with_SvelteComponentTyped.types.push(svelte_comp_typed_part[0]);
module_with_SvelteComponentTyped.types.sort((a, b) => (a.name < b.name ? -1 : 1));
}
}
try {
fs.mkdirSync(new URL('../../src/lib/generated', import.meta.url), { recursive: true });
} catch {}

@ -110,7 +110,9 @@ export async function get_parsed_docs(docs_data, slug) {
try {
const injected = [];
if (source.includes('svelte')) {
console.log(page.file);
if (/(svelte)/.test(source) || page.file.includes('typescript')) {
injected.push(
`// @filename: ambient.d.ts`,
`/// <reference types="svelte" />`,
@ -137,6 +139,10 @@ export async function get_parsed_docs(docs_data, slug) {
injected.push('// @noErrors');
}
if (page.file.includes('typescript')) {
injected.push('// @errors: 2304');
}
if (injected.length) {
const injected_str = injected.join('\n');
if (source.includes('// @filename:')) {

@ -41,7 +41,7 @@
function update() {
content = document.querySelector('.content');
const { top } = content.getBoundingClientRect();
headings = content.querySelectorAll('h2[id], h3[id]');
headings = content.querySelectorAll('h2[id]');
positions = Array.from(headings).map((heading) => {
const style = getComputedStyle(heading);
return heading.getBoundingClientRect().top - parseFloat(style.scrollMarginTop) - top;

Loading…
Cancel
Save