Skip to content

Commit 2a426dd

Browse files
authored
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.
1 parent f1f3d4f commit 2a426dd

File tree

2 files changed

+7
-12
lines changed

2 files changed

+7
-12
lines changed

packages/tools/lib/hbs2lit/src/compiler.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const removeWhiteSpaces = (source) => {
1111
const compileString = async (sInput, config) => {
1212
let sPreprocessed = sInput;
1313

14-
sPreprocessed = await includesReplacer.replace(sPreprocessed, config);
14+
sPreprocessed = includesReplacer.replace(sPreprocessed, config);
1515
sPreprocessed = removeWhiteSpaces(sPreprocessed);
1616

1717
const ast = Handlebars.parse(sPreprocessed);

packages/tools/lib/hbs2lit/src/includesReplacer.js

+6-11
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,18 @@
11
const path = require("path");
2-
const {promisify} = require("util");
32
const nativeFs = require("fs");
43

54
function replaceIncludes(hbs, config) {
65
const fs = config.fs || nativeFs;
7-
const readFile = promisify(fs.readFile);
86
const inclRegex = /{{>\s*include\s*["']([a-zA-Z.\/]+)["']}}/g;
7+
let match;
98

10-
async function replacer(match, p1) {
11-
const includeContent = await readFile(path.join(config.templatesPath, p1), "utf-8");
12-
hbs = hbs.replace(match, includeContent);
9+
while((match = inclRegex.exec(hbs)) !== null) {
10+
inclRegex.lastIndex = 0;
11+
const includeContent = fs.readFileSync(path.join(config.templatesPath, match[1]), "utf-8");
12+
hbs = hbs.replace(match[0], includeContent);
1313
}
1414

15-
let match;
16-
const replacers = [];
17-
while ((match = inclRegex.exec (hbs)) !== null) {
18-
replacers.push(replacer(match[0], match[1]));
19-
}
20-
return Promise.all(replacers).then(() => hbs);
15+
return hbs;
2116
}
2217

2318
module.exports = {

0 commit comments

Comments
 (0)