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

Method trimStartAborted

src/MagicString.ts:1308–1341  ·  view source on GitHub ↗

@internal

(charType?: string)

Source from the content-addressed store, hash-verified

1306
1307 /** @internal */
1308 trimStartAborted(charType?: string): boolean {
1309 const rx = new RegExp(`^${charType || '\\s'}+`)
1310
1311 this.intro = this.intro.replace(rx, '')
1312 if (this.intro.length)
1313 return true
1314
1315 let chunk: Chunk | null = this.firstChunk
1316
1317 do {
1318 const end = chunk.end
1319 const aborted = chunk.trimStart(rx)
1320
1321 if (chunk.end !== end) {
1322 const next = chunk.next! // chunk.trimStart() just split this chunk, so a successor exists
1323 // special case...
1324 if (chunk === this.lastChunk)
1325 this.lastChunk = next
1326
1327 this.byEnd.set(chunk.end, chunk)
1328 this.byStart.set(next.start, next)
1329 this.byEnd.set(next.end, next)
1330 }
1331
1332 if (aborted)
1333 return true
1334 chunk = chunk.next
1335 } while (chunk)
1336
1337 // like Chunk#trimStart, carry on into the outro once everything before it
1338 // has been trimmed away, since the outro is then the start of the string
1339 this.outro = this.outro.replace(rx, '')
1340 return this.outro.length > 0
1341 }
1342
1343 /**
1344 * Trims content matching `charType` (defaults to `\s`, i.e. whitespace) from the start.

Callers 2

trimStartMethod · 0.95
trimStartMethod · 0.45

Calls 2

replaceMethod · 0.45
trimStartMethod · 0.45

Tested by

no test coverage detected