MCPcopy Create free account
hub / github.com/babel/babel / #bufferMapping

Method #bufferMapping

packages/babel-generator/src/source-map.ts:246–283  ·  view source on GitHub ↗
(newMapping: Parameters<typeof maybeAddMapping>[1])

Source from the content-addressed store, hash-verified

244 }
245
246 #bufferMapping(newMapping: Parameters<typeof maybeAddMapping>[1]) {
247 // We keep up to two mappings buffered before committing them to the
248 // underlying map. This lets us detect consecutive range candidate mappings and
249 // collapse them into a single range mapping: buffer0 is the candidate
250 // "range start", buffer1 (when present) is the candidate "range close",
251 // and any subsequent range candidate mapping replaces buffer1 to extend the range.
252 if (this.#mappingsBuffer0 === null) {
253 this.#mappingsBuffer0 = newMapping;
254 return;
255 }
256
257 if (this.#mappingsBuffer1 === null) {
258 if (this.#isRangeCandidate(this.#mappingsBuffer0, newMapping)) {
259 this.#mappingsBuffer1 = newMapping;
260 } else {
261 maybeAddMapping(this._map, this.#mappingsBuffer0);
262 this.#mappingsBuffer0 = newMapping;
263 }
264 return;
265 }
266
267 if (this.#isRangeCandidate(this.#mappingsBuffer1, newMapping)) {
268 // Extend the open range: drop the old close, keep the new one as the
269 // range close so the pair (buffer0, buffer1) still spans range candidate code.
270 this.#mappingsBuffer1 = newMapping;
271 this.#droppedMappingForRange = true;
272 } else {
273 // Only the range-start segment carries the range marker; the next
274 // committed segment is the implicit range close. Only mark the mapping
275 // as range if it actually allowed us to drop other mappings.
276 if (this.#droppedMappingForRange) this.#mappingsBuffer0.isRange = true;
277 maybeAddMapping(this._map, this.#mappingsBuffer0);
278 maybeAddMapping(this._map, this.#mappingsBuffer1);
279 this.#mappingsBuffer0 = newMapping;
280 this.#mappingsBuffer1 = null;
281 this.#droppedMappingForRange = false;
282 }
283 }
284
285 #flushBuffer() {
286 if (this.#mappingsBuffer2 !== null) {

Callers 2

markMethod · 0.95
#flushBufferMethod · 0.95

Calls 1

#isRangeCandidateMethod · 0.95

Tested by

no test coverage detected