Skip to content

Commit 7c92bec

Browse files
alan-agius4filipesilva
authored andcommitted
refactor(@angular-devkit/build-angular): remove workaround for fidelity and performance of babel sourcemaps
With this change we remove the workaround for fidelity and performance of babel sourcemaps as this is no longer needed as Babel now uses `@ampproject/remapping` to merge sourcemaps. See babel/babel#14209 for more context.
1 parent 2fb099c commit 7c92bec

File tree

1 file changed

+1
-26
lines changed

1 file changed

+1
-26
lines changed

packages/angular_devkit/build_angular/src/babel/webpack-loader.ts

+1-26
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import remapping from '@ampproject/remapping';
109
import { custom } from 'babel-loader';
1110
import { ScriptTarget } from 'typescript';
1211
import { loadEsmModule } from '../utils/load-esm';
@@ -23,9 +22,6 @@ interface AngularCustomOptions extends Omit<ApplicationPresetOptions, 'instrumen
2322

2423
export type AngularBabelLoaderOptions = AngularCustomOptions & Record<string, unknown>;
2524

26-
// Extract Sourcemap input type from the remapping function since it is not currently exported
27-
type SourceMapInput = Exclude<Parameters<typeof remapping>[0], unknown[]>;
28-
2925
/**
3026
* Cached instance of the compiler-cli linker's needsLinking function.
3127
*/
@@ -218,7 +214,7 @@ export default custom<ApplicationPresetOptions>(() => {
218214
// Using `false` disables babel from attempting to locate sourcemaps or process any inline maps.
219215
// The babel types do not include the false option even though it is valid
220216
// eslint-disable-next-line @typescript-eslint/no-explicit-any
221-
inputSourceMap: false as any,
217+
inputSourceMap: configuration.options.inputSourceMap ?? (false as any),
222218
presets: [
223219
...(configuration.options.presets || []),
224220
[
@@ -242,26 +238,5 @@ export default custom<ApplicationPresetOptions>(() => {
242238
],
243239
};
244240
},
245-
result(result, { map: inputSourceMap }) {
246-
if (result.map && inputSourceMap) {
247-
// Merge the intermediate sourcemap generated by babel with the input source map.
248-
// The casting is required due to slight differences in the types for babel and
249-
// `@ampproject/remapping` source map objects but both are compatible with Webpack.
250-
// This method for merging is used because it provides more accurate output
251-
// and is faster while using less memory.
252-
result.map = {
253-
// Convert the SourceMap back to simple plain object.
254-
// This is needed because otherwise code-coverage will fail with `don't know how to turn this value into a node`
255-
// Which is thrown by Babel if it is invoked again from `istanbul-lib-instrument`.
256-
// https://github.com/babel/babel/blob/780aa48d2a34dc55f556843074b6aed45e7eabeb/packages/babel-types/src/converters/valueToNode.ts#L115-L130
257-
...(remapping(
258-
[result.map as SourceMapInput, inputSourceMap as SourceMapInput],
259-
() => null,
260-
) as typeof result.map),
261-
};
262-
}
263-
264-
return result;
265-
},
266241
};
267242
});

0 commit comments

Comments
 (0)