Skip to content

Commit 0a33f85

Browse files
refactor: changed locals parsing logic to allow inner locals feature
1 parent 974efb8 commit 0a33f85

1 file changed

Lines changed: 6 additions & 12 deletions

File tree

lib/index.js

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,23 +20,17 @@ module.exports = (options = {}) => {
2020
let content;
2121
let subtree;
2222
let source;
23-
let locals;
24-
25-
const localsString = node.attrs.locals || (node.content ? node.content.join().replace(/\n/g, '') : '');
26-
const tryToParseLocals = localsString.trim() && localsString.trim().startsWith('{');
27-
28-
if (tryToParseLocals) {
29-
try {
30-
locals = JSON.parse(localsString);
31-
} catch {
32-
locals = false;
33-
}
34-
}
23+
let locals = false;
3524

3625
if (src) {
3726
src = path.resolve(options.root, src);
3827
source = fs.readFileSync(src, options.encoding);
3928

29+
try {
30+
const localsRaw = node.attrs.locals || (node.content ? node.content.join().replace(/\n/g, '') : false);
31+
locals = JSON.parse(localsRaw);
32+
} catch {}
33+
4034
if (locals) {
4135
const result = posthtml()
4236
.use(expressions({locals}))

0 commit comments

Comments
 (0)