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

Method lastLine

src/MagicString.ts:830–863  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

828 }
829
830 lastLine(): string {
831 let lineIndex = this.outro.lastIndexOf(n)
832 if (lineIndex !== -1)
833 return this.outro.substr(lineIndex + 1)
834 let lineStr = this.outro
835 let chunk: Chunk | null = this.lastChunk
836 while (chunk) {
837 if (chunk.outro.length > 0) {
838 lineIndex = chunk.outro.lastIndexOf(n)
839 if (lineIndex !== -1)
840 return chunk.outro.substr(lineIndex + 1) + lineStr
841 lineStr = chunk.outro + lineStr
842 }
843
844 if (chunk.content.length > 0) {
845 lineIndex = chunk.content.lastIndexOf(n)
846 if (lineIndex !== -1)
847 return chunk.content.substr(lineIndex + 1) + lineStr
848 lineStr = chunk.content + lineStr
849 }
850
851 if (chunk.intro.length > 0) {
852 lineIndex = chunk.intro.lastIndexOf(n)
853 if (lineIndex !== -1)
854 return chunk.intro.substr(lineIndex + 1) + lineStr
855 lineStr = chunk.intro + lineStr
856 }
857 chunk = chunk.previous
858 }
859 lineIndex = this.intro.lastIndexOf(n)
860 if (lineIndex !== -1)
861 return this.intro.substr(lineIndex + 1) + lineStr
862 return this.intro + lineStr
863 }
864
865 /**
866 * 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