diff --git a/apps/svelte.dev/content/docs/svelte/04-runtime/03-lifecycle-hooks.md b/apps/svelte.dev/content/docs/svelte/04-runtime/03-lifecycle-hooks.md index 05aa38ccbb..0f536cb8bc 100644 --- a/apps/svelte.dev/content/docs/svelte/04-runtime/03-lifecycle-hooks.md +++ b/apps/svelte.dev/content/docs/svelte/04-runtime/03-lifecycle-hooks.md @@ -45,6 +45,11 @@ If a function is returned from `onMount`, it will be called when the component i ## `onDestroy` +Schedules a callback to run immediately before the component is unmounted. + +Out of `onMount`, `beforeUpdate`, `afterUpdate` and `onDestroy`, this is the +only one that runs inside a server-side component. +
```dts @@ -53,6 +58,8 @@ function onDestroy(fn: () => any): void;
+ + Schedules a callback to run immediately before the component is unmounted. Out of `onMount`, `beforeUpdate`, `afterUpdate` and `onDestroy`, this is the only one that runs inside a server-side component. diff --git a/apps/svelte.dev/content/docs/svelte/98-reference/20-svelte.md b/apps/svelte.dev/content/docs/svelte/98-reference/20-svelte.md index 7de3822128..53f735cfac 100644 --- a/apps/svelte.dev/content/docs/svelte/98-reference/20-svelte.md +++ b/apps/svelte.dev/content/docs/svelte/98-reference/20-svelte.md @@ -28,6 +28,12 @@ import { ## afterUpdate +
+ +Use `$effect` instead — see https://svelte-5-preview.vercel.app/docs/deprecations#beforeupdate-and-afterupdate + +
+ Schedules a callback to run immediately after the component has been updated. The first time the callback runs will be after the initial `onMount`. @@ -42,8 +48,16 @@ function afterUpdate(fn: () => void): void; + + ## beforeUpdate +
+ +Use `$effect.pre` instead — see https://svelte-5-preview.vercel.app/docs/deprecations#beforeupdate-and-afterupdate + +
+ Schedules a callback to run immediately before the component is updated after any state change. The first time the callback runs will be before the initial `onMount`. @@ -58,8 +72,16 @@ function beforeUpdate(fn: () => void): void; + + ## createEventDispatcher +
+ +Use callback props and/or the `$host()` rune instead — see https://svelte-5-preview.vercel.app/docs/deprecations#createeventdispatcher + +
+ Creates an event dispatcher that can be used to dispatch [component events](https://svelte.dev/docs#template-syntax-component-directives-on-eventname). Event dispatchers are functions that can take two arguments: `name` and `detail`. @@ -88,6 +110,8 @@ function createEventDispatcher< + + ## createRawSnippet Create a snippet programmatically @@ -105,6 +129,8 @@ function createRawSnippet( + + ## flushSync Synchronously flushes any pending state changes and those that result from it. @@ -117,6 +143,8 @@ function flushSync(fn?: (() => void) | undefined): void; + + ## getAllContexts Retrieves the whole context map that belongs to the closest parent component. @@ -133,6 +161,8 @@ function getAllContexts< + + ## getContext Retrieves the context that belongs to the closest parent component with the specified `key`. @@ -146,6 +176,8 @@ function getContext(key: any): T; + + ## hasContext Checks whether a given `key` has been set in the context of a parent component. @@ -159,6 +191,8 @@ function hasContext(key: any): boolean; + + ## hydrate Hydrates a component on the given target and returns the exports and potentially the props (if compiled with `accessors: true`) of the component @@ -195,6 +229,8 @@ function hydrate< + + ## mount Mounts a component to the given target and returns the exports and potentially the props (if compiled with `accessors: true`) of the component. @@ -232,6 +268,8 @@ function mount< + + ## onDestroy Schedules a callback to run immediately before the component is unmounted. @@ -247,6 +285,8 @@ function onDestroy(fn: () => any): void; + + ## onMount The `onMount` function schedules a callback to run as soon as the component has been mounted to the DOM. @@ -270,6 +310,8 @@ function onMount( + + ## setContext Associates an arbitrary `context` object with the current component and the specified `key` @@ -286,6 +328,8 @@ function setContext(key: any, context: T): T; + + ## tick Returns a promise that resolves once any pending state changes have been applied. @@ -298,6 +342,8 @@ function tick(): Promise; + + ## unmount Unmounts a component that was previously mounted using `mount` or `hydrate`. @@ -310,6 +356,8 @@ function unmount(component: Record): void; + + ## untrack Use `untrack` to prevent something from being treated as an `$effect`/`$derived` dependency. @@ -324,6 +372,8 @@ function untrack(fn: () => T): T; + + ## Component Can be used to create strongly typed Svelte components. @@ -403,8 +453,7 @@ element?: typeof HTMLElement; The custom element version of the component. Only present if compiled with the `customElement` compiler option - - + ## ComponentConstructorOptions @@ -504,8 +553,7 @@ $$inline?: boolean; ```
- - + ## ComponentEvents @@ -524,7 +572,6 @@ type ComponentEvents = : never; ``` - ## ComponentInternals @@ -537,7 +584,6 @@ Internal implementation details that vary between environments type ComponentInternals = Branded<{}, 'ComponentInternals'>; ``` - ## ComponentProps @@ -582,7 +628,6 @@ type ComponentProps< : never; ``` - ## ComponentType @@ -610,7 +655,6 @@ type ComponentType< }; ``` - ## EventDispatcher @@ -636,8 +680,7 @@ interface EventDispatcher< ```
- - + ## Snippet @@ -670,8 +713,7 @@ interface Snippet {/*…*/} ```
- - + ## SvelteComponent @@ -789,8 +831,7 @@ for more info. - - + ## SvelteComponentTyped @@ -810,7 +851,6 @@ class SvelteComponentTyped< > extends SvelteComponent {} ``` - diff --git a/apps/svelte.dev/content/docs/svelte/98-reference/21-svelte-action.md b/apps/svelte.dev/content/docs/svelte/98-reference/21-svelte-action.md index b7798126fb..49f8b9f540 100644 --- a/apps/svelte.dev/content/docs/svelte/98-reference/21-svelte-action.md +++ b/apps/svelte.dev/content/docs/svelte/98-reference/21-svelte-action.md @@ -42,8 +42,7 @@ interface Action< ```
- - + ## ActionReturn @@ -100,7 +99,6 @@ destroy?: () => void; ```
- - + diff --git a/apps/svelte.dev/content/docs/svelte/98-reference/21-svelte-animate.md b/apps/svelte.dev/content/docs/svelte/98-reference/21-svelte-animate.md index ef9123deb4..466f185778 100644 --- a/apps/svelte.dev/content/docs/svelte/98-reference/21-svelte-animate.md +++ b/apps/svelte.dev/content/docs/svelte/98-reference/21-svelte-animate.md @@ -32,6 +32,8 @@ function flip( + + ## AnimationConfig
@@ -83,8 +85,7 @@ tick?: (t: number, u: number) => void; ```
-
- + ## FlipParams @@ -119,7 +120,6 @@ easing?: (t: number) => number; ```
- - + diff --git a/apps/svelte.dev/content/docs/svelte/98-reference/21-svelte-compiler.md b/apps/svelte.dev/content/docs/svelte/98-reference/21-svelte-compiler.md index fa5bf611f5..fe083c64d1 100644 --- a/apps/svelte.dev/content/docs/svelte/98-reference/21-svelte-compiler.md +++ b/apps/svelte.dev/content/docs/svelte/98-reference/21-svelte-compiler.md @@ -31,6 +31,8 @@ const VERSION: string; + + ## compile `compile` converts your `.svelte` source code into a JavaScript module that exports a component @@ -46,6 +48,8 @@ function compile( + + ## compileModule `compileModule` takes your JavaScript source code containing runes, and turns it into a JavaScript module. @@ -61,6 +65,8 @@ function compileModule( + + ## migrate Does a best-effort migration of Svelte code towards using runes, event attributes and render tags. @@ -76,6 +82,8 @@ function migrate(source: string): { + + ## parse The parse function parses a component, returning only its abstract syntax tree. @@ -113,6 +121,8 @@ function parse( + + ## preprocess The preprocess function provides convenient hooks for arbitrarily transforming component source code. @@ -134,9 +144,15 @@ function preprocess( + + ## walk +
+Replace this with `import { walk } from 'estree-walker'` + +
@@ -146,6 +162,8 @@ function walk(): never;
+ + ## AST
@@ -510,7 +528,6 @@ namespace AST { } ``` -
## CompileError @@ -521,7 +538,6 @@ namespace AST { interface CompileError extends ICompileDiagnostic {} ``` - ## CompileOptions @@ -875,8 +891,7 @@ If `true`, returns the modern version of the AST. Will become `true` by default in Svelte 6, and the option will be removed in Svelte 7. - - + ## CompileResult @@ -998,8 +1013,7 @@ ast: any; The AST - - + ## MarkupPreprocessor @@ -1020,7 +1034,6 @@ type MarkupPreprocessor = (options: { }) => Processed | void | Promise; ``` - ## ModuleCompileOptions @@ -1115,8 +1128,7 @@ A function that gets a `Warning` as an argument and returns a boolean. Use this to filter out warnings. Return `true` to keep the warning, `false` to discard it. - - + ## Preprocessor @@ -1145,7 +1157,6 @@ type Preprocessor = (options: { }) => Processed | void | Promise; ``` - ## PreprocessorGroup @@ -1196,8 +1207,7 @@ script?: Preprocessor; ```
- - + ## Processed @@ -1268,8 +1278,7 @@ toString?: () => string; ```
- - + ## Warning @@ -1279,7 +1288,6 @@ toString?: () => string; interface Warning extends ICompileDiagnostic {} ``` - diff --git a/apps/svelte.dev/content/docs/svelte/98-reference/21-svelte-easing.md b/apps/svelte.dev/content/docs/svelte/98-reference/21-svelte-easing.md index ecf8554173..4454fd47aa 100644 --- a/apps/svelte.dev/content/docs/svelte/98-reference/21-svelte-easing.md +++ b/apps/svelte.dev/content/docs/svelte/98-reference/21-svelte-easing.md @@ -43,8 +43,6 @@ import { ## backIn - -
```dts @@ -53,9 +51,9 @@ function backIn(t: number): number;
-## backInOut +## backInOut
@@ -65,9 +63,9 @@ function backInOut(t: number): number;
-## backOut +## backOut
@@ -77,9 +75,9 @@ function backOut(t: number): number;
-## bounceIn +## bounceIn
@@ -89,9 +87,9 @@ function bounceIn(t: number): number;
-## bounceInOut +## bounceInOut
@@ -101,9 +99,9 @@ function bounceInOut(t: number): number;
-## bounceOut +## bounceOut
@@ -113,9 +111,9 @@ function bounceOut(t: number): number;
-## circIn +## circIn
@@ -125,9 +123,9 @@ function circIn(t: number): number;
-## circInOut +## circInOut
@@ -137,9 +135,9 @@ function circInOut(t: number): number;
-## circOut +## circOut
@@ -149,9 +147,9 @@ function circOut(t: number): number;
-## cubicIn +## cubicIn
@@ -161,9 +159,9 @@ function cubicIn(t: number): number;
-## cubicInOut +## cubicInOut
@@ -173,9 +171,9 @@ function cubicInOut(t: number): number;
-## cubicOut +## cubicOut
@@ -185,9 +183,9 @@ function cubicOut(t: number): number;
-## elasticIn +## elasticIn
@@ -197,9 +195,9 @@ function elasticIn(t: number): number;
-## elasticInOut +## elasticInOut
@@ -209,9 +207,9 @@ function elasticInOut(t: number): number;
-## elasticOut +## elasticOut
@@ -221,9 +219,9 @@ function elasticOut(t: number): number;
-## expoIn +## expoIn
@@ -233,9 +231,9 @@ function expoIn(t: number): number;
-## expoInOut +## expoInOut
@@ -245,9 +243,9 @@ function expoInOut(t: number): number;
-## expoOut +## expoOut
@@ -257,9 +255,9 @@ function expoOut(t: number): number;
-## linear +## linear
@@ -269,9 +267,9 @@ function linear(t: number): number;
-## quadIn +## quadIn
@@ -281,9 +279,9 @@ function quadIn(t: number): number;
-## quadInOut +## quadInOut
@@ -293,9 +291,9 @@ function quadInOut(t: number): number;
-## quadOut +## quadOut
@@ -305,9 +303,9 @@ function quadOut(t: number): number;
-## quartIn +## quartIn
@@ -317,9 +315,9 @@ function quartIn(t: number): number;
-## quartInOut +## quartInOut
@@ -329,9 +327,9 @@ function quartInOut(t: number): number;
-## quartOut +## quartOut
@@ -341,9 +339,9 @@ function quartOut(t: number): number;
-## quintIn +## quintIn
@@ -353,9 +351,9 @@ function quintIn(t: number): number;
-## quintInOut +## quintInOut
@@ -365,9 +363,9 @@ function quintInOut(t: number): number;
-## quintOut +## quintOut
@@ -377,9 +375,9 @@ function quintOut(t: number): number;
-## sineIn +## sineIn
@@ -389,9 +387,9 @@ function sineIn(t: number): number;
-## sineInOut +## sineInOut
@@ -401,9 +399,9 @@ function sineInOut(t: number): number;
-## sineOut +## sineOut
@@ -414,3 +412,5 @@ function sineOut(t: number): number;
+ + diff --git a/apps/svelte.dev/content/docs/svelte/98-reference/21-svelte-events.md b/apps/svelte.dev/content/docs/svelte/98-reference/21-svelte-events.md index 46aec88c9f..cbb94e05fc 100644 --- a/apps/svelte.dev/content/docs/svelte/98-reference/21-svelte-events.md +++ b/apps/svelte.dev/content/docs/svelte/98-reference/21-svelte-events.md @@ -99,3 +99,5 @@ function on( + + diff --git a/apps/svelte.dev/content/docs/svelte/98-reference/21-svelte-legacy.md b/apps/svelte.dev/content/docs/svelte/98-reference/21-svelte-legacy.md index dce95ef119..1367df7533 100644 --- a/apps/svelte.dev/content/docs/svelte/98-reference/21-svelte-legacy.md +++ b/apps/svelte.dev/content/docs/svelte/98-reference/21-svelte-legacy.md @@ -25,6 +25,12 @@ import { ## asClassComponent +
+ +Use this only as a temporary solution to migrate your imperative component code to Svelte 5. + +
+ Takes the component function and returns a Svelte 4 compatible component constructor.
@@ -46,8 +52,16 @@ function asClassComponent<
+ + ## createBubbler +
+ +Use this only as a temporary solution to migrate your automatically delegated events in Svelte 5. + +
+ Function to create a `bubble` function that mimic the behavior of `on:click` without handler available in svelte 4.
@@ -60,8 +74,16 @@ function createBubbler(): (
+ + ## createClassComponent +
+ +Use this only as a temporary solution to migrate your imperative component code to Svelte 5. + +
+ Takes the same options as a Svelte 4 component and the component function and returns a Svelte 4 compatible component.
@@ -83,6 +105,8 @@ function createClassComponent<
+ + ## handlers Function to mimic the multiple listeners available in svelte 4 @@ -97,6 +121,8 @@ function handlers( + + ## nonpassive Substitute for the `nonpassive` event modifier, implemented as an action @@ -115,6 +141,8 @@ function nonpassive( + + ## once Substitute for the `once` event modifier @@ -129,6 +157,8 @@ function once( + + ## passive Substitute for the `passive` event modifier, implemented as an action @@ -147,6 +177,8 @@ function passive( + + ## preventDefault Substitute for the `preventDefault` event modifier @@ -161,8 +193,16 @@ function preventDefault( + + ## run +
+ +Use this only as a temporary solution to migrate your component code to Svelte 5. + +
+ Runs the given function once immediately on the server, and works like `$effect.pre` on the client.
@@ -173,6 +213,8 @@ function run(fn: () => void | (() => void)): void;
+ + ## self Substitute for the `self` event modifier @@ -187,6 +229,8 @@ function self( + + ## stopImmediatePropagation Substitute for the `stopImmediatePropagation` event modifier @@ -201,6 +245,8 @@ function stopImmediatePropagation( + + ## stopPropagation Substitute for the `stopPropagation` event modifier @@ -215,6 +261,8 @@ function stopPropagation( + + ## trusted Substitute for the `trusted` event modifier @@ -230,3 +278,5 @@ function trusted( + + diff --git a/apps/svelte.dev/content/docs/svelte/98-reference/21-svelte-motion.md b/apps/svelte.dev/content/docs/svelte/98-reference/21-svelte-motion.md index 0fd62a1d4c..263329be9a 100644 --- a/apps/svelte.dev/content/docs/svelte/98-reference/21-svelte-motion.md +++ b/apps/svelte.dev/content/docs/svelte/98-reference/21-svelte-motion.md @@ -24,6 +24,8 @@ function spring( + + ## tweened A tweened store in Svelte is a special type of store that provides smooth transitions between state values over time. @@ -39,6 +41,8 @@ function tweened( + + ## Spring
@@ -90,8 +94,7 @@ stiffness: number; ```
-
- + ## Tweened @@ -117,7 +120,6 @@ update(updater: Updater, opts?: TweenedOptions): Promise; ```
- - + diff --git a/apps/svelte.dev/content/docs/svelte/98-reference/21-svelte-reactivity.md b/apps/svelte.dev/content/docs/svelte/98-reference/21-svelte-reactivity.md index a65d4dcf41..bb8cddf12e 100644 --- a/apps/svelte.dev/content/docs/svelte/98-reference/21-svelte-reactivity.md +++ b/apps/svelte.dev/content/docs/svelte/98-reference/21-svelte-reactivity.md @@ -26,8 +26,7 @@ constructor(...params: any[]); ```
- - + ## SvelteMap @@ -62,8 +61,7 @@ set(key: K, value: V): this; ```
- - + ## SvelteSet @@ -98,8 +96,7 @@ add(value: T): this; ```
- - + ## SvelteURL @@ -125,8 +122,7 @@ get searchParams(): SvelteURLSearchParams; ```
- - + ## SvelteURLSearchParams @@ -152,7 +148,6 @@ class SvelteURLSearchParams extends URLSearchParams {/*…*/} ```
- - + diff --git a/apps/svelte.dev/content/docs/svelte/98-reference/21-svelte-server.md b/apps/svelte.dev/content/docs/svelte/98-reference/21-svelte-server.md index 75891647ab..cb604efbd4 100644 --- a/apps/svelte.dev/content/docs/svelte/98-reference/21-svelte-server.md +++ b/apps/svelte.dev/content/docs/svelte/98-reference/21-svelte-server.md @@ -46,3 +46,5 @@ function render< + + diff --git a/apps/svelte.dev/content/docs/svelte/98-reference/21-svelte-store.md b/apps/svelte.dev/content/docs/svelte/98-reference/21-svelte-store.md index fbd0adc1ab..8d60fd7be6 100644 --- a/apps/svelte.dev/content/docs/svelte/98-reference/21-svelte-store.md +++ b/apps/svelte.dev/content/docs/svelte/98-reference/21-svelte-store.md @@ -50,9 +50,9 @@ function derived( -## fromStore +## fromStore
@@ -74,6 +74,8 @@ function fromStore(store: Readable): {
+ + ## get Get the current value from a store by subscribing and immediately unsubscribing. @@ -86,6 +88,8 @@ function get(store: Readable): T; + + ## readable Creates a `Readable` store that allows reading by subscription. @@ -101,6 +105,8 @@ function readable( + + ## readonly Takes a store and returns a new one derived from the old one that is readable. @@ -113,9 +119,9 @@ function readonly(store: Readable): Readable; -## toStore +## toStore
@@ -136,6 +142,8 @@ function toStore(get: () => V): Readable;
+ + ## writable Create a `Writable` store that allows both updating and reading by subscription. @@ -151,6 +159,8 @@ function writable( + + ## Readable Readable interface for subscribing. @@ -179,8 +189,7 @@ subscribe(this: void, run: Subscriber, invalidate?: () => void): Unsubscriber Subscribe on value changes. - - + ## StartStopNotifier @@ -196,7 +205,6 @@ type StartStopNotifier = ( ) => void | (() => void); ``` - ## Subscriber @@ -209,7 +217,6 @@ Callback to inform of a value updates. type Subscriber = (value: T) => void; ``` - ## Unsubscriber @@ -222,7 +229,6 @@ Unsubscribes from value updates. type Unsubscriber = () => void; ``` - ## Updater @@ -235,7 +241,6 @@ Callback to update a value. type Updater = (value: T) => T; ``` - ## Writable @@ -284,7 +289,6 @@ update(this: void, updater: Updater): void; Update value using callback and inform subscribers. - - + diff --git a/apps/svelte.dev/content/docs/svelte/98-reference/21-svelte-transition.md b/apps/svelte.dev/content/docs/svelte/98-reference/21-svelte-transition.md index a27e5e0dfd..98f373ab66 100644 --- a/apps/svelte.dev/content/docs/svelte/98-reference/21-svelte-transition.md +++ b/apps/svelte.dev/content/docs/svelte/98-reference/21-svelte-transition.md @@ -38,6 +38,8 @@ function blur( + + ## crossfade The `crossfade` function creates a pair of [transitions](https://svelte.dev/docs#template-syntax-element-directives-transition-fn) called `send` and `receive`. When an element is 'sent', it looks for a corresponding element being 'received', and generates a transition that transforms the element to its counterpart's position and fades it out. When an element is 'received', the reverse happens. If there is no counterpart, the `fallback` transition is used. @@ -72,6 +74,8 @@ function crossfade({ + + ## draw Animates the stroke of an SVG element, like a snake in a tube. `in` transitions begin with the path invisible and draw the path to the screen over time. `out` transitions start in a visible state and gradually erase the path. `draw` only works with elements that have a `getTotalLength` method, like `` and ``. @@ -94,6 +98,8 @@ function draw( + + ## fade Animates the opacity of an element from 0 to the current opacity for `in` transitions and from the current opacity to 0 for `out` transitions. @@ -109,6 +115,8 @@ function fade( + + ## fly Animates the x and y positions and the opacity of an element. `in` transitions animate from the provided values, passed as parameters to the element's default values. `out` transitions animate from the element's default values to the provided values. @@ -131,6 +139,8 @@ function fly( + + ## scale Animates the opacity and scale of an element. `in` transitions animate from an element's current (default) values to the provided values, passed as parameters. `out` transitions animate from the provided values to an element's default values. @@ -152,6 +162,8 @@ function scale( + + ## slide Slides an element in and out. @@ -172,6 +184,8 @@ function slide( + + ## BlurParams
@@ -223,8 +237,7 @@ opacity?: number; ```
-
- + ## CrossfadeParams @@ -259,8 +272,7 @@ easing?: EasingFunction; ```
- - + ## DrawParams @@ -304,8 +316,7 @@ easing?: EasingFunction; ```
- - + ## EasingFunction @@ -315,7 +326,6 @@ easing?: EasingFunction; type EasingFunction = (t: number) => number; ``` - ## FadeParams @@ -351,8 +361,7 @@ easing?: EasingFunction; ```
- - + ## FlyParams @@ -414,8 +423,7 @@ opacity?: number; ```
- - + ## ScaleParams @@ -468,8 +476,7 @@ opacity?: number; ```
- - + ## SlideParams @@ -513,8 +520,7 @@ axis?: 'x' | 'y'; ```
- - + ## TransitionConfig @@ -567,7 +573,6 @@ tick?: (t: number, u: number) => void; ```
- - + diff --git a/packages/site-kit/src/lib/components/Text.svelte b/packages/site-kit/src/lib/components/Text.svelte index 089c62b9a8..fab5159887 100644 --- a/packages/site-kit/src/lib/components/Text.svelte +++ b/packages/site-kit/src/lib/components/Text.svelte @@ -409,8 +409,15 @@ --primary-hsl: var(--sk-text-warning-hsl); --color: var(--primary-hsl); - &::before { - content: 'Deprecated'; + p:first-child::before { + content: 'Deprecated '; + display: block; + /* text-transform: uppercase; */ + font-style: normal; + /* font-family: var(--sk-font-ui); */ + font-size: var(--sk-text-m); + font-weight: 500; + /* color: var(--sk-text-4); */ } a { diff --git a/packages/site-kit/src/lib/markdown/renderer.ts b/packages/site-kit/src/lib/markdown/renderer.ts index 6c2309a3ba..e99588a39c 100644 --- a/packages/site-kit/src/lib/markdown/renderer.ts +++ b/packages/site-kit/src/lib/markdown/renderer.ts @@ -543,6 +543,10 @@ export async function replace_export_type_placeholders(content: string, modules: EXPORTS: /> EXPORTS: (.+)/ }; + if (REGEXES.EXPORTS.test(content)) { + throw new Error('yes'); + } + if (!modules || modules.length === 0) { return content .replace(REGEXES.EXPANDED_TYPES, '') @@ -573,7 +577,7 @@ export async function replace_export_type_placeholders(content: string, modules: if (!type) throw new Error(`Could not find type ${name}#${id}`); - return stringify_type(type); + return render_declaration(type, true); } let comment = ''; @@ -581,7 +585,9 @@ export async function replace_export_type_placeholders(content: string, modules: comment += `${module.comment}\n\n`; } - return comment + module.types.map((t) => `## ${t.name}\n\n${stringify_type(t)}`).join(''); + return ( + comment + module.types.map((t) => `## ${t.name}\n\n${render_declaration(t, true)}`).join('') + ); }); content = await async_replace(content, REGEXES.EXPORT_SNIPPET, async ([_, name, id]) => { @@ -594,15 +600,7 @@ export async function replace_export_type_placeholders(content: string, modules: const exported = module.exports?.filter((t) => t.name === id); - return ( - exported - ?.map((declaration) => - declaration.overloads - .map((overload) => `
${fence(overload.snippet, 'dts')}
`) - .join('\n\n') - ) - .join('\n\n') ?? '' - ); + return exported?.map((d) => render_declaration(d, false)).join('\n\n') ?? ''; }); content = await async_replace(content, REGEXES.MODULE, async ([_, name]) => { @@ -635,15 +633,8 @@ export async function replace_export_type_placeholders(content: string, modules: return `## ${module.name}\n\n${import_block}\n\n${module.comment}\n\n${module.exports .map((declaration) => { - const markdown = declaration.overloads - .map( - (overload) => - `
${fence(overload.snippet, 'dts')}` + - overload.children?.map((v) => stringify(v)).join('\n\n') + - `
` - ) - .join('\n\n'); - return `### ${declaration.name}\n\n${declaration.comment}\n\n${markdown}`; + const markdown = render_declaration(declaration, true); + return `### ${declaration.name}\n\n${markdown}`; }) .join('\n\n')}`; }) @@ -673,15 +664,8 @@ export async function replace_export_type_placeholders(content: string, modules: return `${import_block}\n\n${module.comment}\n\n${module.exports .map((declaration) => { - const markdown = declaration.overloads - .map( - (overload) => - `
${fence(overload.snippet, 'dts')}` + - overload.children?.map((val) => stringify(val, 'dts')).join('\n\n') + - `
` - ) - .join('\n\n'); - return `### ${declaration.name}\n\n${declaration.comment}\n\n${markdown}`; + const markdown = render_declaration(declaration, true); + return `### ${declaration.name}\n\n${markdown}`; }) .join('\n\n')}`; }); @@ -689,6 +673,31 @@ export async function replace_export_type_placeholders(content: string, modules: return content; } +function render_declaration(declaration: Declaration, full: boolean) { + let content = ''; + + if (declaration.deprecated) { + content += `
\n\n${declaration.deprecated}\n\n
\n\n`; + } + + if (declaration.comment) { + content += declaration.comment + '\n\n'; + } + + return ( + content + + declaration.overloads + .map((overload) => { + const children = full + ? overload.children?.map((val) => stringify(val, 'dts')).join('\n\n') + : ''; + + return `
${fence(overload.snippet, 'dts')}${children}
\n\n`; + }) + .join('') + ); +} + /** * Takes a module and returns a markdown string. */ @@ -712,41 +721,12 @@ function stringify_module(module: Modules[0]) { } for (const declaration of module.exports || []) { - const markdown = declaration.overloads - .map( - (overload) => - `
${fence(overload.snippet, 'dts')}` + - overload.children?.map((v) => stringify(v)).join('\n\n') + - `
` - ) - .join('\n\n'); - content += `## ${declaration.name}\n\n${declaration.comment}\n\n${markdown}\n\n`; + const markdown = render_declaration(declaration, true); + content += `## ${declaration.name}\n\n${markdown}\n\n`; } for (const t of module.types || []) { - content += `## ${t.name}\n\n` + stringify_type(t); - } - - return content; -} - -function stringify_type(t: Declaration) { - let content = ''; - - if (t.deprecated) { - content += `
\n\n${t.deprecated}\n\n
\n\n`; - } - - if (t.comment) { - content += `${t.comment}\n\n`; - } - - for (const overload of t.overloads) { - if (overload.children || overload.snippet) { - const children = overload.children?.map((val) => stringify(val, 'dts')).join('\n\n'); - content += - `
${fence(overload.snippet, 'dts')}` + children + `\n
\n\n`; - } + content += `## ${t.name}\n\n` + render_declaration(t, true); } return content;