proposal-do-expressions icon indicating copy to clipboard operation
proposal-do-expressions copied to clipboard

example of do expression with switch/case

Open aaronshaf opened this issue 8 years ago • 2 comments

aaronshaf avatar Oct 10 '17 18:10 aaronshaf

var mode = 1;
var results = do {
  switch (mode) {
    case 1:
      'A string value'; // results is 'A string value'
      break;
    case 2:
      5; // results is 5
      break;
    default:
      { a: 1 }; // results is an object
  }
}

clemmy avatar Dec 14 '17 23:12 clemmy

You can also find some interesting examples in the tests/comments of https://github.com/babel/babel/pull/6975

nicolo-ribaudo avatar Dec 15 '17 06:12 nicolo-ribaudo