diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 6ebcbdc2227..f8d1f82ac05 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -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)) { diff --git a/tests/baselines/reference/jsDeclarationsDocCommentsOnConsts.js b/tests/baselines/reference/jsDeclarationsDocCommentsOnConsts.js new file mode 100644 index 00000000000..3f21446265a --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsDocCommentsOnConsts.js @@ -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; diff --git a/tests/baselines/reference/jsDeclarationsDocCommentsOnConsts.symbols b/tests/baselines/reference/jsDeclarationsDocCommentsOnConsts.symbols new file mode 100644 index 00000000000..1f661953894 --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsDocCommentsOnConsts.symbols @@ -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)) + diff --git a/tests/baselines/reference/jsDeclarationsDocCommentsOnConsts.types b/tests/baselines/reference/jsDeclarationsDocCommentsOnConsts.types new file mode 100644 index 00000000000..b8d8d3506cb --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsDocCommentsOnConsts.types @@ -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 + diff --git a/tests/cases/conformance/jsdoc/declarations/jsDeclarationsDocCommentsOnConsts.ts b/tests/cases/conformance/jsdoc/declarations/jsDeclarationsDocCommentsOnConsts.ts new file mode 100644 index 00000000000..f8732cb4147 --- /dev/null +++ b/tests/cases/conformance/jsdoc/declarations/jsDeclarationsDocCommentsOnConsts.ts @@ -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} \ No newline at end of file