Use comments from host variable declaration when exporting a signature in js declarations (#37594)

This commit is contained in:
Wesley Wigham
2020-04-08 13:32:17 -07:00
committed by GitHub
parent 5a7916962d
commit b4838c8b62
5 changed files with 125 additions and 1 deletions

View File

@@ -6132,7 +6132,8 @@ namespace ts {
// Each overload becomes a separate function declaration, in order
const decl = signatureToSignatureDeclarationHelper(sig, SyntaxKind.FunctionDeclaration, context, includePrivateSymbol, bundled) as FunctionDeclaration;
decl.name = createIdentifier(localName);
addResult(setTextRange(decl, sig.declaration), modifierFlags);
// for expressions assigned to `var`s, use the `var` as the text range
addResult(setTextRange(decl, sig.declaration && isVariableDeclaration(sig.declaration.parent) && sig.declaration.parent.parent || sig.declaration), modifierFlags);
}
// Module symbol emit will take care of module-y members, provided it has exports
if (!(symbol.flags & (SymbolFlags.ValueModule | SymbolFlags.NamespaceModule) && !!symbol.exports && !!symbol.exports.size)) {

View File

@@ -0,0 +1,42 @@
//// [index1.js]
/**
* const doc comment
*/
const x = (a) => {
return '';
};
/**
* function doc comment
*/
function b() {
return 0;
}
module.exports = {x, b}
//// [index1.js]
/**
* const doc comment
*/
var x = function (a) {
return '';
};
/**
* function doc comment
*/
function b() {
return 0;
}
module.exports = { x: x, b: b };
//// [index1.d.ts]
/**
* const doc comment
*/
export function x(a: any): string;
/**
* function doc comment
*/
export function b(): number;

View File

@@ -0,0 +1,27 @@
=== tests/cases/conformance/jsdoc/declarations/index1.js ===
/**
* const doc comment
*/
const x = (a) => {
>x : Symbol(x, Decl(index1.js, 3, 5))
>a : Symbol(a, Decl(index1.js, 3, 11))
return '';
};
/**
* function doc comment
*/
function b() {
>b : Symbol(b, Decl(index1.js, 5, 2))
return 0;
}
module.exports = {x, b}
>module.exports : Symbol("tests/cases/conformance/jsdoc/declarations/index1", Decl(index1.js, 0, 0))
>module : Symbol(export=, Decl(index1.js, 12, 1))
>exports : Symbol(export=, Decl(index1.js, 12, 1))
>x : Symbol(x, Decl(index1.js, 14, 18))
>b : Symbol(b, Decl(index1.js, 14, 20))

View File

@@ -0,0 +1,33 @@
=== tests/cases/conformance/jsdoc/declarations/index1.js ===
/**
* const doc comment
*/
const x = (a) => {
>x : (a: any) => string
>(a) => { return '';} : (a: any) => string
>a : any
return '';
>'' : ""
};
/**
* function doc comment
*/
function b() {
>b : () => number
return 0;
>0 : 0
}
module.exports = {x, b}
>module.exports = {x, b} : { x: (a: any) => string; b: () => number; }
>module.exports : { x: (a: any) => string; b: () => number; }
>module : { "\"tests/cases/conformance/jsdoc/declarations/index1\"": { x: (a: any) => string; b: () => number; }; }
>exports : { x: (a: any) => string; b: () => number; }
>{x, b} : { x: (a: any) => string; b: () => number; }
>x : (a: any) => string
>b : () => number

View File

@@ -0,0 +1,21 @@
// @allowJs: true
// @checkJs: true
// @target: es5
// @outDir: ./out
// @declaration: true
// @filename: index1.js
/**
* const doc comment
*/
const x = (a) => {
return '';
};
/**
* function doc comment
*/
function b() {
return 0;
}
module.exports = {x, b}