( source: SourceDescription, module: Module, pluginDriver: PluginDriver, options: NormalizedInputOptions )
| 31 | import { URL_TRANSFORM } from './urls'; |
| 32 | |
| 33 | export 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 | } |
no test coverage detected
searching dependent graphs…