(statements, declarations)
| 27081 | return i; |
| 27082 | } |
| 27083 | function mergeLexicalEnvironment(statements, declarations) { |
| 27084 | if (!ts.some(declarations)) { |
| 27085 | return statements; |
| 27086 | } |
| 27087 | // When we merge new lexical statements into an existing statement list, we merge them in the following manner: |
| 27088 | // |
| 27089 | // Given: |
| 27090 | // |
| 27091 | // | Left | Right | |
| 27092 | // |------------------------------------|-------------------------------------| |
| 27093 | // | [standard prologues (left)] | [standard prologues (right)] | |
| 27094 | // | [hoisted functions (left)] | [hoisted functions (right)] | |
| 27095 | // | [hoisted variables (left)] | [hoisted variables (right)] | |
| 27096 | // | [lexical init statements (left)] | [lexical init statements (right)] | |
| 27097 | // | [other statements (left)] | | |
| 27098 | // |
| 27099 | // The resulting statement list will be: |
| 27100 | // |
| 27101 | // | Result | |
| 27102 | // |-------------------------------------| |
| 27103 | // | [standard prologues (right)] | |
| 27104 | // | [standard prologues (left)] | |
| 27105 | // | [hoisted functions (right)] | |
| 27106 | // | [hoisted functions (left)] | |
| 27107 | // | [hoisted variables (right)] | |
| 27108 | // | [hoisted variables (left)] | |
| 27109 | // | [lexical init statements (right)] | |
| 27110 | // | [lexical init statements (left)] | |
| 27111 | // | [other statements (left)] | |
| 27112 | // |
| 27113 | // NOTE: It is expected that new lexical init statements must be evaluated before existing lexical init statements, |
| 27114 | // as the prior transformation may depend on the evaluation of the lexical init statements to be in the correct state. |
| 27115 | // find standard prologues on left in the following order: standard directives, hoisted functions, hoisted variables, other custom |
| 27116 | var leftStandardPrologueEnd = findSpanEnd(statements, ts.isPrologueDirective, 0); |
| 27117 | var leftHoistedFunctionsEnd = findSpanEnd(statements, ts.isHoistedFunction, leftStandardPrologueEnd); |
| 27118 | var leftHoistedVariablesEnd = findSpanEnd(statements, ts.isHoistedVariableStatement, leftHoistedFunctionsEnd); |
| 27119 | // find standard prologues on right in the following order: standard directives, hoisted functions, hoisted variables, other custom |
| 27120 | var rightStandardPrologueEnd = findSpanEnd(declarations, ts.isPrologueDirective, 0); |
| 27121 | var rightHoistedFunctionsEnd = findSpanEnd(declarations, ts.isHoistedFunction, rightStandardPrologueEnd); |
| 27122 | var rightHoistedVariablesEnd = findSpanEnd(declarations, ts.isHoistedVariableStatement, rightHoistedFunctionsEnd); |
| 27123 | var rightCustomPrologueEnd = findSpanEnd(declarations, ts.isCustomPrologue, rightHoistedVariablesEnd); |
| 27124 | ts.Debug.assert(rightCustomPrologueEnd === declarations.length, "Expected declarations to be valid standard or custom prologues"); |
| 27125 | // splice prologues from the right into the left. We do this in reverse order |
| 27126 | // so that we don't need to recompute the index on the left when we insert items. |
| 27127 | var left = ts.isNodeArray(statements) ? statements.slice() : statements; |
| 27128 | // splice other custom prologues from right into left |
| 27129 | if (rightCustomPrologueEnd > rightHoistedVariablesEnd) { |
| 27130 | left.splice.apply(left, __spreadArray([leftHoistedVariablesEnd, 0], declarations.slice(rightHoistedVariablesEnd, rightCustomPrologueEnd), false)); |
| 27131 | } |
| 27132 | // splice hoisted variables from right into left |
| 27133 | if (rightHoistedVariablesEnd > rightHoistedFunctionsEnd) { |
| 27134 | left.splice.apply(left, __spreadArray([leftHoistedFunctionsEnd, 0], declarations.slice(rightHoistedFunctionsEnd, rightHoistedVariablesEnd), false)); |
| 27135 | } |
| 27136 | // splice hoisted functions from right into left |
| 27137 | if (rightHoistedFunctionsEnd > rightStandardPrologueEnd) { |
| 27138 | left.splice.apply(left, __spreadArray([leftStandardPrologueEnd, 0], declarations.slice(rightStandardPrologueEnd, rightHoistedFunctionsEnd), false)); |
| 27139 | } |
| 27140 | // splice standard prologues from right into left (that are not already in left) |
nothing calls this directly
no test coverage detected