handle backquotes in template

This commit is contained in:
Ruben Fiszel
2023-01-30 08:31:21 +01:00
parent 652eb65082
commit c186db4e3b
2 changed files with 7 additions and 3 deletions
@@ -60,7 +60,11 @@
}
if (isCodeInjection(rawValue)) {
arg.expr = getDefaultExpr(argName, previousModuleId, `\`${rawValue}\``)
arg.expr = getDefaultExpr(
argName,
previousModuleId,
`\`${rawValue.toString().replaceAll('`', '\\`')}\``
)
arg.type = 'javascript'
propertyType = 'static'
} else {
@@ -161,7 +165,7 @@
argName,
previousModuleId,
staticTemplate
? `\`${arg?.value ?? ''}\``
? `\`${arg?.value.toString().replaceAll('`', '\\`') ?? ''}\``
: arg.value
? JSON.stringify(arg?.value, null, 4)
: ''
+1 -1
View File
@@ -162,7 +162,7 @@ export function codeToStaticTemplate(code?: string): string | undefined {
if (lines.length == 1) {
const line = lines[0].trim()
if (line[0] == '`' && line.charAt(line.length - 1) == '`') {
return line.slice(1, line.length - 1)
return line.slice(1, line.length - 1).replaceAll('\\`', '`')
}
}
return undefined