chunk-5UDS2TPQ.js 15 KB

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