Skip to content

Commit

Permalink
Apply expressions to initial tree and set nextNode after expression p…
Browse files Browse the repository at this point in the history
…rocess
  • Loading branch information
thewebartisan7 committed Oct 18, 2022
1 parent 45f00f5 commit 112ccde
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
8 changes: 6 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ module.exports = (options = {}) => tree => {

log(options, 'options', 'init');

// Apply expressions to initial tree
tree = expressions(options.expressions)(tree);

tree = processTree(options)(tree);

return tree;
Expand Down Expand Up @@ -115,7 +118,7 @@ function processTree(options) {

log(`${++processCounter} ${componentPath}`, 'Processing component', 'processTree');

const nextNode = parser(readFileSync(componentPath, 'utf8'));
let nextNode = parser(readFileSync(componentPath, 'utf8'));

// Set filled slots
setFilledSlots(currentNode, slotContent, options);
Expand All @@ -133,7 +136,8 @@ function processTree(options) {

log({attributes, locals, slotContent}, 'Processed attributes, locals and slots', 'processTree');

expressions(options.expressions)(nextNode);
nextNode = expressions(options.expressions)(nextNode);
// process.exit(0);

// Process <stack> tag
processPushes(nextNode, pushedContent, options);
Expand Down
5 changes: 3 additions & 2 deletions test/templates/components/script-locals.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<script props>
module.exports = {
title: 'Default title'
title: 'Default title',
slotsAccessibleViaScript: locals.$slots
}
</script>
{{ $slots }}
{{ slotsAccessibleViaScript }}
<div>{{ $slots }}</div>
<div><h1>{{title}}</h1></div><div><fill:filled></fill:filled><fill:notfilled></fill:notfilled></div>
2 changes: 1 addition & 1 deletion test/test-locals.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ test('Must process parent and child locals via component', async t => {

test('Must has access to $slots in script locals', async t => {
const actual = `<x-script-locals><slot:filled>filled slot content...</slot:filled></x-script-locals>`;
const expected = `<div>{"filled":{"filled":true,"rendered":false,"tag":"slot:filled","attrs":{},"content":["filled slot content..."],"source":"filled slot content...","locals":{}}}</div><div><h1>Default title</h1></div><div>filled slot content...</div>`;
const expected = `{"filled":{"filled":true,"rendered":false,"tag":"slot:filled","attrs":{},"content":["filled slot content..."],"source":"filled slot content...","locals":{}}}<div>{"filled":{"filled":true,"rendered":false,"tag":"slot:filled","attrs":{},"content":["filled slot content..."],"source":"filled slot content...","locals":{}}}</div><div><h1>Default title</h1></div><div>filled slot content...</div>`;

const html = await posthtml([plugin({root: './test/templates/components'})]).process(actual).then(result => clean(result.html));

Expand Down

0 comments on commit 112ccde

Please sign in to comment.