cwilson1031 / jsdoc-toolkit

Automatically exported from code.google.com/p/jsdoc-toolkit
0 stars 0 forks source link

Aliased items are replaced with the first matching exported variable, even if it is not a full match. #333

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Export a variable that is a subset of another exported variable.
(see test-case at the bottom of this post)

What is the expected output? What do you see instead?
Expected output is that items documented against NameLonger will show up under 
the documentation for Bar. Instead, JsDoc Toolkit attempts to document them 
against FooLonger, which doesn't match a known documented symbol resulting in 
the following warning:

>> WARNING: Trying to document b1 as a member of undocumented symbol 
Common.FooLonger.
1 warning.

What version of the product are you using? On what operating system?
2.4.0

Please provide any additional information below.

In app/lib/JSDOC/Parser.js, the code can be changed from:

        if (symbol.alias.indexOf(n) == 0) {

to:

        match = symbol.alias.match(/^[\w]+/);
        if (match && match[0] === n) {

The variable "match" can be declared here:

if (JSDOC.Parser.rename) {
    var match;

This fix works for original code which clued me in to the problem and the much 
simpler test-case given below:

/**
 * @namespace
 */
var Common = {};

(function () {
    /**
     * @exports Name as Common.Foo
     */
    var Name;

    /**
     * @class
     */
    Common.Foo = function() {}
    Name = Common.Foo;

    /**
     */
    Name.f1 = function() {};
}());

(function () {
    /**
     * @exports NameLonger as Common.Bar
     */
    var NameLonger;

    /**
     * @class
     */
    Common.Bar = function () {}
    NameLonger = Common.Bar;

    /**
     */
    NameLonger.b1 = function() {};
}());

Original issue reported on code.google.com by mcbain....@gmail.com on 25 Jan 2012 at 1:01

GoogleCodeExporter commented 9 years ago
Okay, so a bit of a snag but one easily fixed. If this fix is applied in 
conjunction with Issue #331 , there's cases where things fixed by Issue #331 do 
not work anymore.

Here's the full bit of code for Parser.js that satisfies both tickets:

if (JSDOC.Parser.rename) {
    var replacement, match;
    for (var n in JSDOC.Parser.rename) {

        replacement = JSDOC.Parser.rename[n].replace(/\.prototype(?:\.|$)/g, "#");

        match = symbol.alias.match(/^[\w]+/);
        if (match && match[0] === n) {
            if (/#$/.test(replacement)) {
                n += ".";
            }
            if (symbol.name == symbol.alias) {
                symbol.name = symbol.name.replace(n, replacement);
            }
            symbol.alias = symbol.alias.replace(n, replacement);
        }
    }
}

Original comment by mcbain....@gmail.com on 25 Jan 2012 at 2:30