MCPcopy
hub / github.com/rollup/rollup / transform

Function transform

src/utils/transform.ts:33–198  ·  view source on GitHub ↗
(
	source: SourceDescription,
	module: Module,
	pluginDriver: PluginDriver,
	options: NormalizedInputOptions
)

Source from the content-addressed store, hash-verified

31import { URL_TRANSFORM } from './urls';
32
33export default async function transform(
34 source: SourceDescription,
35 module: Module,
36 pluginDriver: PluginDriver,
37 options: NormalizedInputOptions
38): Promise<TransformModuleJSON> {
39 const id = module.id;
40 const sourcemapChain: DecodedSourceMapOrMissing[] = [];
41
42 let originalSourcemap = source.map === null ? null : decodedSourcemap(source.map);
43 const originalCode = source.code;
44 let ast = source.ast;
45 const transformDependencies: string[] = [];
46 const emittedFiles: EmittedFile[] = [];
47 let customTransformCache = false;
48 const useCustomTransformCache = () => (customTransformCache = true);
49 let pluginName = '';
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 }

Callers 1

addModuleSourceMethod · 0.50

Calls 6

decodedSourcemapFunction · 0.90
getTrackedPluginCacheFunction · 0.90
errorFunction · 0.90
logPluginErrorFunction · 0.90
hookReduceArg0Method · 0.80
getLogHandlerFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…