* Flattens a BindingOrAssignmentElement into zero or more bindings or assignments. * * @param flattenContext Options used to control flattening. * @param element The element to flatten. * @param value The current RHS value to assign to the element. * @param location The loca
(flattenContext, element, value, location, skipInitializer)
| 91194 | * for the element. |
| 91195 | */ |
| 91196 | function flattenBindingOrAssignmentElement(flattenContext, element, value, location, skipInitializer) { |
| 91197 | var bindingTarget = ts.getTargetOfBindingOrAssignmentElement(element); // TODO: GH#18217 |
| 91198 | if (!skipInitializer) { |
| 91199 | var initializer = ts.visitNode(ts.getInitializerOfBindingOrAssignmentElement(element), flattenContext.visitor, ts.isExpression); |
| 91200 | if (initializer) { |
| 91201 | // Combine value and initializer |
| 91202 | if (value) { |
| 91203 | value = createDefaultValueCheck(flattenContext, value, initializer, location); |
| 91204 | // If 'value' is not a simple expression, it could contain side-effecting code that should evaluate before an object or array binding pattern. |
| 91205 | if (!ts.isSimpleInlineableExpression(initializer) && ts.isBindingOrAssignmentPattern(bindingTarget)) { |
| 91206 | value = ensureIdentifier(flattenContext, value, /*reuseIdentifierExpressions*/ true, location); |
| 91207 | } |
| 91208 | } |
| 91209 | else { |
| 91210 | value = initializer; |
| 91211 | } |
| 91212 | } |
| 91213 | else if (!value) { |
| 91214 | // Use 'void 0' in absence of value and initializer |
| 91215 | value = flattenContext.context.factory.createVoidZero(); |
| 91216 | } |
| 91217 | } |
| 91218 | if (ts.isObjectBindingOrAssignmentPattern(bindingTarget)) { |
| 91219 | flattenObjectBindingOrAssignmentPattern(flattenContext, element, bindingTarget, value, location); |
| 91220 | } |
| 91221 | else if (ts.isArrayBindingOrAssignmentPattern(bindingTarget)) { |
| 91222 | flattenArrayBindingOrAssignmentPattern(flattenContext, element, bindingTarget, value, location); |
| 91223 | } |
| 91224 | else { |
| 91225 | flattenContext.emitBindingOrAssignment(bindingTarget, value, location, /*original*/ element); // TODO: GH#18217 |
| 91226 | } |
| 91227 | } |
| 91228 | /** |
| 91229 | * Flattens an ObjectBindingOrAssignmentPattern into zero or more bindings or assignments. |
| 91230 | * |
no test coverage detected