Skip to content

Commit b42b79b

Browse files
authored
fix overload duplication (#183)
* fix overload duplication * fix * i think this is unused?
1 parent ecebcb8 commit b42b79b

File tree

9 files changed

+122
-1600
lines changed

9 files changed

+122
-1600
lines changed

apps/svelte.dev/content/docs/svelte/98-reference/21-svelte-compiler.md

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,6 @@ function parse(
102102

103103
</div>
104104

105-
## parse
106-
107-
The parse function parses a component, returning only its abstract syntax tree.
108-
109-
The `modern` option (`false` by default in Svelte 5) makes the parser return a modern AST instead of the legacy AST.
110-
`modern` will become `true` by default in Svelte 6, and the option will be removed in Svelte 7.
111-
112105
<div class="ts-block">
113106

114107
```ts

apps/svelte.dev/content/docs/svelte/98-reference/21-svelte-events.md

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,6 @@ function on<Type extends keyof WindowEventMap>(
3232

3333
</div>
3434

35-
## on
36-
37-
Attaches an event handler to the document and returns a function that removes the handler. Using this
38-
rather than `addEventListener` will preserve the correct order relative to handlers added declaratively
39-
(with attributes like `onclick`), which use event delegation for performance reasons
40-
4135
<div class="ts-block">
4236

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

5650
</div>
5751

58-
## on
59-
60-
Attaches an event handler to an element and returns a function that removes the handler. Using this
61-
rather than `addEventListener` will preserve the correct order relative to handlers added declaratively
62-
(with attributes like `onclick`), which use event delegation for performance reasons
63-
6452
<div class="ts-block">
6553

6654
```ts
@@ -81,12 +69,6 @@ function on<
8169

8270
</div>
8371

84-
## on
85-
86-
Attaches an event handler to an element and returns a function that removes the handler. Using this
87-
rather than `addEventListener` will preserve the correct order relative to handlers added declaratively
88-
(with attributes like `onclick`), which use event delegation for performance reasons
89-
9072
<div class="ts-block">
9173

9274
```ts
@@ -107,12 +89,6 @@ function on<
10789

10890
</div>
10991

110-
## on
111-
112-
Attaches an event handler to an element and returns a function that removes the handler. Using this
113-
rather than `addEventListener` will preserve the correct order relative to handlers added declaratively
114-
(with attributes like `onclick`), which use event delegation for performance reasons
115-
11692
<div class="ts-block">
11793

11894
```ts

apps/svelte.dev/content/docs/svelte/98-reference/21-svelte-store.md

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,6 @@ function derived<S extends Stores, T>(
3939

4040
</div>
4141

42-
## derived
43-
44-
Derived value store by synchronizing one or more readable stores and
45-
applying an aggregation function over its input values.
46-
4742
<div class="ts-block">
4843

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

7368
</div>
7469

75-
## fromStore
76-
77-
78-
7970
<div class="ts-block">
8071

8172
```ts
@@ -145,10 +136,6 @@ function toStore<V>(
145136

146137
</div>
147138

148-
## toStore
149-
150-
151-
152139
<div class="ts-block">
153140

154141
```ts

apps/svelte.dev/scripts/sync-docs/index.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,12 @@ const packages: Package[] = [
3333
m.types!.find((t) => t?.name === 'ActionReturn')
3434
);
3535
const new_children =
36-
module_with_ActionReturn?.types![1].children!.filter((c) => c.name !== '$$_attributes') ||
37-
[];
36+
module_with_ActionReturn?.types![1].overloads[0].children!.filter(
37+
(c) => c.name !== '$$_attributes'
38+
) || [];
3839

3940
if (module_with_ActionReturn) {
40-
module_with_ActionReturn.types![1].children = new_children;
41+
module_with_ActionReturn.types![1].overloads[0].children = new_children;
4142
}
4243

4344
return modules;

apps/svelte.dev/scripts/sync-docs/types.ts

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,8 @@
11
import fs from 'node:fs';
22
import ts from 'typescript';
33
import { format } from 'prettier';
4-
import { type Modules } from '@sveltejs/site-kit/markdown';
54
import { strip_origin } from './utils';
6-
7-
interface Extracted {
8-
name: string;
9-
comment: string;
10-
markdown?: string;
11-
snippet: string;
12-
deprecated?: string | null;
13-
children: Extracted[];
14-
bullets?: string[];
15-
}
5+
import type { Modules, Declaration, TypeElement } from '@sveltejs/site-kit/markdown';
166

177
export async function read_types(base: string, modules: Modules) {
188
{
@@ -51,8 +41,8 @@ export async function read_types(base: string, modules: Modules) {
5141
}
5242

5343
export async function get_types(code: string, statements: ts.NodeArray<ts.Statement>) {
54-
const exports: Extracted[] = [];
55-
const types: Extracted[] = [];
44+
const exports: Declaration[] = [];
45+
const types: Declaration[] = [];
5646

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

119-
let children: Extracted[] = [];
109+
let children: TypeElement[] = [];
120110

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

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

165-
collection.push({
166-
name,
167-
comment: cleanup_comment(comment),
155+
let declaration = collection.find((statement) => statement.name === name);
156+
157+
if (declaration) {
158+
// TODO tidy these up in the source
159+
if (cleanup_comment(comment) !== declaration.comment) {
160+
console.warn(`${name} overload has mismatched comment`);
161+
}
162+
163+
if (deprecated_notice !== declaration.deprecated) {
164+
console.warn(`${name} overload has mismatched deprecation notices`);
165+
}
166+
} else {
167+
declaration = {
168+
name,
169+
comment: cleanup_comment(comment),
170+
deprecated: deprecated_notice,
171+
overloads: []
172+
};
173+
174+
collection.push(declaration);
175+
}
176+
177+
declaration.overloads.push({
168178
snippet,
169-
children,
170-
deprecated: deprecated_notice
179+
children
171180
});
172181
}
173182
}
@@ -179,13 +188,13 @@ export async function get_types(code: string, statements: ts.NodeArray<ts.Statem
179188
return { types, exports };
180189
}
181190

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

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

188-
const children: Extracted[] = [];
197+
const children: TypeElement[] = [];
189198

190199
// @ts-ignore
191200
const name = member.name?.escapedText ?? member.name?.getText() ?? 'unknown';

0 commit comments

Comments
 (0)