Hi there, I'm trying to do something which seems like it should be very straightforward. I'm attempting to pass some data to a javascript function in a riot template as below. In the Riot documentation it is stated that:
All template expressions are “just JavaScript™️”:
<pre>{ JSON.stringify(props) }</pre>
So I am expecting that the below should function correctly as it is valid javascript.
<date-test>
<p>Test date string: { state.test }</p>
<p>Test transformed literal date string: { (new Date('2006-09-16T00:00:00Z')).toLocaleDateString() }</p>
<p>Test transformed date string: { (new Date(state.test)).toLocaleDateString() }</p>
<script>
export default {
state: {
test: '2006-09-16T00:00:00Z'
}
}
</script>
</date-test>
The first two <p> tags are rendered correctly but with the last one I'm encountering the following error reported in Chrome dev console
Uncaught (in promise) ReferenceError: state is not defined
Please note that I am not experienced in javascript - I write python, c/c++ for my day job - so it's possible that I'm doing something which is clearly wrong... Any guidance as to the correct way to do this would be much appreciated.
Can you reproduce the issue?
Post the link using one of our bug report templates:
On which browser/OS does the issue appear?
Ubuntu 20.04
Chromium Version 83.0.4103.61 (Official Build) snap (64-bit)
Which version of Riot does it affect?
Riot.js 4.0.5
How would you tag this issue?
It's a compiler bug, I will check it asap
Fixed in Riot.[email protected]
Excellent. All working as expected. Thanks!
Most helpful comment
It's a compiler bug, I will check it asap