@volar/language-core 2.3.0-alpha.8 → 2.3.0-alpha.9

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 (3) hide show
  1. package/index.js +16 -14
  2. package/lib/types.d.ts +1 -1
  3. package/package.json +3 -3
package/index.js CHANGED
@@ -142,30 +142,32 @@ function createLanguage(plugins, scriptRegistry, sync) {
142
142
  },
143
143
  },
144
144
  maps: {
145
- get(virtualCode) {
146
- for (const map of this.forEach(virtualCode)) {
147
- return map[2];
148
- }
149
- throw `no map found for ${virtualCode.id}`;
150
- },
151
- *forEach(virtualCode) {
145
+ get(virtualCode, sourceScript, mappings) {
152
146
  let mapCache = virtualCodeToSourceMap.get(virtualCode.snapshot);
153
147
  if (!mapCache) {
154
148
  virtualCodeToSourceMap.set(virtualCode.snapshot, mapCache = new WeakMap());
155
149
  }
156
- const sourceScript = virtualCodeToSourceScriptMap.get(virtualCode);
157
150
  if (!mapCache.has(sourceScript.snapshot)) {
158
- mapCache.set(sourceScript.snapshot, new source_map_1.SourceMap(virtualCode.mappings));
151
+ mapCache.set(sourceScript.snapshot, new source_map_1.SourceMap(mappings ?? virtualCode.mappings));
159
152
  }
160
- yield [sourceScript.id, sourceScript.snapshot, mapCache.get(sourceScript.snapshot)];
153
+ return mapCache.get(sourceScript.snapshot);
154
+ },
155
+ *forEach(virtualCode) {
156
+ const sourceScript = virtualCodeToSourceScriptMap.get(virtualCode);
157
+ yield [
158
+ sourceScript.id,
159
+ sourceScript.snapshot,
160
+ this.get(virtualCode, sourceScript),
161
+ ];
161
162
  if (virtualCode.associatedScriptMappings) {
162
163
  for (const [relatedScriptId, relatedMappings] of virtualCode.associatedScriptMappings) {
163
164
  const relatedSourceScript = scriptRegistry.get(relatedScriptId);
164
165
  if (relatedSourceScript) {
165
- if (!mapCache.has(relatedSourceScript.snapshot)) {
166
- mapCache.set(relatedSourceScript.snapshot, new source_map_1.SourceMap(relatedMappings));
167
- }
168
- yield [relatedSourceScript.id, relatedSourceScript.snapshot, mapCache.get(relatedSourceScript.snapshot)];
166
+ yield [
167
+ relatedSourceScript.id,
168
+ relatedSourceScript.snapshot,
169
+ this.get(virtualCode, relatedSourceScript, relatedMappings),
170
+ ];
169
171
  }
170
172
  }
171
173
  }
package/lib/types.d.ts CHANGED
@@ -10,7 +10,7 @@ export interface Language<T = unknown> {
10
10
  fromVirtualCode(virtualCode: VirtualCode): SourceScript<T>;
11
11
  };
12
12
  maps: {
13
- get(virtualCode: VirtualCode): SourceMap<CodeInformation>;
13
+ get(virtualCode: VirtualCode, sourceScript: SourceScript<T>, mappings?: Mapping<CodeInformation>[]): SourceMap<CodeInformation>;
14
14
  forEach(virtualCode: VirtualCode): Generator<[id: T, snapshot: ts.IScriptSnapshot, map: SourceMap<CodeInformation>]>;
15
15
  };
16
16
  linkedCodeMaps: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@volar/language-core",
3
- "version": "2.3.0-alpha.8",
3
+ "version": "2.3.0-alpha.9",
4
4
  "license": "MIT",
5
5
  "files": [
6
6
  "**/*.js",
@@ -12,7 +12,7 @@
12
12
  "directory": "packages/language-core"
13
13
  },
14
14
  "dependencies": {
15
- "@volar/source-map": "2.3.0-alpha.8"
15
+ "@volar/source-map": "2.3.0-alpha.9"
16
16
  },
17
- "gitHead": "377a0083ac697a476509805a6777a2339391dcaf"
17
+ "gitHead": "3f741930343896dfc464a893ebe5f3619bb1a1aa"
18
18
  }