From e89ecd615f02855d50df008f5238c4e1717f2c00 Mon Sep 17 00:00:00 2001 From: Jeff Williams Date: Sat, 24 Jan 2015 08:40:55 -0800 Subject: [PATCH] resolve `this` for computed properties (#890) --- lib/jsdoc/src/handlers.js | 12 ++++++++++-- test/specs/documentation/specialchars.js | 3 +-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/lib/jsdoc/src/handlers.js b/lib/jsdoc/src/handlers.js index 6773e9b4..19517087 100644 --- a/lib/jsdoc/src/handlers.js +++ b/lib/jsdoc/src/handlers.js @@ -143,9 +143,17 @@ function processAlias(parser, doclet, astNode) { // TODO: separate code that resolves `this` from code that resolves the module object function findSymbolMemberof(parser, doclet, astNode, nameStartsWith, trailingPunc) { var memberof = ''; - var nameAndPunc = nameStartsWith + (trailingPunc || ''); + var nameAndPunc; var scopePunc = ''; + // handle computed properties like foo['bar'] + if (trailingPunc === '[') { + // we don't know yet whether the symbol is a static or instance member + trailingPunc = null; + } + + nameAndPunc = nameStartsWith + (trailingPunc || ''); + // remove stuff that indicates module membership (but don't touch the name `module.exports`, // which identifies the module object itself) if (doclet.name !== 'module.exports') { @@ -204,7 +212,7 @@ function addSymbolMemberof(parser, doclet, astNode) { moduleOriginalName = '|' + currentModule.originalName; } resolveTargetRegExp = new RegExp('^((?:module.)?exports|this' + moduleOriginalName + - ')(\\.|$)'); + ')(\\.|\\[|$)'); unresolved = resolveTargetRegExp.exec(doclet.name); if (unresolved) { diff --git a/test/specs/documentation/specialchars.js b/test/specs/documentation/specialchars.js index 5dcc7745..43fab8e2 100644 --- a/test/specs/documentation/specialchars.js +++ b/test/specs/documentation/specialchars.js @@ -5,8 +5,7 @@ describe('longnames with special characters', function() { var portNumber = docSet.getByLongname('Socket#\'port#number\'')[0]; var open = docSet.getByLongname('Socket#\'open~a.connection#now\'')[0]; - // currently broken: https://github.com/jsdoc3/jsdoc/issues/890 - xit('should use the correct longname for instance members of "this" whose names contain ' + + it('should use the correct longname for instance members of "this" whose names contain ' + 'scope punctuation', function() { expect(portNumber).toBeDefined(); });