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

Method lastLine

src/MagicString.ts:1003–1036  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1001 }
1002
1003 lastLine(): string {
1004 let lineIndex = this.outro.lastIndexOf(n)
1005 if (lineIndex !== -1)
1006 return this.outro.substr(lineIndex + 1)
1007 let lineStr = this.outro
1008 let chunk: Chunk | null = this.lastChunk
1009 while (chunk) {
1010 if (chunk.outro.length > 0) {
1011 lineIndex = chunk.outro.lastIndexOf(n)
1012 if (lineIndex !== -1)
1013 return chunk.outro.substr(lineIndex + 1) + lineStr
1014 lineStr = chunk.outro + lineStr
1015 }
1016
1017 if (chunk.content.length > 0) {
1018 lineIndex = chunk.content.lastIndexOf(n)
1019 if (lineIndex !== -1)
1020 return chunk.content.substr(lineIndex + 1) + lineStr
1021 lineStr = chunk.content + lineStr
1022 }
1023
1024 if (chunk.intro.length > 0) {
1025 lineIndex = chunk.intro.lastIndexOf(n)
1026 if (lineIndex !== -1)
1027 return chunk.intro.substr(lineIndex + 1) + lineStr
1028 lineStr = chunk.intro + lineStr
1029 }
1030 chunk = chunk.previous
1031 }
1032 lineIndex = this.intro.lastIndexOf(n)
1033 if (lineIndex !== -1)
1034 return this.intro.substr(lineIndex + 1) + lineStr
1035 return this.intro + lineStr
1036 }
1037
1038 /**
1039 * Returns the content of the generated string that corresponds to the slice between `start` and `end` of the original string.

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected