diff --git a/src/index.js b/src/index.js index cca72af..3a24192 100644 --- a/src/index.js +++ b/src/index.js @@ -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; @@ -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); @@ -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 tag processPushes(nextNode, pushedContent, options); diff --git a/test/templates/components/script-locals.html b/test/templates/components/script-locals.html index fb082da..4d38283 100644 --- a/test/templates/components/script-locals.html +++ b/test/templates/components/script-locals.html @@ -1,8 +1,9 @@ -{{ $slots }} +{{ slotsAccessibleViaScript }}
{{ $slots }}

{{title}}

diff --git a/test/test-locals.js b/test/test-locals.js index abdfa7a..115677e 100644 --- a/test/test-locals.js +++ b/test/test-locals.js @@ -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 = `filled slot content...`; - const expected = `
{"filled":{"filled":true,"rendered":false,"tag":"slot:filled","attrs":{},"content":["filled slot content..."],"source":"filled slot content...","locals":{}}}

Default title

filled slot content...
`; + const expected = `{"filled":{"filled":true,"rendered":false,"tag":"slot:filled","attrs":{},"content":["filled slot content..."],"source":"filled slot content...","locals":{}}}
{"filled":{"filled":true,"rendered":false,"tag":"slot:filled","attrs":{},"content":["filled slot content..."],"source":"filled slot content...","locals":{}}}

Default title

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