From 4cdc6d63531e7c08c160929e922acaef1d6f1d56 Mon Sep 17 00:00:00 2001 From: Alan Mimms Date: Thu, 24 Aug 2017 12:11:49 -0700 Subject: [PATCH] Do not indent backtick quoted strings in code blocks (#492) * Do not indent backtick quoted strings in initializer or rule action code blocks * Use const instead of var for ESLint happiness * Fix ESLint issues for double quotes and indent6 --- lib/compiler/passes/generate-js.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/compiler/passes/generate-js.js b/lib/compiler/passes/generate-js.js index 4c80939..4b9124d 100644 --- a/lib/compiler/passes/generate-js.js +++ b/lib/compiler/passes/generate-js.js @@ -6,9 +6,10 @@ let op = require("../opcodes"); // Generates parser JavaScript code. function generateJS(ast, options) { - // These only indent non-empty lines to avoid trailing whitespace. - function indent2(code) { return code.replace(/^(.+)$/gm, " $1"); } - function indent10(code) { return code.replace(/^(.+)$/gm, " $1"); } + /* These only indent non-empty lines to avoid trailing whitespace. */ + const lineMatchRE = /^([^`\r\n]+?(?:`[^`]*?`[^\r\n]*?)?)$/gm; + function indent2(code) { return code.replace(lineMatchRE, " $1"); } + function indent10(code) { return code.replace(lineMatchRE, " $1"); } function generateTables() { if (options.optimize === "size") {