@@ -182,6 +182,33 @@ const errorNaN = [
182
182
} ,
183
183
] ;
184
184
185
+ const errorPositiveInfinity = [
186
+ {
187
+ messageId : MESSAGE_ID_ERROR ,
188
+ data : {
189
+ description : 'Infinity' ,
190
+ property : 'POSITIVE_INFINITY' ,
191
+ } ,
192
+ } ,
193
+ ] ;
194
+
195
+ const errorNegativeInfinity = [
196
+ {
197
+ messageId : MESSAGE_ID_ERROR ,
198
+ data : {
199
+ description : '-Infinity' ,
200
+ property : 'NEGATIVE_INFINITY' ,
201
+ } ,
202
+ } ,
203
+ ] ;
204
+
205
+ function withCheckInfinity ( code ) {
206
+ return {
207
+ code,
208
+ options : [ { checkInfinity : true } ] ,
209
+ } ;
210
+ }
211
+
185
212
test ( {
186
213
valid : [
187
214
'const foo = Number.NaN;' ,
@@ -252,14 +279,8 @@ test({
252
279
'function Infinity() {}' ,
253
280
'class Infinity {}' ,
254
281
'class Foo { Infinity(){}}' ,
255
- {
256
- code : 'const foo = Infinity;' ,
257
- options : [ { checkInfinity : false } ] ,
258
- } ,
259
- {
260
- code : 'const foo = -Infinity;' ,
261
- options : [ { checkInfinity : false } ] ,
262
- } ,
282
+ 'const foo = Infinity;' ,
283
+ 'const foo = -Infinity;' ,
263
284
] ,
264
285
invalid : [
265
286
{
@@ -307,6 +328,16 @@ test({
307
328
output : 'class Foo3 {[Number.NaN] = 1}' ,
308
329
errors : errorNaN ,
309
330
} ,
331
+ {
332
+ ...withCheckInfinity ( 'const foo = Infinity;' ) ,
333
+ output : 'const foo = Number.POSITIVE_INFINITY;' ,
334
+ errors : errorPositiveInfinity ,
335
+ } ,
336
+ {
337
+ ...withCheckInfinity ( 'const foo = -Infinity;' ) ,
338
+ output : 'const foo = Number.NEGATIVE_INFINITY;' ,
339
+ errors : errorNegativeInfinity ,
340
+ } ,
310
341
] ,
311
342
} ) ;
312
343
@@ -370,30 +401,28 @@ test.snapshot({
370
401
'foo[NaN] = 1;' ,
371
402
'class A {[NaN](){}}' ,
372
403
'foo = {[NaN]: 1}' ,
373
-
374
- 'const foo = Infinity;' ,
375
- 'if (Number.isNaN(Infinity)) {}' ,
376
- 'if (Object.is(foo, Infinity)) {}' ,
377
- 'const foo = bar[Infinity];' ,
378
- 'const foo = {Infinity};' ,
379
- 'const foo = {Infinity: Infinity};' ,
380
- 'const foo = {[Infinity]: -Infinity};' ,
381
- 'const foo = {[-Infinity]: Infinity};' ,
382
- 'const foo = {Infinity: -Infinity};' ,
383
- 'const {foo = Infinity} = {};' ,
384
- 'const {foo = -Infinity} = {};' ,
385
- 'const foo = Infinity.toString();' ,
386
- 'const foo = -Infinity.toString();' ,
387
- 'const foo = (-Infinity).toString();' ,
388
- 'const foo = +Infinity;' ,
389
- 'const foo = +-Infinity;' ,
390
- 'const foo = -Infinity;' ,
391
- 'const foo = -(-Infinity);' ,
392
- 'const foo = 1 - Infinity;' ,
393
- 'const foo = 1 - -Infinity;' ,
394
- 'const isPositiveZero = value => value === 0 && 1 / value === Infinity;' ,
395
- 'const isNegativeZero = value => value === 0 && 1 / value === -Infinity;' ,
396
-
404
+ withCheckInfinity ( 'const foo = Infinity;' ) ,
405
+ withCheckInfinity ( 'if (Number.isNaN(Infinity)) {}' ) ,
406
+ withCheckInfinity ( 'if (Object.is(foo, Infinity)) {}' ) ,
407
+ withCheckInfinity ( 'const foo = bar[Infinity];' ) ,
408
+ withCheckInfinity ( 'const foo = {Infinity};' ) ,
409
+ withCheckInfinity ( 'const foo = {Infinity: Infinity};' ) ,
410
+ withCheckInfinity ( 'const foo = {[Infinity]: -Infinity};' ) ,
411
+ withCheckInfinity ( 'const foo = {[-Infinity]: Infinity};' ) ,
412
+ withCheckInfinity ( 'const foo = {Infinity: -Infinity};' ) ,
413
+ withCheckInfinity ( 'const {foo = Infinity} = {};' ) ,
414
+ withCheckInfinity ( 'const {foo = -Infinity} = {};' ) ,
415
+ withCheckInfinity ( 'const foo = Infinity.toString();' ) ,
416
+ withCheckInfinity ( 'const foo = -Infinity.toString();' ) ,
417
+ withCheckInfinity ( 'const foo = (-Infinity).toString();' ) ,
418
+ withCheckInfinity ( 'const foo = +Infinity;' ) ,
419
+ withCheckInfinity ( 'const foo = +-Infinity;' ) ,
420
+ withCheckInfinity ( 'const foo = -Infinity;' ) ,
421
+ withCheckInfinity ( 'const foo = -(-Infinity);' ) ,
422
+ withCheckInfinity ( 'const foo = 1 - Infinity;' ) ,
423
+ withCheckInfinity ( 'const foo = 1 - -Infinity;' ) ,
424
+ withCheckInfinity ( 'const isPositiveZero = value => value === 0 && 1 / value === Infinity;' ) ,
425
+ withCheckInfinity ( 'const isNegativeZero = value => value === 0 && 1 / value === -Infinity;' ) ,
397
426
'const {a = NaN} = {};' ,
398
427
'const {[NaN]: a = NaN} = {};' ,
399
428
'const [a = NaN] = [];' ,
@@ -402,7 +431,7 @@ test.snapshot({
402
431
'function foo([a = NaN]) {}' ,
403
432
404
433
// Space after keywords
405
- 'function foo() {return-Infinity}' ,
434
+ withCheckInfinity ( 'function foo() {return-Infinity}' ) ,
406
435
407
436
'globalThis.isNaN(foo);' ,
408
437
'global.isNaN(foo);' ,
@@ -413,7 +442,7 @@ test.snapshot({
413
442
'window.parseFloat(foo);' ,
414
443
'self.parseFloat(foo);' ,
415
444
'globalThis.NaN' ,
416
- '-globalThis.Infinity' ,
445
+ withCheckInfinity ( '-globalThis.Infinity' ) ,
417
446
418
447
// Not a call
419
448
outdent `
0 commit comments