MCPcopy
hub / github.com/microsoft/vscode-js-debug / constructor

Method constructor

src/targets/sourceMapOverrides.ts:37–103  ·  view source on GitHub ↗
(sourceMapOverrides: { [from: string]: string }, private readonly logger: ILogger)

Source from the content-addressed store, hash-verified

35 private readonly replacers: [RegExp, string][] = [];
36
37 constructor(sourceMapOverrides: { [from: string]: string }, private readonly logger: ILogger) {
38 // Sort the overrides by length, large to small
39 const sortedOverrideKeys = Object.keys(sourceMapOverrides).sort(
40 (a, b) => b.replace(nonCapturingGroup, '*').length - a.replace(nonCapturingGroup, '*').length,
41 );
42
43 // Iterate the key/vals, only apply the first one that matches.
44 for (const leftPatternRaw of sortedOverrideKeys) {
45 let rightPattern = sourceMapOverrides[leftPatternRaw];
46 if (!rightPattern.includes('*') && /\$[0-9'`&]/.test(rightPattern)) {
47 this.replacers.push([new RegExp(`^${leftPatternRaw}$`, 'i'), rightPattern]);
48 continue;
49 }
50
51 const leftPattern = forceForwardSlashes(leftPatternRaw);
52 const entryStr = `"${leftPattern}": "${rightPattern}"`;
53 const capturedGroups = occurencesInString(capturingGroupRe, leftPattern)
54 - occurencesInString(nonCapturingGroupRe, leftPattern);
55
56 if (capturedGroups > 1) {
57 logger.warn(
58 LogTag.RuntimeSourceMap,
59 `Warning: only one asterisk allowed in a sourceMapPathOverrides entry - ${entryStr}`,
60 );
61 continue;
62 }
63
64 if (occurencesInString(capturingGroupRe, rightPattern) > capturedGroups) {
65 logger.warn(
66 LogTag.RuntimeSourceMap,
67 `The right side of a sourceMapPathOverrides entry must have 0 or 1 asterisks - ${entryStr}}`,
68 );
69 continue;
70 }
71
72 let reSource = '^';
73 let leftIndex = 0;
74 anyGroupRe.lastIndex = 0;
75
76 while (true) {
77 const next = anyGroupRe.exec(leftPattern);
78 reSource += escapeRegexSpecialChars(leftPattern.slice(leftIndex, next?.index), '/');
79
80 if (!next) {
81 break;
82 }
83
84 if (next[0] === capturingGroup) {
85 reSource += '(.*?)';
86 } else {
87 reSource += '.*?';
88 }
89
90 leftIndex = next.index + next[0].length;
91 }
92
93 if (capturedGroups === 0) {
94 reSource += `([\\/\\\\].*)?`;

Callers

nothing calls this directly

Calls 8

forceForwardSlashesFunction · 0.90
escapeRegexSpecialCharsFunction · 0.90
occurencesInStringFunction · 0.85
testMethod · 0.80
keysMethod · 0.65
replaceMethod · 0.65
pushMethod · 0.65
warnMethod · 0.65

Tested by

no test coverage detected