dsherret / dsherret/ts-morph

`getChildrenOfKind` does not work for `StringLiteral`

Open
#1,632 4 comments 0 reactions 0 assignees View on GitHub
breaking change
Dominant language
TypeScript
Stars
6.2k
Forks
238
Avg merge
2m
Merged PRs (30d)
1

Description

**Describe the bug**

Hi,

`getChildrenOfKind` returns nothing for `SyntaxKind.StringLiteral` because `useParseTreeSearchForKind` returns `false` which should be `true`.

Version: 25.0.1

**To Reproduce**

```javascript
import { Project, SyntaxKind } from 'ts-morph';

const src = '["abc", "def"];';
const project = new Project();
const source = project.createSourceFile('dummy.js', src);
for (const es of source.getChildrenOfKind(SyntaxKind.ExpressionStatement)) {
for (const ale of es.getChildrenOfKind(SyntaxKind.ArrayLiteralExpression)) {
for (const sl of ale.getChildrenOfKind(SyntaxKind.StringLiteral)) {
console.log(sl); // not found
}
for (const sl of ale._getCompilerForEachChildren().filter((c) => c.kind === SyntaxKind.StringLiteral)) {
console.log(sl); // found
}
}
}

```

**Expected behavior**

`getChildrenOfKind` returns the children of `StringLiteral`.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.