MCPcopy
hub / github.com/evanw/esbuild / printNumber

Method printNumber

internal/js_printer/js_printer.go:484–547  ·  view source on GitHub ↗
(value float64, level js_ast.L)

Source from the content-addressed store, hash-verified

482}
483
484func (p *printer) printNumber(value float64, level js_ast.L) {
485 absValue := math.Abs(value)
486
487 if value != value {
488 p.printSpaceBeforeIdentifier()
489 if p.withNesting != 0 {
490 // "with (x) NaN" really means "x.NaN" so avoid identifiers when "with" is present
491 wrap := level >= js_ast.LMultiply
492 if wrap {
493 p.print("(")
494 }
495 if p.options.MinifyWhitespace {
496 p.print("0/0")
497 } else {
498 p.print("0 / 0")
499 }
500 if wrap {
501 p.print(")")
502 }
503 } else {
504 p.print("NaN")
505 }
506 } else if value == positiveInfinity || value == negativeInfinity {
507 // "with (x) Infinity" really means "x.Infinity" so avoid identifiers when "with" is present
508 wrap := ((p.options.MinifySyntax || p.withNesting != 0) && level >= js_ast.LMultiply) ||
509 (value == negativeInfinity && level >= js_ast.LPrefix)
510 if wrap {
511 p.print("(")
512 }
513 if value == negativeInfinity {
514 p.printSpaceBeforeOperator(js_ast.UnOpNeg)
515 p.print("-")
516 } else {
517 p.printSpaceBeforeIdentifier()
518 }
519 if !p.options.MinifySyntax && p.withNesting == 0 {
520 p.print("Infinity")
521 } else if p.options.MinifyWhitespace {
522 p.print("1/0")
523 } else {
524 p.print("1 / 0")
525 }
526 if wrap {
527 p.print(")")
528 }
529 } else {
530 if !math.Signbit(value) {
531 p.printSpaceBeforeIdentifier()
532 p.printNonNegativeFloat(absValue)
533 } else if level >= js_ast.LPrefix {
534 // Expressions such as "(-1).toString" need to wrap negative numbers.
535 // Instead of testing for "value < 0" we test for "signbit(value)" and
536 // "!isNaN(value)" because we need this to be true for "-0" and "-0 < 0"
537 // is false.
538 p.print("(-")
539 p.printNonNegativeFloat(absValue)
540 p.print(")")
541 } else {

Callers 1

printExprMethod · 0.95

Calls 5

printMethod · 0.95
printNonNegativeFloatMethod · 0.95
AbsMethod · 0.65

Tested by

no test coverage detected