-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
[fix] handle lone returns in migration tool, turn on strict mode #5831
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
Conversation
🦋 Changeset detectedLatest commit: 4bdfeda The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
|
||
| if (!set_cookie_value || is_string_like(set_cookie_value)) { | ||
| safe_headers = true; | ||
| if (expr) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what if we changed the implementation of rewrite_returns instead? I don't think there's any reason we'd need to do anything with a return;, we can just leave it be:
-if (ts.isReturnStatement(node)) {
+if (ts.isReturnStatement(node) && node.expression) {There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Depends on how we answer the questions in the PR description - so yeah, definitely possible
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At present the type of Load is this:
kit/packages/kit/types/index.d.ts
Lines 180 to 186 in ac5b00b
| export interface Load< | |
| Params extends Record<string, string> = Record<string, string>, | |
| InputData extends Record<string, any> = Record<string, any>, | |
| OutputData extends Record<string, any> = Record<string, any> | |
| > { | |
| (event: LoadEvent<Params, InputData>): MaybePromise<OutputData | void>; | |
| } |
i.e. a void return is fine, and so assuming we're okay with that then return; is fine
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, but currently the RequestHandler type does not allow a void return - which makes me think that we should probably align these. So Load is ok with a void, so GET should, too. In the case of standalone endpoints we always need to return a response now. If we assume that people have their returns correctly already, we can just skip the return; case - if you agree with that, I'll adjust the code accordingly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If standalone endpoint returns void today, it'll be an error, so I think it's fine for RequestHandler to require a Response return value — it'll just continue to error if it doesn't
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True - ok I'll adjust this to leave lone returns as-is then
Adding strict mode uncovered that we previously failed on lone
return;statements. This PR fixes that - but it brought up an interesting question: Should lonereturn;statements still be allowed in the newloadfunction? Right now it's implemented as "no, you need to adjust this". If we allow it, we should adjust the types for the handler functions in+page.server.jsto allow it as well. If we don't allow it, we should adjust theloadfunction return type to reflect hat.Please don't delete this checklist! Before submitting the PR, please make sure you do the following:
Tests
pnpm testand lint the project withpnpm lintandpnpm checkChangesets
pnpm changesetand following the prompts. All changesets should bepatchuntil SvelteKit 1.0