Fix newline issues when adding multiple imports (#38119)

* Add new import declarations in a single TextChanges call

* Refactor
This commit is contained in:
Andrew Branch
2020-04-23 11:59:38 -07:00
committed by GitHub
parent c28bd6579d
commit 9569e8aaa4
7 changed files with 96 additions and 23 deletions

View File

@@ -844,6 +844,28 @@ namespace ts {
return to;
}
/**
* Combines two arrays, values, or undefineds into the smallest container that can accommodate the resulting set:
*
* ```
* undefined -> undefined -> undefined
* T -> undefined -> T
* T -> T -> T[]
* T[] -> undefined -> T[] (no-op)
* T[] -> T -> T[] (append)
* T[] -> T[] -> T[] (concatenate)
* ```
*/
export function combine<T>(xs: T | readonly T[] | undefined, ys: T | readonly T[] | undefined): T | readonly T[] | undefined;
export function combine<T>(xs: T | T[] | undefined, ys: T | T[] | undefined): T | T[] | undefined;
export function combine<T>(xs: T | T[] | undefined, ys: T | T[] | undefined) {
if (xs === undefined) return ys;
if (ys === undefined) return xs;
if (isArray(xs)) return isArray(ys) ? concatenate(xs, ys) : append(xs, ys);
if (isArray(ys)) return append(ys, xs);
return [xs, ys];
}
/**
* Gets the actual offset into an array for a relative offset. Negative offsets indicate a
* position offset from the end of the array.