-
Notifications
You must be signed in to change notification settings - Fork 29.6k
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
test: replace function with arrow function #17345
Conversation
Among the list of [Code and Learn](nodejs/code-and-learn#72 (comment)), I solved the unfinished task of replacing function with arrow function
test/parallel/test-assert.js
Outdated
@@ -26,7 +26,7 @@ const a = assert; | |||
|
|||
function makeBlock(f) { | |||
const args = Array.prototype.slice.call(arguments, 1); | |||
return function() { | |||
return () => { |
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.
This makes this
lexical. Is it OK here?
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.
Thank you for your review.
I think that it is OK because test passed locally.
It is not called with neither .call
nor .apply
in this file.
This code equivalent to:
return () => {
return f.apply(null, args);
};
Should I replace this
with null
?
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.
Maybe, for a clarity, but let's see what others think)
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.
I got it.
Please let us know what others think.
test/parallel/test-assert.js
Outdated
@@ -183,7 +183,7 @@ assert.doesNotThrow(makeBlock(a.deepEqual, a1, a2)); | |||
|
|||
// having an identical prototype property | |||
const nbRoot = { | |||
toString: function() { return `${this.first} ${this.last}`; } | |||
toString: () => { return `${this.first} ${this.last}`; } |
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.
The same.
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.
Thank you for your review.
I was mistaken.
I'll fix this problem with like:
toString() { return `${this.first} ${this.last}`; }
@@ -12,7 +12,7 @@ const { test, assert_equals, assert_true, assert_array_equals } = | |||
License: http://www.w3.org/Consortium/Legal/2008/04-testsuite-copyright.html | |||
*/ | |||
/* eslint-disable */ | |||
test(function() { | |||
test(() => { |
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.
As per the comment above, it seems we should not change this fragment.
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.
Modifications to them should be upstreamed first.
I'm sorry to have missed it.
I'll revert changes in this file.
@@ -25,7 +25,7 @@ test(function() { | |||
assert_array_equals(params.getAll('a'), ['', 'e']); | |||
}, 'getAll() basics'); | |||
|
|||
test(function() { | |||
test(() => { |
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.
Ditto.
Arrow function makes `this` lexical scope. But toString expects evaluate `this` in runtime.
These tests are copied from WPT. I should not changed it directly.
test/parallel/test-assert.js
Outdated
@@ -607,7 +607,7 @@ testAssertionMessage([1, 2, 3], '[ 1, 2, 3 ]'); | |||
testAssertionMessage(/a/, '/a/'); | |||
testAssertionMessage(/abc/gim, '/abc/gim'); | |||
testAssertionMessage(function f() {}, '[Function: f]'); | |||
testAssertionMessage(function() {}, '[Function]'); | |||
testAssertionMessage(() => {}, '[Function]'); |
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.
I think that it should be reverted because function() {}
and () => {}
are should be tested both.
This PR changes only syntax, should not change test case.
So it better of separated by another PR.
What do you think about it ?
test/parallel/test-assert.js
Outdated
@@ -607,7 +607,7 @@ testAssertionMessage([1, 2, 3], '[ 1, 2, 3 ]'); | |||
testAssertionMessage(/a/, '/a/'); | |||
testAssertionMessage(/abc/gim, '/abc/gim'); | |||
testAssertionMessage(function f() {}, '[Function: f]'); | |||
testAssertionMessage(function() {}, '[Function]'); | |||
testAssertionMessage(() => {}, '[Function]'); |
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.
In my humble opinion, this check would be better to not replace arrow function. Because assert message also should have '[Function]' when function() {}
is input.
We would be better to check both function style arrow function
and normal function
.
makeBlock does not need `this`. update `this` with `null` to clarify the intent.
`function() {}` and `() => {}` are should be tested both. See also #17345 (comment)
Hmm. It seems CI does not post status to PR currently. |
Yesterday, status integration is worked fine. |
Hi @vsemozhetbyt. |
@Leko Sorry for the delay. Let's run the CI again. If it is green, we will land it today. |
@vsemozhetbyt I got it. Thank you for quick reply ! |
One CI failure seems unrelated. Landing... |
1. Among the list of Code and Learn, I solved the unfinished task of replacing function with arrow function: nodejs/code-and-learn#72 (comment) 2. Replace arrow function with shorter property syntax Arrow function makes `this` lexical scope. But toString expects evaluate `this` in runtime. 3. Replace this with null makeBlock does not need `this`. update `this` with `null` to clarify the intent. PR-URL: #17345 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Jon Moss <me@jonathanmoss.me> Reviewed-By: Yosuke Furukawa <yosuke.furukawa@gmail.com>
1. Among the list of Code and Learn, I solved the unfinished task of replacing function with arrow function: nodejs/code-and-learn#72 (comment) 2. Replace arrow function with shorter property syntax Arrow function makes `this` lexical scope. But toString expects evaluate `this` in runtime. 3. Replace this with null makeBlock does not need `this`. update `this` with `null` to clarify the intent. PR-URL: #17345 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Jon Moss <me@jonathanmoss.me> Reviewed-By: Yosuke Furukawa <yosuke.furukawa@gmail.com>
1. Among the list of Code and Learn, I solved the unfinished task of replacing function with arrow function: nodejs/code-and-learn#72 (comment) 2. Replace arrow function with shorter property syntax Arrow function makes `this` lexical scope. But toString expects evaluate `this` in runtime. 3. Replace this with null makeBlock does not need `this`. update `this` with `null` to clarify the intent. PR-URL: #17345 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Jon Moss <me@jonathanmoss.me> Reviewed-By: Yosuke Furukawa <yosuke.furukawa@gmail.com>
1. Among the list of Code and Learn, I solved the unfinished task of replacing function with arrow function: nodejs/code-and-learn#72 (comment) 2. Replace arrow function with shorter property syntax Arrow function makes `this` lexical scope. But toString expects evaluate `this` in runtime. 3. Replace this with null makeBlock does not need `this`. update `this` with `null` to clarify the intent. PR-URL: #17345 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Jon Moss <me@jonathanmoss.me> Reviewed-By: Yosuke Furukawa <yosuke.furukawa@gmail.com>
1. Among the list of Code and Learn, I solved the unfinished task of replacing function with arrow function: nodejs/code-and-learn#72 (comment) 2. Replace arrow function with shorter property syntax Arrow function makes `this` lexical scope. But toString expects evaluate `this` in runtime. 3. Replace this with null makeBlock does not need `this`. update `this` with `null` to clarify the intent. PR-URL: #17345 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Jon Moss <me@jonathanmoss.me> Reviewed-By: Yosuke Furukawa <yosuke.furukawa@gmail.com>
This is part of Nodefest's Code and Learn nodejs/code-and-learn#72
Among the list of Code and Learn, I solved the unfinished task of replacing function with arrow function
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)
test