@@ -1277,15 +1277,15 @@ namespace ts {
12771277 * @param node The declaration node.
12781278 * @param allDecorators An object containing all of the decorators for the declaration.
12791279 */
1280- function transformAllDecoratorsOfDeclaration ( node : Declaration , allDecorators : AllDecorators ) {
1280+ function transformAllDecoratorsOfDeclaration ( node : Declaration , container : ClassLikeDeclaration , allDecorators : AllDecorators ) {
12811281 if ( ! allDecorators ) {
12821282 return undefined ;
12831283 }
12841284
12851285 const decoratorExpressions : Expression [ ] = [ ] ;
12861286 addRange ( decoratorExpressions , map ( allDecorators . decorators , transformDecorator ) ) ;
12871287 addRange ( decoratorExpressions , flatMap ( allDecorators . parameters , transformDecoratorsOfParameter ) ) ;
1288- addTypeMetadata ( node , decoratorExpressions ) ;
1288+ addTypeMetadata ( node , container , decoratorExpressions ) ;
12891289 return decoratorExpressions ;
12901290 }
12911291
@@ -1334,7 +1334,7 @@ namespace ts {
13341334 */
13351335 function generateClassElementDecorationExpression ( node : ClassExpression | ClassDeclaration , member : ClassElement ) {
13361336 const allDecorators = getAllDecoratorsOfClassElement ( node , member ) ;
1337- const decoratorExpressions = transformAllDecoratorsOfDeclaration ( member , allDecorators ) ;
1337+ const decoratorExpressions = transformAllDecoratorsOfDeclaration ( member , node , allDecorators ) ;
13381338 if ( ! decoratorExpressions ) {
13391339 return undefined ;
13401340 }
@@ -1415,7 +1415,7 @@ namespace ts {
14151415 */
14161416 function generateConstructorDecorationExpression ( node : ClassExpression | ClassDeclaration ) {
14171417 const allDecorators = getAllDecoratorsOfConstructor ( node ) ;
1418- const decoratorExpressions = transformAllDecoratorsOfDeclaration ( node , allDecorators ) ;
1418+ const decoratorExpressions = transformAllDecoratorsOfDeclaration ( node , node , allDecorators ) ;
14191419 if ( ! decoratorExpressions ) {
14201420 return undefined ;
14211421 }
@@ -1468,37 +1468,37 @@ namespace ts {
14681468 * @param node The declaration node.
14691469 * @param decoratorExpressions The destination array to which to add new decorator expressions.
14701470 */
1471- function addTypeMetadata ( node : Declaration , decoratorExpressions : Expression [ ] ) {
1471+ function addTypeMetadata ( node : Declaration , container : ClassLikeDeclaration , decoratorExpressions : Expression [ ] ) {
14721472 if ( USE_NEW_TYPE_METADATA_FORMAT ) {
1473- addNewTypeMetadata ( node , decoratorExpressions ) ;
1473+ addNewTypeMetadata ( node , container , decoratorExpressions ) ;
14741474 }
14751475 else {
1476- addOldTypeMetadata ( node , decoratorExpressions ) ;
1476+ addOldTypeMetadata ( node , container , decoratorExpressions ) ;
14771477 }
14781478 }
14791479
1480- function addOldTypeMetadata ( node : Declaration , decoratorExpressions : Expression [ ] ) {
1480+ function addOldTypeMetadata ( node : Declaration , container : ClassLikeDeclaration , decoratorExpressions : Expression [ ] ) {
14811481 if ( compilerOptions . emitDecoratorMetadata ) {
14821482 if ( shouldAddTypeMetadata ( node ) ) {
14831483 decoratorExpressions . push ( createMetadataHelper ( context , "design:type" , serializeTypeOfNode ( node ) ) ) ;
14841484 }
14851485 if ( shouldAddParamTypesMetadata ( node ) ) {
1486- decoratorExpressions . push ( createMetadataHelper ( context , "design:paramtypes" , serializeParameterTypesOfNode ( node ) ) ) ;
1486+ decoratorExpressions . push ( createMetadataHelper ( context , "design:paramtypes" , serializeParameterTypesOfNode ( node , container ) ) ) ;
14871487 }
14881488 if ( shouldAddReturnTypeMetadata ( node ) ) {
14891489 decoratorExpressions . push ( createMetadataHelper ( context , "design:returntype" , serializeReturnTypeOfNode ( node ) ) ) ;
14901490 }
14911491 }
14921492 }
14931493
1494- function addNewTypeMetadata ( node : Declaration , decoratorExpressions : Expression [ ] ) {
1494+ function addNewTypeMetadata ( node : Declaration , container : ClassLikeDeclaration , decoratorExpressions : Expression [ ] ) {
14951495 if ( compilerOptions . emitDecoratorMetadata ) {
14961496 let properties : ObjectLiteralElementLike [ ] ;
14971497 if ( shouldAddTypeMetadata ( node ) ) {
14981498 ( properties || ( properties = [ ] ) ) . push ( createPropertyAssignment ( "type" , createArrowFunction ( /*modifiers*/ undefined , /*typeParameters*/ undefined , [ ] , /*type*/ undefined , createToken ( SyntaxKind . EqualsGreaterThanToken ) , serializeTypeOfNode ( node ) ) ) ) ;
14991499 }
15001500 if ( shouldAddParamTypesMetadata ( node ) ) {
1501- ( properties || ( properties = [ ] ) ) . push ( createPropertyAssignment ( "paramTypes" , createArrowFunction ( /*modifiers*/ undefined , /*typeParameters*/ undefined , [ ] , /*type*/ undefined , createToken ( SyntaxKind . EqualsGreaterThanToken ) , serializeParameterTypesOfNode ( node ) ) ) ) ;
1501+ ( properties || ( properties = [ ] ) ) . push ( createPropertyAssignment ( "paramTypes" , createArrowFunction ( /*modifiers*/ undefined , /*typeParameters*/ undefined , [ ] , /*type*/ undefined , createToken ( SyntaxKind . EqualsGreaterThanToken ) , serializeParameterTypesOfNode ( node , container ) ) ) ) ;
15021502 }
15031503 if ( shouldAddReturnTypeMetadata ( node ) ) {
15041504 ( properties || ( properties = [ ] ) ) . push ( createPropertyAssignment ( "returnType" , createArrowFunction ( /*modifiers*/ undefined , /*typeParameters*/ undefined , [ ] , /*type*/ undefined , createToken ( SyntaxKind . EqualsGreaterThanToken ) , serializeReturnTypeOfNode ( node ) ) ) ) ;
@@ -1543,12 +1543,16 @@ namespace ts {
15431543 * @param node The node to test.
15441544 */
15451545 function shouldAddParamTypesMetadata ( node : Declaration ) : boolean {
1546- const kind = node . kind ;
1547- return kind === SyntaxKind . ClassDeclaration
1548- || kind === SyntaxKind . ClassExpression
1549- || kind === SyntaxKind . MethodDeclaration
1550- || kind === SyntaxKind . GetAccessor
1551- || kind === SyntaxKind . SetAccessor ;
1546+ switch ( node . kind ) {
1547+ case SyntaxKind . ClassDeclaration :
1548+ case SyntaxKind . ClassExpression :
1549+ return getFirstConstructorWithBody ( < ClassLikeDeclaration > node ) !== undefined ;
1550+ case SyntaxKind . MethodDeclaration :
1551+ case SyntaxKind . GetAccessor :
1552+ case SyntaxKind . SetAccessor :
1553+ return true ;
1554+ }
1555+ return false ;
15521556 }
15531557
15541558 /**
@@ -1596,7 +1600,7 @@ namespace ts {
15961600 *
15971601 * @param node The node that should have its parameter types serialized.
15981602 */
1599- function serializeParameterTypesOfNode ( node : Node ) : Expression {
1603+ function serializeParameterTypesOfNode ( node : Node , container : ClassLikeDeclaration ) : Expression {
16001604 const valueDeclaration =
16011605 isClassLike ( node )
16021606 ? getFirstConstructorWithBody ( node )
@@ -1606,7 +1610,7 @@ namespace ts {
16061610
16071611 const expressions : Expression [ ] = [ ] ;
16081612 if ( valueDeclaration ) {
1609- const parameters = valueDeclaration . parameters ;
1613+ const parameters = getParametersOfDecoratedDeclaration ( valueDeclaration , container ) ;
16101614 const numParameters = parameters . length ;
16111615 for ( let i = 0 ; i < numParameters ; i ++ ) {
16121616 const parameter = parameters [ i ] ;
@@ -1625,6 +1629,16 @@ namespace ts {
16251629 return createArrayLiteral ( expressions ) ;
16261630 }
16271631
1632+ function getParametersOfDecoratedDeclaration ( node : FunctionLikeDeclaration , container : ClassLikeDeclaration ) {
1633+ if ( container && node . kind === SyntaxKind . GetAccessor ) {
1634+ const { setAccessor } = getAllAccessorDeclarations ( container . members , < AccessorDeclaration > node ) ;
1635+ if ( setAccessor ) {
1636+ return setAccessor . parameters ;
1637+ }
1638+ }
1639+ return node . parameters ;
1640+ }
1641+
16281642 /**
16291643 * Serializes the return type of a node for use with decorator type metadata.
16301644 *
0 commit comments