({
ast,
code,
customTransformCache,
originalCode,
originalSourcemap,
resolvedIds,
sourcemapChain,
transformDependencies,
transformFiles,
safeVariableNames,
...moduleOptions
}: TransformModuleJSON & {
resolvedIds?: ResolvedIdMap;
transformFiles?: EmittedFile[] | undefined;
})
| 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), |
no test coverage detected