1 | (function (factory) {
|
---|
2 | if (typeof module === "object" && typeof module.exports === "object") {
|
---|
3 | var v = factory(require, exports);
|
---|
4 | if (v !== undefined) module.exports = v;
|
---|
5 | }
|
---|
6 | else if (typeof define === "function" && define.amd) {
|
---|
7 | define("@angular/compiler-cli/ngcc/src/rendering/source_maps", ["require", "exports", "convert-source-map", "@angular/compiler-cli/src/ngtsc/file_system", "@angular/compiler-cli/src/ngtsc/sourcemaps"], factory);
|
---|
8 | }
|
---|
9 | })(function (require, exports) {
|
---|
10 | "use strict";
|
---|
11 | Object.defineProperty(exports, "__esModule", { value: true });
|
---|
12 | exports.renderSourceAndMap = void 0;
|
---|
13 | /**
|
---|
14 | * @license
|
---|
15 | * Copyright Google LLC All Rights Reserved.
|
---|
16 | *
|
---|
17 | * Use of this source code is governed by an MIT-style license that can be
|
---|
18 | * found in the LICENSE file at https://angular.io/license
|
---|
19 | */
|
---|
20 | var convert_source_map_1 = require("convert-source-map");
|
---|
21 | var file_system_1 = require("@angular/compiler-cli/src/ngtsc/file_system");
|
---|
22 | var sourcemaps_1 = require("@angular/compiler-cli/src/ngtsc/sourcemaps");
|
---|
23 | /**
|
---|
24 | * Merge the input and output source-maps, replacing the source-map comment in the output file
|
---|
25 | * with an appropriate source-map comment pointing to the merged source-map.
|
---|
26 | */
|
---|
27 | function renderSourceAndMap(logger, fs, sourceFile, generatedMagicString) {
|
---|
28 | var _a;
|
---|
29 | var sourceFilePath = file_system_1.absoluteFromSourceFile(sourceFile);
|
---|
30 | var sourceMapPath = file_system_1.absoluteFrom(sourceFilePath + ".map");
|
---|
31 | var generatedContent = generatedMagicString.toString();
|
---|
32 | var generatedMap = generatedMagicString.generateMap({ file: sourceFilePath, source: sourceFilePath, includeContent: true });
|
---|
33 | try {
|
---|
34 | var loader = new sourcemaps_1.SourceFileLoader(fs, logger, {});
|
---|
35 | var generatedFile = loader.loadSourceFile(sourceFilePath, generatedContent, { map: generatedMap, mapPath: sourceMapPath });
|
---|
36 | var rawMergedMap = generatedFile.renderFlattenedSourceMap();
|
---|
37 | var mergedMap = convert_source_map_1.fromObject(rawMergedMap);
|
---|
38 | var originalFile = loader.loadSourceFile(sourceFilePath, generatedMagicString.original);
|
---|
39 | if (originalFile.rawMap === null && !sourceFile.isDeclarationFile ||
|
---|
40 | ((_a = originalFile.rawMap) === null || _a === void 0 ? void 0 : _a.origin) === sourcemaps_1.ContentOrigin.Inline) {
|
---|
41 | // We render an inline source map if one of:
|
---|
42 | // * there was no input source map and this is not a typings file;
|
---|
43 | // * the input source map exists and was inline.
|
---|
44 | //
|
---|
45 | // We do not generate inline source maps for typings files unless there explicitly was one in
|
---|
46 | // the input file because these inline source maps can be very large and it impacts on the
|
---|
47 | // performance of IDEs that need to read them to provide intellisense etc.
|
---|
48 | return [
|
---|
49 | { path: sourceFilePath, contents: generatedFile.contents + "\n" + mergedMap.toComment() }
|
---|
50 | ];
|
---|
51 | }
|
---|
52 | var sourceMapComment = convert_source_map_1.generateMapFileComment(fs.basename(sourceFilePath) + ".map");
|
---|
53 | return [
|
---|
54 | { path: sourceFilePath, contents: generatedFile.contents + "\n" + sourceMapComment },
|
---|
55 | { path: sourceMapPath, contents: mergedMap.toJSON() }
|
---|
56 | ];
|
---|
57 | }
|
---|
58 | catch (e) {
|
---|
59 | logger.error("Error when flattening the source-map \"" + sourceMapPath + "\" for \"" + sourceFilePath + "\": " + e.toString());
|
---|
60 | return [
|
---|
61 | { path: sourceFilePath, contents: generatedContent },
|
---|
62 | { path: sourceMapPath, contents: convert_source_map_1.fromObject(generatedMap).toJSON() },
|
---|
63 | ];
|
---|
64 | }
|
---|
65 | }
|
---|
66 | exports.renderSourceAndMap = renderSourceAndMap;
|
---|
67 | });
|
---|
68 | //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic291cmNlX21hcHMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi8uLi8uLi8uLi8uLi9wYWNrYWdlc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