g-plane / markup_fmt

Configurable HTML, Vue, Svelte, Astro, Angular, Jinja, Twig, Nunjucks and Vento formatter with dprint integration.
https://dprint.dev/plugins/markup_fmt/
MIT License
91 stars 4 forks source link

[svelte] Error while parsing inline closures #6

Closed Hebilicious closed 8 months ago

Hebilicious commented 8 months ago

Using dpring v0.45, I'm unable to parse components in svelte files that have a closure with an inline definition :

        <InputField
          onFocusIn={() => {
            if (userNameError) userNameError = '';
            return null;
          }}
          onFocusOut={validateUserName}
         />

Here's the error message :

Message: [markup_fmt] failed to format code with external formatter: `let e = () => {
            if (userNameError) userNameError = '';
            return null;`:

dprint.json

{
  "lineWidth": 100,
  "indentWidth": 2,
  "typescript": {
    "useTabs": false,
    "quoteStyle": "alwaysSingle",
    "trailingCommas": "never"
  },
  "json": {
  },
  "markdown": {
  },
  "toml": {
  },
  "dockerfile": {
  },
  "markup": {
    "useTabs": true,
    "svg.selfClosing": true,
    "component.selfClosing": true,
    "html.normal.selfClosing": true,
    "html.void.selfClosing": true,
    "svelteAttrShorthand": true,
    "svelteDirectiveShorthand": true
  },
  "excludes": [
    "**/node_modules",
    "**/*-lock.json",
    "drizzle/migrations/**"
  ],
  "plugins": [
    "https://plugins.dprint.dev/typescript-0.88.9.wasm",
    "https://plugins.dprint.dev/json-0.19.1.wasm",
    "https://plugins.dprint.dev/markdown-0.16.3.wasm",
    "https://plugins.dprint.dev/toml-0.5.4.wasm",
    "https://plugins.dprint.dev/dockerfile-0.3.0.wasm",
    "https://plugins.dprint.dev/g-plane/markup_fmt-v0.3.1.wasm",
    "https://plugins.dprint.dev/g-plane/malva-v0.1.4.wasm"
  ]
}
Hebilicious commented 8 months ago

Additionally, the following code also isn't parsed properly :

<div class={`card ${$$props.class} ${classList[variant]} ${classList[sm]}`}>
  <slot />
</div>
 Message: [markup_fmt] failed to format code with external formatter: `let e = `card ${$$props.class`:
Unexpected eof at expr.ts:1:30

  let e = `card ${$$props.class
g-plane commented 8 months ago

v0.3.2 is released. Feel free to open new issues if any problems are encountered. Also, don't forget to recommend this plugin to others if you like.

Hebilicious commented 8 months ago

Thanks for the quick fix, will try that soon. I'm really surprised that this project is not more popular!