Skip to content

Do expressions transform incorrectly for switch statements (T6822) #3872

@babel-bot

Description

@babel-bot

Issue originally made by @AppShipIt

Bug information

  • Babel version: 6.3.17
  • Node version: 5.0.0
  • npm version: 3.5.1

Options

{
  "presets": [
    "es2015",
    "stage-0"
  ]
}

Input code

const testSwitch = () => do {
  switch (new Date().getDay()) {
    case 0: case 6: "weekend 🚵"; break
    default: "weekday 🚴"
  }
}

alert(`Today is a ${testSwitch() || "🐛"}`)

Description

Per [[ https://twitter.com/BrendanEich/status/676497551495856129 | tweet ]] from Brendan Eich:

Expected

"use strict";

var testSwitch = function testSwitch() {
  return (function () {
    switch (new Date().getDay()) {
      case 0:case 6:
        return "weekend 🚵";
      default:
        return "weekday 🚴";
    }
  })();
};

alert("Today is a " + (testSwitch() || "🐛"));

Got

"use strict";

var testSwitch = function testSwitch() {
  return (function () {
    switch (new Date().getDay()) {
      case 0:case 6:
        "weekend 🚵";break;
      default:
        "weekday 🚴";
    }
  })();
};

alert("Today is a " + (testSwitch() || "🐛"));

[[ http://codepen.io/dnalot/pen/VewJez | Live demo ]]

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions