Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Syntax error in .astro file when trying to render multiple nodes in map #405

Closed
TzviPM opened this issue Jun 12, 2021 · 3 comments · Fixed by #433
Closed

Syntax error in .astro file when trying to render multiple nodes in map #405

TzviPM opened this issue Jun 12, 2021 · 3 comments · Fixed by #433
Assignees

Comments

@TzviPM
Copy link

TzviPM commented Jun 12, 2021

Syntax example:

<ul>
{items.map(item => (
<li>{item.first}</li>
<li>{item.second}</li>
))}
</ul>

This is a contrived example, but my actual use case is for multiple nodes of an SVG. I also tried using a fragment node to wrap the contents of the map, but received an error that the fragment is not defined.

@FredKSchott FredKSchott added this to Needs Triage in 🐛 Bug Tracker Jun 13, 2021
@ejb
Copy link

ejb commented Jun 14, 2021

Not sure if this is the same bug, but I don't seem to be able to use JSX within the head matter.

This works within an .astro file:

<ul>
  {['foo','bar'].map(x => <li>{x}</li>)}
</ul>

This does not:

---
let items = ['foo','bar'].map(x => <li>{x}</li>);
---
<ul>
  {items}
</ul>

Neither does this:

---
let item = <li>{x}</li>;
---
<ul>
  {item}
</ul>

Here are the full details of the 500 error:

Error: Parse error @:16:27
    at parse$n (/Users/Elliot/Sites/ejb.github.io/node_modules/snowpack/lib/index.js:113435:379)
    at scanCodeImportsExports (/Users/Elliot/Sites/ejb.github.io/node_modules/snowpack/lib/index.js:114662:29)
    at transformEsmImports (/Users/Elliot/Sites/ejb.github.io/node_modules/snowpack/lib/index.js:114678:27)
    at Object.transformFileImports (/Users/Elliot/Sites/ejb.github.io/node_modules/snowpack/lib/index.js:114749:16)
    at FileBuilder.resolveImports (/Users/Elliot/Sites/ejb.github.io/node_modules/snowpack/lib/index.js:163324:45)
    at Object.loadUrl (/Users/Elliot/Sites/ejb.github.io/node_modules/snowpack/lib/index.js:182840:39)
    at load (/Users/Elliot/Sites/ejb.github.io/node_modules/snowpack/lib/index.js:182430:28)
    at /Users/Elliot/Sites/ejb.github.io/node_modules/snowpack/lib/index.js:175004:32
    at async Promise.all (index 3)
    at initializeModule (/Users/Elliot/Sites/ejb.github.io/node_modules/snowpack/lib/index.js:175003:17)
    at load (file:///Users/Elliot/Sites/ejb.github.io/node_modules/astro/src/runtime.ts:95:17)
    at Server.<anonymous> (file:///Users/Elliot/Sites/ejb.github.io/node_modules/astro/src/dev.ts:33:20)

@FredKSchott FredKSchott moved this from Needs Triage to Bug in 🐛 Bug Tracker Jun 14, 2021
@FredKSchott FredKSchott moved this from Bug to Priority TODO in 🐛 Bug Tracker Jun 14, 2021
@natemoo-re natemoo-re added the bug label Jun 14, 2021
@natemoo-re
Copy link
Member

Discussing this with the team! We'll likely need a built-in Fragment component.

@TzviPM
Copy link
Author

TzviPM commented Jun 26, 2021

Just saw this; works like a charm :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Development

Successfully merging a pull request may close this issue.

3 participants