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

Method lastLine

src/MagicString.ts:815–848  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

813 }
814
815 lastLine(): string {
816 let lineIndex = this.outro.lastIndexOf(n)
817 if (lineIndex !== -1)
818 return this.outro.substr(lineIndex + 1)
819 let lineStr = this.outro
820 let chunk: Chunk | null = this.lastChunk
821 while (chunk) {
822 if (chunk.outro.length > 0) {
823 lineIndex = chunk.outro.lastIndexOf(n)
824 if (lineIndex !== -1)
825 return chunk.outro.substr(lineIndex + 1) + lineStr
826 lineStr = chunk.outro + lineStr
827 }
828
829 if (chunk.content.length > 0) {
830 lineIndex = chunk.content.lastIndexOf(n)
831 if (lineIndex !== -1)
832 return chunk.content.substr(lineIndex + 1) + lineStr
833 lineStr = chunk.content + lineStr
834 }
835
836 if (chunk.intro.length > 0) {
837 lineIndex = chunk.intro.lastIndexOf(n)
838 if (lineIndex !== -1)
839 return chunk.intro.substr(lineIndex + 1) + lineStr
840 lineStr = chunk.intro + lineStr
841 }
842 chunk = chunk.previous
843 }
844 lineIndex = this.intro.lastIndexOf(n)
845 if (lineIndex !== -1)
846 return this.intro.substr(lineIndex + 1) + lineStr
847 return this.intro + lineStr
848 }
849
850 /**
851 * 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