Skip to content

Commit

Permalink
only inject artificial error annotation in js blocks (#9693)
Browse files Browse the repository at this point in the history
Co-authored-by: Rich Harris <git@rich-harris.dev>
  • Loading branch information
Rich-Harris and Rich Harris committed May 4, 2023
1 parent 285c606 commit d7ba04c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
16 changes: 8 additions & 8 deletions packages/kit/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
* <script>
* import { beforeNavigate } from '$app/navigation';
* import { updated } from '$app/stores';
* import { beforeNavigate } from '$app/navigation';
* import { updated } from '$app/stores';
*
* beforeNavigate(({ willUnload, to }) => {
* if ($updated && !willUnload && to?.url) {
* location.href = to.url.href;
* }
* });
* beforeNavigate(({ willUnload, to }) => {
* if ($updated && !willUnload && to?.url) {
* location.href = to.url.href;
* }
* });
* </script>
* ```
*
Expand Down
8 changes: 4 additions & 4 deletions sites/kit.svelte.dev/scripts/types/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}\`\`\``;
});
}

{
Expand Down

0 comments on commit d7ba04c

Please sign in to comment.