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.73k stars 147 forks source link

fix: allow pug template inheritance #572

Open benblazak opened 1 year ago

benblazak commented 1 year ago

Fixes #459.

Allows for pug template inheritance.

The issue was that extends statements must occur first in a pug file, but the svelte mixins were being inserted at the top of the file contents before being passed to pug.

I made changes so that if an extends statement occurs as the first line in a file, it is split off from the rest of the content and inserted before the svelte mixins.

notes

I wasn't able to research or test whether there are other things that should also be kept before svelte mixins.

kaisermann commented 1 year ago

Hey @benblazak, thanks for this! Just added a small suggestion 🙏

benblazak commented 1 year ago

Ahh good catch @kaisermann. To properly allow comments though, we'd probably need to parse them (there can be more than one before extends right? and multi-line comments are allowed in that location too?), which is more than I'm up for right now (in the middle of a move -> new job).

Thinking about it, it might make more sense to stop including mixins by default at all, and put them in a separate file for people to include if they want. But that would be a breaking change.

simiraaaa commented 1 year ago

@kaisermann @benblazak https://github.com/sveltejs/svelte-preprocess/pull/599

Fixed so that extends works with comments and prependData. Please refer to it.

(Machine translation from Japanese to English at DeepL)