sveltejs / svelte-preprocess

A ✨ magical ✨ Svelte preprocessor with sensible defaults and support for: PostCSS, SCSS, Less, Stylus, Coffeescript, TypeScript, Pug and much more.
MIT License
1.75k stars 151 forks source link

pug preprocessor doesn't support spread props #332

Closed icheer closed 3 years ago

icheer commented 3 years ago

Describe the bug pug preprocessor doesn't support spread props

Logs Syntax Error: Unexpected token

To Reproduce

<template lang="pug">
input({...props})
</template>

<script>
let props = {
  type: 'number',
  disabled: true
};
</script>

Expected behavior it should render a < input type="number" disabled / > in HTML

Information about your project:

paradis-A commented 3 years ago

+1 up for this.

paradis-A commented 3 years ago

Your code actually works on mine. I think this issue maybe language tools related. AFAIK isn't fully supported yet, so might want to try to raise issue there too.

ZerdoX-x commented 3 years ago

Bumped in the same thing. Got Syntax Error: Unexpected token

Usage case:

ul.slider: +each('slides as slide')
  li.slide: svelte:component(this="{slide.comp}" {...slide.props})
kaisermann commented 3 years ago

Putting it between quotes " should be enough to make it work. Unfortunately, pug support for svelte syntax is quite weak at the moment.

So this:

<template lang="pug">
  ul.slider: +each('slides as slide')
    li.slide: svelte:component(this="{slide.comp}" "{...slide.props}")
</template>

Will be transformed into:

<ul class="slider">
  {#each slides as slide}<li class="slide">
    <svelte:component this="{slide.comp}" {...slide.props}></svelte:component></li>
  {/each}
</ul>
kaisermann commented 3 years ago

I've added a section in the preprocessing.md file: https://github.com/sveltejs/svelte-preprocess/blob/main/docs/preprocessing.md#:~:text=button.big(type%3D%22button%22%20disabled%20%22%7B...slide.props%7D%22)%20Send

ClaytonFarr commented 3 years ago

@kaisermann It looks like an 'unexpected token' error still occurs when trying to use ...$$props or ...$$restProps, even when they are double-quoted.

image image

This is with: svelte-preprocess 4.7.3, svelte 3.38.2, and SvelteKit 1.0.0-next.112

kaisermann commented 3 years ago

@ClaytonFarr I'm unable to reproduce the error with that markup. The test still passes.

ClaytonFarr commented 3 years ago

Thanks for checking @kaisermann. Odd, it's still creating the 'unexpected error' even when I try to implement same markup as test -

image

Here's a sample repo from a skeleton SvelteKit project that reproduces the problem (at least locally), if that helps at all -

https://github.com/ClaytonFarr/svelte-preprocess-restprops-test

kaisermann commented 3 years ago

Oh, I see! That's happening only on the IDE side, so I'd talk with the folks in the language tools repo. If I'm not mistaken, there's a known issue regarding pug and other markup languages.

The generated markup is:

<button class="big" type="button" disabled {...$$restProps}>Send</button>
ClaytonFarr commented 3 years ago

Thanks @kaisermann

kingcw commented 2 years ago

still having "Unexpected Token" error on "{...$$restProps}" using pug in sveltekit@next, it's not IDE, I ran build script on linux terminal

geoidesic commented 1 year ago

Me too @kaisermann Doesn't compile for me.