Skip to content

Commit 86a7be5

Browse files
committed
Fix logic in getModuleInfo
1 parent 7000b9b commit 86a7be5

File tree

2 files changed

+17
-17
lines changed

2 files changed

+17
-17
lines changed

index.js

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,24 +28,25 @@ function getModuleInfo(moduleId, parser) {
2828
namedExports: {}
2929
};
3030
if (!fileNodes[moduleId]) {
31-
const classDeclarations = {};
3231
const absolutePath = path.join(process.cwd(), moduleRoot, moduleId + '.js');
3332
const file = fs.readFileSync(absolutePath, 'UTF-8');
34-
const node = fileNodes[moduleId] = parser.astBuilder.build(file, absolutePath);
35-
if (node.program && node.program.body) {
36-
const nodes = node.program.body;
37-
for (let i = 0, ii = nodes.length; i < ii; ++i) {
38-
const node = nodes[i];
39-
if (node.type === 'ClassDeclaration') {
40-
classDeclarations[node.id.name] = node;
41-
} else if (node.type === 'ExportDefaultDeclaration') {
42-
const classDeclaration = classDeclarations[node.declaration.name];
43-
if (classDeclaration) {
44-
moduleInfo.defaultExport = classDeclaration.id.name;
45-
}
46-
} else if (node.type === 'ExportNamedDeclaration' && node.declaration && node.declaration.type === 'ClassDeclaration') {
47-
moduleInfo.namedExports[node.declaration.id.name] = true;
33+
fileNodes[moduleId] = parser.astBuilder.build(file, absolutePath);
34+
}
35+
const node = fileNodes[moduleId];
36+
if (node.program && node.program.body) {
37+
const classDeclarations = {};
38+
const nodes = node.program.body;
39+
for (let i = 0, ii = nodes.length; i < ii; ++i) {
40+
const node = nodes[i];
41+
if (node.type === 'ClassDeclaration') {
42+
classDeclarations[node.id.name] = node;
43+
} else if (node.type === 'ExportDefaultDeclaration') {
44+
const classDeclaration = classDeclarations[node.declaration.name];
45+
if (classDeclaration) {
46+
moduleInfo.defaultExport = classDeclaration.id.name;
4847
}
48+
} else if (node.type === 'ExportNamedDeclaration' && node.declaration && node.declaration.type === 'ClassDeclaration') {
49+
moduleInfo.namedExports[node.declaration.id.name] = true;
4950
}
5051
}
5152
}
@@ -154,7 +155,6 @@ exports.astNodeVisitor = {
154155
node.comments.forEach(comment => {
155156
// Replace typeof Foo with Class<Foo>
156157
comment.value = comment.value.replace(/typeof ([^,\|\}\>]*)([,\|\}\>])/g, 'Class<$1>$2');
157-
debugger
158158

159159
// Convert `import("path/to/module").export` to
160160
// `module:path/to/module~Name`

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "jsdoc-plugin-typescript",
3-
"version": "1.0.1",
3+
"version": "1.0.2",
44
"description": "Plugin to make TypeScript's JSDoc type annotations work with JSDoc",
55
"main": "index.js",
66
"scripts": {

0 commit comments

Comments
 (0)