fix(utils): fix json-template type checking logic (#2177)

This commit is contained in:
Junyi 2023-07-04 19:41:20 +07:00 committed by GitHub
parent 46294692dd
commit 637ccb0457
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -92,20 +92,21 @@ const parseString = (() => {
return matches.reduce((result, match, i) => {
const parameter = parameters[i];
let value = objectPath.get(context, parameter.key);
const type = typeof value;
if (type === 'undefined') {
if (typeof parameter.defaultValue === 'undefined') {
return value;
}
if (typeof value === 'undefined') {
value = parameter.defaultValue;
}
if (type === 'function') {
if (typeof value === 'function') {
value = value();
}
if (type === 'object') {
if (typeof value === 'object' && value !== null) {
return value;
}
// Accommodate numbers as values.
if (matches.length === 1 && str.startsWith('{{') && str.endsWith('}}')) {
return value;
}