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