svelte-preprocess icon indicating copy to clipboard operation
svelte-preprocess copied to clipboard

Components used in Pug cause warning `declared but its value is never read`

Open probablykasper opened this issue 5 years ago • 10 comments

Describe the bug As you can see in the screenshot below, the Svelte VSCode extension does not see that Router and Nested are used inside <Template>. It does however detect that routes was used. screenshot

This issue is also mentioned when running svelte-check, so it's not caused by the text editor. My guess is that this is an issue with svelte-preprocess, but may very well be something else.

To Reproduce Use a component inside a <template lang='pug'> block.

Information about your project:

  • Your operating system: macOS 10.14.6
  • svelte-preprocess version 4.4.2
  • Bundler: Svite/Vite

probablykasper avatar Oct 06 '20 05:10 probablykasper

Hey @probablykasper 👋

This seems to be a duplicate of #207

kaisermann avatar Oct 06 '20 12:10 kaisermann

@kaisermann I don't think it is, because in that issue the problem is variables created by Pug. In this case, the variable is created in TypeScript

probablykasper avatar Oct 06 '20 12:10 probablykasper

@kaisermann Got any thoughts on this issue?

probablykasper avatar Oct 20 '20 23:10 probablykasper

@kaisermann Would love to know what could be done about this.

Svelte's Pug support seems quite spotty considering the invalid warnings and errors it generates. Perhaps there should be a note about this if it's not something that's likely to improve anytime soon.

probablykasper avatar Jan 11 '21 02:01 probablykasper

Hey @probablykasper 👋 Unfortunately there's not much I can do from this side (see https://github.com/sveltejs/svelte-preprocess/issues/207#issuecomment-677452657). A comment about the semi-support for pug could be nice, yeah!

kaisermann avatar Feb 04 '21 00:02 kaisermann

@kaisermann I don't quite understand. Is the issue that Pug can't be compiled synchronously?

probablykasper avatar Feb 04 '21 01:02 probablykasper

The problem is that pug does not provide source maps by itself, and that the source mapper we use is asynchronous. We also cannot know which other preprocessors people might mix in, and those could be asynchronous.

dummdidumm avatar Feb 04 '21 08:02 dummdidumm

@dummdidumm But why would a source map be needed to tell if a component is used or not? I would think that source maps are useful when you have an error and you want to show it in the right place, but not when you have an error that shouldn't exist.

probablykasper avatar Feb 04 '21 17:02 probablykasper

You can turn off diagnostics and not get false errors that way. We could also investigate turning off diagnostics if we detect pug in the template.

dummdidumm avatar Feb 04 '21 19:02 dummdidumm

@dummdidumm What are the source maps needed for in this case?

probablykasper avatar Feb 04 '21 20:02 probablykasper