[fix] handle lone returns in migration tool, turn on strict mode#5831
[fix] handle lone returns in migration tool, turn on strict mode#5831Rich-Harris merged 6 commits intomasterfrom
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.
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.
Depends on how we answer the questions in the PR description - so yeah, definitely possible
There was a problem hiding this comment.
At present the type of Load is this:
kit/packages/kit/types/index.d.ts
Lines 180 to 186 in ac5b00b
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.
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.
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.
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