@volar/source-map 0.28.10 → 0.29.0

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.
package/out/index.d.ts CHANGED
@@ -63,65 +63,65 @@ export declare type Mapping<T> = MappingBase & {
63
63
  data: T;
64
64
  additional?: MappingBase[];
65
65
  };
66
- export declare class SourceMap<Data = unknown> extends Set<Mapping<Data>> {
67
- sourceDocument: TextDocument;
68
- mappedDocument: TextDocument;
69
- constructor(sourceDocument: TextDocument, mappedDocument: TextDocument, mappings?: Mapping<Data>[]);
70
- cache: Map<string, {
71
- data: Data;
72
- start: vscode.Position;
73
- end: vscode.Position;
74
- }[]>;
75
- cache2: Map<string, {
66
+ export declare class SourceMapBase<Data = undefined> {
67
+ mappings: Mapping<Data>[];
68
+ constructor(_mappings?: Mapping<Data>[]);
69
+ private cache;
70
+ getSourceRange(start: number, end?: number): {
76
71
  data: Data;
77
72
  start: number;
78
73
  end: number;
79
- }[]>;
80
- isSourceRange(start: vscode.Position, end?: vscode.Position): boolean;
81
- isMappedRange(start: vscode.Position, end?: vscode.Position): boolean;
82
- getSourceRange(start: vscode.Position, end?: vscode.Position): {
83
- data: Data;
84
- start: vscode.Position;
85
- end: vscode.Position;
86
- } | undefined;
87
- getMappedRange(start: vscode.Position, end?: vscode.Position): {
88
- data: Data;
89
- start: vscode.Position;
90
- end: vscode.Position;
91
74
  } | undefined;
92
- getSourceRanges(start: vscode.Position, end?: vscode.Position): {
93
- data: Data;
94
- start: vscode.Position;
95
- end: vscode.Position;
96
- }[];
97
- getMappedRanges(start: vscode.Position, end?: vscode.Position): {
98
- data: Data;
99
- start: vscode.Position;
100
- end: vscode.Position;
101
- }[];
102
- private getRanges;
103
- isSourceRange2(start: number, end?: number): boolean;
104
- isMappedRange2(start: number, end?: number): boolean;
105
- getSourceRange2(start: number, end?: number): {
75
+ getMappedRange(start: number, end?: number): {
106
76
  data: Data;
107
77
  start: number;
108
78
  end: number;
109
79
  } | undefined;
110
- getMappedRange2(start: number, end?: number): {
80
+ getSourceRanges(start: number, end?: number): Generator<{
111
81
  data: Data;
112
82
  start: number;
113
83
  end: number;
114
- } | undefined;
115
- getSourceRanges2(start: number, end?: number): {
84
+ }, void, unknown>;
85
+ getMappedRanges(start: number, end?: number): Generator<{
116
86
  data: Data;
117
87
  start: number;
118
88
  end: number;
119
- }[];
120
- getMappedRanges2(start: number, end?: number): {
89
+ }, void, unknown>;
90
+ protected getRanges(startOffset: number, endOffset: number, sourceToTarget: boolean): Generator<{
121
91
  data: Data;
122
92
  start: number;
123
93
  end: number;
124
- }[];
125
- private getRanges2;
94
+ }, void, unknown>;
126
95
  private getRange;
127
96
  }
97
+ export declare class SourceMap<Data = undefined> extends SourceMapBase<Data> {
98
+ sourceDocument: TextDocument;
99
+ mappedDocument: TextDocument;
100
+ _mappings?: Mapping<Data>[] | undefined;
101
+ constructor(sourceDocument: TextDocument, mappedDocument: TextDocument, _mappings?: Mapping<Data>[] | undefined);
102
+ getSourceRange<T extends number | vscode.Position>(start: T, end?: T): {
103
+ data: Data;
104
+ start: T;
105
+ end: T;
106
+ } | undefined;
107
+ getMappedRange<T extends number | vscode.Position>(start: T, end?: T): {
108
+ data: Data;
109
+ start: T;
110
+ end: T;
111
+ } | undefined;
112
+ getSourceRanges<T extends number | vscode.Position>(start: T, end?: T): Generator<{
113
+ data: Data;
114
+ start: T;
115
+ end: T;
116
+ }, void, unknown>;
117
+ getMappedRanges<T extends number | vscode.Position>(start: T, end?: T): Generator<{
118
+ data: Data;
119
+ start: T;
120
+ end: T;
121
+ }, void, unknown>;
122
+ protected getRanges<T extends number | vscode.Position>(start: T, end: T, sourceToTarget: boolean): Generator<{
123
+ data: Data;
124
+ start: T;
125
+ end: T;
126
+ }, void, unknown>;
127
+ }
package/out/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SourceMap = exports.Mode = void 0;
3
+ exports.SourceMap = exports.SourceMapBase = exports.Mode = void 0;
4
4
  var Mode;
5
5
  (function (Mode) {
6
6
  /**
@@ -52,30 +52,20 @@ var Mode;
52
52
  */
53
53
  Mode[Mode["Overlap"] = 3] = "Overlap";
54
54
  })(Mode = exports.Mode || (exports.Mode = {}));
55
- class SourceMap extends Set {
56
- constructor(sourceDocument, mappedDocument, mappings) {
57
- super(mappings);
58
- this.sourceDocument = sourceDocument;
59
- this.mappedDocument = mappedDocument;
55
+ class SourceMapBase {
56
+ constructor(_mappings) {
60
57
  this.cache = new Map();
61
- this.cache2 = new Map();
62
- }
63
- // Range
64
- isSourceRange(start, end) {
65
- return this.getRanges(start, end !== null && end !== void 0 ? end : start, true, true).length > 0;
66
- }
67
- isMappedRange(start, end) {
68
- return this.getRanges(start, end !== null && end !== void 0 ? end : start, false, true).length > 0;
58
+ this.mappings = _mappings !== null && _mappings !== void 0 ? _mappings : [];
69
59
  }
70
60
  getSourceRange(start, end) {
71
- const result = this.getRanges(start, end !== null && end !== void 0 ? end : start, false, true);
72
- if (result.length)
73
- return result[0];
61
+ for (const maped of this.getRanges(start, end !== null && end !== void 0 ? end : start, false)) {
62
+ return maped;
63
+ }
74
64
  }
75
65
  getMappedRange(start, end) {
76
- const result = this.getRanges(start, end !== null && end !== void 0 ? end : start, true, true);
77
- if (result.length)
78
- return result[0];
66
+ for (const maped of this.getRanges(start, end !== null && end !== void 0 ? end : start, true)) {
67
+ return maped;
68
+ }
79
69
  }
80
70
  getSourceRanges(start, end) {
81
71
  return this.getRanges(start, end !== null && end !== void 0 ? end : start, false);
@@ -83,72 +73,40 @@ class SourceMap extends Set {
83
73
  getMappedRanges(start, end) {
84
74
  return this.getRanges(start, end !== null && end !== void 0 ? end : start, true);
85
75
  }
86
- getRanges(start, end, sourceToTarget, returnFirstResult) {
87
- const key = start.line + ':' + start.character + ':' + end.line + ':' + end.character + ':' + sourceToTarget + ':' + returnFirstResult;
88
- if (this.cache.has(key))
89
- return this.cache.get(key);
90
- const toDoc = sourceToTarget ? this.mappedDocument : this.sourceDocument;
91
- const fromDoc = sourceToTarget ? this.sourceDocument : this.mappedDocument;
92
- const startOffset = fromDoc.offsetAt(start);
93
- const endOffset = fromDoc.offsetAt(end);
94
- const result = this
95
- .getRanges2(startOffset, endOffset, sourceToTarget, returnFirstResult)
96
- .map(result => ({
97
- data: result.data,
98
- start: toDoc.positionAt(result.start),
99
- end: toDoc.positionAt(result.end),
100
- }));
101
- this.cache.set(key, result);
102
- return result;
103
- }
104
- // MapedRange
105
- isSourceRange2(start, end) {
106
- return this.getRanges2(start, end !== null && end !== void 0 ? end : start, true, true).length > 0;
107
- }
108
- isMappedRange2(start, end) {
109
- return this.getRanges2(start, end !== null && end !== void 0 ? end : start, false, true).length > 0;
110
- }
111
- getSourceRange2(start, end) {
112
- const result = this.getRanges2(start, end !== null && end !== void 0 ? end : start, false, true);
113
- if (result.length)
114
- return result[0];
115
- }
116
- getMappedRange2(start, end) {
117
- const result = this.getRanges2(start, end !== null && end !== void 0 ? end : start, true, true);
118
- if (result.length)
119
- return result[0];
120
- }
121
- getSourceRanges2(start, end) {
122
- return this.getRanges2(start, end !== null && end !== void 0 ? end : start, false);
123
- }
124
- getMappedRanges2(start, end) {
125
- return this.getRanges2(start, end !== null && end !== void 0 ? end : start, true);
126
- }
127
- getRanges2(start, end, sourceToTarget, returnFirstResult) {
128
- const key = start + ':' + end + ':' + sourceToTarget + ':' + returnFirstResult;
129
- if (this.cache2.has(key))
130
- return this.cache2.get(key);
131
- let result = [];
132
- for (const mapping of this) {
133
- const maped = this.getRange(start, end, sourceToTarget, mapping.mode, mapping.sourceRange, mapping.mappedRange, mapping.data);
76
+ *getRanges(startOffset, endOffset, sourceToTarget) {
77
+ const key = startOffset + ':' + endOffset + ':' + sourceToTarget;
78
+ let result = this.cache.get(key);
79
+ if (!result) {
80
+ result = {
81
+ index: 0,
82
+ mapeds: [],
83
+ };
84
+ this.cache.set(key, result);
85
+ }
86
+ for (const maped of result.mapeds) {
87
+ yield getMaped(maped);
88
+ }
89
+ while (result.index < this.mappings.length) {
90
+ const mapping = this.mappings[result.index++];
91
+ const maped = this.getRange(startOffset, endOffset, sourceToTarget, mapping.mode, mapping.sourceRange, mapping.mappedRange, mapping.data);
134
92
  if (maped) {
135
- result.push(maped);
136
- if (returnFirstResult)
137
- return result;
93
+ result.mapeds.push(maped);
94
+ yield getMaped(maped);
138
95
  }
139
- if (mapping.additional) {
96
+ else if (mapping.additional) {
140
97
  for (const other of mapping.additional) {
141
- const maped = this.getRange(start, end, sourceToTarget, other.mode, other.sourceRange, other.mappedRange, mapping.data);
98
+ const maped = this.getRange(startOffset, endOffset, sourceToTarget, other.mode, other.sourceRange, other.mappedRange, mapping.data);
142
99
  if (maped) {
143
- result.push(maped);
144
- if (returnFirstResult)
145
- return result;
100
+ result.mapeds.push(maped);
101
+ yield getMaped(maped);
102
+ break; // only return first match additional range
146
103
  }
147
104
  }
148
105
  }
149
106
  }
150
- this.cache2.set(key, result);
151
- return result;
107
+ function getMaped(maped) {
108
+ return maped;
109
+ }
152
110
  }
153
111
  getRange(start, end, sourceToTarget, mode, sourceRange, targetRange, data) {
154
112
  const mapedToRange = sourceToTarget ? targetRange : sourceRange;
@@ -202,5 +160,51 @@ class SourceMap extends Set {
202
160
  }
203
161
  }
204
162
  }
163
+ exports.SourceMapBase = SourceMapBase;
164
+ class SourceMap extends SourceMapBase {
165
+ constructor(sourceDocument, mappedDocument, _mappings) {
166
+ super(_mappings);
167
+ this.sourceDocument = sourceDocument;
168
+ this.mappedDocument = mappedDocument;
169
+ this._mappings = _mappings;
170
+ }
171
+ getSourceRange(start, end) {
172
+ for (const maped of this.getRanges(start, end !== null && end !== void 0 ? end : start, false)) {
173
+ return maped;
174
+ }
175
+ }
176
+ getMappedRange(start, end) {
177
+ for (const maped of this.getRanges(start, end !== null && end !== void 0 ? end : start, true)) {
178
+ return maped;
179
+ }
180
+ }
181
+ getSourceRanges(start, end) {
182
+ return this.getRanges(start, end !== null && end !== void 0 ? end : start, false);
183
+ }
184
+ getMappedRanges(start, end) {
185
+ return this.getRanges(start, end !== null && end !== void 0 ? end : start, true);
186
+ }
187
+ *getRanges(start, end, sourceToTarget) {
188
+ const startIsNumber = typeof start === 'number';
189
+ const endIsNumber = typeof end === 'number';
190
+ const toDoc = sourceToTarget ? this.mappedDocument : this.sourceDocument;
191
+ const fromDoc = sourceToTarget ? this.sourceDocument : this.mappedDocument;
192
+ const startOffset = startIsNumber ? start : fromDoc.offsetAt(start);
193
+ const endOffset = endIsNumber ? end : fromDoc.offsetAt(end);
194
+ for (const maped of super.getRanges(startOffset, endOffset, sourceToTarget)) {
195
+ yield getMaped(maped);
196
+ }
197
+ function getMaped(maped) {
198
+ if (startIsNumber) {
199
+ return maped;
200
+ }
201
+ return {
202
+ data: maped.data,
203
+ start: toDoc.positionAt(maped.start),
204
+ end: toDoc.positionAt(maped.end),
205
+ };
206
+ }
207
+ }
208
+ }
205
209
  exports.SourceMap = SourceMap;
206
210
  //# sourceMappingURL=index.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@volar/source-map",
3
- "version": "0.28.10",
3
+ "version": "0.29.0",
4
4
  "main": "out/index.js",
5
5
  "license": "MIT",
6
6
  "files": [
@@ -13,7 +13,7 @@
13
13
  "directory": "packages/source-map"
14
14
  },
15
15
  "dependencies": {
16
- "@volar/shared": "0.28.10"
16
+ "@volar/shared": "0.29.0"
17
17
  },
18
- "gitHead": "2b49fd7084e5be2a763cbc50f2f17e82f6d1a084"
18
+ "gitHead": "3a2f1db33d92410455811bc119041e800de115ab"
19
19
  }