clean up usage of null/undefined#377
Closed
wjhsf wants to merge 13 commits into
Closed
Conversation
Instead, change `putCookie` invocation depending on whether `callback` is provided.
`promiseCallback.resolve()` is implemented as `cb(); return promise`, so doing `promiseCallback.callback(); return promiseCallback.promise` is unnecessary.
Primarily allowing either value for user input.
wjhsf
commented
Mar 1, 2024
| secure: boolean | undefined | ||
| httpOnly: boolean | undefined | ||
| extensions: string[] | null | undefined | ||
| key: string |
Contributor
Author
There was a problem hiding this comment.
All of these props seem to have | undefined, but not actually need it, because none of the cookieDefaults are undefined.
| hostOnly: boolean | null | ||
| pathIsDefault: boolean | null | ||
| lastAccessed: Date | 'Infinity' | null | ||
| sameSite: string | undefined |
Contributor
Author
There was a problem hiding this comment.
sameSite does actually use undefined to mean "no value". Which is anomalous, but more of a change than I'd want to deal with, here.
Comment on lines
+426
to
+439
| this.key = options.key ?? cookieDefaults.key | ||
| this.value = options.value ?? cookieDefaults.value | ||
| this.expires = options.expires ?? cookieDefaults.expires | ||
| this.maxAge = options.maxAge ?? cookieDefaults.maxAge | ||
| this.domain = options.domain ?? cookieDefaults.domain | ||
| this.path = options.path ?? cookieDefaults.path | ||
| this.secure = options.secure ?? cookieDefaults.secure | ||
| this.httpOnly = options.httpOnly ?? cookieDefaults.httpOnly | ||
| this.extensions = options.extensions ?? cookieDefaults.extensions | ||
| this.creation = options.creation ?? cookieDefaults.creation | ||
| this.hostOnly = options.hostOnly ?? cookieDefaults.hostOnly | ||
| this.pathIsDefault = options.pathIsDefault ?? cookieDefaults.pathIsDefault | ||
| this.lastAccessed = options.lastAccessed ?? cookieDefaults.lastAccessed | ||
| this.sameSite = options.sameSite ?? cookieDefaults.sameSite |
Contributor
Author
There was a problem hiding this comment.
TypeScript complains if we use Object.assign, so I just made it all explicit.
Contributor
|
@wjhsf I'm finding this PR a bit too hard to review. Now that we've done most of the major cleanup with the migration to TypeScript I think this would be easier to review as separate, smaller PRs for each of the included changes such as:
|
This was referenced Mar 13, 2024
Contributor
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This standardizes most of our methods to accept both null and undefined, and mostly return a value or undefined. Exceptions that I noticed are
canonicalDomain,getPublicSuffix,permuteDomain, anddomainMatch, which all return null. I don't remember why I skipped them when I originally did this, so I figured I'd just leave them for now. (I did most of this work a while ago, and evidently never pushed!)This also introduces a helper type
Nullable<T>for readability.