MCPcopy
hub / github.com/rollup/rollup / transformChunk

Function transformChunk

src/utils/renderChunks.ts:109–200  ·  view source on GitHub ↗
(
	magicString: MagicStringBundle,
	fileName: string,
	usedModules: Module[],
	chunkGraph: Record<string, RenderedChunk>,
	options: NormalizedOutputOptions,
	outputPluginDriver: PluginDriver,
	log: LogHandler
)

Source from the content-addressed store, hash-verified

107}
108
109async 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,

Calls 9

decodedSourcemapFunction · 0.90
resolveFunction · 0.90
collapseSourcemapsFunction · 0.90
errorFunction · 0.90
logFailedValidationFunction · 0.90
normalizeFunction · 0.90
hookReduceArg0Method · 0.80
toStringMethod · 0.80
pushMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…