Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,6 @@ function parse(

</div>

## parse

The parse function parses a component, returning only its abstract syntax tree.

The `modern` option (`false` by default in Svelte 5) makes the parser return a modern AST instead of the legacy AST.
`modern` will become `true` by default in Svelte 6, and the option will be removed in Svelte 7.

<div class="ts-block">

```ts
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,6 @@ function on<Type extends keyof WindowEventMap>(

</div>

## on

Attaches an event handler to the document and returns a function that removes the handler. Using this
rather than `addEventListener` will preserve the correct order relative to handlers added declaratively
(with attributes like `onclick`), which use event delegation for performance reasons

<div class="ts-block">

```ts
Expand All @@ -55,12 +49,6 @@ function on<Type extends keyof DocumentEventMap>(

</div>

## on

Attaches an event handler to an element and returns a function that removes the handler. Using this
rather than `addEventListener` will preserve the correct order relative to handlers added declaratively
(with attributes like `onclick`), which use event delegation for performance reasons

<div class="ts-block">

```ts
Expand All @@ -81,12 +69,6 @@ function on<

</div>

## on

Attaches an event handler to an element and returns a function that removes the handler. Using this
rather than `addEventListener` will preserve the correct order relative to handlers added declaratively
(with attributes like `onclick`), which use event delegation for performance reasons

<div class="ts-block">

```ts
Expand All @@ -107,12 +89,6 @@ function on<

</div>

## on

Attaches an event handler to an element and returns a function that removes the handler. Using this
rather than `addEventListener` will preserve the correct order relative to handlers added declaratively
(with attributes like `onclick`), which use event delegation for performance reasons

<div class="ts-block">

```ts
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,6 @@ function derived<S extends Stores, T>(

</div>

## derived

Derived value store by synchronizing one or more readable stores and
applying an aggregation function over its input values.

<div class="ts-block">

```ts
Expand Down Expand Up @@ -72,10 +67,6 @@ function fromStore<V>(store: Writable<V>): {

</div>

## fromStore



<div class="ts-block">

```ts
Expand Down Expand Up @@ -145,10 +136,6 @@ function toStore<V>(

</div>

## toStore



<div class="ts-block">

```ts
Expand Down
7 changes: 4 additions & 3 deletions apps/svelte.dev/scripts/sync-docs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,12 @@ const packages: Package[] = [
m.types!.find((t) => t?.name === 'ActionReturn')
);
const new_children =
module_with_ActionReturn?.types![1].children!.filter((c) => c.name !== '$$_attributes') ||
[];
module_with_ActionReturn?.types![1].overloads[0].children!.filter(
(c) => c.name !== '$$_attributes'
) || [];

if (module_with_ActionReturn) {
module_with_ActionReturn.types![1].children = new_children;
module_with_ActionReturn.types![1].overloads[0].children = new_children;
}

return modules;
Expand Down
51 changes: 30 additions & 21 deletions apps/svelte.dev/scripts/sync-docs/types.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,8 @@
import fs from 'node:fs';
import ts from 'typescript';
import { format } from 'prettier';
import { type Modules } from '@sveltejs/site-kit/markdown';
import { strip_origin } from './utils';

interface Extracted {
name: string;
comment: string;
markdown?: string;
snippet: string;
deprecated?: string | null;
children: Extracted[];
bullets?: string[];
}
import type { Modules, Declaration, TypeElement } from '@sveltejs/site-kit/markdown';

export async function read_types(base: string, modules: Modules) {
{
Expand Down Expand Up @@ -51,8 +41,8 @@ export async function read_types(base: string, modules: Modules) {
}

export async function get_types(code: string, statements: ts.NodeArray<ts.Statement>) {
const exports: Extracted[] = [];
const types: Extracted[] = [];
const exports: Declaration[] = [];
const types: Declaration[] = [];

if (statements) {
for (const statement of statements) {
Expand Down Expand Up @@ -116,7 +106,7 @@ export async function get_types(code: string, statements: ts.NodeArray<ts.Statem
const i = code.indexOf('export', start);
start = i + 6;

let children: Extracted[] = [];
let children: TypeElement[] = [];

let snippet_unformatted = code.slice(start, statement.end).trim();

Expand Down Expand Up @@ -162,12 +152,31 @@ export async function get_types(code: string, statements: ts.NodeArray<ts.Statem
? exports
: types;

collection.push({
name,
comment: cleanup_comment(comment),
let declaration = collection.find((statement) => statement.name === name);

if (declaration) {
// TODO tidy these up in the source
if (cleanup_comment(comment) !== declaration.comment) {
console.warn(`${name} overload has mismatched comment`);
}

if (deprecated_notice !== declaration.deprecated) {
console.warn(`${name} overload has mismatched deprecation notices`);
}
} else {
declaration = {
name,
comment: cleanup_comment(comment),
deprecated: deprecated_notice,
overloads: []
};

collection.push(declaration);
}

declaration.overloads.push({
snippet,
children,
deprecated: deprecated_notice
children
});
}
}
Expand All @@ -179,13 +188,13 @@ export async function get_types(code: string, statements: ts.NodeArray<ts.Statem
return { types, exports };
}

function munge_type_element(member: ts.TypeElement, depth = 1): Extracted | undefined {
function munge_type_element(member: ts.TypeElement, depth = 1): TypeElement | undefined {
// @ts-ignore
const doc = member.jsDoc?.[0];

if (/private api|DO NOT USE/i.test(doc?.comment)) return;

const children: Extracted[] = [];
const children: TypeElement[] = [];

// @ts-ignore
const name = member.name?.escapedText ?? member.name?.getText() ?? 'unknown';
Expand Down
Loading
Loading