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

Method lastLine

src/MagicString.ts:816–849  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

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