typescript-svelte-plugin 0.3.1 → 0.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -229,7 +229,27 @@ class SvelteSnapshotManager {
229
229
  patchProjectServiceReadFile() {
230
230
  const readFile = this.projectService.host.readFile;
231
231
  this.projectService.host.readFile = (path) => {
232
- if ((0, utils_1.isSvelteFilePath)(path) && this.configManager.getConfig().enable) {
232
+ // The following (very hacky) first two checks make sure that the ambient module definitions
233
+ // that tell TS "every import ending with .svelte is a valid module" are removed.
234
+ // They exist in svelte2tsx and svelte to make sure that people don't
235
+ // get errors in their TS files when importing Svelte files and not using our TS plugin.
236
+ // If someone wants to get back the behavior they can add an ambient module definition
237
+ // on their own.
238
+ const normalizedPath = path.replace(/\\/g, '/');
239
+ if (normalizedPath.endsWith('node_modules/svelte/types/runtime/ambient.d.ts')) {
240
+ return '';
241
+ }
242
+ else if (normalizedPath.endsWith('svelte2tsx/svelte-shims.d.ts')) {
243
+ let originalText = readFile(path) || '';
244
+ if (!originalText.includes('// -- start svelte-ls-remove --')) {
245
+ return originalText; // uses an older version of svelte2tsx
246
+ }
247
+ originalText =
248
+ originalText.substring(0, originalText.indexOf('// -- start svelte-ls-remove --')) +
249
+ originalText.substring(originalText.indexOf('// -- end svelte-ls-remove --'));
250
+ return originalText;
251
+ }
252
+ else if ((0, utils_1.isSvelteFilePath)(path) && this.configManager.getConfig().enable) {
233
253
  this.logger.debug('Read Svelte file:', path);
234
254
  const svelteCode = readFile(path) || '';
235
255
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "typescript-svelte-plugin",
3
- "version": "0.3.1",
3
+ "version": "0.3.2",
4
4
  "description": "A TypeScript Plugin providing Svelte intellisense",
5
5
  "main": "dist/src/index.js",
6
6
  "scripts": {