mirror of
https://github.com/denoland/std.git
synced 2024-11-22 04:59:05 +00:00
refactor(yaml): inline mergeMappings()
(#5777)
This commit is contained in:
parent
1d2d33ad1a
commit
bb0db58caa
@ -348,6 +348,28 @@ export class LoaderState {
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
mergeMappings(
|
||||||
|
destination: Record<string, unknown>,
|
||||||
|
source: Record<string, unknown>,
|
||||||
|
overridableKeys: Set<string>,
|
||||||
|
) {
|
||||||
|
if (!isObject(source)) {
|
||||||
|
return this.throwError(
|
||||||
|
"cannot merge mappings; the provided source object is unacceptable",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const [key, value] of Object.entries(source)) {
|
||||||
|
if (Object.hasOwn(destination, key)) continue;
|
||||||
|
Object.defineProperty(destination, key, {
|
||||||
|
value,
|
||||||
|
writable: true,
|
||||||
|
enumerable: true,
|
||||||
|
configurable: true,
|
||||||
|
});
|
||||||
|
overridableKeys.add(key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
readDocument() {
|
readDocument() {
|
||||||
const documentStart = this.position;
|
const documentStart = this.position;
|
||||||
@ -475,30 +497,6 @@ export class LoaderState {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function mergeMappings(
|
|
||||||
state: LoaderState,
|
|
||||||
destination: Record<string, unknown>,
|
|
||||||
source: Record<string, unknown>,
|
|
||||||
overridableKeys: Set<string>,
|
|
||||||
) {
|
|
||||||
if (!isObject(source)) {
|
|
||||||
return state.throwError(
|
|
||||||
"cannot merge mappings; the provided source object is unacceptable",
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const [key, value] of Object.entries(source)) {
|
|
||||||
if (Object.hasOwn(destination, key)) continue;
|
|
||||||
Object.defineProperty(destination, key, {
|
|
||||||
value,
|
|
||||||
writable: true,
|
|
||||||
enumerable: true,
|
|
||||||
configurable: true,
|
|
||||||
});
|
|
||||||
overridableKeys.add(key);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function storeMappingPair(
|
function storeMappingPair(
|
||||||
state: LoaderState,
|
state: LoaderState,
|
||||||
result: Record<string, unknown> | null,
|
result: Record<string, unknown> | null,
|
||||||
@ -552,11 +550,10 @@ function storeMappingPair(
|
|||||||
index < valueNode.length;
|
index < valueNode.length;
|
||||||
index++
|
index++
|
||||||
) {
|
) {
|
||||||
mergeMappings(state, result, valueNode[index], overridableKeys);
|
state.mergeMappings(result, valueNode[index], overridableKeys);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
mergeMappings(
|
state.mergeMappings(
|
||||||
state,
|
|
||||||
result,
|
result,
|
||||||
valueNode as Record<string, unknown>,
|
valueNode as Record<string, unknown>,
|
||||||
overridableKeys,
|
overridableKeys,
|
||||||
|
Loading…
Reference in New Issue
Block a user