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

Do expressions transform for switch statements #10070

Merged
merged 13 commits into from Aug 1, 2019
@@ -0,0 +1,36 @@
// `blockExpressions` before `break` is hard to deal with
// https://github.com/babel/babel/pull/10070#discussion_r296048106
const x = (n) => do {
switch (n) {
case 0:
{ "a"; }
{ "b"; };
case 1:
{ "c"; }
break;
{ "d"; };
case 2:
"a";
"b";
case 3:
{}
{ break; }
case 4:
{ "d"; }
{ "e"; }
case 5:
"f";
case 6:
{}
case 7:
}
}

expect(x(0)).toBe('c')
expect(x(1)).toBe('c')
expect(x(2)).toBeUndefined()
expect(x(3)).toBeUndefined()
expect(x(4)).toBe('f')
expect(x(5)).toBe('f')
expect(x(6)).toBeUndefined()
expect(x(7)).toBeUndefined()
@@ -0,0 +1,25 @@
const x = (n) => do {
switch (n) {
case 0:
{ "a"; }
{ "b"; };
case 1:
{ "c"; }
break;
{ "d"; };
case 2:
"a";
"b";
case 3:
{}
{ break; }
case 4:
{ "a"; }
{ "b"; }
case 5:
"c";
case 6:
{}
case 7:
}
}
@@ -0,0 +1,9 @@
const x = (n) => do {
switch (n) {
case 0:
case 6:
const b = 1;
break;
default: 'bar';
}
}
@@ -0,0 +1,11 @@
const x = n => function () {
switch (n) {
case 0:
case 6:
const b = 1;
return void 0;

default:
return 'bar';
}
}();
@@ -0,0 +1,7 @@
const x = () => do {
switch (new Date().getDay()) {
case 0:
break;
default: "weekday 🚴"
}
}
@@ -0,0 +1,9 @@
const x = () => function () {
switch (new Date().getDay()) {
case 0:
return void 0;

default:
return "weekday 🚴";
}
}();
@@ -0,0 +1,26 @@
const x = (n) => do {
switch (n) {
case 0: {
'a';
}
case 1: {
'b';
break;
}
default: {
'd';
}
case 2: {
'c';
}
case 3:
case 4:
}
}

expect(x(0)).toBe('b');
expect(x(1)).toBe('b');
expect(x(2)).toBe('c');
expect(x(3)).toBeUndefined();
expect(x(4)).toBeUndefined();
expect(x(5)).toBe('c');
@@ -0,0 +1,19 @@
const x = (n) => do {
switch (n) {
case 0: {
'a';
}
case 1: {
'b';
break;
}
default: {
'd';
}
case 2: {
'c';
}
case 3:
case 4:
}
}
@@ -0,0 +1,26 @@
const x = n => function () {
switch (n) {
case 0:
{
'a';
}

case 1:
{
return 'b';
}

default:
{
'd';
}

case 2:
{
return 'c';
}

case 3:
case 4:
}
}();
@@ -0,0 +1,30 @@
const x = (n) => do {
switch (n) {
case 0: {
'a';
}
case 1: {
'b';
break;
}
case 2: {
'c';
break;
}
case 3: {
break;
}
case 4: {
'd';
'e';
}
default: 'f';
}
}

expect(x(0)).toBe('b');
expect(x(1)).toBe('b');
expect(x(2)).toBe('c');
expect(x(3)).toBeUndefined();
expect(x(4)).toBe('f');
expect(x(5)).toBe('f');
@@ -0,0 +1,23 @@
const x = (n) => do {
switch (n) {
case 0: {
'a';
}
case 1: {
'b';
break;
}
case 2: {
'c';
break;
}
case 3: {
break;
}
case 4: {
'd';
'e';
}
default: 'f';
}
}
@@ -0,0 +1,30 @@
const x = n => function () {
switch (n) {
case 0:
{
'a';
}

case 1:
{
return 'b';
}

case 2:
{
return 'c';
}

case 3:
return void 0;

case 4:
{
'd';
'e';
}

default:
return 'f';
}
}();
@@ -0,0 +1,21 @@
const x = (n) => do {
switch (n) {
case 0:
'a';
case 1:
'b';
break;
default: 'd';
case 2:
'c';
case 3:
case 4:
}
}

expect(x(0)).toBe('b');
expect(x(1)).toBe('b');
expect(x(2)).toBe('c');
expect(x(3)).toBeUndefined();
expect(x(4)).toBeUndefined();
expect(x(5)).toBe('c');
@@ -0,0 +1,14 @@
const x = (n) => do {
switch (n) {
case 0:
'a';
case 1:
'b';
break;
default: 'd';
case 2:
'c';
case 3:
case 4:
}
}
@@ -0,0 +1,18 @@
const x = n => function () {
switch (n) {
case 0:
'a';

case 1:
return 'b';

default:
'd';

case 2:
return 'c';

case 3:
case 4:
}
}();
@@ -0,0 +1,25 @@
const x = (n) => do {
switch (n) {
case 0:
'a';
case 1:
'b';
break;
case 2:
'c';
break;
case 3:
break;
case 4:
'd';
'e';
default: 'f';
}
}

expect(x(0)).toBe('b');
expect(x(1)).toBe('b');
expect(x(2)).toBe('c');
expect(x(3)).toBeUndefined();
expect(x(4)).toBe('f');
expect(x(5)).toBe('f');
@@ -0,0 +1,18 @@
const x = (n) => do {
switch (n) {
case 0:
'a';
case 1:
'b';
break;
case 2:
'c';
break;
case 3:
break;
case 4:
'd';
'e';
default: 'f';
}
}
@@ -0,0 +1,22 @@
const x = n => function () {
switch (n) {
case 0:
'a';

case 1:
return 'b';

case 2:
return 'c';

case 3:
return void 0;

case 4:
'd';
'e';

default:
return 'f';
}
}();