@@ -401,10 +401,7 @@ namespace ts {
401401 return ! nodeIsMissing ( node ) ;
402402 }
403403
404- /**
405- * Prepends statements to an array while taking care of prologue directives.
406- */
407- export function addStatementsAfterPrologue < T extends Statement > ( to : T [ ] , from : ReadonlyArray < T > | undefined ) : T [ ] {
404+ function insertStatementsAfterPrologue < T extends Statement > ( to : T [ ] , from : ReadonlyArray < T > | undefined , isPrologueDirective : ( node : Node ) => boolean ) : T [ ] {
408405 if ( from === undefined || from . length === 0 ) return to ;
409406 let statementIndex = 0 ;
410407 // skip all prologue directives to insert at the correct position
@@ -417,6 +414,46 @@ namespace ts {
417414 return to ;
418415 }
419416
417+ function insertStatementAfterPrologue < T extends Statement > ( to : T [ ] , statement : T | undefined , isPrologueDirective : ( node : Node ) => boolean ) : T [ ] {
418+ if ( statement === undefined ) return to ;
419+ let statementIndex = 0 ;
420+ // skip all prologue directives to insert at the correct position
421+ for ( ; statementIndex < to . length ; ++ statementIndex ) {
422+ if ( ! isPrologueDirective ( to [ statementIndex ] ) ) {
423+ break ;
424+ }
425+ }
426+ to . splice ( statementIndex , 0 , statement ) ;
427+ return to ;
428+ }
429+
430+
431+ function isAnyPrologueDirective ( node : Node ) {
432+ return isPrologueDirective ( node ) || ! ! ( getEmitFlags ( node ) & EmitFlags . CustomPrologue ) ;
433+ }
434+
435+ /**
436+ * Prepends statements to an array while taking care of prologue directives.
437+ */
438+ export function insertStatementsAfterStandardPrologue < T extends Statement > ( to : T [ ] , from : ReadonlyArray < T > | undefined ) : T [ ] {
439+ return insertStatementsAfterPrologue ( to , from , isPrologueDirective ) ;
440+ }
441+
442+ export function insertStatementsAfterCustomPrologue < T extends Statement > ( to : T [ ] , from : ReadonlyArray < T > | undefined ) : T [ ] {
443+ return insertStatementsAfterPrologue ( to , from , isAnyPrologueDirective ) ;
444+ }
445+
446+ /**
447+ * Prepends statements to an array while taking care of prologue directives.
448+ */
449+ export function insertStatementAfterStandardPrologue < T extends Statement > ( to : T [ ] , statement : T | undefined ) : T [ ] {
450+ return insertStatementAfterPrologue ( to , statement , isPrologueDirective ) ;
451+ }
452+
453+ export function insertStatementAfterCustomPrologue < T extends Statement > ( to : T [ ] , statement : T | undefined ) : T [ ] {
454+ return insertStatementAfterPrologue ( to , statement , isAnyPrologueDirective ) ;
455+ }
456+
420457 /**
421458 * Determine if the given comment is a triple-slash
422459 *
@@ -3418,8 +3455,8 @@ namespace ts {
34183455 return computeLineAndCharacterOfPosition ( lineMap , pos ) . line ;
34193456 }
34203457
3421- export function getFirstConstructorWithBody ( node : ClassLikeDeclaration ) : ConstructorDeclaration | undefined {
3422- return find ( node . members , ( member ) : member is ConstructorDeclaration => isConstructorDeclaration ( member ) && nodeIsPresent ( member . body ) ) ;
3458+ export function getFirstConstructorWithBody ( node : ClassLikeDeclaration ) : ConstructorDeclaration & { body : FunctionBody } | undefined {
3459+ return find ( node . members , ( member ) : member is ConstructorDeclaration & { body : FunctionBody } => isConstructorDeclaration ( member ) && nodeIsPresent ( member . body ) ) ;
34233460 }
34243461
34253462 function getSetAccessorValueParameter ( accessor : SetAccessorDeclaration ) : ParameterDeclaration | undefined {
0 commit comments