没有换行符的多行模板字符串?

Ale*_*lls 3 javascript node.js template-strings template-literals

我有这行代码:

 console.log(`now running each hook with name '${chalk.yellow(aBeforeOrAfterEach.desc)}', for test case with name '${chalk.magenta(test.desc)}'.`);
Run Code Online (Sandbox Code Playgroud)

问题是我必须将它放在我的 IDE 中的多行上,以使其适合(我使用 100 列)。当我将模板字符串放在多行上时,模板字符串将其解释为换行符,这不是我想要的。

所以我的问题是 - 如何在不使用换行符记录的情况下有多行模板字符串代码?

Kri*_*itk 6

\在每一行的末尾使用反斜杠 --以避免插入\n

 console.log(`\
 now running each hook with name \
'${'foo'}', for test case with name '${'bar'}' \
.`);
Run Code Online (Sandbox Code Playgroud)

另一种选择应该是使用.split("\n").join('')它将用空字符串替换所有换行符