Debian Codegraph @

packages/babel-core/src/config/util.ts

raw
1 import type { ValidatedOptions, NormalizedOptions } from "./validation/options";
2
3 export function mergeOptions(
4 target: ValidatedOptions,
5 source: ValidatedOptions | NormalizedOptions,
6 ): void {
7 for (const k of Object.keys(source)) {
8 if (
9 (k === "parserOpts" || k === "generatorOpts" || k === "assumptions") &&
10 source[k]
11 ) {
12 const parserOpts = source[k];
13 const targetObj = target[k] || (target[k] = {});
14 mergeDefaultFields(targetObj, parserOpts);
15 } else {
16 //@ts-expect-error k must index source
17 const val = source[k];
18 //@ts-expect-error assigning source to target
19 if (val !== undefined) target[k] = val as any;
20 }
21 }
22 }
23
24 function mergeDefaultFields<T extends {}>(target: T, source: T) {
25 for (const k of Object.keys(source) as (keyof T)[]) {
26 const val = source[k];
27 if (val !== undefined) target[k] = val;
28 }
29 }
30
31 export function isIterableIterator(value: any): value is IterableIterator<any> {
32 return (
33 !!value &&
34 typeof value.next === "function" &&
35 typeof value[Symbol.iterator] === "function"
36 );
37 }