Defining dynamic comments on the fly

ES source code is first parsed, then executed. You cannot alter the parser's behaviour with a run-time function.

What you want has nothing to do with comments, actually. You're asking for backticks to be treated literally in a chunk of code, instead of terminating the template as they do now. I understand that. But that's not exclusive to comments, it's a problem outside comments, too:

html`<div>can I have a backtick ` here? no.</div>`

A proven technique for embedding arbitrary text in a different language is with custom start/end tags.

  • Shell: <<"TAG" \n anytext \n TAG
  • PostgreSQL: $TAG$ anytext $TAG$
  • C++: R"TAG( anytext )TAG"
  • Lua: [====[ anytext ]====]
  • Markdown: 3+ backticks on both ends
1 Like