Skip to content

Commit

Permalink
Merge 91a26c5 into 21b664b
Browse files Browse the repository at this point in the history
  • Loading branch information
Idered committed Mar 28, 2022
2 parents 21b664b + 91a26c5 commit 0fb2619
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
8 changes: 6 additions & 2 deletions index.js
Expand Up @@ -70,7 +70,7 @@ function parse(options) {

tree.match(match(`${options.tag}[${options.attribute}]`), node => {
promises.push(
readFile(options, node.attrs[options.attribute])
() => readFile(options, node.attrs[options.attribute])
.then(processNodeContentWithPosthtml(node, options))
.then(tree => { // Recursively call parse with node's content tree
return parse(Object.assign({}, options, {
Expand Down Expand Up @@ -107,7 +107,11 @@ function parse(options) {
return node;
});

return promises.length > 0 ? Promise.all(promises).then(() => tree) : tree;
return promises
.reverse()
.concat(() => tree)
// eslint-disable-next-line unicorn/no-array-reduce
.reduce((previous, task) => previous.then(task), Promise.resolve());
};
}

Expand Down
2 changes: 1 addition & 1 deletion test/test.js
Expand Up @@ -37,7 +37,7 @@ test('Must process nested modules', async t => {
t.is(html, expected);
});

test.skip('Must process nested modules with locals', async t => {
test('Must process nested modules with locals', async t => {
const actual = `<module href="./tree.spec/layout.html" locals='{"foo": "bar"}'>Test<module href="./tree.spec/_/button.html">Button</module></module>`;
const expected = '<div class="container">Test<button class="button">Button</button></div>';
const html = await posthtml().use(plugin({root: './test/tree.spec', from: __filename})).process(actual).then(result => clean(result.html));
Expand Down

0 comments on commit 0fb2619

Please sign in to comment.