File tree Expand file tree Collapse file tree 2 files changed +15
-0
lines changed
src/com/google/javascript/jscomp
test/com/google/javascript/jscomp Expand file tree Collapse file tree 2 files changed +15
-0
lines changed Original file line number Diff line number Diff line change 24
24
import com .google .javascript .rhino .Node ;
25
25
import com .google .javascript .rhino .Token ;
26
26
import com .google .javascript .rhino .jstype .TernaryValue ;
27
+ import java .math .BigInteger ;
27
28
28
29
/**
29
30
* Peephole optimization to fold constants (e.g. x + 1 + 7 --> x + 8).
@@ -411,6 +412,12 @@ private Node tryFoldUnaryOperator(Node n) {
411
412
report (FRACTIONAL_BITWISE_OPERAND , left );
412
413
return n ;
413
414
}
415
+ } else if (left .isBigInt ()) {
416
+ BigInteger val = left .getBigInt ();
417
+ Node notValNode = IR .bigint (val .not ());
418
+ parent .replaceChild (n , notValNode );
419
+ reportChangeToEnclosingScope (parent );
420
+ return notValNode ;
414
421
} else {
415
422
return n ;
416
423
}
Original file line number Diff line number Diff line change @@ -522,6 +522,14 @@ public void testUnaryOps() {
522
522
testSame ("a=~.5" , PeepholeFoldConstants .FRACTIONAL_BITWISE_OPERAND );
523
523
}
524
524
525
+ @ Test
526
+ public void testUnaryOpsWithBigInt () {
527
+ fold ("-(1n)" , "-1n" );
528
+ fold ("- -1n" , "1n" );
529
+ fold ("!1n" , "false" );
530
+ fold ("~0n" , "-1n" );
531
+ }
532
+
525
533
@ Test
526
534
public void testUnaryOpsStringCompare () {
527
535
foldSame ("a = -1" );
You can’t perform that action at this time.
0 commit comments