MCPcopy Create free account
hub / github.com/Rich-Harris/magic-string / drain

Method drain

src/utils/MappingsEncoder.ts:83–123  ·  view source on GitHub ↗
(trailing: FullSegment[] | null)

Source from the content-addressed store, hash-verified

81 }
82
83 private drain(trailing: FullSegment[] | null): void {
84 const lines = this.lines
85 const lineCount = lines.length
86
87 for (let l = 0; l <= lineCount; l++) {
88 const line = l < lineCount ? lines[l] : trailing
89 if (line === null)
90 break
91
92 for (let i = 0; i < line.length; i++) {
93 if (this.pos > FLUSH_THRESHOLD)
94 this.flush()
95 const segment = line[i]
96 if (this.needsComma)
97 scratch[this.pos++] = COMMA
98 this.needsComma = true
99 this.pos = writeVlq(this.pos, segment[0] - this.prevGenColumn)
100 this.prevGenColumn = segment[0]
101 this.pos = writeVlq(this.pos, segment[1] - this.prevSourceIndex)
102 this.prevSourceIndex = segment[1]
103 this.pos = writeVlq(this.pos, segment[2] - this.prevSourceLine)
104 this.prevSourceLine = segment[2]
105 this.pos = writeVlq(this.pos, segment[3] - this.prevSourceColumn)
106 this.prevSourceColumn = segment[3]
107 if (segment.length === 5) {
108 this.pos = writeVlq(this.pos, segment[4] - this.prevNameIndex)
109 this.prevNameIndex = segment[4]
110 }
111 }
112
113 if (l < lineCount) {
114 if (this.pos > FLUSH_THRESHOLD)
115 this.flush()
116 scratch[this.pos++] = SEMICOLON
117 this.needsComma = false
118 this.prevGenColumn = 0
119 }
120 }
121 lines.length = 0
122 this.buffered = 0
123 }
124
125 private flush(): void {
126 this.out += decoder.decode(scratch.subarray(0, this.pos))

Callers 3

endLineMethod · 0.95
segmentsMethod · 0.95
finishMethod · 0.95

Calls 2

flushMethod · 0.95
writeVlqFunction · 0.85

Tested by

no test coverage detected