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

Method trimEndAborted

src/MagicString.ts:1030–1060  ·  view source on GitHub ↗

@internal

(charType?: string)

Source from the content-addressed store, hash-verified

1028
1029 /** @internal */
1030 trimEndAborted(charType?: string): boolean {
1031 const rx = new RegExp(`${charType || '\\s'}+$`)
1032
1033 this.outro = this.outro.replace(rx, '')
1034 if (this.outro.length)
1035 return true
1036
1037 let chunk = this.lastChunk
1038
1039 do {
1040 const end = chunk.end
1041 const aborted = chunk.trimEnd(rx)
1042
1043 // if chunk was trimmed, we have a new lastChunk
1044 if (chunk.end !== end) {
1045 if (this.lastChunk === chunk) {
1046 this.lastChunk = chunk.next
1047 }
1048
1049 this.byEnd.set(chunk.end, chunk)
1050 this.byStart.set(chunk.next.start, chunk.next)
1051 this.byEnd.set(chunk.next.end, chunk.next)
1052 }
1053
1054 if (aborted)
1055 return true
1056 chunk = chunk.previous
1057 } while (chunk)
1058
1059 return false
1060 }
1061
1062 /**
1063 * 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