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

Support self-closing <style> tag #5080

Closed
rondonjon opened this issue Jun 27, 2020 · 4 comments
Closed

Support self-closing <style> tag #5080

rondonjon opened this issue Jun 27, 2020 · 4 comments

Comments

@rondonjon
Copy link

rondonjon commented Jun 27, 2020

I am using a preprocessor to import styles in SCSS into my Svelte components.

Some of the stylesheets have grown rather big, so eventually I started to swap them out as follows:

<style lang="scss">
  @import "./CheckBox.scss";
</style>

Out of curiosity I tried out something shorter and was surprised that it actually worked:

<style lang="scss" src="./CheckBox.scss"></style>

One minor point that still bothers me is that the compiler raises an error when I try to make the tag self-closing. The following is currently not possible:

<style lang="scss" src="./CheckBox.scss" />

Output from svelte-loader:

ERROR in ./src/CheckBox/CheckBox.svelte
Module build failed (from /......./node_modules/svelte-loader/index.js):
Error: ParseError: Expected > (13:41)
11: </script>
12: 
13: <style lang="scss" src="./CheckBox.scss" />

I think it would be nice to have that supported.

@Conduitry
Copy link
Member

Yeah it probably makes sense for svelte.preprocess() to treat self-closing <style> and <script> tags the same as empty ones when running style or script preprocessor callbacks.

@lukasmoellerch
Copy link
Contributor

@Conduitry If it is planned to implement to implement this feature request - can I try to implement it? I've never contributed to svelte before, but I really like the project and thought that this feature wouldn't be too hard to implement?

@Conduitry
Copy link
Member

Conduitry commented Jun 28, 2020

Sure, feel free to take a look, thank you! To get you started, the implementation would go in https://github.com/sveltejs/svelte/tree/master/src/compiler/preprocess and tests would go in https://github.com/sveltejs/svelte/tree/master/test/preprocess

@Conduitry
Copy link
Member

Self-closing <script/> and <style/> tags are now handled by the preprocessor the same as empty ones as of 3.24.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants