-
Notifications
You must be signed in to change notification settings - Fork 504
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
Comments cause crash #250
Comments
I had the same issue with a comment at the beginning of the file: // hey
import { Show } from '@builder.io/mitosis';
export interface ButtonProps {
attributes?: any;
text?: string;
link?: string;
openLinkInNewTab?: boolean;
}
export default function Button(props: ButtonProps) {
return (
<>
<Show
when={props.link}
else={<span {...props.attributes}>{props.text}</span>}
>
<a
{...props.attributes}
role="button"
href={props.link}
target={props.openLinkInNewTab ? '_blank' : undefined}
>
{props.text}
</a>
</Show>
</>
);
} will generate the following error with the compiler:
Removing the comment fixes the issue |
useState
block cause crash
Similarly, comments within JSX cause issues: see They end up making it to the final version of the code. The parser thinks that As a first step, we might want to trim all |
I'm working on this 👍🏾 |
I think one of the main reasons we have these issues is that the JSX parser works by updating the AST and replacing it with the appropriate JSON: mitosis/packages/core/src/parsers/jsx/jsx.ts Line 148 in 8980fd5
Instead, we could try storing the output of mitosis/packages/core/src/parsers/jsx/jsx.ts Line 187 in 8980fd5
Let me know how that plays out. I think it should fix the issues around top-level comments at least, but not sure about the comments in JSX 😅 |
A simple solution would be to just remove the comments. Is that an option? Otherwise, I think encoding the comments in json5 could be an option. |
Keeping the comments and adding them in the JSON would actually be helpful in some cases. EDIT: in fact, a more fine grained "positioning" of the comments inside the JSON would be great (i.e. keep the relation between a Node and the comments above or after it). That could help reposition them in compiled code at the "same" place, thus documenting the code. |
There are a bunch of different places where comments cause the compiler to crash, because we try to JSON5 parse the given block (and comments aren't JSON5 parse-able).
Describe the bug
comments right above function declarations in
useState
cause endless loop/crash in MitosisTo Reproduce
If possible, a link to a https://mitosis.builder.io/ fiddle containing the bug: Fiddle causes infinite loop, so I put a code block here instead.
Expected behavior
Expect comments to be ignored/stripped before any Mitosis logic runs, and not cause any issues
Additional context
The comment above a constant property works fine, but one above a function declaration isn't
The text was updated successfully, but these errors were encountered: