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

(feat) detect invalid Svelte import paths #1448

Merged
merged 2 commits into from
Apr 14, 2022

Conversation

dummdidumm
Copy link
Member

@dummdidumm dummdidumm commented Apr 13, 2022

Detect that an import of a .svelte file is pointing to a non-existent file by removing the ambient module definitions in svelte and svelte2tsx from the eyes of TS.

If you want the old behavior back, add a ambient.d.ts file (or similar; you can add it to app.d.ts in a SvelteKit project for example) with the following:

declare module "*.svelte";

#1444

@jasonlyu123 please tell me if this too hacky or actually a good idea 😅

Simon added 2 commits April 13, 2022 15:30
Detect that an import of a .svelte file is pointing to a non-existent file by removing the ambient module definitions in svelte and svelte2tsx from the eyes of TS
sveltejs#1444
@jasonlyu123
Copy link
Member

jasonlyu123 commented Apr 14, 2022

I am ok with this.

Alternatively, we can also add the error by ourselves. We could use the type-checker to get the symbol of the ImportDeclartion.moduleSpecifier. And see if the symbol name is "*.svelte" or if the declaration is from the two files. But to turn this into a diagnostic message. We need to either use typescript internal APIs or copy the error message and other info. So it's also kind of hacky. And we still need to filter out the *.svelte hover or completion.

@dummdidumm
Copy link
Member Author

Yeah, I feel that this would be just as hacky and more code - ok, I'll merge this then, thanks for your insights!

@dummdidumm dummdidumm merged commit 1415196 into sveltejs:master Apr 14, 2022
@dummdidumm dummdidumm deleted the svelteinvalidimport branch April 14, 2022 07:20
@DetachHead
Copy link
Contributor

@dummdidumm thanks for fixing this! one question though, is this change supposed to only effect the behavior in vscode's intellisense? as the ambient.d.ts module is still present in the svelte package so when i run svelte-check it still has the old behavior

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

Successfully merging this pull request may close these issues.

3 participants