typescript-svelte-plugin 0.3.10 → 0.3.11

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.
@@ -7,7 +7,8 @@ const utils_1 = require("./utils");
7
7
  * Caches resolved modules.
8
8
  */
9
9
  class ModuleResolutionCache {
10
- constructor() {
10
+ constructor(projectService) {
11
+ this.projectService = projectService;
11
12
  this.cache = new Map();
12
13
  }
13
14
  /**
@@ -30,8 +31,9 @@ class ModuleResolutionCache {
30
31
  * @param resolvedModuleName full path of the module
31
32
  */
32
33
  delete(resolvedModuleName) {
34
+ resolvedModuleName = this.projectService.toCanonicalFileName(resolvedModuleName);
33
35
  this.cache.forEach((val, key) => {
34
- if (val.resolvedFileName === resolvedModuleName) {
36
+ if (this.projectService.toCanonicalFileName(val.resolvedFileName) === resolvedModuleName) {
35
37
  this.cache.delete(key);
36
38
  }
37
39
  });
@@ -40,7 +42,9 @@ class ModuleResolutionCache {
40
42
  this.cache.clear();
41
43
  }
42
44
  getKey(moduleName, containingFile) {
43
- return containingFile + ':::' + (0, utils_1.ensureRealSvelteFilePath)(moduleName);
45
+ return (this.projectService.toCanonicalFileName(containingFile) +
46
+ ':::' +
47
+ this.projectService.toCanonicalFileName((0, utils_1.ensureRealSvelteFilePath)(moduleName)));
44
48
  }
45
49
  }
46
50
  /**
@@ -55,7 +59,7 @@ class ModuleResolutionCache {
55
59
  function patchModuleLoader(logger, snapshotManager, typescript, lsHost, project, configManager) {
56
60
  var _a;
57
61
  const svelteSys = (0, svelte_sys_1.createSvelteSys)(logger);
58
- const moduleCache = new ModuleResolutionCache();
62
+ const moduleCache = new ModuleResolutionCache(project.projectService);
59
63
  const origResolveModuleNames = (_a = lsHost.resolveModuleNames) === null || _a === void 0 ? void 0 : _a.bind(lsHost);
60
64
  lsHost.resolveModuleNames = resolveModuleNames;
61
65
  const origRemoveFile = project.removeFile.bind(project);
@@ -3,6 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ProjectSvelteFilesManager = void 0;
4
4
  const utils_1 = require("./utils");
5
5
  class ProjectSvelteFilesManager {
6
+ static getInstance(projectName) {
7
+ return this.instances.get(projectName);
8
+ }
6
9
  constructor(typescript, project, serverHost, snapshotManager, parsedCommandLine, configManager) {
7
10
  this.typescript = typescript;
8
11
  this.project = project;
@@ -18,9 +21,6 @@ class ProjectSvelteFilesManager {
18
21
  configManager.onConfigurationChanged(this.onConfigChanged.bind(this));
19
22
  ProjectSvelteFilesManager.instances.set(project.getProjectName(), this);
20
23
  }
21
- static getInstance(projectName) {
22
- return this.instances.get(projectName);
23
- }
24
24
  updateProjectConfig(serviceHost) {
25
25
  var _a;
26
26
  const parsedCommandLine = (_a = serviceHost.getParsedCommandLine) === null || _a === void 0 ? void 0 : _a.call(serviceHost, (0, utils_1.getConfigPathForProject)(this.project));
@@ -1,8 +1,8 @@
1
1
  import type ts from 'typescript/lib/tsserverlibrary';
2
- declare type LineChar = ts.LineAndCharacter;
3
- declare type FileMapping = LineMapping[];
4
- declare type LineMapping = CharacterMapping[];
5
- declare type CharacterMapping = [
2
+ type LineChar = ts.LineAndCharacter;
3
+ type FileMapping = LineMapping[];
4
+ type LineMapping = CharacterMapping[];
5
+ type CharacterMapping = [
6
6
  number,
7
7
  number,
8
8
  number,
@@ -199,11 +199,12 @@ class SvelteSnapshotManager {
199
199
  this.patchProjectServiceReadFile();
200
200
  }
201
201
  get(fileName) {
202
- return this.snapshots.get(fileName);
202
+ return this.snapshots.get(this.projectService.toCanonicalFileName(fileName));
203
203
  }
204
204
  create(fileName) {
205
- if (this.snapshots.has(fileName)) {
206
- return this.snapshots.get(fileName);
205
+ const canonicalFilePath = this.projectService.toCanonicalFileName(fileName);
206
+ if (this.snapshots.has(canonicalFilePath)) {
207
+ return this.snapshots.get(canonicalFilePath);
207
208
  }
208
209
  // This will trigger projectService.host.readFile which is patched below
209
210
  const scriptInfo = this.projectService.getOrCreateScriptInfoForNormalizedPath(this.typescript.server.toNormalizedPath(fileName), false);
@@ -217,13 +218,13 @@ class SvelteSnapshotManager {
217
218
  catch (e) {
218
219
  this.logger.log('Loading Snapshot failed', fileName);
219
220
  }
220
- const snapshot = this.snapshots.get(fileName);
221
+ const snapshot = this.snapshots.get(this.projectService.toCanonicalFileName(fileName));
221
222
  if (!snapshot) {
222
223
  this.logger.log('Svelte snapshot was not found after trying to load script snapshot for', fileName);
223
224
  return; // should never get here
224
225
  }
225
226
  snapshot.setAndPatchScriptInfo(scriptInfo);
226
- this.snapshots.set(fileName, snapshot);
227
+ this.snapshots.set(canonicalFilePath, snapshot);
227
228
  return snapshot;
228
229
  }
229
230
  patchProjectServiceReadFile() {
@@ -263,12 +264,13 @@ class SvelteSnapshotManager {
263
264
  mode: 'ts',
264
265
  typingsNamespace: this.svelteOptions.namespace
265
266
  });
266
- const existingSnapshot = this.snapshots.get(path);
267
+ const canonicalFilePath = this.projectService.toCanonicalFileName(path);
268
+ const existingSnapshot = this.snapshots.get(canonicalFilePath);
267
269
  if (existingSnapshot) {
268
270
  existingSnapshot.update(svelteCode, new source_mapper_1.SourceMapper(result.map.mappings));
269
271
  }
270
272
  else {
271
- this.snapshots.set(path, new SvelteSnapshot(this.typescript, path, svelteCode, new source_mapper_1.SourceMapper(result.map.mappings), this.logger, isTsFile));
273
+ this.snapshots.set(canonicalFilePath, new SvelteSnapshot(this.typescript, path, svelteCode, new source_mapper_1.SourceMapper(result.map.mappings), this.logger, isTsFile));
272
274
  }
273
275
  this.logger.log('Successfully read Svelte file contents of', path);
274
276
  return result.code;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "typescript-svelte-plugin",
3
- "version": "0.3.10",
3
+ "version": "0.3.11",
4
4
  "description": "A TypeScript Plugin providing Svelte intellisense",
5
5
  "main": "dist/src/index.js",
6
6
  "scripts": {