Skip to content

Instantly share code, notes, and snippets.

@jridgewell
Last active February 7, 2024 23:18
Show Gist options
  • Save jridgewell/2685608246f0a43cd1c3f3177eabb5ef to your computer and use it in GitHub Desktop.
Save jridgewell/2685608246f0a43cd1c3f3177eabb5ef to your computer and use it in GitHub Desktop.
String.raw can't represent all strings

For reference, the only things that can't be represented in with String.raw are:

  1. Backslash as last char
    • String.raw`\` is a syntax error, it thinks you're escaping the closing `.
    • String.raw`\\` will output \\, not \.
  2. Interpolation sigils anywhere
    • String.raw`${` is another syntax error, it thinks you're trying to interpolate but you don't have the expression and closing }.
    • String.raw`\${` and String.raw`$\{` both contain a backslash in the output
  3. Backticks anywhere – String.raw``` is another syntax error, that's actually 2 tagged template literals with the second one missing its closing `.
    • String.raw`\`` contains a backslash in the output.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment