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

Method trimEndAborted

src/MagicString.ts:1196–1226  ·  view source on GitHub ↗

@internal

(charType?: string)

Source from the content-addressed store, hash-verified

1194
1195 /** @internal */
1196 trimEndAborted(charType?: string): boolean {
1197 const rx = new RegExp(`${charType || '\\s'}+$`)
1198
1199 this.outro = this.outro.replace(rx, '')
1200 if (this.outro.length)
1201 return true
1202
1203 let chunk = this.lastChunk
1204
1205 do {
1206 const end = chunk.end
1207 const aborted = chunk.trimEnd(rx)
1208
1209 // if chunk was trimmed, we have a new lastChunk
1210 if (chunk.end !== end) {
1211 if (this.lastChunk === chunk) {
1212 this.lastChunk = chunk.next
1213 }
1214
1215 this.byEnd.set(chunk.end, chunk)
1216 this.byStart.set(chunk.next.start, chunk.next)
1217 this.byEnd.set(chunk.next.end, chunk.next)
1218 }
1219
1220 if (aborted)
1221 return true
1222 chunk = chunk.previous
1223 } while (chunk)
1224
1225 return false
1226 }
1227
1228 /**
1229 * Trims content matching `charType` (defaults to `\s`, i.e. whitespace) from the end.

Callers 2

trimEndMethod · 0.95
trimEndMethod · 0.45

Calls 2

replaceMethod · 0.45
trimEndMethod · 0.45

Tested by

no test coverage detected