( magicString: MagicStringBundle, fileName: string, usedModules: Module[], chunkGraph: Record<string, RenderedChunk>, options: NormalizedOutputOptions, outputPluginDriver: PluginDriver, log: LogHandler )
| 107 | } |
| 108 | |
| 109 | async function transformChunk( |
| 110 | magicString: MagicStringBundle, |
| 111 | fileName: string, |
| 112 | usedModules: Module[], |
| 113 | chunkGraph: Record<string, RenderedChunk>, |
| 114 | options: NormalizedOutputOptions, |
| 115 | outputPluginDriver: PluginDriver, |
| 116 | log: LogHandler |
| 117 | ) { |
| 118 | let map: SourceMap | null = null; |
| 119 | const sourcemapChain: DecodedSourceMapOrMissing[] = []; |
| 120 | let code = await outputPluginDriver.hookReduceArg0( |
| 121 | 'renderChunk', |
| 122 | [magicString.toString(), chunkGraph[fileName], options, { chunks: chunkGraph }], |
| 123 | (code, result, plugin) => { |
| 124 | if (result == null) return code; |
| 125 | |
| 126 | if (typeof result === 'string') |
| 127 | result = { |
| 128 | code: result, |
| 129 | map: undefined |
| 130 | }; |
| 131 | |
| 132 | // strict null check allows 'null' maps to not be pushed to the chain, while 'undefined' gets the missing map warning |
| 133 | if (result.map !== null) { |
| 134 | const map = decodedSourcemap(result.map); |
| 135 | sourcemapChain.push(map || { missing: true, plugin: plugin.name }); |
| 136 | } |
| 137 | |
| 138 | return result.code; |
| 139 | } |
| 140 | ); |
| 141 | const { |
| 142 | compact, |
| 143 | dir, |
| 144 | file, |
| 145 | sourcemap, |
| 146 | sourcemapExcludeSources, |
| 147 | sourcemapFile, |
| 148 | sourcemapPathTransform, |
| 149 | sourcemapIgnoreList |
| 150 | } = options; |
| 151 | if (!compact && code[code.length - 1] !== '\n') code += '\n'; |
| 152 | |
| 153 | if (sourcemap) { |
| 154 | timeStart('sourcemaps', 3); |
| 155 | |
| 156 | let resultingFile: string; |
| 157 | if (file) resultingFile = resolve(sourcemapFile || file); |
| 158 | else if (dir) resultingFile = resolve(dir, fileName); |
| 159 | else resultingFile = resolve(fileName); |
| 160 | |
| 161 | const decodedMap = magicString.generateDecodedMap({}); |
| 162 | map = collapseSourcemaps( |
| 163 | resultingFile, |
| 164 | decodedMap, |
| 165 | usedModules, |
| 166 | sourcemapChain, |
no test coverage detected
searching dependent graphs…