(args, event, opt_args)
| 1130 | * @private |
| 1131 | */ |
| 1132 | export function dereferenceArgsVariables(args, event, opt_args) { |
| 1133 | if (!args) { |
| 1134 | return args; |
| 1135 | } |
| 1136 | const data = opt_args || {}; |
| 1137 | if (event) { |
| 1138 | const detail = getDetail(/** @type {!Event} */ (event)); |
| 1139 | if (detail) { |
| 1140 | data['event'] = detail; |
| 1141 | } |
| 1142 | } |
| 1143 | const applied = map(); |
| 1144 | Object.keys(args).forEach((key) => { |
| 1145 | let value = args[key]; |
| 1146 | // Only JSON expression strings that contain dereferences (e.g. `foo.bar`) |
| 1147 | // are processed as ActionInfoArgExpressionDef. We also support |
| 1148 | // dereferencing strings like `foo` iff there is a corresponding key in |
| 1149 | // `data`. Otherwise, `foo` is treated as a string "foo". |
| 1150 | if (typeof value == 'object' && value.expression) { |
| 1151 | const expr = /** @type {ActionInfoArgExpressionDef} */ (value).expression; |
| 1152 | const exprValue = getValueForExpr(data, expr); |
| 1153 | // If expr can't be found in data, use null instead of undefined. |
| 1154 | value = exprValue === undefined ? null : exprValue; |
| 1155 | } |
| 1156 | if (data[value]) { |
| 1157 | applied[key] = data[value]; |
| 1158 | } else { |
| 1159 | applied[key] = value; |
| 1160 | } |
| 1161 | }); |
| 1162 | return applied; |
| 1163 | } |
| 1164 | |
| 1165 | /** |
| 1166 | * @param {string} s |
no test coverage detected