Skip to content

clean up usage of null/undefined#377

Closed
wjhsf wants to merge 13 commits into
masterfrom
null-undefined
Closed

clean up usage of null/undefined#377
wjhsf wants to merge 13 commits into
masterfrom
null-undefined

Conversation

@wjhsf
Copy link
Copy Markdown
Contributor

@wjhsf wjhsf commented Mar 1, 2024

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, and domainMatch, 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.

Comment thread lib/cookie/cookie.ts
secure: boolean | undefined
httpOnly: boolean | undefined
extensions: string[] | null | undefined
key: string
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All of these props seem to have | undefined, but not actually need it, because none of the cookieDefaults are undefined.

Comment thread lib/cookie/cookie.ts
hostOnly: boolean | null
pathIsDefault: boolean | null
lastAccessed: Date | 'Infinity' | null
sameSite: string | undefined
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 thread lib/cookie/cookie.ts
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
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TypeScript complains if we use Object.assign, so I just made it all explicit.

@colincasey
Copy link
Copy Markdown
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:

  • Clean up cookie creation options
  • Prefer promiseCallback.resolve where possible
  • Introduction and usage of the Nullable type
  • etc.

@wjhsf
Copy link
Copy Markdown
Contributor Author

wjhsf commented Mar 13, 2024

Replaced by #380 #381.

@wjhsf wjhsf closed this Mar 13, 2024
@wjhsf wjhsf deleted the null-undefined branch March 19, 2024 19:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants