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

Method drain

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

Source from the content-addressed store, hash-verified

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