Skip to content

Commit 597e942

Browse files
committed
fix #3880 optimize option pattern match
1 parent 6298c1f commit 597e942

File tree

6 files changed

+19
-7
lines changed

6 files changed

+19
-7
lines changed

jscomp/core/js_exp_make.ml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -623,6 +623,10 @@ let rec and_ ?comment (e1 : t) (e2 : t) : t =
623623
| Var i, Bin (And , l, ({expression_desc = Var j ; _} as r))
624624
when Js_op_util.same_vident i j ->
625625
{ e2 with expression_desc = Bin(And, r,l)}
626+
| Bin(NotEqEq, {expression_desc = Var i}, {expression_desc = Undefined } ),
627+
Bin(EqEqEq, {expression_desc = Var j}, {expression_desc = Str _ | Number _ | Unicode _})
628+
when Js_op_util.same_vident i j
629+
-> e2
626630
| _, _ ->
627631
{ expression_desc = Bin(And, e1,e2) ; comment }
628632

jscomp/test/gpr_3875_test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ var Xx = {
1717
function compilerBug(a, b, c, f) {
1818
var exit = 0;
1919
var exit$1 = 0;
20-
if (a !== undefined && a === "x") {
20+
if (a === "x") {
2121
exit = 2;
2222
} else {
2323
exit$1 = 3;
2424
}
2525
if (exit$1 === 3) {
26-
exit = b !== undefined && b === "x" ? 2 : 1;
26+
exit = b === "x" ? 2 : 1;
2727
}
2828
switch (exit) {
2929
case 1 :

jscomp/test/nested_pattern_match_test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,11 @@ function f_opion(x) {
6161
var match$3 = match$2[1];
6262
if (match$3) {
6363
var match$4 = match$3[0];
64-
if (match$4 !== undefined && match$4 === 2) {
64+
if (match$4 === 2) {
6565
var match$5 = match$3[1];
6666
if (match$5) {
6767
var match$6 = match$5[0];
68-
if (match$6 !== undefined && match$6 === 1) {
68+
if (match$6 === 1) {
6969
var match$7 = match$5[1];
7070
if (match$7 && match$7[0] !== undefined) {
7171
return 2;
@@ -99,11 +99,11 @@ function f_opion(x) {
9999
var match$10 = match$9[1];
100100
if (match$10) {
101101
var match$11 = match$10[0];
102-
if (match$11 !== undefined && match$11 === 2) {
102+
if (match$11 === 2) {
103103
var match$12 = match$10[1];
104104
if (match$12) {
105105
var match$13 = match$12[0];
106-
if (match$13 !== undefined && match$13 === 1) {
106+
if (match$13 === 1) {
107107
var match$14 = match$12[1];
108108
if (match$14 && match$14[0] !== undefined) {
109109
return 3;

lib/4.02.3/unstable/js_compiler.ml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82811,6 +82811,10 @@ let rec and_ ?comment (e1 : t) (e2 : t) : t =
8281182811
| Var i, Bin (And , l, ({expression_desc = Var j ; _} as r))
8281282812
when Js_op_util.same_vident i j ->
8281382813
{ e2 with expression_desc = Bin(And, r,l)}
82814+
| Bin(NotEqEq, {expression_desc = Var i}, {expression_desc = Undefined } ),
82815+
Bin(EqEqEq, {expression_desc = Var j}, {expression_desc = Str _ | Number _ | Unicode _})
82816+
when Js_op_util.same_vident i j
82817+
-> e2
8281482818
| _, _ ->
8281582819
{ expression_desc = Bin(And, e1,e2) ; comment }
8281682820

lib/4.02.3/whole_compiler.ml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73003,6 +73003,10 @@ let rec and_ ?comment (e1 : t) (e2 : t) : t =
7300373003
| Var i, Bin (And , l, ({expression_desc = Var j ; _} as r))
7300473004
when Js_op_util.same_vident i j ->
7300573005
{ e2 with expression_desc = Bin(And, r,l)}
73006+
| Bin(NotEqEq, {expression_desc = Var i}, {expression_desc = Undefined } ),
73007+
Bin(EqEqEq, {expression_desc = Var j}, {expression_desc = Str _ | Number _ | Unicode _})
73008+
when Js_op_util.same_vident i j
73009+
-> e2
7300673010
| _, _ ->
7300773011
{ expression_desc = Bin(And, e1,e2) ; comment }
7300873012

lib/js/genlex.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ function make_lexer(keywords) {
132132
Stream.junk(strm__);
133133
var strm__$1 = strm__;
134134
var match$2 = Stream.peek(strm__$1);
135-
if (match$2 !== undefined && match$2 === 42) {
135+
if (match$2 === 42) {
136136
Stream.junk(strm__$1);
137137
comment(strm__$1);
138138
return next_token(strm__$1);

0 commit comments

Comments
 (0)