chore: 调整 dataMapping 中 '&' 特殊 key 的逻辑 始终优先处理 Close: #7247 (#7264)

This commit is contained in:
liaoxuezhi 2023-06-28 19:27:46 +08:00 committed by GitHub
parent bc43375b81
commit 8aacd4361e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -99,19 +99,21 @@ export function dataMapping(
); );
} }
} else { } else {
Object.keys(to).forEach(key => { const objectKeys = Object.keys(to);
const value = to[key]; // 如果存在 '&' 作为 key则特殊处理
let keys: Array<string>; // 就是无论这个 key 的位置在什么地方始终都是当放在最前面
const idx = objectKeys.indexOf('&');
if (~idx) {
const value = to['&'];
objectKeys.splice(idx, 1);
if (typeof ignoreFunction === 'function' && ignoreFunction(key, value)) { if (value === '$$') {
// 如果被ignore不做数据映射处理。
setVariable(ret, key, value, convertKeyToPath);
} else if (key === '&' && value === '$$') {
ret = { ret = {
...ret, ...ret,
...from ...from
}; };
} else if (key === '&') { } else {
let keys: Array<string>;
const v = const v =
isPlainObject(value) && isPlainObject(value) &&
(keys = Object.keys(value)) && (keys = Object.keys(value)) &&
@ -142,6 +144,15 @@ export function dataMapping(
...v ...v
}; };
} }
}
}
objectKeys.forEach(key => {
const value = to[key];
if (typeof ignoreFunction === 'function' && ignoreFunction(key, value)) {
// 如果被ignore不做数据映射处理。
setVariable(ret, key, value, convertKeyToPath);
} else if (value === '$$') { } else if (value === '$$') {
setVariable(ret, key, from, convertKeyToPath); setVariable(ret, key, from, convertKeyToPath);
} else if (value && value[0] === '$') { } else if (value && value[0] === '$') {