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: Convert logical nullish assignment for backward compatibility #1625

Merged
merged 2 commits into from Sep 2, 2022

Conversation

avanelli
Copy link
Contributor

Motivation

Backward compatibility
??= is only supported from ecmaVersion: 2021

Solution

Converted logical nullish assignment x ??= y to x ?? (x = y)
(Ref: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Logical_nullish_assignment)

Related Issue

Closes #1479

@KhafraDev
Copy link
Member

Is it possible to add a test?

Comment on lines 404 to 406
get [kHeadersSortedMap] () {
this[kHeadersList][kHeadersSortedMap] ??= new Map([...this[kHeadersList]].sort((a, b) => a[0] < b[0] ? -1 : 1))
this[kHeadersList][kHeadersSortedMap] ?? (this[kHeadersList][kHeadersSortedMap] = new Map([...this[kHeadersList]].sort((a, b) => a[0] < b[0] ? -1 : 1)))
return this[kHeadersList][kHeadersSortedMap]
Copy link
Member

Choose a reason for hiding this comment

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

if (!this[kHeadersList][kHeadersSortedMap]) {
 this[kHeadersList][kHeadersSortedMap] = new Map([...this[kHeadersList]].sort((a, b) => a[0] < b[0] ? -1 : 1)))
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is this for code clarity?

Copy link
Member

Choose a reason for hiding this comment

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

yes

@avanelli
Copy link
Contributor Author

avanelli commented Sep 2, 2022

Is it possible to add a test?

I double checked and these lines are already covered by existing tests

@avanelli avanelli requested a review from ronag September 2, 2022 14:40
@codecov-commenter
Copy link

codecov-commenter commented Sep 2, 2022

Codecov Report

Merging #1625 (105f75e) into main (03cfc4b) will decrease coverage by 0.04%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main    #1625      +/-   ##
==========================================
- Coverage   94.93%   94.89%   -0.05%     
==========================================
  Files          50       50              
  Lines        4798     4799       +1     
==========================================
- Hits         4555     4554       -1     
- Misses        243      245       +2     
Impacted Files Coverage Δ
lib/fetch/headers.js 94.48% <100.00%> (+0.03%) ⬆️
lib/core/connect.js 98.27% <0.00%> (-1.73%) ⬇️
lib/fetch/file.js 91.76% <0.00%> (-1.10%) ⬇️
lib/fetch/util.js 86.30% <0.00%> (-0.28%) ⬇️
lib/fetch/index.js 84.10% <0.00%> (+0.05%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

Copy link
Member

@KhafraDev KhafraDev left a comment

Choose a reason for hiding this comment

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

The main issue is that we don't have tests for regressions, which unfortunately are very hard to make.

@ronag ronag merged commit 3f8542b into nodejs:main Sep 2, 2022
metcoder95 pushed a commit to metcoder95/undici that referenced this pull request Dec 26, 2022
…odejs#1625)

* fix: remove logical nullish assignment

* more readable code
@oojacoboo
Copy link

oojacoboo commented Oct 11, 2023

Was a new ??= introduced? Running into the same error, but now on like 122:

if (lowercaseName === 'set-cookie') {
  this.cookies ??= []
  this.cookies.push(value)
}

Edit: Seems like it was introduced in 5.15.0

@KhafraDev
Copy link
Member

??= has been supported since node 15, I recommend updating node to v18 or v20

@oojacoboo
Copy link

Yea, don't have any control over the target, unfortunately. We've downgraded to 5.14.0 until who knows when. Thanks for the reply.

crysmags pushed a commit to crysmags/undici that referenced this pull request Feb 27, 2024
…odejs#1625)

* fix: remove logical nullish assignment

* more readable code
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.

undici/lib/fetch/headers.js: Unexpected token (300:44)
5 participants