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

Labelled block and switch statements #189

Open
kaleidawave opened this issue Aug 13, 2024 · 0 comments
Open

Labelled block and switch statements #189

kaleidawave opened this issue Aug 13, 2024 · 0 comments
Labels
checking Issues around checking enhancement New feature or request events-effects Related to operations and side effects good-second-issue Moderately difficult issue

Comments

@kaleidawave
Copy link
Owner

You can do the following in JS

label1: {
	console.log("here");

	if (condition) {
		break 'label1;
	}

	console.log("here");
}

break is 50% handled for for loops. The following needs to be handled in a similar manner. It might require a new Event variant to handle breaks inside.

Additionally solving this would make supporting switch statements simple.

switch (x) {
	case "x": 
		thing1();
	case "y":
		break;
	case "z":
		thing2();
}

Apart from the fact you lift all the variable identifiers

swtch: {
	if (x === "x") {
		thing1();
	}
	if (x === "y") {
		break 'swtch;
	}
	if (x === "y") {
		thing2();
	}
}

No idea what happens for continue and I am afraid to find out

And another case for #124 🤦‍♀️🤦‍♀️🤦‍♀️🤦‍♀️🤦‍♀️

switch(true) {
    case false:
        const x = 2;
    case true: 
        console.log(x)
}
@kaleidawave kaleidawave added enhancement New feature or request good-second-issue Moderately difficult issue checking Issues around checking events-effects Related to operations and side effects labels Aug 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
checking Issues around checking enhancement New feature or request events-effects Related to operations and side effects good-second-issue Moderately difficult issue
Projects
None yet
Development

No branches or pull requests

1 participant