chunk-OULZQUKT.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419
  1. import {createRequire as __cjsCompatRequire} from 'module';
  2. const require = __cjsCompatRequire(import.meta.url);
  3. // bazel-out/darwin-fastbuild/bin/packages/compiler-cli/src/ngtsc/sourcemaps/src/source_file.mjs
  4. import { decode, encode } from "@jridgewell/sourcemap-codec";
  5. import mapHelpers from "convert-source-map";
  6. // bazel-out/darwin-fastbuild/bin/packages/compiler-cli/src/ngtsc/sourcemaps/src/segment_marker.mjs
  7. function compareSegments(a, b) {
  8. return a.position - b.position;
  9. }
  10. function offsetSegment(startOfLinePositions, marker, offset) {
  11. if (offset === 0) {
  12. return marker;
  13. }
  14. let line = marker.line;
  15. const position = marker.position + offset;
  16. while (line < startOfLinePositions.length - 1 && startOfLinePositions[line + 1] <= position) {
  17. line++;
  18. }
  19. while (line > 0 && startOfLinePositions[line] > position) {
  20. line--;
  21. }
  22. const column = position - startOfLinePositions[line];
  23. return { line, column, position, next: void 0 };
  24. }
  25. // bazel-out/darwin-fastbuild/bin/packages/compiler-cli/src/ngtsc/sourcemaps/src/source_file.mjs
  26. function removeSourceMapComments(contents) {
  27. return mapHelpers.removeMapFileComments(mapHelpers.removeComments(contents)).replace(/\n\n$/, "\n");
  28. }
  29. var SourceFile = class {
  30. constructor(sourcePath, contents, rawMap, sources, fs) {
  31. this.sourcePath = sourcePath;
  32. this.contents = contents;
  33. this.rawMap = rawMap;
  34. this.sources = sources;
  35. this.fs = fs;
  36. this.contents = removeSourceMapComments(contents);
  37. this.startOfLinePositions = computeStartOfLinePositions(this.contents);
  38. this.flattenedMappings = this.flattenMappings();
  39. }
  40. renderFlattenedSourceMap() {
  41. const sources = new IndexedMap();
  42. const names = new IndexedSet();
  43. const mappings = [];
  44. const sourcePathDir = this.fs.dirname(this.sourcePath);
  45. const relativeSourcePathCache = new Cache((input) => this.fs.relative(sourcePathDir, input));
  46. for (const mapping of this.flattenedMappings) {
  47. const sourceIndex = sources.set(relativeSourcePathCache.get(mapping.originalSource.sourcePath), mapping.originalSource.contents);
  48. const mappingArray = [
  49. mapping.generatedSegment.column,
  50. sourceIndex,
  51. mapping.originalSegment.line,
  52. mapping.originalSegment.column
  53. ];
  54. if (mapping.name !== void 0) {
  55. const nameIndex = names.add(mapping.name);
  56. mappingArray.push(nameIndex);
  57. }
  58. const line = mapping.generatedSegment.line;
  59. while (line >= mappings.length) {
  60. mappings.push([]);
  61. }
  62. mappings[line].push(mappingArray);
  63. }
  64. const sourceMap = {
  65. version: 3,
  66. file: this.fs.relative(sourcePathDir, this.sourcePath),
  67. sources: sources.keys,
  68. names: names.values,
  69. mappings: encode(mappings),
  70. sourcesContent: sources.values
  71. };
  72. return sourceMap;
  73. }
  74. getOriginalLocation(line, column) {
  75. if (this.flattenedMappings.length === 0) {
  76. return null;
  77. }
  78. let position;
  79. if (line < this.startOfLinePositions.length) {
  80. position = this.startOfLinePositions[line] + column;
  81. } else {
  82. position = this.contents.length;
  83. }
  84. const locationSegment = { line, column, position, next: void 0 };
  85. let mappingIndex = findLastMappingIndexBefore(this.flattenedMappings, locationSegment, false, 0);
  86. if (mappingIndex < 0) {
  87. mappingIndex = 0;
  88. }
  89. const { originalSegment, originalSource, generatedSegment } = this.flattenedMappings[mappingIndex];
  90. const offset = locationSegment.position - generatedSegment.position;
  91. const offsetOriginalSegment = offsetSegment(originalSource.startOfLinePositions, originalSegment, offset);
  92. return {
  93. file: originalSource.sourcePath,
  94. line: offsetOriginalSegment.line,
  95. column: offsetOriginalSegment.column
  96. };
  97. }
  98. flattenMappings() {
  99. const mappings = parseMappings(this.rawMap && this.rawMap.map, this.sources, this.startOfLinePositions);
  100. ensureOriginalSegmentLinks(mappings);
  101. const flattenedMappings = [];
  102. for (let mappingIndex = 0; mappingIndex < mappings.length; mappingIndex++) {
  103. const aToBmapping = mappings[mappingIndex];
  104. const bSource = aToBmapping.originalSource;
  105. if (bSource.flattenedMappings.length === 0) {
  106. flattenedMappings.push(aToBmapping);
  107. continue;
  108. }
  109. const incomingStart = aToBmapping.originalSegment;
  110. const incomingEnd = incomingStart.next;
  111. let outgoingStartIndex = findLastMappingIndexBefore(bSource.flattenedMappings, incomingStart, false, 0);
  112. if (outgoingStartIndex < 0) {
  113. outgoingStartIndex = 0;
  114. }
  115. const outgoingEndIndex = incomingEnd !== void 0 ? findLastMappingIndexBefore(bSource.flattenedMappings, incomingEnd, true, outgoingStartIndex) : bSource.flattenedMappings.length - 1;
  116. for (let bToCmappingIndex = outgoingStartIndex; bToCmappingIndex <= outgoingEndIndex; bToCmappingIndex++) {
  117. const bToCmapping = bSource.flattenedMappings[bToCmappingIndex];
  118. flattenedMappings.push(mergeMappings(this, aToBmapping, bToCmapping));
  119. }
  120. }
  121. return flattenedMappings;
  122. }
  123. };
  124. function findLastMappingIndexBefore(mappings, marker, exclusive, lowerIndex) {
  125. let upperIndex = mappings.length - 1;
  126. const test = exclusive ? -1 : 0;
  127. if (compareSegments(mappings[lowerIndex].generatedSegment, marker) > test) {
  128. return -1;
  129. }
  130. let matchingIndex = -1;
  131. while (lowerIndex <= upperIndex) {
  132. const index = upperIndex + lowerIndex >> 1;
  133. if (compareSegments(mappings[index].generatedSegment, marker) <= test) {
  134. matchingIndex = index;
  135. lowerIndex = index + 1;
  136. } else {
  137. upperIndex = index - 1;
  138. }
  139. }
  140. return matchingIndex;
  141. }
  142. function mergeMappings(generatedSource, ab, bc) {
  143. const name = bc.name || ab.name;
  144. const diff = compareSegments(bc.generatedSegment, ab.originalSegment);
  145. if (diff > 0) {
  146. return {
  147. name,
  148. generatedSegment: offsetSegment(generatedSource.startOfLinePositions, ab.generatedSegment, diff),
  149. originalSource: bc.originalSource,
  150. originalSegment: bc.originalSegment
  151. };
  152. } else {
  153. return {
  154. name,
  155. generatedSegment: ab.generatedSegment,
  156. originalSource: bc.originalSource,
  157. originalSegment: offsetSegment(bc.originalSource.startOfLinePositions, bc.originalSegment, -diff)
  158. };
  159. }
  160. }
  161. function parseMappings(rawMap, sources, generatedSourceStartOfLinePositions) {
  162. if (rawMap === null) {
  163. return [];
  164. }
  165. const rawMappings = decode(rawMap.mappings);
  166. if (rawMappings === null) {
  167. return [];
  168. }
  169. const mappings = [];
  170. for (let generatedLine = 0; generatedLine < rawMappings.length; generatedLine++) {
  171. const generatedLineMappings = rawMappings[generatedLine];
  172. for (const rawMapping of generatedLineMappings) {
  173. if (rawMapping.length >= 4) {
  174. const originalSource = sources[rawMapping[1]];
  175. if (originalSource === null || originalSource === void 0) {
  176. continue;
  177. }
  178. const generatedColumn = rawMapping[0];
  179. const name = rawMapping.length === 5 ? rawMap.names[rawMapping[4]] : void 0;
  180. const line = rawMapping[2];
  181. const column = rawMapping[3];
  182. const generatedSegment = {
  183. line: generatedLine,
  184. column: generatedColumn,
  185. position: generatedSourceStartOfLinePositions[generatedLine] + generatedColumn,
  186. next: void 0
  187. };
  188. const originalSegment = {
  189. line,
  190. column,
  191. position: originalSource.startOfLinePositions[line] + column,
  192. next: void 0
  193. };
  194. mappings.push({ name, generatedSegment, originalSegment, originalSource });
  195. }
  196. }
  197. }
  198. return mappings;
  199. }
  200. function extractOriginalSegments(mappings) {
  201. const originalSegments = /* @__PURE__ */ new Map();
  202. for (const mapping of mappings) {
  203. const originalSource = mapping.originalSource;
  204. if (!originalSegments.has(originalSource)) {
  205. originalSegments.set(originalSource, []);
  206. }
  207. const segments = originalSegments.get(originalSource);
  208. segments.push(mapping.originalSegment);
  209. }
  210. originalSegments.forEach((segmentMarkers) => segmentMarkers.sort(compareSegments));
  211. return originalSegments;
  212. }
  213. function ensureOriginalSegmentLinks(mappings) {
  214. const segmentsBySource = extractOriginalSegments(mappings);
  215. segmentsBySource.forEach((markers) => {
  216. for (let i = 0; i < markers.length - 1; i++) {
  217. markers[i].next = markers[i + 1];
  218. }
  219. });
  220. }
  221. function computeStartOfLinePositions(str) {
  222. const NEWLINE_MARKER_OFFSET = 1;
  223. const lineLengths = computeLineLengths(str);
  224. const startPositions = [0];
  225. for (let i = 0; i < lineLengths.length - 1; i++) {
  226. startPositions.push(startPositions[i] + lineLengths[i] + NEWLINE_MARKER_OFFSET);
  227. }
  228. return startPositions;
  229. }
  230. function computeLineLengths(str) {
  231. return str.split(/\n/).map((s) => s.length);
  232. }
  233. var IndexedMap = class {
  234. constructor() {
  235. this.map = /* @__PURE__ */ new Map();
  236. this.keys = [];
  237. this.values = [];
  238. }
  239. set(key, value) {
  240. if (this.map.has(key)) {
  241. return this.map.get(key);
  242. }
  243. const index = this.values.push(value) - 1;
  244. this.keys.push(key);
  245. this.map.set(key, index);
  246. return index;
  247. }
  248. };
  249. var IndexedSet = class {
  250. constructor() {
  251. this.map = /* @__PURE__ */ new Map();
  252. this.values = [];
  253. }
  254. add(value) {
  255. if (this.map.has(value)) {
  256. return this.map.get(value);
  257. }
  258. const index = this.values.push(value) - 1;
  259. this.map.set(value, index);
  260. return index;
  261. }
  262. };
  263. var Cache = class {
  264. constructor(computeFn) {
  265. this.computeFn = computeFn;
  266. this.map = /* @__PURE__ */ new Map();
  267. }
  268. get(input) {
  269. if (!this.map.has(input)) {
  270. this.map.set(input, this.computeFn(input));
  271. }
  272. return this.map.get(input);
  273. }
  274. };
  275. // bazel-out/darwin-fastbuild/bin/packages/compiler-cli/src/ngtsc/sourcemaps/src/source_file_loader.mjs
  276. import mapHelpers2 from "convert-source-map";
  277. // bazel-out/darwin-fastbuild/bin/packages/compiler-cli/src/ngtsc/sourcemaps/src/content_origin.mjs
  278. var ContentOrigin;
  279. (function(ContentOrigin2) {
  280. ContentOrigin2[ContentOrigin2["Provided"] = 0] = "Provided";
  281. ContentOrigin2[ContentOrigin2["Inline"] = 1] = "Inline";
  282. ContentOrigin2[ContentOrigin2["FileSystem"] = 2] = "FileSystem";
  283. })(ContentOrigin || (ContentOrigin = {}));
  284. // bazel-out/darwin-fastbuild/bin/packages/compiler-cli/src/ngtsc/sourcemaps/src/source_file_loader.mjs
  285. var SCHEME_MATCHER = /^([a-z][a-z0-9.-]*):\/\//i;
  286. var SourceFileLoader = class {
  287. constructor(fs, logger, schemeMap) {
  288. this.fs = fs;
  289. this.logger = logger;
  290. this.schemeMap = schemeMap;
  291. this.currentPaths = [];
  292. }
  293. loadSourceFile(sourcePath, contents = null, mapAndPath = null) {
  294. const contentsOrigin = contents !== null ? ContentOrigin.Provided : ContentOrigin.FileSystem;
  295. const sourceMapInfo = mapAndPath && { origin: ContentOrigin.Provided, ...mapAndPath };
  296. return this.loadSourceFileInternal(sourcePath, contents, contentsOrigin, sourceMapInfo);
  297. }
  298. loadSourceFileInternal(sourcePath, contents, sourceOrigin, sourceMapInfo) {
  299. const previousPaths = this.currentPaths.slice();
  300. try {
  301. if (contents === null) {
  302. if (!this.fs.exists(sourcePath)) {
  303. return null;
  304. }
  305. contents = this.readSourceFile(sourcePath);
  306. }
  307. if (sourceMapInfo === null) {
  308. sourceMapInfo = this.loadSourceMap(sourcePath, contents, sourceOrigin);
  309. }
  310. let sources = [];
  311. if (sourceMapInfo !== null) {
  312. const basePath = sourceMapInfo.mapPath || sourcePath;
  313. sources = this.processSources(basePath, sourceMapInfo);
  314. }
  315. return new SourceFile(sourcePath, contents, sourceMapInfo, sources, this.fs);
  316. } catch (e) {
  317. this.logger.warn(`Unable to fully load ${sourcePath} for source-map flattening: ${e.message}`);
  318. return null;
  319. } finally {
  320. this.currentPaths = previousPaths;
  321. }
  322. }
  323. loadSourceMap(sourcePath, sourceContents, sourceOrigin) {
  324. const lastLine = this.getLastNonEmptyLine(sourceContents);
  325. const inline = mapHelpers2.commentRegex.exec(lastLine);
  326. if (inline !== null) {
  327. return {
  328. map: mapHelpers2.fromComment(inline.pop()).sourcemap,
  329. mapPath: null,
  330. origin: ContentOrigin.Inline
  331. };
  332. }
  333. if (sourceOrigin === ContentOrigin.Inline) {
  334. return null;
  335. }
  336. const external = mapHelpers2.mapFileCommentRegex.exec(lastLine);
  337. if (external) {
  338. try {
  339. const fileName = external[1] || external[2];
  340. const externalMapPath = this.fs.resolve(this.fs.dirname(sourcePath), fileName);
  341. return {
  342. map: this.readRawSourceMap(externalMapPath),
  343. mapPath: externalMapPath,
  344. origin: ContentOrigin.FileSystem
  345. };
  346. } catch (e) {
  347. this.logger.warn(`Unable to fully load ${sourcePath} for source-map flattening: ${e.message}`);
  348. return null;
  349. }
  350. }
  351. const impliedMapPath = this.fs.resolve(sourcePath + ".map");
  352. if (this.fs.exists(impliedMapPath)) {
  353. return {
  354. map: this.readRawSourceMap(impliedMapPath),
  355. mapPath: impliedMapPath,
  356. origin: ContentOrigin.FileSystem
  357. };
  358. }
  359. return null;
  360. }
  361. processSources(basePath, { map, origin: sourceMapOrigin }) {
  362. const sourceRoot = this.fs.resolve(this.fs.dirname(basePath), this.replaceSchemeWithPath(map.sourceRoot || ""));
  363. return map.sources.map((source, index) => {
  364. const path = this.fs.resolve(sourceRoot, this.replaceSchemeWithPath(source));
  365. const content = map.sourcesContent && map.sourcesContent[index] || null;
  366. const sourceOrigin = content !== null && sourceMapOrigin !== ContentOrigin.Provided ? ContentOrigin.Inline : ContentOrigin.FileSystem;
  367. return this.loadSourceFileInternal(path, content, sourceOrigin, null);
  368. });
  369. }
  370. readSourceFile(sourcePath) {
  371. this.trackPath(sourcePath);
  372. return this.fs.readFile(sourcePath);
  373. }
  374. readRawSourceMap(mapPath) {
  375. this.trackPath(mapPath);
  376. return JSON.parse(this.fs.readFile(mapPath));
  377. }
  378. trackPath(path) {
  379. if (this.currentPaths.includes(path)) {
  380. throw new Error(`Circular source file mapping dependency: ${this.currentPaths.join(" -> ")} -> ${path}`);
  381. }
  382. this.currentPaths.push(path);
  383. }
  384. getLastNonEmptyLine(contents) {
  385. let trailingWhitespaceIndex = contents.length - 1;
  386. while (trailingWhitespaceIndex > 0 && (contents[trailingWhitespaceIndex] === "\n" || contents[trailingWhitespaceIndex] === "\r")) {
  387. trailingWhitespaceIndex--;
  388. }
  389. let lastRealLineIndex = contents.lastIndexOf("\n", trailingWhitespaceIndex - 1);
  390. if (lastRealLineIndex === -1) {
  391. lastRealLineIndex = 0;
  392. }
  393. return contents.slice(lastRealLineIndex + 1);
  394. }
  395. replaceSchemeWithPath(path) {
  396. return path.replace(SCHEME_MATCHER, (_, scheme) => this.schemeMap[scheme.toLowerCase()] || "");
  397. }
  398. };
  399. export {
  400. SourceFile,
  401. SourceFileLoader
  402. };
  403. /**
  404. * @license
  405. * Copyright Google LLC All Rights Reserved.
  406. *
  407. * Use of this source code is governed by an MIT-style license that can be
  408. * found in the LICENSE file at https://angular.io/license
  409. */
  410. //# sourceMappingURL=chunk-OULZQUKT.js.map