From 2a426dd3b5b3ed87137cf67700154071e6192db2 Mon Sep 17 00:00:00 2001 From: Martin Date: Tue, 12 May 2020 10:29:03 +0300 Subject: [PATCH] fix(hbs2ui5): enables 3 or more levels of inheritance with templates (#1593) - lookup for include statements in the hbs files used to be just one level above the class. --- packages/tools/lib/hbs2lit/src/compiler.js | 2 +- .../tools/lib/hbs2lit/src/includesReplacer.js | 17 ++++++----------- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/packages/tools/lib/hbs2lit/src/compiler.js b/packages/tools/lib/hbs2lit/src/compiler.js index 36456ba6c248..20ce67f237e7 100644 --- a/packages/tools/lib/hbs2lit/src/compiler.js +++ b/packages/tools/lib/hbs2lit/src/compiler.js @@ -11,7 +11,7 @@ const removeWhiteSpaces = (source) => { const compileString = async (sInput, config) => { let sPreprocessed = sInput; - sPreprocessed = await includesReplacer.replace(sPreprocessed, config); + sPreprocessed = includesReplacer.replace(sPreprocessed, config); sPreprocessed = removeWhiteSpaces(sPreprocessed); const ast = Handlebars.parse(sPreprocessed); diff --git a/packages/tools/lib/hbs2lit/src/includesReplacer.js b/packages/tools/lib/hbs2lit/src/includesReplacer.js index e96306f4b621..93cdc2df4d5b 100644 --- a/packages/tools/lib/hbs2lit/src/includesReplacer.js +++ b/packages/tools/lib/hbs2lit/src/includesReplacer.js @@ -1,23 +1,18 @@ const path = require("path"); -const {promisify} = require("util"); const nativeFs = require("fs"); function replaceIncludes(hbs, config) { const fs = config.fs || nativeFs; - const readFile = promisify(fs.readFile); const inclRegex = /{{>\s*include\s*["']([a-zA-Z.\/]+)["']}}/g; + let match; - async function replacer(match, p1) { - const includeContent = await readFile(path.join(config.templatesPath, p1), "utf-8"); - hbs = hbs.replace(match, includeContent); + while((match = inclRegex.exec(hbs)) !== null) { + inclRegex.lastIndex = 0; + const includeContent = fs.readFileSync(path.join(config.templatesPath, match[1]), "utf-8"); + hbs = hbs.replace(match[0], includeContent); } - let match; - const replacers = []; - while ((match = inclRegex.exec (hbs)) !== null) { - replacers.push(replacer(match[0], match[1])); - } - return Promise.all(replacers).then(() => hbs); + return hbs; } module.exports = {