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

Method lastLine

src/MagicString.ts:861–894  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

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