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

Method lastLine

src/MagicString.ts:867–900  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

865 }
866
867 lastLine(): string {
868 let lineIndex = this.outro.lastIndexOf(n)
869 if (lineIndex !== -1)
870 return this.outro.substr(lineIndex + 1)
871 let lineStr = this.outro
872 let chunk: Chunk | null = this.lastChunk
873 while (chunk) {
874 if (chunk.outro.length > 0) {
875 lineIndex = chunk.outro.lastIndexOf(n)
876 if (lineIndex !== -1)
877 return chunk.outro.substr(lineIndex + 1) + lineStr
878 lineStr = chunk.outro + lineStr
879 }
880
881 if (chunk.content.length > 0) {
882 lineIndex = chunk.content.lastIndexOf(n)
883 if (lineIndex !== -1)
884 return chunk.content.substr(lineIndex + 1) + lineStr
885 lineStr = chunk.content + lineStr
886 }
887
888 if (chunk.intro.length > 0) {
889 lineIndex = chunk.intro.lastIndexOf(n)
890 if (lineIndex !== -1)
891 return chunk.intro.substr(lineIndex + 1) + lineStr
892 lineStr = chunk.intro + lineStr
893 }
894 chunk = chunk.previous
895 }
896 lineIndex = this.intro.lastIndexOf(n)
897 if (lineIndex !== -1)
898 return this.intro.substr(lineIndex + 1) + lineStr
899 return this.intro + lineStr
900 }
901
902 /**
903 * 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