@@ -182,6 +182,33 @@ const errorNaN = [
182182 } ,
183183] ;
184184
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+
185212test ( {
186213 valid : [
187214 'const foo = Number.NaN;' ,
@@ -252,14 +279,8 @@ test({
252279 'function Infinity() {}' ,
253280 'class Infinity {}' ,
254281 '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;' ,
263284 ] ,
264285 invalid : [
265286 {
@@ -307,6 +328,16 @@ test({
307328 output : 'class Foo3 {[Number.NaN] = 1}' ,
308329 errors : errorNaN ,
309330 } ,
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+ } ,
310341 ] ,
311342} ) ;
312343
@@ -370,30 +401,28 @@ test.snapshot({
370401 'foo[NaN] = 1;' ,
371402 'class A {[NaN](){}}' ,
372403 '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;' ) ,
397426 'const {a = NaN} = {};' ,
398427 'const {[NaN]: a = NaN} = {};' ,
399428 'const [a = NaN] = [];' ,
@@ -402,7 +431,7 @@ test.snapshot({
402431 'function foo([a = NaN]) {}' ,
403432
404433 // Space after keywords
405- 'function foo() {return-Infinity}' ,
434+ withCheckInfinity ( 'function foo() {return-Infinity}' ) ,
406435
407436 'globalThis.isNaN(foo);' ,
408437 'global.isNaN(foo);' ,
@@ -413,7 +442,7 @@ test.snapshot({
413442 'window.parseFloat(foo);' ,
414443 'self.parseFloat(foo);' ,
415444 'globalThis.NaN' ,
416- '-globalThis.Infinity' ,
445+ withCheckInfinity ( '-globalThis.Infinity' ) ,
417446
418447 // Not a call
419448 outdent `
0 commit comments