From f4d82d066e0af56f16f7b7558eb066591b59c5f1 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Tue, 1 Oct 2024 19:29:46 -0400 Subject: [PATCH 1/2] tidy up --- .../svelte/04-runtime/03-lifecycle-hooks.md | 2 + .../docs/svelte/98-reference/20-svelte.md | 52 ++++++++++---- .../svelte/98-reference/21-svelte-action.md | 6 +- .../svelte/98-reference/21-svelte-animate.md | 8 +-- .../svelte/98-reference/21-svelte-compiler.md | 34 +++++---- .../svelte/98-reference/21-svelte-easing.md | 62 ++++++++++++++++ .../svelte/98-reference/21-svelte-events.md | 2 + .../svelte/98-reference/21-svelte-legacy.md | 26 +++++++ .../svelte/98-reference/21-svelte-motion.md | 10 +-- .../98-reference/21-svelte-reactivity.md | 15 ++-- .../svelte/98-reference/21-svelte-server.md | 2 + .../svelte/98-reference/21-svelte-store.md | 24 ++++--- .../98-reference/21-svelte-transition.md | 39 +++++----- .../site-kit/src/lib/markdown/renderer.ts | 71 +++++++------------ 14 files changed, 231 insertions(+), 122 deletions(-) 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..8ec7f47bd5 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 @@ -53,6 +53,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..e46cb80754 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 @@ -42,6 +42,8 @@ function afterUpdate(fn: () => void): void; + + ## beforeUpdate Schedules a callback to run immediately before the component is updated after any state change. @@ -58,6 +60,8 @@ function beforeUpdate(fn: () => void): void; + + ## createEventDispatcher Creates an event dispatcher that can be used to dispatch [component events](https://svelte.dev/docs#template-syntax-component-directives-on-eventname). @@ -88,6 +92,8 @@ function createEventDispatcher< + + ## createRawSnippet Create a snippet programmatically @@ -105,6 +111,8 @@ function createRawSnippet( + + ## flushSync Synchronously flushes any pending state changes and those that result from it. @@ -117,6 +125,8 @@ function flushSync(fn?: (() => void) | undefined): void; + + ## getAllContexts Retrieves the whole context map that belongs to the closest parent component. @@ -133,6 +143,8 @@ function getAllContexts< + + ## getContext Retrieves the context that belongs to the closest parent component with the specified `key`. @@ -146,6 +158,8 @@ function getContext(key: any): T; + + ## hasContext Checks whether a given `key` has been set in the context of a parent component. @@ -159,6 +173,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 +211,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 +250,8 @@ function mount< + + ## onDestroy Schedules a callback to run immediately before the component is unmounted. @@ -247,6 +267,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 +292,8 @@ function onMount( + + ## setContext Associates an arbitrary `context` object with the current component and the specified `key` @@ -286,6 +310,8 @@ function setContext(key: any, context: T): T; + + ## tick Returns a promise that resolves once any pending state changes have been applied. @@ -298,6 +324,8 @@ function tick(): Promise; + + ## unmount Unmounts a component that was previously mounted using `mount` or `hydrate`. @@ -310,6 +338,8 @@ function unmount(component: Record): void; + + ## untrack Use `untrack` to prevent something from being treated as an `$effect`/`$derived` dependency. @@ -324,6 +354,8 @@ function untrack(fn: () => T): T; + + ## Component Can be used to create strongly typed Svelte components. @@ -403,8 +435,7 @@ element?: typeof HTMLElement; The custom element version of the component. Only present if compiled with the `customElement` compiler option - - + ## ComponentConstructorOptions @@ -504,8 +535,7 @@ $$inline?: boolean; ```
- - + ## ComponentEvents @@ -524,7 +554,6 @@ type ComponentEvents = : never; ``` - ## ComponentInternals @@ -537,7 +566,6 @@ Internal implementation details that vary between environments type ComponentInternals = Branded<{}, 'ComponentInternals'>; ``` - ## ComponentProps @@ -582,7 +610,6 @@ type ComponentProps< : never; ``` - ## ComponentType @@ -610,7 +637,6 @@ type ComponentType< }; ``` - ## EventDispatcher @@ -636,8 +662,7 @@ interface EventDispatcher< ```
- - + ## Snippet @@ -670,8 +695,7 @@ interface Snippet {/*…*/} ```
- - + ## SvelteComponent @@ -789,8 +813,7 @@ for more info. - - + ## SvelteComponentTyped @@ -810,7 +833,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..4211c6a028 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,6 +144,8 @@ function preprocess( + + ## walk @@ -146,6 +158,8 @@ function walk(): never; + + ## AST
@@ -510,7 +524,6 @@ namespace AST { } ``` -
## CompileError @@ -521,7 +534,6 @@ namespace AST { interface CompileError extends ICompileDiagnostic {} ``` - ## CompileOptions @@ -875,8 +887,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 +1009,7 @@ ast: any; The AST - - + ## MarkupPreprocessor @@ -1020,7 +1030,6 @@ type MarkupPreprocessor = (options: { }) => Processed | void | Promise; ``` - ## ModuleCompileOptions @@ -1115,8 +1124,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 +1153,6 @@ type Preprocessor = (options: { }) => Processed | void | Promise; ``` - ## PreprocessorGroup @@ -1196,8 +1203,7 @@ script?: Preprocessor; ```
- - + ## Processed @@ -1268,8 +1274,7 @@ toString?: () => string; ```
- - + ## Warning @@ -1279,7 +1284,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..fc1f591713 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 @@ -53,6 +53,8 @@ function backIn(t: number): number; + + ## backInOut @@ -65,6 +67,8 @@ function backInOut(t: number): number; + + ## backOut @@ -77,6 +81,8 @@ function backOut(t: number): number; + + ## bounceIn @@ -89,6 +95,8 @@ function bounceIn(t: number): number; + + ## bounceInOut @@ -101,6 +109,8 @@ function bounceInOut(t: number): number; + + ## bounceOut @@ -113,6 +123,8 @@ function bounceOut(t: number): number; + + ## circIn @@ -125,6 +137,8 @@ function circIn(t: number): number; + + ## circInOut @@ -137,6 +151,8 @@ function circInOut(t: number): number; + + ## circOut @@ -149,6 +165,8 @@ function circOut(t: number): number; + + ## cubicIn @@ -161,6 +179,8 @@ function cubicIn(t: number): number; + + ## cubicInOut @@ -173,6 +193,8 @@ function cubicInOut(t: number): number; + + ## cubicOut @@ -185,6 +207,8 @@ function cubicOut(t: number): number; + + ## elasticIn @@ -197,6 +221,8 @@ function elasticIn(t: number): number; + + ## elasticInOut @@ -209,6 +235,8 @@ function elasticInOut(t: number): number; + + ## elasticOut @@ -221,6 +249,8 @@ function elasticOut(t: number): number; + + ## expoIn @@ -233,6 +263,8 @@ function expoIn(t: number): number; + + ## expoInOut @@ -245,6 +277,8 @@ function expoInOut(t: number): number; + + ## expoOut @@ -257,6 +291,8 @@ function expoOut(t: number): number; + + ## linear @@ -269,6 +305,8 @@ function linear(t: number): number; + + ## quadIn @@ -281,6 +319,8 @@ function quadIn(t: number): number; + + ## quadInOut @@ -293,6 +333,8 @@ function quadInOut(t: number): number; + + ## quadOut @@ -305,6 +347,8 @@ function quadOut(t: number): number; + + ## quartIn @@ -317,6 +361,8 @@ function quartIn(t: number): number; + + ## quartInOut @@ -329,6 +375,8 @@ function quartInOut(t: number): number; + + ## quartOut @@ -341,6 +389,8 @@ function quartOut(t: number): number; + + ## quintIn @@ -353,6 +403,8 @@ function quintIn(t: number): number; + + ## quintInOut @@ -365,6 +417,8 @@ function quintInOut(t: number): number; + + ## quintOut @@ -377,6 +431,8 @@ function quintOut(t: number): number; + + ## sineIn @@ -389,6 +445,8 @@ function sineIn(t: number): number; + + ## sineInOut @@ -401,6 +459,8 @@ function sineInOut(t: number): number; + + ## sineOut @@ -414,3 +474,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..14e7c00edf 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 @@ -46,6 +46,8 @@ function asClassComponent< + + ## createBubbler Function to create a `bubble` function that mimic the behavior of `on:click` without handler available in svelte 4. @@ -60,6 +62,8 @@ function createBubbler(): ( + + ## createClassComponent Takes the same options as a Svelte 4 component and the component function and returns a Svelte 4 compatible component. @@ -83,6 +87,8 @@ function createClassComponent< + + ## handlers Function to mimic the multiple listeners available in svelte 4 @@ -97,6 +103,8 @@ function handlers( + + ## nonpassive Substitute for the `nonpassive` event modifier, implemented as an action @@ -115,6 +123,8 @@ function nonpassive( + + ## once Substitute for the `once` event modifier @@ -129,6 +139,8 @@ function once( + + ## passive Substitute for the `passive` event modifier, implemented as an action @@ -147,6 +159,8 @@ function passive( + + ## preventDefault Substitute for the `preventDefault` event modifier @@ -161,6 +175,8 @@ function preventDefault( + + ## run Runs the given function once immediately on the server, and works like `$effect.pre` on the client. @@ -173,6 +189,8 @@ function run(fn: () => void | (() => void)): void; + + ## self Substitute for the `self` event modifier @@ -187,6 +205,8 @@ function self( + + ## stopImmediatePropagation Substitute for the `stopImmediatePropagation` event modifier @@ -201,6 +221,8 @@ function stopImmediatePropagation( + + ## stopPropagation Substitute for the `stopPropagation` event modifier @@ -215,6 +237,8 @@ function stopPropagation( + + ## trusted Substitute for the `trusted` event modifier @@ -230,3 +254,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..c436a8547a 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,6 +50,8 @@ function derived( + + ## fromStore @@ -74,6 +76,8 @@ function fromStore(store: Readable): { + + ## get Get the current value from a store by subscribing and immediately unsubscribing. @@ -86,6 +90,8 @@ function get(store: Readable): T; + + ## readable Creates a `Readable` store that allows reading by subscription. @@ -101,6 +107,8 @@ function readable( + + ## readonly Takes a store and returns a new one derived from the old one that is readable. @@ -113,6 +121,8 @@ function readonly(store: Readable): Readable; + + ## toStore @@ -136,6 +146,8 @@ function toStore(get: () => V): Readable; + + ## writable Create a `Writable` store that allows both updating and reading by subscription. @@ -151,6 +163,8 @@ function writable( + + ## Readable Readable interface for subscribing. @@ -179,8 +193,7 @@ subscribe(this: void, run: Subscriber, invalidate?: () => void): Unsubscriber Subscribe on value changes. - - + ## StartStopNotifier @@ -196,7 +209,6 @@ type StartStopNotifier = ( ) => void | (() => void); ``` - ## Subscriber @@ -209,7 +221,6 @@ Callback to inform of a value updates. type Subscriber = (value: T) => void; ``` - ## Unsubscriber @@ -222,7 +233,6 @@ Unsubscribes from value updates. type Unsubscriber = () => void; ``` - ## Updater @@ -235,7 +245,6 @@ Callback to update a value. type Updater = (value: T) => T; ``` - ## Writable @@ -284,7 +293,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/markdown/renderer.ts b/packages/site-kit/src/lib/markdown/renderer.ts index 6c2309a3ba..56731356f1 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, '') @@ -594,15 +598,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,14 +631,7 @@ 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'); + const markdown = render_declaration(declaration, true); return `### ${declaration.name}\n\n${declaration.comment}\n\n${markdown}`; }) .join('\n\n')}`; @@ -673,14 +662,7 @@ 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'); + const markdown = render_declaration(declaration, true); return `### ${declaration.name}\n\n${declaration.comment}\n\n${markdown}`; }) .join('\n\n')}`; @@ -689,6 +671,18 @@ export async function replace_export_type_placeholders(content: string, modules: return content; } +function render_declaration(declaration: Declaration, full: boolean) { + return 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,14 +706,7 @@ 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'); + const markdown = render_declaration(declaration, true); content += `## ${declaration.name}\n\n${declaration.comment}\n\n${markdown}\n\n`; } @@ -730,24 +717,18 @@ function stringify_module(module: Modules[0]) { return content; } -function stringify_type(t: Declaration) { +function stringify_type(declaration: Declaration) { let content = ''; - if (t.deprecated) { - content += `
\n\n${t.deprecated}\n\n
\n\n`; + if (declaration.deprecated) { + content += `
\n\n${declaration.deprecated}\n\n
\n\n`; } - if (t.comment) { - content += `${t.comment}\n\n`; + if (declaration.comment) { + content += `${declaration.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 += render_declaration(declaration, true); return content; } From ebbf426e0b27b866c5d320e43790c2bef2721a9b Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Tue, 1 Oct 2024 19:50:20 -0400 Subject: [PATCH 2/2] display deprecation notices --- .../svelte/04-runtime/03-lifecycle-hooks.md | 5 ++ .../docs/svelte/98-reference/20-svelte.md | 18 ++++++ .../svelte/98-reference/21-svelte-compiler.md | 4 ++ .../svelte/98-reference/21-svelte-easing.md | 62 ------------------- .../svelte/98-reference/21-svelte-legacy.md | 24 +++++++ .../svelte/98-reference/21-svelte-store.md | 4 -- .../site-kit/src/lib/components/Text.svelte | 11 +++- .../site-kit/src/lib/markdown/renderer.ts | 61 +++++++++--------- 8 files changed, 90 insertions(+), 99 deletions(-) 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 8ec7f47bd5..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 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 e46cb80754..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`. @@ -46,6 +52,12 @@ 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`. @@ -64,6 +76,12 @@ 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`. 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 4211c6a028..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 @@ -148,7 +148,11 @@ function preprocess( ## walk +
+Replace this with `import { walk } from 'estree-walker'` + +
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 fc1f591713..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 @@ -57,8 +55,6 @@ function backIn(t: number): number; ## backInOut - -
```dts @@ -71,8 +67,6 @@ function backInOut(t: number): number; ## backOut - -
```dts @@ -85,8 +79,6 @@ function backOut(t: number): number; ## bounceIn - -
```dts @@ -99,8 +91,6 @@ function bounceIn(t: number): number; ## bounceInOut - -
```dts @@ -113,8 +103,6 @@ function bounceInOut(t: number): number; ## bounceOut - -
```dts @@ -127,8 +115,6 @@ function bounceOut(t: number): number; ## circIn - -
```dts @@ -141,8 +127,6 @@ function circIn(t: number): number; ## circInOut - -
```dts @@ -155,8 +139,6 @@ function circInOut(t: number): number; ## circOut - -
```dts @@ -169,8 +151,6 @@ function circOut(t: number): number; ## cubicIn - -
```dts @@ -183,8 +163,6 @@ function cubicIn(t: number): number; ## cubicInOut - -
```dts @@ -197,8 +175,6 @@ function cubicInOut(t: number): number; ## cubicOut - -
```dts @@ -211,8 +187,6 @@ function cubicOut(t: number): number; ## elasticIn - -
```dts @@ -225,8 +199,6 @@ function elasticIn(t: number): number; ## elasticInOut - -
```dts @@ -239,8 +211,6 @@ function elasticInOut(t: number): number; ## elasticOut - -
```dts @@ -253,8 +223,6 @@ function elasticOut(t: number): number; ## expoIn - -
```dts @@ -267,8 +235,6 @@ function expoIn(t: number): number; ## expoInOut - -
```dts @@ -281,8 +247,6 @@ function expoInOut(t: number): number; ## expoOut - -
```dts @@ -295,8 +259,6 @@ function expoOut(t: number): number; ## linear - -
```dts @@ -309,8 +271,6 @@ function linear(t: number): number; ## quadIn - -
```dts @@ -323,8 +283,6 @@ function quadIn(t: number): number; ## quadInOut - -
```dts @@ -337,8 +295,6 @@ function quadInOut(t: number): number; ## quadOut - -
```dts @@ -351,8 +307,6 @@ function quadOut(t: number): number; ## quartIn - -
```dts @@ -365,8 +319,6 @@ function quartIn(t: number): number; ## quartInOut - -
```dts @@ -379,8 +331,6 @@ function quartInOut(t: number): number; ## quartOut - -
```dts @@ -393,8 +343,6 @@ function quartOut(t: number): number; ## quintIn - -
```dts @@ -407,8 +355,6 @@ function quintIn(t: number): number; ## quintInOut - -
```dts @@ -421,8 +367,6 @@ function quintInOut(t: number): number; ## quintOut - -
```dts @@ -435,8 +379,6 @@ function quintOut(t: number): number; ## sineIn - -
```dts @@ -449,8 +391,6 @@ function sineIn(t: number): number; ## sineInOut - -
```dts @@ -463,8 +403,6 @@ function sineInOut(t: number): number; ## sineOut - -
```dts 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 14e7c00edf..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.
@@ -50,6 +56,12 @@ 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.
@@ -66,6 +78,12 @@ 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.
@@ -179,6 +197,12 @@ 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.
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 c436a8547a..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 @@ -54,8 +54,6 @@ function derived( ## fromStore - -
```dts @@ -125,8 +123,6 @@ function readonly(store: Readable): Readable; ## toStore - -
```dts 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 56731356f1..e99588a39c 100644 --- a/packages/site-kit/src/lib/markdown/renderer.ts +++ b/packages/site-kit/src/lib/markdown/renderer.ts @@ -577,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 = ''; @@ -585,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]) => { @@ -632,7 +634,7 @@ 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 = render_declaration(declaration, true); - return `### ${declaration.name}\n\n${declaration.comment}\n\n${markdown}`; + return `### ${declaration.name}\n\n${markdown}`; }) .join('\n\n')}`; }) @@ -663,7 +665,7 @@ 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 = render_declaration(declaration, true); - return `### ${declaration.name}\n\n${declaration.comment}\n\n${markdown}`; + return `### ${declaration.name}\n\n${markdown}`; }) .join('\n\n')}`; }); @@ -672,15 +674,28 @@ export async function replace_export_type_placeholders(content: string, modules: } function render_declaration(declaration: Declaration, full: boolean) { - return 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(''); + 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('') + ); } /** @@ -707,32 +722,16 @@ function stringify_module(module: Modules[0]) { for (const declaration of module.exports || []) { const markdown = render_declaration(declaration, true); - content += `## ${declaration.name}\n\n${declaration.comment}\n\n${markdown}\n\n`; + content += `## ${declaration.name}\n\n${markdown}\n\n`; } for (const t of module.types || []) { - content += `## ${t.name}\n\n` + stringify_type(t); + content += `## ${t.name}\n\n` + render_declaration(t, true); } return content; } -function stringify_type(declaration: Declaration) { - let content = ''; - - if (declaration.deprecated) { - content += `
\n\n${declaration.deprecated}\n\n
\n\n`; - } - - if (declaration.comment) { - content += `${declaration.comment}\n\n`; - } - - content += render_declaration(declaration, true); - - return content; -} - function stringify_expanded_type(type: Declaration) { return ( type.comment +