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

Method trimEndAborted

src/MagicString.ts:1077–1107  ·  view source on GitHub ↗

@internal

(charType?: string)

Source from the content-addressed store, hash-verified

1075
1076 /** @internal */
1077 trimEndAborted(charType?: string): boolean {
1078 const rx = new RegExp(`${charType || '\\s'}+$`)
1079
1080 this.outro = this.outro.replace(rx, '')
1081 if (this.outro.length)
1082 return true
1083
1084 let chunk = this.lastChunk
1085
1086 do {
1087 const end = chunk.end
1088 const aborted = chunk.trimEnd(rx)
1089
1090 // if chunk was trimmed, we have a new lastChunk
1091 if (chunk.end !== end) {
1092 if (this.lastChunk === chunk) {
1093 this.lastChunk = chunk.next
1094 }
1095
1096 this.byEnd.set(chunk.end, chunk)
1097 this.byStart.set(chunk.next.start, chunk.next)
1098 this.byEnd.set(chunk.next.end, chunk.next)
1099 }
1100
1101 if (aborted)
1102 return true
1103 chunk = chunk.previous
1104 } while (chunk)
1105
1106 return false
1107 }
1108
1109 /**
1110 * 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