'In recast, why is a Literal that is a string not a StringLiteral?

This mainly stems from me not finding extended documentation to read, apart from the bits that are on the related github pages.

const recast = import("recast");
const example = "let s = 'some text';";
let ast = recast.parse(example);
recast.types.namedTypes.StringLiteral.check(ast.program.body[0].declarations[0].init) === false;
recast.types.namedTypes.Literal.check(ast.program.body[0].declarations[0].init) === true;
typeof ast.program.body[0].declarations[0].init.value === "string";

I was expecting the StringLiteral check to result in true, why is it not? My best guess is, that StringLiteral is something, that doesn't occur in vanilla javascript, but e.g. in typescript or related.

As i don't have proper documentation, i am going by best-guess, which is sadly often not a good idea. I'd be thankful for links to anything informative.

Side question: Is there a good way to check, whether a string literal is a valid identifier name, or do i have to do that with regex?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source