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

Method lastLine

src/MagicString.ts:856–889  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

854 }
855
856 lastLine(): string {
857 let lineIndex = this.outro.lastIndexOf(n)
858 if (lineIndex !== -1)
859 return this.outro.substr(lineIndex + 1)
860 let lineStr = this.outro
861 let chunk: Chunk | null = this.lastChunk
862 while (chunk) {
863 if (chunk.outro.length > 0) {
864 lineIndex = chunk.outro.lastIndexOf(n)
865 if (lineIndex !== -1)
866 return chunk.outro.substr(lineIndex + 1) + lineStr
867 lineStr = chunk.outro + lineStr
868 }
869
870 if (chunk.content.length > 0) {
871 lineIndex = chunk.content.lastIndexOf(n)
872 if (lineIndex !== -1)
873 return chunk.content.substr(lineIndex + 1) + lineStr
874 lineStr = chunk.content + lineStr
875 }
876
877 if (chunk.intro.length > 0) {
878 lineIndex = chunk.intro.lastIndexOf(n)
879 if (lineIndex !== -1)
880 return chunk.intro.substr(lineIndex + 1) + lineStr
881 lineStr = chunk.intro + lineStr
882 }
883 chunk = chunk.previous
884 }
885 lineIndex = this.intro.lastIndexOf(n)
886 if (lineIndex !== -1)
887 return this.intro.substr(lineIndex + 1) + lineStr
888 return this.intro + lineStr
889 }
890
891 /**
892 * 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