Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix] handle jsdoc without tags while generating proxy types #6884

Merged
merged 2 commits into from
Sep 19, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -484,7 +484,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