@volar/language-core 1.6.0 → 1.6.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.
Files changed (2) hide show
  1. package/out/virtualFiles.js +20 -21
  2. package/package.json +3 -3
@@ -6,7 +6,7 @@ const sourceMaps_1 = require("./sourceMaps");
6
6
  function createVirtualFiles(languages) {
7
7
  const sourceFiles = new Map();
8
8
  const virtualFiles = new Map();
9
- const virtualFileToSourceMapsMap = new WeakMap();
9
+ const virtualFileMaps = new WeakMap();
10
10
  const virtualFileToMirrorMap = new WeakMap();
11
11
  let sourceFilesDirty = true;
12
12
  return {
@@ -53,19 +53,19 @@ function createVirtualFiles(languages) {
53
53
  },
54
54
  hasSource: (fileName) => sourceFiles.has(normalizePath(fileName)),
55
55
  getMirrorMap: getMirrorMap,
56
- getMaps: getSourceMaps,
56
+ getMaps: getMapsByVirtualFile,
57
57
  hasVirtualFile(fileName) {
58
- return !!getVirtualFilesMap().get(normalizePath(fileName));
58
+ return !!getVirtualFileToSourceFileMap().get(normalizePath(fileName));
59
59
  },
60
60
  getVirtualFile(fileName) {
61
- const sourceAndVirtual = getVirtualFilesMap().get(normalizePath(fileName));
61
+ const sourceAndVirtual = getVirtualFileToSourceFileMap().get(normalizePath(fileName));
62
62
  if (sourceAndVirtual) {
63
63
  return [sourceAndVirtual.virtualFile, sourceAndVirtual.source];
64
64
  }
65
65
  return [undefined, undefined];
66
66
  },
67
67
  };
68
- function getVirtualFilesMap() {
68
+ function getVirtualFileToSourceFileMap() {
69
69
  if (sourceFilesDirty) {
70
70
  sourceFilesDirty = false;
71
71
  virtualFiles.clear();
@@ -77,26 +77,25 @@ function createVirtualFiles(languages) {
77
77
  }
78
78
  return virtualFiles;
79
79
  }
80
- function getSourceMaps(virtualFile) {
81
- let sourceMapsBySourceFileName = virtualFileToSourceMapsMap.get(virtualFile.snapshot);
82
- if (!sourceMapsBySourceFileName) {
83
- sourceMapsBySourceFileName = new Map();
84
- virtualFileToSourceMapsMap.set(virtualFile.snapshot, sourceMapsBySourceFileName);
80
+ function getMapsByVirtualFile(virtualFile) {
81
+ if (!virtualFileMaps.has(virtualFile.snapshot)) {
82
+ virtualFileMaps.set(virtualFile.snapshot, new Map());
85
83
  }
84
+ const map = virtualFileMaps.get(virtualFile.snapshot);
86
85
  const sources = new Set();
87
- for (const map of virtualFile.mappings) {
88
- sources.add(map.source);
89
- }
90
- for (const source of sources) {
91
- const sourceFileName = source ?? getVirtualFilesMap().get(normalizePath(virtualFile.fileName)).source.fileName;
92
- if (!sourceMapsBySourceFileName.has(sourceFileName)) {
93
- sourceMapsBySourceFileName.set(sourceFileName, [
94
- sourceFileName,
95
- new source_map_1.SourceMap(virtualFile.mappings.filter(mapping => mapping.source === source)),
96
- ]);
86
+ const result = [];
87
+ for (const mapping of virtualFile.mappings) {
88
+ if (sources.has(mapping.source))
89
+ continue;
90
+ sources.add(mapping.source);
91
+ const sourceFileName = mapping.source ?? getVirtualFileToSourceFileMap().get(normalizePath(virtualFile.fileName)).source.fileName;
92
+ const sourceSnapshot = mapping.source ? sourceFiles.get(normalizePath(mapping.source)).snapshot : getVirtualFileToSourceFileMap().get(normalizePath(virtualFile.fileName)).source.snapshot;
93
+ if (!map.has(sourceSnapshot)) {
94
+ map.set(sourceSnapshot, [sourceFileName, new source_map_1.SourceMap(virtualFile.mappings.filter(mapping2 => mapping2.source === mapping.source))]);
97
95
  }
96
+ result.push(map.get(sourceSnapshot));
98
97
  }
99
- return [...sourceMapsBySourceFileName.values()];
98
+ return result;
100
99
  }
101
100
  function getMirrorMap(file) {
102
101
  if (!virtualFileToMirrorMap.has(file.snapshot)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@volar/language-core",
3
- "version": "1.6.0",
3
+ "version": "1.6.2",
4
4
  "main": "out/index.js",
5
5
  "license": "MIT",
6
6
  "files": [
@@ -13,7 +13,7 @@
13
13
  "directory": "packages/language-core"
14
14
  },
15
15
  "dependencies": {
16
- "@volar/source-map": "1.6.0"
16
+ "@volar/source-map": "1.6.2"
17
17
  },
18
- "gitHead": "3ef1b023cb1f77662fd7bdb0f1099ab726f772d6"
18
+ "gitHead": "1a044d2d633de5beb7e1a14689141037854ea441"
19
19
  }