fix: allow JS snapshots within TS plugin
#2565So far we've always assumed that a Svelte file is a TS file for simplicity, due to our default language (which was removed a long time ago) and also because IIRC there were issues with TS having its snapshot scriptKind being switched. That seems to be no longer the case, and so we can get better at properly analyzing whether or not this is a TS file, to allow JSDoc to take action when it's a JS file.
@jasonlyu123 do you remember why that scriptKind switch broke previously, but apparently doesn't anymore? I vaguely remember us having the same problem within the language server, but you PRd a change at some point stating that it's no longer a problem.
Also, is this a breaking change, because if someone has no allowJS
in their config they would get errors?
Yes, there is a Debug.assert
for ScriptKind changes. TypeScript added a fix for it some time ago. The Debug.assert
is still there, so it might still happen in some edge cases, but it shouldn't happen in most cases. #2538 is an example. In ts-plugin, you'll need file save to trigger updates, so for #2538 to happen in ts-plugin, it is edge case + edge case. Also, The more reliable reproduction for #2538 should only happen in module resolution "node16"+ because of the impliedNodeFormat patch but we didn't patch it in ts-plugin.
As for allowJs
, I am leaning toward this as a correctness fix. It also should only affect files loaded through import and not in project files because we can't know if the files are lang="ts" without reading it.
So far we've always assumed that a Svelte file is a TS file for simplicity, due to our default language (which was removed a long time ago) and also because IIRC there were issues with TS having its snapshot scriptKind being switched. That seems to be no longer the case, and so we can get better at properly analyzing whether or not this is a TS file, to allow JSDoc to take action when it's a JS file. #2555