@@ -3142,30 +3142,41 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
3142
3142
return ;
3143
3143
}
3144
3144
3145
- let paramName = parameter . name ;
3145
+ let { name : paramName , initializer } = parameter ;
3146
3146
if ( isBindingPattern ( paramName ) ) {
3147
- // In cases where a binding patternm is simply '[]' or '{}',
3148
- // we don't want to emit anything.
3149
- if ( paramName . elements . length > 0 ) {
3147
+ // In cases where a binding pattern is simply '[]' or '{}',
3148
+ // we usually don't want to emit a var declaration; however, in the presence
3149
+ // of an initializer, we must emit that expression to preserve side effects.
3150
+ let hasBindingElements = paramName . elements . length > 0 ;
3151
+ if ( hasBindingElements || initializer ) {
3150
3152
writeLine ( ) ;
3151
3153
write ( "var " ) ;
3152
- emitDestructuring ( parameter , /*isAssignmentExpressionStatement*/ false , tempParameters [ tempIndex ] ) ;
3154
+
3155
+ if ( hasBindingElements ) {
3156
+ emitDestructuring ( parameter , /*isAssignmentExpressionStatement*/ false , tempParameters [ tempIndex ] ) ;
3157
+ }
3158
+ else {
3159
+ emit ( tempParameters [ tempIndex ] ) ;
3160
+ write ( " = " ) ;
3161
+ emit ( initializer ) ;
3162
+ }
3163
+
3153
3164
write ( ";" ) ;
3154
3165
tempIndex ++ ;
3155
3166
}
3156
3167
}
3157
- else if ( parameter . initializer ) {
3168
+ else if ( initializer ) {
3158
3169
writeLine ( ) ;
3159
3170
emitStart ( parameter ) ;
3160
3171
write ( "if (" ) ;
3161
- emitNodeWithoutSourceMap ( parameter . name ) ;
3172
+ emitNodeWithoutSourceMap ( paramName ) ;
3162
3173
write ( " === void 0)" ) ;
3163
3174
emitEnd ( parameter ) ;
3164
3175
write ( " { " ) ;
3165
3176
emitStart ( parameter ) ;
3166
- emitNodeWithoutSourceMap ( parameter . name ) ;
3177
+ emitNodeWithoutSourceMap ( paramName ) ;
3167
3178
write ( " = " ) ;
3168
- emitNodeWithoutSourceMap ( parameter . initializer ) ;
3179
+ emitNodeWithoutSourceMap ( initializer ) ;
3169
3180
emitEnd ( parameter ) ;
3170
3181
write ( "; }" ) ;
3171
3182
}
0 commit comments