diff --git a/src/parser.ts b/src/parser.ts index 8aac376..a5dcac0 100644 --- a/src/parser.ts +++ b/src/parser.ts @@ -223,6 +223,7 @@ const generate = (node: luaparse.Node): string | MemExpr => { const S = node.value .replace(/([^\\])?\\(\d{1,3})/g, (_, pre, dec) => `${pre || ''}${String.fromCharCode(dec)}`) .replace(/\\/g, '\\\\') + .replace(/`/g, '\\`') return `\`${S}\`` } diff --git a/tests/test.js b/tests/test.js index 062c99d..9406ea5 100644 --- a/tests/test.js +++ b/tests/test.js @@ -40,4 +40,17 @@ let exitCode = 0 } } +{ + const luaEnv = luainjs.createEnv() + let str + try { + str = luaEnv.parse('return "Backtick `literals` in strings work"').exec() + } catch (e) { + throw Error('Backticks in strings transpile into invalid code!') + } + if (str !== 'Backtick `literals` in strings work') { + throw Error('Backticks in strings transpile incorrectly!') + } +} + process.exit(exitCode)