Skip to content

Commit 52974b6

Browse files
asvetliakovbuehler
authored andcommitted
fix(indexing): occasionally processing modules on re-index (#16)
1 parent eea9b47 commit 52974b6

File tree

5 files changed

+111
-2
lines changed

5 files changed

+111
-2
lines changed

src/DeclarationIndex.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,8 +281,8 @@ export class DeclarationIndex {
281281
Object
282282
.keys(this.parsedResources)
283283
.forEach((key) => {
284-
const resource = this.parsedResources[key] as File;
285-
if (this.doesExportResource(resource, resourceToCheck)) {
284+
const resource = this.parsedResources[key];
285+
if (resource instanceof File && this.doesExportResource(resource, resourceToCheck)) {
286286
resources.push(resource.filePath);
287287
}
288288
});
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
export class MyClass {
3+
public doSomething(): void { }
4+
}

test/_workspace/declaration-index/specific-cases/reindex-with-global-module-export/node_modules/@types/some-module/index.d.ts

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { FileChanges } from '../../../../src';
2+
import { join, resolve } from 'path';
3+
4+
import { DeclarationIndex } from '../../../../src/DeclarationIndex';
5+
import { TypescriptParser } from '../../../../src/TypescriptParser';
6+
7+
describe('DeclarationIndex - specific case "reindex-with-global-module"', () => {
8+
9+
const rootPath = resolve(
10+
__dirname, '..', '..', '..', '_workspace', 'declaration-index', 'specific-cases',
11+
'reindex-with-global-module-export',
12+
);
13+
const files = [
14+
join(rootPath, 'node_modules', '@types', 'some-module', 'index.d.ts'),
15+
join(rootPath, 'classes.ts'),
16+
];
17+
18+
let declarationIndex: DeclarationIndex;
19+
20+
beforeEach(async () => {
21+
declarationIndex = new DeclarationIndex(new TypescriptParser(), rootPath);
22+
await declarationIndex.buildIndex(files);
23+
});
24+
25+
it('should parse the declarations', () => {
26+
expect(declarationIndex.index['some-module']).toMatchSnapshot();
27+
expect(declarationIndex.index['SomeInterface']).toMatchSnapshot();
28+
expect(declarationIndex.index['MyClass']).toMatchSnapshot();
29+
});
30+
31+
it(`reindex local file doesn't throw error`, async () => {
32+
const changes: FileChanges = {
33+
created: [],
34+
deleted: [],
35+
updated: [files[1]],
36+
};
37+
await declarationIndex.reindexForChanges(changes);
38+
});
39+
40+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`DeclarationIndex - specific case "reindex-with-global-module" should parse the declarations 1`] = `
4+
Array [
5+
DeclarationInfo {
6+
"declaration": ModuleDeclaration {
7+
"end": 206,
8+
"name": "someModule",
9+
"start": 74,
10+
},
11+
"from": "some-module",
12+
},
13+
]
14+
`;
15+
16+
exports[`DeclarationIndex - specific case "reindex-with-global-module" should parse the declarations 2`] = `
17+
Array [
18+
DeclarationInfo {
19+
"declaration": InterfaceDeclaration {
20+
"end": 70,
21+
"isExported": true,
22+
"methods": Array [],
23+
"name": "SomeInterface",
24+
"properties": Array [],
25+
"start": 36,
26+
},
27+
"from": "some-module",
28+
},
29+
]
30+
`;
31+
32+
exports[`DeclarationIndex - specific case "reindex-with-global-module" should parse the declarations 3`] = `
33+
Array [
34+
DeclarationInfo {
35+
"declaration": ClassDeclaration {
36+
"end": 61,
37+
"isExported": true,
38+
"methods": Array [
39+
MethodDeclaration {
40+
"end": 59,
41+
"isAbstract": false,
42+
"name": "doSomething",
43+
"parameters": Array [],
44+
"start": 29,
45+
"type": "void",
46+
"variables": Array [],
47+
"visibility": 2,
48+
},
49+
],
50+
"name": "MyClass",
51+
"properties": Array [],
52+
"start": 1,
53+
},
54+
"from": "/classes",
55+
},
56+
]
57+
`;

0 commit comments

Comments
 (0)