test: replace function with arrow function · nodejs/node@a27df5d · GitHub
Skip to content

Commit a27df5d

Browse files
Lekogibfahn
authored andcommitted
test: replace function with arrow function
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 parent a6c7030 commit a27df5d

5 files changed

Lines changed: 40 additions & 40 deletions

File tree

test/parallel/test-assert.js

Lines changed: 9 additions & 9 deletions

test/parallel/test-domain-top-level-error-handler-clears-stack.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ const domain = require('domain');
99
*/
1010
const d = domain.create();
1111

12-
d.on('error', common.mustCall(function() {
13-
process.nextTick(function() {
12+
d.on('error', common.mustCall(() => {
13+
process.nextTick(() => {
1414
// Scheduling a callback with process.nextTick will enter a _new_ domain,
1515
// and the callback will be called after the domain that handled the error
1616
// was exited. So there should be only one domain on the domains stack if
@@ -29,6 +29,6 @@ d.on('error', common.mustCall(function() {
2929
});
3030
}));
3131

32-
d.run(function() {
32+
d.run(() => {
3333
throw new Error('Error from domain');
3434
});

test/parallel/test-querystring.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ const qsWeirdObjects = [
129129
[{ regexp: /./g }, 'regexp=', { 'regexp': '' }],
130130
// eslint-disable-next-line no-unescaped-regexp-dot
131131
[{ regexp: new RegExp('.', 'g') }, 'regexp=', { 'regexp': '' }],
132-
[{ fn: function() {} }, 'fn=', { 'fn': '' }],
132+
[{ fn: () => {} }, 'fn=', { 'fn': '' }],
133133
[{ fn: new Function('') }, 'fn=', { 'fn': '' }],
134134
[{ math: Math }, 'math=', { 'math': '' }],
135135
[{ e: extendedFunction }, 'e=', { 'e': '' }],
@@ -189,7 +189,7 @@ function check(actual, expected, input) {
189189
`Expected keys: ${inspect(expectedKeys)}`;
190190
}
191191
assert.deepStrictEqual(actualKeys, expectedKeys, msg);
192-
expectedKeys.forEach(function(key) {
192+
expectedKeys.forEach((key) => {
193193
if (typeof input === 'string') {
194194
msg = `Input: ${inspect(input)}\n` +
195195
`Key: ${inspect(key)}\n` +
@@ -203,21 +203,21 @@ function check(actual, expected, input) {
203203
}
204204

205205
// test that the canonical qs is parsed properly.
206-
qsTestCases.forEach(function(testCase) {
206+
qsTestCases.forEach((testCase) => {
207207
check(qs.parse(testCase[0]), testCase[2], testCase[0]);
208208
});
209209

210210
// test that the colon test cases can do the same
211-
qsColonTestCases.forEach(function(testCase) {
211+
qsColonTestCases.forEach((testCase) => {
212212
check(qs.parse(testCase[0], ';', ':'), testCase[2], testCase[0]);
213213
});
214214

215215
// test the weird objects, that they get parsed properly
216-
qsWeirdObjects.forEach(function(testCase) {
216+
qsWeirdObjects.forEach((testCase) => {
217217
check(qs.parse(testCase[1]), testCase[2], testCase[1]);
218218
});
219219

220-
qsNoMungeTestCases.forEach(function(testCase) {
220+
qsNoMungeTestCases.forEach((testCase) => {
221221
assert.deepStrictEqual(testCase[0], qs.stringify(testCase[1], '&', '='));
222222
});
223223

@@ -255,15 +255,15 @@ qsNoMungeTestCases.forEach(function(testCase) {
255255
// now test stringifying
256256

257257
// basic
258-
qsTestCases.forEach(function(testCase) {
258+
qsTestCases.forEach((testCase) => {
259259
assert.strictEqual(testCase[1], qs.stringify(testCase[2]));
260260
});
261261

262-
qsColonTestCases.forEach(function(testCase) {
262+
qsColonTestCases.forEach((testCase) => {
263263
assert.strictEqual(testCase[1], qs.stringify(testCase[2], ';', ':'));
264264
});
265265

266-
qsWeirdObjects.forEach(function(testCase) {
266+
qsWeirdObjects.forEach((testCase) => {
267267
assert.strictEqual(testCase[1], qs.stringify(testCase[0]));
268268
});
269269

@@ -292,7 +292,7 @@ assert.strictEqual('foo=', qs.stringify({ foo: Infinity }));
292292
assert.strictEqual(f, 'a=b&q=x%3Dy%26y%3Dz');
293293
}
294294

295-
assert.doesNotThrow(function() {
295+
assert.doesNotThrow(() => {
296296
qs.parse(undefined);
297297
});
298298

@@ -423,15 +423,15 @@ check(qs.parse('%\u0100=%\u0101'), { '%Ā': '%ā' });
423423
}
424424

425425
// Test QueryString.unescapeBuffer
426-
qsUnescapeTestCases.forEach(function(testCase) {
426+
qsUnescapeTestCases.forEach((testCase) => {
427427
assert.strictEqual(qs.unescape(testCase[0]), testCase[1]);
428428
assert.strictEqual(qs.unescapeBuffer(testCase[0]).toString(), testCase[1]);
429429
});
430430

431431
// test overriding .unescape
432432
{
433433
const prevUnescape = qs.unescape;
434-
qs.unescape = function(str) {
434+
qs.unescape = (str) => {
435435
return str.replace(/o/g, '_');
436436
};
437437
check(

test/parallel/test-writeint.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ function test8(clazz) {
3737
assert.strictEqual(0xfb, buffer[1]);
3838

3939
/* Make sure we handle truncation correctly */
40-
assert.throws(function() {
40+
assert.throws(() => {
4141
buffer.writeInt8(0xabc, 0);
4242
}, errorOutOfBounds);
43-
assert.throws(function() {
43+
assert.throws(() => {
4444
buffer.writeInt8(0xabc, 0);
4545
}, errorOutOfBounds);
4646

@@ -50,10 +50,10 @@ function test8(clazz) {
5050

5151
assert.strictEqual(0x7f, buffer[0]);
5252
assert.strictEqual(0x80, buffer[1]);
53-
assert.throws(function() {
53+
assert.throws(() => {
5454
buffer.writeInt8(0x7f + 1, 0);
5555
}, errorOutOfBounds);
56-
assert.throws(function() {
56+
assert.throws(() => {
5757
buffer.writeInt8(-0x80 - 1, 0);
5858
}, errorOutOfBounds);
5959
}
@@ -90,10 +90,10 @@ function test16(clazz) {
9090
assert.strictEqual(0xff, buffer[1]);
9191
assert.strictEqual(0x80, buffer[2]);
9292
assert.strictEqual(0x00, buffer[3]);
93-
assert.throws(function() {
93+
assert.throws(() => {
9494
buffer.writeInt16BE(0x7fff + 1, 0);
9595
}, errorOutOfBounds);
96-
assert.throws(function() {
96+
assert.throws(() => {
9797
buffer.writeInt16BE(-0x8000 - 1, 0);
9898
}, errorOutOfBounds);
9999

@@ -103,10 +103,10 @@ function test16(clazz) {
103103
assert.strictEqual(0x7f, buffer[1]);
104104
assert.strictEqual(0x00, buffer[2]);
105105
assert.strictEqual(0x80, buffer[3]);
106-
assert.throws(function() {
106+
assert.throws(() => {
107107
buffer.writeInt16LE(0x7fff + 1, 0);
108108
}, errorOutOfBounds);
109-
assert.throws(function() {
109+
assert.throws(() => {
110110
buffer.writeInt16LE(-0x8000 - 1, 0);
111111
}, errorOutOfBounds);
112112
}
@@ -159,10 +159,10 @@ function test32(clazz) {
159159
assert.strictEqual(0x00, buffer[5]);
160160
assert.strictEqual(0x00, buffer[6]);
161161
assert.strictEqual(0x00, buffer[7]);
162-
assert.throws(function() {
162+
assert.throws(() => {
163163
buffer.writeInt32BE(0x7fffffff + 1, 0);
164164
}, errorOutOfBounds);
165-
assert.throws(function() {
165+
assert.throws(() => {
166166
buffer.writeInt32BE(-0x80000000 - 1, 0);
167167
}, errorOutOfBounds);
168168

@@ -176,10 +176,10 @@ function test32(clazz) {
176176
assert.strictEqual(0x00, buffer[5]);
177177
assert.strictEqual(0x00, buffer[6]);
178178
assert.strictEqual(0x80, buffer[7]);
179-
assert.throws(function() {
179+
assert.throws(() => {
180180
buffer.writeInt32LE(0x7fffffff + 1, 0);
181181
}, errorOutOfBounds);
182-
assert.throws(function() {
182+
assert.throws(() => {
183183
buffer.writeInt32LE(-0x80000000 - 1, 0);
184184
}, errorOutOfBounds);
185185
}

test/parallel/test-zerolengthbufferbug.js

Lines changed: 4 additions & 4 deletions

0 commit comments

Comments
 (0)