Skip to content

Commit

Permalink
revert: render original reference when a variable is undefined
Browse files Browse the repository at this point in the history
caused issues with how variables inside components were rendered, since as far as expressions are concerned, they are undefined - they ended up output as-is too... needs more testing to get right
  • Loading branch information
cossssmin committed Feb 29, 2024
1 parent a8c64f9 commit 532e40d
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 5 deletions.
1 change: 0 additions & 1 deletion src/generators/posthtml/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ module.exports = async (html, config) => {
const expressionsOptions = merge(
{
loopTags: ['each', 'for'],
missingLocal: '{local}',
strictMode: false
},
get(componentsUserOptions, 'expressions', {}),
Expand Down
4 changes: 2 additions & 2 deletions test/test-tostring.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ test('locals work when defined in all supported places', async t => {
}
})

t.is(result, `1, 2, 3, {{ inline }}`)
t.is(result, `1, 2, 3, undefined`)
})

test.serial('prevents overwriting page object', async t => {
Expand All @@ -111,7 +111,7 @@ test.serial('prevents overwriting page object', async t => {
}
})

t.is(result, `1, 2, 3, {{ inline }}`)
t.is(result, `1, 2, 3, undefined`)
})

test('preserves css in marked style tags (tailwindcss)', async t => {
Expand Down
4 changes: 2 additions & 2 deletions types/expressions.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ export default interface ExpressionsConfig {
/**
What to render when referencing a value that is not defined in `locals`.
By default the original expression reference will be output, i.e. `{{ foo }}`.
By default, the string 'undefined' will be output.
@default '{local}'
@default undefined
@example
Expand Down

1 comment on commit 532e40d

@landoDanziger
Copy link

@landoDanziger landoDanziger commented on 532e40d Mar 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I may be experiencing this.

I have a lot of variables defined in the build env.
example: "something for the build env"

In my components I do things like {{ example || page.example || 'fallback example' }}

Then use in the template - <x-example property="{{ example || page.example || 'fallback example' }}" />

It seems to work everywhere except in one example, but that example changes. If I remove the fallback and just write {{ page.example }} it works.

I will try and prepare an example repo and see if i can replicate it on a clean install, although it might be challenging.

Please sign in to comment.