There are a lot of similar questions, but I haven't understood how to apply them to my situation, so I'll try to be really specific. I have a very long tagged template literal, for example;
tag`This is a very long string that will be shown to ${userName}, that is annoying to have all on one line in the codebase.`
Of course, I don't want a line that long in my codebase, so I'd like to break it up. There are many options for breaking up a long (un-tagged) template literal, like using +
. I tried to use this, but it messes with the operation precedence. If I use
tag`my` + `string`
Then the tag only applies to my
. If I try (with or without a plus)
tag(`mystring`)
the functionality of the tag stopped working. As a sanity check, I opened my browser console and defined;
function myTag(strings) { return `${strings[0]}` }
If I used this as a tag with the normal syntax, it output the input string. If I used the parens, it output the first character of the input string. So I have no idea what's happening there.
I can use
tag`my\
string`
But that doesn't allow the second line to be indented, which is just as bad as a long line.
Given this, I don't know how to apply the methods for breaking up a long un-tagged template literal to a tagged template literal.
In case it ends up being relevant, the function I'm using is the t
tag from the library ttag.