News for hackers. Stuff that matters.
Re:ECMAScript 2018 Language Specification by xamuel on Tuesday November 07, 2017 @11:43AM (#15644901)
Template Literal Revision [1] is a welcome change, but still falls way short, as there's still no way to easily include the backtick itself inside raw text.

I wish ES would adopt python-style triple-quotes, so you could do things like:

String.raw```Look, this is a backtick: "`"```

(The inability to do this is a pain point when you want to embed a language in ES and that language itself makes use of backticks.)

[1] http://2ality.com/2016/09/template-literal-revision.html

Re:ECMAScript 2018 Language Specification by tehno on Tuesday November 07, 2017 @01:25PM (#15646021)
Encoding backtick as unicode escape is one easy enough and "clean" way:

`foo \u0060bar\u0060`

Re:ECMAScript 2018 Language Specification by mistercow on Tuesday November 07, 2017 @11:51AM (#15644971)
Can't you just do `Look, this is a backtick: ${'`'}`? Or are you not counting that as "easy" because it's horrible.
Re:ECMAScript 2018 Language Specification by xamuel on Tuesday November 07, 2017 @12:02PM (#15645105)
Suppose I wanted to embed your solution itself into a template literal. It would look like this:

`${'`'}Look, this is a backtick: \${'${'`'}'}${'`'}`

Re:ECMAScript 2018 Language Specification by Arnavion on Tuesday November 07, 2017 @12:58PM (#15645754)
Rust has a nice solution to this.

    r"foo" == "foo" // r" means the literal ends at "
    r#""foo""# == "\"foo\"" // r#" means the literal ends at "#
    r##"r#""foo""#"## == "r#\"\"foo\"\"#" // r##" means the literal ends at "##
and so on.

Basically you add as many # outside as necessary to distinguish the end of the literal (double-quote followed by some #) from any such sequence in the middle of the literal.

Re:ECMAScript 2018 Language Specification by analogic on Tuesday November 07, 2017 @09:27PM (#15649523)
just blue my mind. is there a babel plugin that will let me do this?
Re:ECMAScript 2018 Language Specification by sterlingfs on Tuesday November 07, 2017 @01:20PM (#15645961)
Web components are the answer for creating composable templates.
Re:ECMAScript 2018 Language Specification by johnhenry on Tuesday November 07, 2017 @12:10PM (#15645193)
Won't this cause issues if i ever want to embed "```"?
Re:ECMAScript 2018 Language Specification by mistercow on Tuesday November 07, 2017 @12:43PM (#15645602)
Pretty much. This is why some languages offer the ability to define an arbitrary quote end token.
Re:ECMAScript 2018 Language Specification by GroSacASacs on Thursday November 09, 2017 @03:26AM (#15660767)
you can escape backticks with \