Skip to content
Permalink
Browse files
fix(ClassDoc): error when extends nested class.
e.g ``class Foo extends Bar.Baz {}``
#5
  • Loading branch information
h13i32maru committed May 31, 2015
1 parent 3a5cfb6 commit 2d634d06f7a9475e92fae5c0773dfae579b5b314
@@ -554,13 +554,16 @@ export default class AbstractDoc {
*/
_resolveLongname(name) {
let importPath = ASTUtil.findPathInImportDeclaration(this._ast, name);
if (importPath) {
if (!importPath) return name;

if (importPath.charAt(0) === '.' || importPath.charAt(0) === '/') {
let resolvedPath = this._pathResolver.resolve(importPath);
let longname = `${resolvedPath}~${name}`;
return longname;
} else {
let longname = `${importPath}~${name}`;
return longname;
}

return name;
}

/**
@@ -61,9 +61,22 @@ export default class ClassDoc extends AbstractDoc {
}

let node = this._node;
let longname;
if (node.superClass) {
let longname = this._resolveLongname(node.superClass.name);
this._value.extends = [longname];
switch (node.superClass.type) {
case 'Identifier':
longname = this._resolveLongname(node.superClass.name);
this._value.extends = [longname];
break;
case 'MemberExpression':
let fullIdentifier = this._flattenMemberExpression(node.superClass);
let rootIdentifier = fullIdentifier.split('.')[0];
let rootLongname = this._resolveLongname(rootIdentifier);
let filePath = rootLongname.replace(/~.*/, '');
longname = `${filePath}~${fullIdentifier}`;
this._value.extends = [longname];
break;
}
}
}

@@ -0,0 +1,12 @@
import TeraClass from 'tera';

/**
* this is MyKiloClass desc.
* @private
*/
export default class MyKiloClass extends TeraClass.GigaClass.MegaClass {
/**
* this is method1 class.
*/
method1(){}
}
@@ -8,9 +8,9 @@ describe('Coverage:', ()=> {
it('has coverage.json', ()=>{
let json = fs.readFileSync('./test/fixture/esdoc/coverage.json', {encoding: 'utf8'}).toString();
let coverage = JSON.parse(json);
assert.equal(coverage.coverage, '78.57%');
assert.equal(coverage.expectCount, 84);
assert.equal(coverage.actualCount, 66);
assert.equal(coverage.coverage, '79.06%');
assert.equal(coverage.expectCount, 86);
assert.equal(coverage.actualCount, 68);
assert.deepEqual(coverage.files, {
"src/ForTestDoc/AbstractDoc.js": {
"expectCount": 3,
@@ -40,6 +40,10 @@ describe('Coverage:', ()=> {
"expectCount": 3,
"actualCount": 3
},
"src/ExtendNest.js": {
"expectCount": 2,
"actualCount": 2
},
"src/ReactJSX.js": {
"expectCount": 2,
"actualCount": 2
@@ -11,6 +11,6 @@ describe('Index:', ()=> {

/** @test {IndexDocBuilder#_buildIndexDoc} */
it('has coverage badge', ()=>{
assert.includes(doc, '.esdoc-coverage .esdoc-coverage-ratio', '78%');
assert.includes(doc, '.esdoc-coverage .esdoc-coverage-ratio', '79%');
});
});
@@ -0,0 +1,12 @@
import {assert} from '../util.js';

/** @test {ClassDoc} */
describe('ClassDoc:', ()=>{

/** @test {ClassDoc#@extends} */
it('can parse nested extend.', ()=>{
let doc = global.db.find({name: 'MyKiloClass'})[0];
assert.equal(doc.extends.length, 1);
assert.equal(doc.extends[0], "tera~TeraClass.GigaClass.MegaClass");
});
});

0 comments on commit 2d634d0

Please sign in to comment.