firefish5000 / svelte-trim

Strips whitespace from svelte files.
8 stars 2 forks source link

"Error: Unsupported mustache syntax detected!" with toLocaleString #1

Open rururux opened 3 years ago

rururux commented 3 years ago

svelteTrim throw an error when i used toLocaleString.

code:

<span>{new Date("2020-12-04T10:00:00").toLocaleString("en-US", { month: "short", day: "numeric" })}</span>

error log:

[!] (plugin svelte) Error: Unsupported mustache syntax detected!
Node type: "ObjectExpression"
Text: "{ month: \"short\", day: \"numeric\" }"
Anscestors: [null,"Fragment","Element","MustacheTag","CallExpression"]
Prop: arguments
firefish5000 commented 3 years ago

I see. Seems like we are currently looking for content we support trimming of even inside the mustache tags themselves. I'll stop it from descending tags inner content and add some basic tests latter tonight.

eugeneilyin commented 3 years ago

@firefish5000, I have the same problem. The minimal code to reproduce is:

<script>
  let visible = true;
</script>
{#if visible}
  <p>Some text</p>
{/if}

Gives some AST parsing/building error when used with svelte-trim preprocessor:

Error: Unsupported mustache syntax detected!
Node type: "Fragment"
Text: "{#if visible}\r\n 

With any combination of options:

const { asMarkupPreprocessor } = require('svelte-as-markup-preprocessor')
const sveltePreprocess = require('svelte-preprocess')
const { mdsvex } = require('mdsvex')
const { svelteTrim } = require('svelte-trim')
...
  preprocess: [
    asMarkupPreprocessor([
      sveltePreprocess(),
      mdsvex(),
    ]),
    svelteTrim({
      // removalMethod: 'trim',
      removalMethod: 'comment',
      inline: false,
      // multiline: true,
      multiline: false,
      // componentSiblings: true,
      componentSiblings: false,
      // elementSiblings: true,
      elementSiblings: false,
      // mustacheBlockSiblings: true,
      mustacheBlockSiblings: false,
      // mustacheDirectiveSiblings: true,
      mustacheDirectiveSiblings: false,
      // mustacheTextSiblings: false,
      mustacheTextSiblings: true,
    }),
  ],
vgpechenkin commented 2 years ago

Hi, I have the same problem. Somebody has the solution to fix it? @firefish5000 do you continue to support this preprocessor?