Permalink
Browse files

fix: separated export and class declaration.

  • Loading branch information...
h13i32maru committed May 24, 2015
1 parent c34f568 commit 6159c3ad28f5c0736d2a2c22f39c94e2e1b6de61
View
@@ -40,6 +40,8 @@ export default class DocFactory {
this._results = [];
this._processedClassNodes = [];
+ this._joinSeparatedExport();
+
// file doc
let doc = new FileDoc(ast, ast, pathResolver, []);
this._results.push(doc.value);
@@ -51,6 +53,37 @@ export default class DocFactory {
}
}
+ /**
+ * join separated export declaration in AST internal.
+ *
+ * ```javascript
+ * class Foo {}
+ *
+ * export default Foo;
+ * ```
+ * ↓
+ * ```javascript
+ * export default class Foo {}
+ * ```
+ *
+ * @private
+ */
+ _joinSeparatedExport() {
+ for (let node1 of this._ast.body) {
+ if (!['ExportDefaultDeclaration', 'ExportNamedDeclaration'].includes(node1.type)) continue;
+
+ for (let node2 of this._ast.body) {
+ if (!node2.id) continue;
+ if (node2.id.type !== 'Identifier') continue;
+ if (node2.id.name !== node1.declaration.name) continue;
+
+ node1.declaration = this._copy(node2);
+ node2.type = 'Identifier'; // to ignore node2
+ break;
+ }
+ }
+ }
+
/**
* push node, and factory processes node.
* @param {ASTNode} node - target node.
@@ -0,0 +1,7 @@
+class SeparateExportClass {
+ constructor(){}
+
+ method1(){}
+}
+
+export default SeparateExportClass;
@@ -8,8 +8,8 @@ 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, '81.48%');
- assert.equal(coverage.expectCount, 81);
+ assert.equal(coverage.coverage, '78.57%');
+ assert.equal(coverage.expectCount, 84);
assert.equal(coverage.actualCount, 66);
assert.deepEqual(coverage.files, {
"src/ForTestDoc/AbstractDoc.js": {
@@ -40,14 +40,18 @@ describe('Coverage:', ()=> {
"expectCount": 3,
"actualCount": 3
},
+ "src/ReactJSX.js": {
+ "expectCount": 2,
+ "actualCount": 2
+ },
+ "src/SeparateExport.js": {
+ "expectCount": 3,
+ "actualCount": 0
+ },
"src/OtherClass/SuperMyClass.js": {
"expectCount": 19,
"actualCount": 19
},
- "src/ReactJSX.js": {
- "actualCount": 2,
- "expectCount": 2
- },
"src/myFunction.js": {
"expectCount": 8,
"actualCount": 6
@@ -8,7 +8,7 @@ describe('Identifiers:', ()=> {
it('has class summary.', ()=>{
find(doc, '[data-ice="classSummary"]', (doc)=>{
assert.includes(doc, '[data-ice="target"]:nth-of-type(4)', 'public MyClass1 this class was deprecated. use MyClass1Ex instead of this class. this class is experimental. this class is dangerous. this is MyClass1 desc.');
- assert.includes(doc, '[data-ice="target"]:nth-of-type(13)', 'public SuperMyClass1 this is SuperMyClass1.');
+ assert.includes(doc, '[data-ice="target"]:nth-of-type(14)', 'public SuperMyClass1 this is SuperMyClass1.');
});
});
@@ -11,6 +11,6 @@ describe('Index:', ()=> {
/** @test {IndexDocBuilder#_buildIndexDoc} */
it('has coverage badge', ()=>{
- assert.includes(doc, '.esdoc-coverage .esdoc-coverage-ratio', '81%');
+ assert.includes(doc, '.esdoc-coverage .esdoc-coverage-ratio', '78%');
});
});

0 comments on commit 6159c3a

Please sign in to comment.