Involve groups of extractors
parent
fd049a4d30
commit
b0872d04b2
|
@ -82,8 +82,10 @@ class Collector {
|
|||
if (isNode(node)) {
|
||||
const {type} = node;
|
||||
|
||||
if (type && type in extractors) {
|
||||
const task = this._collect(node, scope);
|
||||
const group = type && getExtractorsGroup(type);
|
||||
|
||||
if (group) {
|
||||
const task = this._collect(group, node, scope);
|
||||
|
||||
this.tasks.add(task);
|
||||
++this.taskCount;
|
||||
|
@ -99,12 +101,15 @@ class Collector {
|
|||
} while (stack);
|
||||
}
|
||||
|
||||
* _collect(node, scope) {
|
||||
const extractor = extractors[node.type];
|
||||
* _collect(group, node, scope) {
|
||||
const extractor = group[node.type];
|
||||
|
||||
if (!extractor) {
|
||||
this._spawn(node, scope);
|
||||
console.log('!!!!', node.type, group.entries);
|
||||
//console.dir(node, {colors: true, depth: 5});
|
||||
return null;
|
||||
//this._spawn(node, scope);
|
||||
//return null;
|
||||
}
|
||||
|
||||
const iter = extractor(node);
|
||||
|
@ -163,11 +168,11 @@ class Collector {
|
|||
result = [];
|
||||
|
||||
for (const val of value) {
|
||||
result.push(yield* this._collect(val, scope));
|
||||
result.push(yield* this._collect(group, val, scope));
|
||||
}
|
||||
} else {
|
||||
assert(isNode(value));
|
||||
result = yield* this._collect(value, scope);
|
||||
result = yield* this._collect(group, value, scope);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -247,4 +252,8 @@ function pathToNamespace(path) {
|
|||
.join('.');
|
||||
}
|
||||
|
||||
function getExtractorsGroup(type) {
|
||||
return extractors.find(group => group.entries.includes(type));
|
||||
}
|
||||
|
||||
module.exports = Collector;
|
||||
|
|
|
@ -5,7 +5,9 @@ const assert = require('assert');
|
|||
const {spawn, define, external, provide, query, enter, exit, namespace} = require('./commands');
|
||||
const {partition} = require('./utils');
|
||||
|
||||
const extractors = {
|
||||
const typedefsGroup = {
|
||||
entries: ['TypeAlias', 'InterfaceDeclaration', 'ClassDeclaration'],
|
||||
|
||||
* TypeAlias(node) {
|
||||
let schema = yield node.right;
|
||||
|
||||
|
@ -216,12 +218,6 @@ const extractors = {
|
|||
return null;
|
||||
},
|
||||
|
||||
* BlockStatement(node) {
|
||||
yield enter();
|
||||
yield node.body;
|
||||
yield exit();
|
||||
},
|
||||
|
||||
* InterfaceExtends(node) {
|
||||
return yield node.id;
|
||||
},
|
||||
|
@ -237,13 +233,27 @@ const extractors = {
|
|||
* CommentBlock(node) {
|
||||
return extractPragma(node.value);
|
||||
},
|
||||
};
|
||||
|
||||
/*
|
||||
* Imports.
|
||||
*
|
||||
* TODO: warning about "import typeof".
|
||||
* TODO: support form "import *".
|
||||
*/
|
||||
/*
|
||||
* TODO: declarations.
|
||||
*/
|
||||
const blocksGroup = {
|
||||
entries: ['BlockStatement'],
|
||||
|
||||
* BlockStatement(node) {
|
||||
yield enter();
|
||||
yield spawn(node.body);
|
||||
yield exit();
|
||||
},
|
||||
};
|
||||
|
||||
/*
|
||||
* TODO: warning about "import typeof".
|
||||
* TODO: support form "import *".
|
||||
*/
|
||||
const importsGroup = {
|
||||
entries: ['ImportDeclaration', 'VariableDeclarator'],
|
||||
|
||||
* ImportDeclaration(node) {
|
||||
const specifiers = yield node.specifiers;
|
||||
|
@ -319,12 +329,17 @@ const extractors = {
|
|||
return node.value;
|
||||
},
|
||||
|
||||
/*
|
||||
* Exports.
|
||||
*
|
||||
* TODO: support "export from" form.
|
||||
* TODO: support commonjs.
|
||||
*/
|
||||
* Identifier(node) {
|
||||
return node.name;
|
||||
},
|
||||
};
|
||||
|
||||
/*
|
||||
* TODO: support "export from" form.
|
||||
* TODO: support commonjs.
|
||||
*/
|
||||
const exportsGroup = Object.assign({}, typedefsGroup, {
|
||||
entries: ['ExportNamedDeclaration', 'ExportDefaultDeclaration'],
|
||||
|
||||
* ExportDefaultDeclaration(node) {
|
||||
let schema = yield node.declaration;
|
||||
|
@ -375,7 +390,7 @@ const extractors = {
|
|||
exported,
|
||||
});
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
function* extractLastPragma(comments) {
|
||||
const pragmas = (yield comments).filter(Boolean);
|
||||
|
@ -541,4 +556,9 @@ function mergeSchemas(schemas) {
|
|||
};
|
||||
}
|
||||
|
||||
module.exports = extractors;
|
||||
module.exports = [
|
||||
typedefsGroup,
|
||||
blocksGroup,
|
||||
importsGroup,
|
||||
exportsGroup,
|
||||
];
|
||||
|
|
|
@ -76,5 +76,5 @@
|
|||
]
|
||||
}
|
||||
],
|
||||
"taskCount": 7
|
||||
"taskCount": 16
|
||||
}
|
||||
|
|
|
@ -23,5 +23,5 @@
|
|||
]
|
||||
}
|
||||
],
|
||||
"taskCount": 2
|
||||
"taskCount": 4
|
||||
}
|
||||
|
|
|
@ -13,5 +13,5 @@
|
|||
"fields": [{"name": "t", "type": "typeInMethod.Test"}]
|
||||
}
|
||||
],
|
||||
"taskCount": 2
|
||||
"taskCount": 3
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue