From d7ba04cb7e0f7056d7ab02bc7395a1853b88cc6a Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Wed, 3 May 2023 23:30:00 -0400 Subject: [PATCH] only inject artificial error annotation in js blocks (#9693) Co-authored-by: Rich Harris --- packages/kit/types/index.d.ts | 16 ++++++++-------- sites/kit.svelte.dev/scripts/types/index.js | 8 ++++---- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/packages/kit/types/index.d.ts b/packages/kit/types/index.d.ts index c24174f45862..d8f5ce8f82db 100644 --- a/packages/kit/types/index.d.ts +++ b/packages/kit/types/index.d.ts @@ -557,16 +557,16 @@ export interface KitConfig { * If SvelteKit encounters an error while loading the page and detects that a new version has been deployed (using the `name` specified here, which defaults to a timestamp of the build) it will fall back to traditional full-page navigation. * Not all navigations will result in an error though, for example if the JavaScript for the next page is already loaded. If you still want to force a full-page navigation in these cases, use techniques such as setting the `pollInterval` and then using `beforeNavigate`: * ```html - * /// +layout.svelte + * /// file: +layout.svelte * * ``` * diff --git a/sites/kit.svelte.dev/scripts/types/index.js b/sites/kit.svelte.dev/scripts/types/index.js index a609c7bfe0d4..365ad50820bc 100644 --- a/sites/kit.svelte.dev/scripts/types/index.js +++ b/sites/kit.svelte.dev/scripts/types/index.js @@ -201,10 +201,10 @@ function read_d_ts_file(file) { // We can't use JSDoc comments inside JSDoc, so we would get ts(7031) errors if // we didn't ignore this error specifically for `/// file:` code examples const str = fs.readFileSync(resolved, 'utf-8'); - return str.replace( - /(\s*\*\s*)\/\/\/ file:/g, - (match, prefix) => prefix + '// @errors: 7031' + match - ); + + return str.replace(/(\s*\*\s*)```js([\s\S]+?)```/g, (match, prefix, code) => { + return `${prefix}\`\`\`js${prefix}// @errors: 7031${code}\`\`\``; + }); } {