MCPcopy
hub / github.com/rollup/rollup / setSource

Method setSource

src/Module.ts:839–964  ·  view source on GitHub ↗
({
		ast,
		code,
		customTransformCache,
		originalCode,
		originalSourcemap,
		resolvedIds,
		sourcemapChain,
		transformDependencies,
		transformFiles,
		safeVariableNames,
		...moduleOptions
	}: TransformModuleJSON & {
		resolvedIds?: ResolvedIdMap;
		transformFiles?: EmittedFile[] | undefined;
	})

Source from the content-addressed store, hash-verified

837 }
838
839 async setSource({
840 ast,
841 code,
842 customTransformCache,
843 originalCode,
844 originalSourcemap,
845 resolvedIds,
846 sourcemapChain,
847 transformDependencies,
848 transformFiles,
849 safeVariableNames,
850 ...moduleOptions
851 }: TransformModuleJSON & {
852 resolvedIds?: ResolvedIdMap;
853 transformFiles?: EmittedFile[] | undefined;
854 }): Promise<void> {
855 timeStart('generate ast', 3);
856 if (code.startsWith('#!')) {
857 const shebangEndPosition = code.indexOf('\n');
858 this.shebang = code.slice(2, shebangEndPosition);
859 }
860
861 this.info.code = code;
862 this.info.safeVariableNames = safeVariableNames;
863 this.originalCode = originalCode;
864
865 // We need to call decodedSourcemap on the input in case they were hydrated from json in the cache and don't
866 // have the lazy evaluation cache configured. Right now this isn't enforced by the type system because the
867 // RollupCache stores `ExistingDecodedSourcemap` instead of `ExistingRawSourcemap`
868 this.originalSourcemap = decodedSourcemap(originalSourcemap);
869 this.sourcemapChain = sourcemapChain.map(mapOrMissing =>
870 mapOrMissing.missing ? mapOrMissing : decodedSourcemap(mapOrMissing)
871 );
872
873 // If coming from cache and this value is already fully decoded, we want to re-encode here to save memory.
874 resetSourcemapCache(this.originalSourcemap, this.sourcemapChain);
875
876 if (transformFiles) {
877 this.transformFiles = transformFiles;
878 }
879 this.transformDependencies = transformDependencies;
880 this.customTransformCache = customTransformCache;
881 this.updateOptions(moduleOptions);
882
883 this.resolvedIds = resolvedIds ?? Object.create(null);
884
885 // By default, `id` is the file name. Custom resolvers and loaders
886 // can change that, but it makes sense to use it for the source file name
887 const fileName = this.id;
888
889 this.magicString = new MagicString(code, {
890 filename: (this.excludeFromSourcemap ? null : fileName)!, // don't include plugin helpers in sourcemap
891 indentExclusionRanges: []
892 });
893
894 this.astContext = {
895 addDynamicImport: this.addDynamicImport.bind(this),
896 addExport: this.addExport.bind(this),

Callers 1

addModuleSourceMethod · 0.80

Calls 12

updateOptionsMethod · 0.95
tryParseMethod · 0.95
decodedSourcemapFunction · 0.90
resetSourcemapCacheFunction · 0.90
convertProgramFunction · 0.90
parseAsyncFunction · 0.85
getMethod · 0.80
bindMethod · 0.65
hasMethod · 0.65
setMethod · 0.65
parseNodeMethod · 0.45

Tested by

no test coverage detected