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

🐛 BUG: Error: unhandled node type: 'expression' #193

Closed
jasikpark opened this issue May 9, 2022 · 11 comments
Closed

🐛 BUG: Error: unhandled node type: 'expression' #193

jasikpark opened this issue May 9, 2022 · 11 comments

Comments

@jasikpark
Copy link
Collaborator

Describe the Bug

A reduced example of code that triggers the bug is:

{true && <div {...{ style: 'color:red;'}}>hello</div>}

which result in this error message:

["ERROR" - 4:44:37 PM] Unhandled node type "expression"!
Error: Unhandled node type "expression"!

Steps to Reproduce

Format the above code snippet w/ prettier plugin version 0.1.0-next.4

@mvolfik
Copy link

mvolfik commented May 10, 2022

Another case of this (not entirely sure if it's the exact same bug though):

{["/", "/a"].map((href) => <a {href}>hi</a>)}

This is valid Astro, but doesn't format. Replacing {href} with href={href} works

@mvolfik
Copy link

mvolfik commented May 10, 2022

This doesn't seem too similar to the other cases, so reporting it as well:

{a.split("\n").map(x => <p>{x}</p>)}

Works when you remove the \n from the split pattern

@ota-meshi
Copy link
Contributor

ota-meshi commented May 15, 2022

Hi @mvolfik.
I think the escape issue will probably be resolved in the following pull request.
withastro/compiler#393

@ota-meshi
Copy link
Contributor

@natemoo-re I have debugged this. There seems to be a problem with the serialize method of @astrojs/compiler/utils. Serializing the spread attribute returns an unfinished script "{...}".

https://github.com/withastro/compiler/blob/d5dd438d3f0aa5f005e9b4d7127230711ab126a1/packages/compiler/node/utils.ts#L96
I think we probably need to use attr.name instead of attr.value.

@jasikpark
Copy link
Collaborator Author

Another case where I get this error is

---
---

<p>below is a js-style comment</p>
{/** this is a comment that throws the "unhandled node type: 'expression'" error */}

maybe there's a new version I should try?

@ota-meshi
Copy link
Contributor

It is not fixed in PR. The cause seems to be different. I think we need to open a new issue.

@Princesseuh
Copy link
Member

I can confirm the original issue is fixed in the latest next version, however it still happens in that example. I think it's fine to keep it in the same issue for now, if it shows up in more cases we'll make a new issue 👍

@simonwiles
Copy link

simonwiles commented Jun 24, 2022

Original issue appears to remain. I can trigger it with something as simple as:

{(record.length) ? <Record {record} /> : null}

or

{(record.length) && <Record {record} /> }

(using 0.1.1 which includes #223).

@ota-meshi
Copy link
Contributor

The cause is a shorthand attribute. I have already reported it. #224

@simonwiles
Copy link

Thanks -- apologies for the noise.

@Princesseuh
Copy link
Member

Princesseuh commented Jul 21, 2022

Closing in favor of issues about the specific problems causing this error. This error happens whenever the babel parser is not able to parse an expression, as such it'll happens for multiple reasons that requires different fixes in most cases

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

No branches or pull requests

5 participants