MCPcopy
hub / github.com/eslint/eslint / buildSource

Function buildSource

tools/code-sample-minimizer.js:109–123  ·  view source on GitHub ↗

* Applies all committed modifications (plus an optional pending one) to the * original source text and returns the result. Modifications are applied in * reverse source order so that each offset remains valid when applied. * @param {{ start: number, end: number, replacement: string } | null} [

(pendingMod)

Source from the content-addressed store, hash-verified

107 * @returns {string} The modified source text
108 */
109 function buildSource(pendingMod) {
110 const allMods = pendingMod
111 ? [...modifications, pendingMod]
112 : [...modifications];
113
114 allMods.sort((a, b) => b.start - a.start);
115
116 let result = sourceText;
117
118 for (const { start, end, replacement } of allMods) {
119 result = result.slice(0, start) + replacement + result.slice(end);
120 }
121
122 return result;
123 }
124
125 /**
126 * Recursively removes descendant subtrees of the given AST node and replaces

Callers 2

pruneIrrelevantSubtreesFunction · 0.85
reduceBadExampleSizeFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…