Skip to content

getChildrenOfKind does not work for StringLiteral #1632

Description

@char101

Describe the bug

Hi,

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

Version: 25.0.1

To Reproduce

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.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions