Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor switch support in NodePath#getCompletionRecords #13030

Merged
merged 11 commits into from Apr 2, 2021
@@ -1,6 +1,9 @@
const x = n => function () {
switch (n) {
case 0:
if (true) return void 0;
if (true) {
return void 0;
}

}
}();
@@ -0,0 +1,38 @@
const x = (n) => do {
switch (n) {
case 0:
case 6:
const b = 1;
break;
case 1: {
("a");
{
const c = 1;
{
break;
}
}
}
case 2:
case 3: {
("b");
if (n === 2) {
const c = 1;
} else {
("c");
}
{
break;
}
}
default:
"bar";
}
};

expect(x(0)).toBeUndefined();
expect(x(1)).toBeUndefined();
expect(x(2)).toBeUndefined();
expect(x(3)).toBe("c");
expect(x(6)).toBeUndefined();
expect(x(7)).toBe("bar");
@@ -1,9 +1,31 @@
const x = (n) => do {
switch (n) {
case 0:
case 6:
case 0:
case 6:
const b = 1;
break;
default: 'bar';
case 1: {
("a");
{
const c = 1;
{
break;
}
}
}
case 2:
case 3: {
("b");
if (n === 2) {
const c = 1;
} else {
("c");
}
{
break;
}
}
default:
"bar";
}
}
};
Expand Up @@ -5,7 +5,34 @@ const x = n => function () {
const b = 1;
return void 0;

case 1:
{
"a";
{
const c = 1;
{
return void 0;
}
}
}

case 2:
case 3:
{
"b";

if (n === 2) {
const c = 1;
} else {
return "c";
}

{
return void 0;
}
}

default:
return 'bar';
return "bar";
}
}();
Expand Up @@ -16,7 +16,9 @@ const x = n => function () {
}

case 3:
return void 0;
{
return void 0;
}

case 4:
{
Expand Down
Expand Up @@ -2,14 +2,14 @@
// https://github.com/babel/babel/pull/10070#discussion_r296048106
const x = (n) => do {
switch (n) {
case 0:
case 0:
{ "a"; }
{ "b"; };
case 1:
case 1:
{ "c"; }
break;
{ "d"; };
case 2:
case 2:
"a";
"b";
case 3:
Expand Down
@@ -0,0 +1,47 @@
const x = n => function () {
switch (n) {
case 0:
{
"a";
}
{
"b";
}
;

case 1:
{
return "c";
}
{
"d";
}
;

case 2:
"a";
"b";

case 3:
{}
{
return void 0;
}

case 4:
{
"a";
}
{
"b";
}

case 5:
return "c";

case 6:
{}

case 7:
}
}();
Expand Up @@ -4,6 +4,7 @@ const x = n => function () {
{
return "a";
}
{}
{
"b";
}
Expand All @@ -20,6 +21,7 @@ const x = n => function () {

case 2:
return "a";
{}
"b";

case 3:
Expand Down Expand Up @@ -52,6 +54,9 @@ const x = n => function () {
{
return "a";
}
{
"b";
}
{
break;
"c";
Expand Down
@@ -0,0 +1,34 @@
const x = (n) => do {
switch (n) {
case 0:
{ "a"; { break; } }
{ "b"; };
case 1:
{ "c"; }
{ "d"; { { { { break; }}}}};
case 2:
case 3:
{ "e"; { if (true) { break; } } }
{ break; }
case 4:
{ "g"; { { break; "h"; } "i" } }
case 5:
case 6:
if (n === 5) {
"j"
} else {
"k"
}
{ break; "l" }
case 7:
}
}

expect(x(0)).toBe('a')
expect(x(1)).toBe('d')
expect(x(2)).toBeUndefined()
expect(x(3)).toBeUndefined()
expect(x(4)).toBe("g")
expect(x(5)).toBe("j")
expect(x(6)).toBe("k")
expect(x(7)).toBeUndefined()
@@ -0,0 +1,25 @@
const x = (n) => do {
switch (n) {
case 0:
{ "a"; { break; } }
{ "b"; };
case 1:
{ "c"; }
{ "d"; { { { { break; }}}}};
case 2:
case 3:
{ "e"; { if (true) { break; } } }
{ break; }
case 4:
{ "g"; { { break; "h"; } "i" } }
case 5:
case 6:
if (n === 5) {
"j"
} else {
"k"
}
{ break; "l" }
case 7:
}
}
@@ -0,0 +1,66 @@
const x = n => function () {
switch (n) {
case 0:
{
return "a";
{}
}
{
"b";
}
;

case 1:
{
"c";
}
{
return "d";
{
{
{
{}
}
}
}
}
;

case 2:
case 3:
{
"e";
{
if (true) {
return void 0;
}
}
}
{}

case 4:
{
return "g";
{
{
"h";
}
"i";
}
}

case 5:
case 6:
if (n === 5) {
return "j";
} else {
return "k";
}

{
"l";
}

case 7:
}
}();