Skip to content

When used in switch, escape sequences (of strings) are compiled incorrectly #6060

Closed
@LuKuangChen

Description

@LuKuangChen
let f = s => {
  switch s {
  | "\\" => "backslash"
  | "\"" => "doublequote"
  | _ => "other"
  }
}
let s1 = "\\"
let s2 = "\""

actual output (by the latest playground as of today)

function f(s) {
  switch (s) {
    case "\\\"" :
        return "doublequote";
    case "\\\\" :
        return "backslash";
    default:
      return "other";
  }
}

var s1 = "\\";
var s2 = "\"";

I expect the two cases to be case "\"" and case "\\" instead. Not that escape sequences that are used outside the switch-case context are translated appropriately.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions