MCPcopy
hub / github.com/rollup/rollup / transformReducer

Function transformReducer

src/utils/transform.ts:52–97  ·  view source on GitHub ↗
(
		this: PluginContext,
		previousCode: string,
		result: TransformResult,
		plugin: Plugin
	)

Source from the content-addressed store, hash-verified

50 let currentSource = source.code;
51
52 function transformReducer(
53 this: PluginContext,
54 previousCode: string,
55 result: TransformResult,
56 plugin: Plugin
57 ): string {
58 let code: string;
59 let map: string | ExistingRawSourceMap | { mappings: '' } | null | undefined;
60 if (typeof result === 'string') {
61 code = result;
62 } else if (result && typeof result === 'object') {
63 module.updateOptions(result);
64 if (result.code == null) {
65 if (result.map || result.ast) {
66 options.onLog(LOGLEVEL_WARN, logNoTransformMapOrAstWithoutCode(plugin.name));
67 }
68 return previousCode;
69 }
70 if (result.attributes) {
71 warnDeprecation(
72 'Returning attributes from the "transform" hook is forbidden.',
73 URL_TRANSFORM,
74 false,
75 options
76 );
77 }
78 ({ code, map, ast } = result);
79 } else {
80 return previousCode;
81 }
82
83 // strict null check allows 'null' maps to not be pushed to the chain,
84 // while 'undefined' gets the missing map warning
85 if (map !== null) {
86 sourcemapChain.push(
87 decodedSourcemap(typeof map === 'string' ? JSON.parse(map) : map) || {
88 missing: true,
89 plugin: plugin.name
90 }
91 );
92 }
93
94 currentSource = code;
95
96 return code;
97 }
98
99 const getLogHandler =
100 (handler: LoggingFunctionWithPosition): LoggingFunctionWithPosition =>

Callers

nothing calls this directly

Calls 5

warnDeprecationFunction · 0.90
decodedSourcemapFunction · 0.90
updateOptionsMethod · 0.80
pushMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…