From 72e3889ff45d75db3186332d3163f64f7eebca62 Mon Sep 17 00:00:00 2001 From: patrick Date: Wed, 15 Nov 2023 15:42:34 +0100 Subject: [PATCH] fix when bad templates --- lib/parsers/gjs-gts-parser.js | 10 ++++++---- tests/lib/rules-preprocessor/gjs-gts-parser-test.js | 4 ++++ 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/parsers/gjs-gts-parser.js b/lib/parsers/gjs-gts-parser.js index c4f4e11eeb..fdf0d0747d 100644 --- a/lib/parsers/gjs-gts-parser.js +++ b/lib/parsers/gjs-gts-parser.js @@ -388,7 +388,7 @@ function convertAst(result, preprocessedResult, visitorKeys) { if ( node.type === 'ExpressionStatement' || node.type === 'StaticBlock' || - node.type === 'TemplateLiteral' || + node.type === 'TaggedTemplateExpression' || node.type === 'ExportDefaultDeclaration' ) { let range = node.range; @@ -397,7 +397,9 @@ function convertAst(result, preprocessedResult, visitorKeys) { } const template = templateInfos.find( - (t) => t.templateRange[0] === range[0] && t.templateRange[1] === range[1] + (t) => + t.templateRange[0] === range[0] && + (t.templateRange[1] === range[1] || t.templateRange[1] === range[1] + 1) ); if (!template) { return null; @@ -501,9 +503,9 @@ function transformForLint(code) { jsCode = replaceRange(jsCode, tplInfo.range.start, tplInfo.range.end, replacementCode); } else { const tplLength = tplInfo.range.end - tplInfo.range.start; - const spaces = tplLength - '`'.length - '`'.length - lineBreaks; + const spaces = tplLength - '""`'.length - '`'.length - lineBreaks; const total = ' '.repeat(spaces) + '\n'.repeat(lineBreaks); - const replacementCode = `\`${total}\``; + const replacementCode = `""\`${total}\``; jsCode = replaceRange(jsCode, tplInfo.range.start, tplInfo.range.end, replacementCode); } } diff --git a/tests/lib/rules-preprocessor/gjs-gts-parser-test.js b/tests/lib/rules-preprocessor/gjs-gts-parser-test.js index cbd5b86b8b..fddf56b539 100644 --- a/tests/lib/rules-preprocessor/gjs-gts-parser-test.js +++ b/tests/lib/rules-preprocessor/gjs-gts-parser-test.js @@ -91,6 +91,10 @@ const valid = [ + + `, }, {