* Emits the mappings for one MagicString: its intro, every chunk (with the * chunk's own intro/outro) and its outro. `sourceIndex === -1` means the * string has no source of its own, so its content only advances the * generated position without mapping anything.
(magicString: MagicString, sourceIndex: number, nameIndex: Map<string, number>)
| 60 | * generated position without mapping anything. |
| 61 | */ |
| 62 | addMagicString(magicString: MagicString, sourceIndex: number, nameIndex: Map<string, number>): void { |
| 63 | const { original } = magicString |
| 64 | const locate = getLocator(original) |
| 65 | |
| 66 | if (magicString.intro) |
| 67 | this.advance(magicString.intro) |
| 68 | |
| 69 | magicString.firstChunk.eachNext((chunk) => { |
| 70 | if (chunk.intro.length) |
| 71 | this.advance(chunk.intro) |
| 72 | |
| 73 | if (sourceIndex === -1) { |
| 74 | this.advance(chunk.content) |
| 75 | } |
| 76 | else if (chunk.edited) { |
| 77 | const name = chunk.storeName ? nameIndex.get(original.slice(chunk.start, chunk.replacesUntil)) : undefined |
| 78 | this.addEdit(sourceIndex, chunk.content, locate(chunk.start), name ?? -1) |
| 79 | } |
| 80 | else { |
| 81 | this.addUneditedChunk(sourceIndex, chunk, original, locate(chunk.start), magicString.sourcemapLocations) |
| 82 | } |
| 83 | |
| 84 | if (chunk.outro.length) |
| 85 | this.advance(chunk.outro) |
| 86 | }) |
| 87 | |
| 88 | if (magicString.outro) |
| 89 | this.advance(magicString.outro) |
| 90 | } |
| 91 | |
| 92 | addEdit(sourceIndex: number, content: string, loc: SourceLocation, nameIndex: number): void { |
| 93 | if (content.length) { |
no test coverage detected