It runs on Yuku's native core, installed for your platform. In browsers and edge runtimes, load the WebAssembly core from @yuku-core/wasm and pass it in as core.
Usage
import { parse } from "yuku-parser";const { program, comments, diagnostics } = parse("const x = 1 + 2;");
The AST
ESTree for JavaScript and JSX, identical to Acorn, and TypeScript-ESTree for TypeScript, matching Oxc for both. On top of the specs, it carries stage 3 decorators, and as on imports and , and the of .
position is "before", "after", or "inside" an otherwise empty node, such as function f() { /* hi */ }.
Tokens
tokens: true keeps every token in a TokenList, a view over the parser's token table where a token is an index.
import { parse, TokenKind } from "yuku-parser";const { tokens } = parse(source, { tokens: true });for (let i = 0; i < tokens.length; i++) { if (tokens.kind(i) === TokenKind.Arrow) console.log(tokens.start(i), tokens.text(i));}
tokens.kind(i) // one of TokenKindtokens.text(i) // its source texttokens.start(i) // UTF-16 offsetstokens.end(i)tokens.isKeyword(i)tokens.isReserved(i) // reserved unconditionally or in strict modetokens.isUnconditionallyReserved(i)tokens.isStrictModeReserved(i)tokens.isIdentifierLike(i) // an identifier or any keywordtokens.isNumericLiteral(i)tokens.isBinaryOperator(i)tokens.isLogicalOperator(i)tokens.isUnaryOperator(i)tokens.isAssignmentOperator(i)tokens.precedence
The queries answer with an index, or -1 when there is none. Tokens are as the parser resolved them, so a regex is one RegexLiteral, and comments are not tokens. The kinds are listed in tokens.d.ts.