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

Scriptlet and static statements print as blocks more than it needs to #1

Open
AngusMorton opened this issue Apr 5, 2024 · 0 comments

Comments

@AngusMorton
Copy link
Owner

AngusMorton commented Apr 5, 2024

The following scriptlet breaks when it's printed

$ const isWebpSupported = $global.request.headers.get("accept")?.includes("image/webp");

Breaks into:

$ const isWebpSupported = $global.request.headers
  .get("accept")
  ?.includes("image/webp");

Which isn't valid Marko - it needs to be a block scriptlet OR have the assignment wrapped in braces, otherwise the html-js parser will fail to parse it.

Ideally, we would wrap the rhs of the assignment in braces, but we don't have the full babel AST here, so we can't do that. Instead, we wrap the entire scriptlet in a block.

$ {
  const isWebpSupported = $global.request.headers
    .get("accept")
    ?.includes("image/webp");
}

In a perfect world we could format it in the same way that prettier-plugin-marko formats it:

$ const isWebpSupported = ($global.request.headers
  .get("accept")
  ?.includes("image/webp"))
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

1 participant