@@ -1570,6 +1570,11 @@ namespace ts {
15701570 return getFirstJSDocTag ( node , SyntaxKind . JSDocReturnTag ) as JSDocReturnTag ;
15711571 }
15721572
1573+ export function getJSDocReturnType ( node : Node ) : JSDocType {
1574+ const returnTag = getJSDocReturnTag ( node ) ;
1575+ return returnTag && returnTag . typeExpression && returnTag . typeExpression . type ;
1576+ }
1577+
15731578 export function getJSDocTemplateTag ( node : Node ) : JSDocTemplateTag {
15741579 return getFirstJSDocTag ( node , SyntaxKind . JSDocTemplateTag ) as JSDocTemplateTag ;
15751580 }
@@ -2615,14 +2620,19 @@ namespace ts {
26152620 } ) ;
26162621 }
26172622
2618- /** Get the type annotaion for the value parameter. */
2619- export function getSetAccessorTypeAnnotationNode ( accessor : SetAccessorDeclaration ) : TypeNode {
2623+ function getSetAccessorValueParameter ( accessor : SetAccessorDeclaration ) : ParameterDeclaration | undefined {
26202624 if ( accessor && accessor . parameters . length > 0 ) {
26212625 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 ] ;
26232627 }
26242628 }
26252629
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+
26262636 export function getThisParameter ( signature : SignatureDeclaration ) : ParameterDeclaration | undefined {
26272637 if ( signature . parameters . length ) {
26282638 const thisParameter = signature . parameters [ 0 ] ;
@@ -2701,6 +2711,41 @@ namespace ts {
27012711 } ;
27022712 }
27032713
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+
27042749 export function emitNewLineBeforeLeadingComments ( lineMap : number [ ] , writer : EmitTextWriter , node : TextRange , leadingComments : CommentRange [ ] ) {
27052750 emitNewLineBeforeLeadingCommentsOfPosition ( lineMap , writer , node . pos , leadingComments ) ;
27062751 }
0 commit comments