@@ -1570,6 +1570,11 @@ namespace ts {
1570
1570
return getFirstJSDocTag ( node , SyntaxKind . JSDocReturnTag ) as JSDocReturnTag ;
1571
1571
}
1572
1572
1573
+ export function getJSDocReturnType ( node : Node ) : JSDocType {
1574
+ const returnTag = getJSDocReturnTag ( node ) ;
1575
+ return returnTag && returnTag . typeExpression && returnTag . typeExpression . type ;
1576
+ }
1577
+
1573
1578
export function getJSDocTemplateTag ( node : Node ) : JSDocTemplateTag {
1574
1579
return getFirstJSDocTag ( node , SyntaxKind . JSDocTemplateTag ) as JSDocTemplateTag ;
1575
1580
}
@@ -2615,14 +2620,19 @@ namespace ts {
2615
2620
} ) ;
2616
2621
}
2617
2622
2618
- /** Get the type annotaion for the value parameter. */
2619
- export function getSetAccessorTypeAnnotationNode ( accessor : SetAccessorDeclaration ) : TypeNode {
2623
+ function getSetAccessorValueParameter ( accessor : SetAccessorDeclaration ) : ParameterDeclaration | undefined {
2620
2624
if ( accessor && accessor . parameters . length > 0 ) {
2621
2625
const hasThis = accessor . parameters . length === 2 && parameterIsThisKeyword ( accessor . parameters [ 0 ] ) ;
2622
- return accessor . parameters [ hasThis ? 1 : 0 ] . type ;
2626
+ return accessor . parameters [ hasThis ? 1 : 0 ] ;
2623
2627
}
2624
2628
}
2625
2629
2630
+ /** Get the type annotation for the value parameter. */
2631
+ export function getSetAccessorTypeAnnotationNode ( accessor : SetAccessorDeclaration ) : TypeNode {
2632
+ const parameter = getSetAccessorValueParameter ( accessor ) ;
2633
+ return parameter && parameter . type ;
2634
+ }
2635
+
2626
2636
export function getThisParameter ( signature : SignatureDeclaration ) : ParameterDeclaration | undefined {
2627
2637
if ( signature . parameters . length ) {
2628
2638
const thisParameter = signature . parameters [ 0 ] ;
@@ -2701,6 +2711,41 @@ namespace ts {
2701
2711
} ;
2702
2712
}
2703
2713
2714
+ /**
2715
+ * Gets the effective type annotation of a variable, parameter, or property. If the node was
2716
+ * parsed in a JavaScript file, gets the type annotation from JSDoc.
2717
+ */
2718
+ export function getEffectiveTypeAnnotationNode ( node : VariableLikeDeclaration ) : TypeNode {
2719
+ if ( node . type ) {
2720
+ return node . type ;
2721
+ }
2722
+ if ( node . flags & NodeFlags . JavaScriptFile ) {
2723
+ return getJSDocType ( node ) ;
2724
+ }
2725
+ }
2726
+
2727
+ /**
2728
+ * Gets the effective return type annotation of a signature. If the node was parsed in a
2729
+ * JavaScript file, gets the return type annotation from JSDoc.
2730
+ */
2731
+ export function getEffectiveReturnTypeNode ( node : SignatureDeclaration ) : TypeNode {
2732
+ if ( node . type ) {
2733
+ return node . type ;
2734
+ }
2735
+ if ( node . flags & NodeFlags . JavaScriptFile ) {
2736
+ return getJSDocReturnType ( node ) ;
2737
+ }
2738
+ }
2739
+
2740
+ /**
2741
+ * Gets the effective type annotation of the value parameter of a set accessor. If the node
2742
+ * was parsed in a JavaScript file, gets the type annotation from JSDoc.
2743
+ */
2744
+ export function getEffectiveSetAccessorTypeAnnotationNode ( node : SetAccessorDeclaration ) : TypeNode {
2745
+ const parameter = getSetAccessorValueParameter ( node ) ;
2746
+ return parameter && getEffectiveTypeAnnotationNode ( parameter ) ;
2747
+ }
2748
+
2704
2749
export function emitNewLineBeforeLeadingComments ( lineMap : number [ ] , writer : EmitTextWriter , node : TextRange , leadingComments : CommentRange [ ] ) {
2705
2750
emitNewLineBeforeLeadingCommentsOfPosition ( lineMap , writer , node . pos , leadingComments ) ;
2706
2751
}
0 commit comments