test: replace function with arrow function#17345
test: replace function with arrow function#17345Leko wants to merge 5 commits intonodejs:masterfrom Leko:replace_function_with_arrow_function
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
| function makeBlock(f) { | ||
| const args = Array.prototype.slice.call(arguments, 1); | ||
| return function() { | ||
| return () => { |
There was a problem hiding this comment.
This makes this lexical. Is it OK here?
There was a problem hiding this comment.
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.
Maybe, for a clarity, but let's see what others think)
There was a problem hiding this comment.
I got it.
Please let us know what others think.
test/parallel/test-assert.js
Outdated
| // 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.
Thank you for your review.
I was mistaken.
I'll fix this problem with like:
toString() { return `${this.first} ${this.last}`; }| */ | ||
| /* eslint-disable */ | ||
| test(function() { | ||
| test(() => { |
There was a problem hiding this comment.
As per the comment above, it seems we should not change this fragment.
There was a problem hiding this comment.
Modifications to them should be upstreamed first.
I'm sorry to have missed it.
I'll revert changes in this file.
| }, 'getAll() basics'); | ||
|
|
||
| test(function() { | ||
| test(() => { |
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
| testAssertionMessage(/abc/gim, '/abc/gim'); | ||
| testAssertionMessage(function f() {}, '[Function: f]'); | ||
| testAssertionMessage(function() {}, '[Function]'); | ||
| testAssertionMessage(() => {}, '[Function]'); |
There was a problem hiding this comment.
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
| testAssertionMessage(/abc/gim, '/abc/gim'); | ||
| testAssertionMessage(function f() {}, '[Function: f]'); | ||
| testAssertionMessage(function() {}, '[Function]'); | ||
| testAssertionMessage(() => {}, '[Function]'); |
There was a problem hiding this comment.
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 <[email protected]> Reviewed-By: Jon Moss <[email protected]> Reviewed-By: Yosuke Furukawa <[email protected]>
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 <[email protected]> Reviewed-By: Jon Moss <[email protected]> Reviewed-By: Yosuke Furukawa <[email protected]>
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 <[email protected]> Reviewed-By: Jon Moss <[email protected]> Reviewed-By: Yosuke Furukawa <[email protected]>
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 <[email protected]> Reviewed-By: Jon Moss <[email protected]> Reviewed-By: Yosuke Furukawa <[email protected]>
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 <[email protected]> Reviewed-By: Jon Moss <[email protected]> Reviewed-By: Yosuke Furukawa <[email protected]>
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