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

Method trimEndAborted

src/MagicString.ts:1263–1297  ·  view source on GitHub ↗

@internal

(charType?: string)

Source from the content-addressed store, hash-verified

1261
1262 /** @internal */
1263 trimEndAborted(charType?: string): boolean {
1264 const rx = new RegExp(`${charType || '\\s'}+$`)
1265
1266 this.outro = this.outro.replace(rx, '')
1267 if (this.outro.length)
1268 return true
1269
1270 let chunk: Chunk | null = this.lastChunk
1271
1272 do {
1273 const end = chunk.end
1274 const aborted = chunk.trimEnd(rx)
1275
1276 // if chunk was trimmed, we have a new lastChunk
1277 if (chunk.end !== end) {
1278 const next = chunk.next! // chunk.trimEnd() just split this chunk, so a successor exists
1279 if (this.lastChunk === chunk) {
1280 this.lastChunk = next
1281 }
1282
1283 this.byEnd.set(chunk.end, chunk)
1284 this.byStart.set(next.start, next)
1285 this.byEnd.set(next.end, next)
1286 }
1287
1288 if (aborted)
1289 return true
1290 chunk = chunk.previous
1291 } while (chunk)
1292
1293 // like Chunk#trimEnd, carry on into the intro once everything after it has
1294 // been trimmed away, since the intro is then the end of the string
1295 this.intro = this.intro.replace(rx, '')
1296 return this.intro.length > 0
1297 }
1298
1299 /**
1300 * 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