Skip to content

Commit

Permalink
[fix] handle jsdoc without tags while generating proxy types (#6884)
Browse files Browse the repository at this point in the history
Fixes #6834

Co-authored-by: Rich Harris <[email protected]>
  • Loading branch information
dummdidumm and Rich-Harris authored Sep 19, 2022
1 parent 1c65651 commit 6c706c3
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/fair-tables-peel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

[fix] handle jsdoc without tags while generating proxy types
2 changes: 1 addition & 1 deletion packages/kit/src/core/sync/write_types/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ export function tweak_types(content, is_server) {
if (node.jsDoc) {
// @ts-ignore
for (const comment of node.jsDoc) {
for (const tag of comment.tags) {
for (const tag of comment.tags ?? []) {
if (ts.isJSDocTypeTag(tag)) {
const is_fn =
ts.isFunctionDeclaration(value) ||
Expand Down
27 changes: 27 additions & 0 deletions packages/kit/src/core/sync/write_types/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,33 @@ test('Rewrites types for a TypeScript module without param', () => {
);
});

test('Rewrites types for a TypeScript module without param and jsdoc without types', () => {
const source = `
/** test */
export const load: Get = () => {
return {
a: 1
};
};
`;

const rewritten = tweak_types(source, false);

assert.equal(rewritten?.exports, ['load']);
assert.equal(
rewritten?.code,
`// @ts-nocheck
/** test */
export const load = () => {
return {
a: 1
};
};
;null as any as Get;`
);
});

test('Rewrites types for a JavaScript module with `function`', () => {
const source = `
/** @type {import('./$types').Get} */
Expand Down

0 comments on commit 6c706c3

Please sign in to comment.