MCPcopy Index your code
hub / github.com/kpdecker/jsdiff / buildValues

Method buildValues

src/diff/base.ts:315–364  ·  view source on GitHub ↗
(
    lastComponent: DraftChangeObject | undefined,
    newTokens: TokenT[],
    oldTokens: TokenT[]
  )

Source from the content-addressed store, hash-verified

313 }
314
315 private buildValues(
316 lastComponent: DraftChangeObject | undefined,
317 newTokens: TokenT[],
318 oldTokens: TokenT[]
319 ): ChangeObject<ValueT>[] {
320 // First we convert our linked list of components in reverse order to an
321 // array in the right order:
322 const components: DraftChangeObject[] = [];
323 let nextComponent;
324 while (lastComponent) {
325 components.push(lastComponent);
326 nextComponent = lastComponent.previousComponent;
327 delete lastComponent.previousComponent;
328 lastComponent = nextComponent;
329 }
330 components.reverse();
331
332 const componentLen = components.length;
333 let componentPos = 0,
334 newPos = 0,
335 oldPos = 0;
336
337 for (; componentPos < componentLen; componentPos++) {
338 const component = components[componentPos];
339 if (!component.removed) {
340 if (!component.added && this.useLongestToken) {
341 let value = newTokens.slice(newPos, newPos + component.count);
342 value = value.map(function(value, i) {
343 const oldValue = oldTokens[oldPos + i];
344 return (oldValue as string).length > (value as string).length ? oldValue : value;
345 });
346
347 component.value = this.join(value);
348 } else {
349 component.value = this.join(newTokens.slice(newPos, newPos + component.count));
350 }
351 newPos += component.count;
352
353 // Common case
354 if (!component.added) {
355 oldPos += component.count;
356 }
357 } else {
358 component.value = this.join(oldTokens.slice(oldPos, oldPos + component.count));
359 oldPos += component.count;
360 }
361 }
362
363 return components as ChangeObject<ValueT>[];
364 }
365}
366

Callers 2

diffWithOptionsObjMethod · 0.95
execEditLengthMethod · 0.95

Calls 1

joinMethod · 0.95

Tested by

no test coverage detected