@@ -1277,15 +1277,15 @@ namespace ts {
1277
1277
* @param node The declaration node.
1278
1278
* @param allDecorators An object containing all of the decorators for the declaration.
1279
1279
*/
1280
- function transformAllDecoratorsOfDeclaration ( node : Declaration , allDecorators : AllDecorators ) {
1280
+ function transformAllDecoratorsOfDeclaration ( node : Declaration , container : ClassLikeDeclaration , allDecorators : AllDecorators ) {
1281
1281
if ( ! allDecorators ) {
1282
1282
return undefined ;
1283
1283
}
1284
1284
1285
1285
const decoratorExpressions : Expression [ ] = [ ] ;
1286
1286
addRange ( decoratorExpressions , map ( allDecorators . decorators , transformDecorator ) ) ;
1287
1287
addRange ( decoratorExpressions , flatMap ( allDecorators . parameters , transformDecoratorsOfParameter ) ) ;
1288
- addTypeMetadata ( node , decoratorExpressions ) ;
1288
+ addTypeMetadata ( node , container , decoratorExpressions ) ;
1289
1289
return decoratorExpressions ;
1290
1290
}
1291
1291
@@ -1334,7 +1334,7 @@ namespace ts {
1334
1334
*/
1335
1335
function generateClassElementDecorationExpression ( node : ClassExpression | ClassDeclaration , member : ClassElement ) {
1336
1336
const allDecorators = getAllDecoratorsOfClassElement ( node , member ) ;
1337
- const decoratorExpressions = transformAllDecoratorsOfDeclaration ( member , allDecorators ) ;
1337
+ const decoratorExpressions = transformAllDecoratorsOfDeclaration ( member , node , allDecorators ) ;
1338
1338
if ( ! decoratorExpressions ) {
1339
1339
return undefined ;
1340
1340
}
@@ -1415,7 +1415,7 @@ namespace ts {
1415
1415
*/
1416
1416
function generateConstructorDecorationExpression ( node : ClassExpression | ClassDeclaration ) {
1417
1417
const allDecorators = getAllDecoratorsOfConstructor ( node ) ;
1418
- const decoratorExpressions = transformAllDecoratorsOfDeclaration ( node , allDecorators ) ;
1418
+ const decoratorExpressions = transformAllDecoratorsOfDeclaration ( node , node , allDecorators ) ;
1419
1419
if ( ! decoratorExpressions ) {
1420
1420
return undefined ;
1421
1421
}
@@ -1468,37 +1468,37 @@ namespace ts {
1468
1468
* @param node The declaration node.
1469
1469
* @param decoratorExpressions The destination array to which to add new decorator expressions.
1470
1470
*/
1471
- function addTypeMetadata ( node : Declaration , decoratorExpressions : Expression [ ] ) {
1471
+ function addTypeMetadata ( node : Declaration , container : ClassLikeDeclaration , decoratorExpressions : Expression [ ] ) {
1472
1472
if ( USE_NEW_TYPE_METADATA_FORMAT ) {
1473
- addNewTypeMetadata ( node , decoratorExpressions ) ;
1473
+ addNewTypeMetadata ( node , container , decoratorExpressions ) ;
1474
1474
}
1475
1475
else {
1476
- addOldTypeMetadata ( node , decoratorExpressions ) ;
1476
+ addOldTypeMetadata ( node , container , decoratorExpressions ) ;
1477
1477
}
1478
1478
}
1479
1479
1480
- function addOldTypeMetadata ( node : Declaration , decoratorExpressions : Expression [ ] ) {
1480
+ function addOldTypeMetadata ( node : Declaration , container : ClassLikeDeclaration , decoratorExpressions : Expression [ ] ) {
1481
1481
if ( compilerOptions . emitDecoratorMetadata ) {
1482
1482
if ( shouldAddTypeMetadata ( node ) ) {
1483
1483
decoratorExpressions . push ( createMetadataHelper ( context , "design:type" , serializeTypeOfNode ( node ) ) ) ;
1484
1484
}
1485
1485
if ( shouldAddParamTypesMetadata ( node ) ) {
1486
- decoratorExpressions . push ( createMetadataHelper ( context , "design:paramtypes" , serializeParameterTypesOfNode ( node ) ) ) ;
1486
+ decoratorExpressions . push ( createMetadataHelper ( context , "design:paramtypes" , serializeParameterTypesOfNode ( node , container ) ) ) ;
1487
1487
}
1488
1488
if ( shouldAddReturnTypeMetadata ( node ) ) {
1489
1489
decoratorExpressions . push ( createMetadataHelper ( context , "design:returntype" , serializeReturnTypeOfNode ( node ) ) ) ;
1490
1490
}
1491
1491
}
1492
1492
}
1493
1493
1494
- function addNewTypeMetadata ( node : Declaration , decoratorExpressions : Expression [ ] ) {
1494
+ function addNewTypeMetadata ( node : Declaration , container : ClassLikeDeclaration , decoratorExpressions : Expression [ ] ) {
1495
1495
if ( compilerOptions . emitDecoratorMetadata ) {
1496
1496
let properties : ObjectLiteralElementLike [ ] ;
1497
1497
if ( shouldAddTypeMetadata ( node ) ) {
1498
1498
( properties || ( properties = [ ] ) ) . push ( createPropertyAssignment ( "type" , createArrowFunction ( /*modifiers*/ undefined , /*typeParameters*/ undefined , [ ] , /*type*/ undefined , createToken ( SyntaxKind . EqualsGreaterThanToken ) , serializeTypeOfNode ( node ) ) ) ) ;
1499
1499
}
1500
1500
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 ) ) ) ) ;
1502
1502
}
1503
1503
if ( shouldAddReturnTypeMetadata ( node ) ) {
1504
1504
( properties || ( properties = [ ] ) ) . push ( createPropertyAssignment ( "returnType" , createArrowFunction ( /*modifiers*/ undefined , /*typeParameters*/ undefined , [ ] , /*type*/ undefined , createToken ( SyntaxKind . EqualsGreaterThanToken ) , serializeReturnTypeOfNode ( node ) ) ) ) ;
@@ -1543,12 +1543,16 @@ namespace ts {
1543
1543
* @param node The node to test.
1544
1544
*/
1545
1545
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 ;
1552
1556
}
1553
1557
1554
1558
/**
@@ -1596,7 +1600,7 @@ namespace ts {
1596
1600
*
1597
1601
* @param node The node that should have its parameter types serialized.
1598
1602
*/
1599
- function serializeParameterTypesOfNode ( node : Node ) : Expression {
1603
+ function serializeParameterTypesOfNode ( node : Node , container : ClassLikeDeclaration ) : Expression {
1600
1604
const valueDeclaration =
1601
1605
isClassLike ( node )
1602
1606
? getFirstConstructorWithBody ( node )
@@ -1606,7 +1610,7 @@ namespace ts {
1606
1610
1607
1611
const expressions : Expression [ ] = [ ] ;
1608
1612
if ( valueDeclaration ) {
1609
- const parameters = valueDeclaration . parameters ;
1613
+ const parameters = getParametersOfDecoratedDeclaration ( valueDeclaration , container ) ;
1610
1614
const numParameters = parameters . length ;
1611
1615
for ( let i = 0 ; i < numParameters ; i ++ ) {
1612
1616
const parameter = parameters [ i ] ;
@@ -1625,6 +1629,16 @@ namespace ts {
1625
1629
return createArrayLiteral ( expressions ) ;
1626
1630
}
1627
1631
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
+
1628
1642
/**
1629
1643
* Serializes the return type of a node for use with decorator type metadata.
1630
1644
*
0 commit comments