Skip to content

Commit

Permalink
Merge pull request #1319 from Jordinateur/fix-expression-config
Browse files Browse the repository at this point in the history
  • Loading branch information
cossssmin authored Aug 1, 2024
2 parents 566dc54 + b4714d2 commit 810c87e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
7 changes: 4 additions & 3 deletions src/posthtml/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,10 @@ export async function process(html = '', config = {}) {
components(
merge(
{
expressions: {
locals,
}
expressions: merge(
{ locals },
expressionsOptions,
)
},
componentsUserOptions,
defaultComponentsConfig
Expand Down
25 changes: 21 additions & 4 deletions test/render.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,22 +113,39 @@ describe.concurrent('Render', () => {
})

test('fetch component', async () => {
const source = `
const { html } = await render(`
<x-list>
<fetch url="test/stubs/data.json">
{{ undefinedVariable }}
<each loop="user in response">{{ user.name + (loop.last ? '' : ', ') }}</each>
@{{ ignored }}
</fetch>
</x-list>
`

const { html } = await render(source, {
`, {
components: {
folders: ['test/stubs/components'],
}
})

expect(cleanString(html)).toBe('<h1>Results</h1> {{ undefinedVariable }} Leanne Graham, Ervin Howell {{ ignored }}')
})

test('uses expressions options', async () => {
const { html } = await render(`
<script locals>
module.exports = { name: 'John' }
</script>
<h1>Hello {{ name }}</h1>
`,
{
build: {
expressions: {
removeScriptLocals: true,
}
}
}
)

expect(cleanString(html)).toBe('<h1>Hello John</h1>')
})
})

0 comments on commit 810c87e

Please sign in to comment.