diff --git a/source/lib/parser.ts b/source/lib/parser.ts index 5b72a06c..8ad952f4 100644 --- a/source/lib/parser.ts +++ b/source/lib/parser.ts @@ -14,33 +14,47 @@ export const extractAssertions = (program: Program): Map(); - const nodes = assertions.get(assertion) ?? new Set(); + nodes.add(node); - nodes.add(node); + assertions.set(assertion, nodes); + } + } - assertions.set(assertion, nodes); - } - } + /** + * Recursively loop over all the nodes and extract all the assertions out of the source files. + */ + function walkNodes(node: Node) { + if (isCallExpression(node)) { + handleNode(node); } forEachChild(node, walkNodes); diff --git a/source/test/fixtures/undefined-symbol/index.d.ts b/source/test/fixtures/undefined-symbol/index.d.ts new file mode 100644 index 00000000..336ce12b --- /dev/null +++ b/source/test/fixtures/undefined-symbol/index.d.ts @@ -0,0 +1 @@ +export {} diff --git a/source/test/fixtures/undefined-symbol/index.test-d.ts b/source/test/fixtures/undefined-symbol/index.test-d.ts new file mode 100644 index 00000000..810a76b8 --- /dev/null +++ b/source/test/fixtures/undefined-symbol/index.test-d.ts @@ -0,0 +1,7 @@ +import {expectType} from '../../../..'; + +// Identifier `bar` has no Symbol +const anyCall = (foo: any) => foo.bar(); + +// Fails with `Cannot read properties of undefined (reading 'flags')` in 0.24.0 +expectType(anyCall('foo')); diff --git a/source/test/fixtures/undefined-symbol/package.json b/source/test/fixtures/undefined-symbol/package.json new file mode 100644 index 00000000..de6dc1db --- /dev/null +++ b/source/test/fixtures/undefined-symbol/package.json @@ -0,0 +1,3 @@ +{ + "name": "foo" +} diff --git a/source/test/test.ts b/source/test/test.ts index 21ad2930..b29f9063 100644 --- a/source/test/test.ts +++ b/source/test/test.ts @@ -466,3 +466,9 @@ test('assertions should be identified if aliased', async t => { verify(t, diagnostics, []); }); + +test('parsing undefined symbol should not fail', async t => { + const diagnostics = await tsd({cwd: path.join(__dirname, 'fixtures/undefined-symbol')}); + + verify(t, diagnostics, []); +});