(file, asset, options, registry)
| 121 | * @returns {{ source: string, sourceMap: RawSourceMap, mapSource: Source } | undefined} extracted pair or `undefined` when no map is recoverable |
| 122 | */ |
| 123 | const extractSourceAndMap = (file, asset, options, registry) => { |
| 124 | /** @type {string | Buffer} */ |
| 125 | let source; |
| 126 | /** @type {null | RawSourceMap} */ |
| 127 | let sourceMap; |
| 128 | if (asset.sourceAndMap) { |
| 129 | const sourceAndMap = asset.sourceAndMap(options); |
| 130 | source = sourceAndMap.source; |
| 131 | sourceMap = sourceAndMap.map; |
| 132 | } else { |
| 133 | source = asset.source(); |
| 134 | sourceMap = asset.map(options); |
| 135 | } |
| 136 | class="cm">// Bail before touching the registry if we can't return a usable string |
| 137 | class="cm">// source — pinning a non-string-producing asset would only waste the slot. |
| 138 | if (typeof source !== class="st">"string") return; |
| 139 | if (sourceMap) { |
| 140 | class="cm">// The current asset still owns the original map — pin a reference so |
| 141 | class="cm">// that a later plugin instance (which will see a rewrapped asset |
| 142 | class="cm">// without a map) can recover it on demand. |
| 143 | if (!registry.has(file)) registry.set(file, asset); |
| 144 | return { source, sourceMap, mapSource: asset }; |
| 145 | } |
| 146 | class="cm">// The current asset (typically a `RawSource` left by an earlier |
| 147 | class="cm">// SourceMapDevToolPlugin instance) has no internal map. Re-extract |
| 148 | class="cm">// the map from the original Source we pinned earlier. We keep using |
| 149 | class="cm">// `source` from the current asset so that any prior wrappers (e.g. |
| 150 | class="cm">// appended sourceMappingURL comments) are preserved. |
| 151 | const original = registry.get(file); |
| 152 | if (!original) return; |
| 153 | sourceMap = original.sourceAndMap |
| 154 | ? original.sourceAndMap(options).map |
| 155 | : original.map(options); |
| 156 | if (!sourceMap) return; |
| 157 | return { source, sourceMap, mapSource: original }; |
| 158 | }; |
| 159 | |
| 160 | /** |
| 161 | * Creating {@link SourceMapTask} for given file |
no test coverage detected