uast-javascript
JavaScript read with swc's parser into swc's own module
AST. JavaScriptParser::parse reads the source as an ECMAScript module with
JSX enabled and returns a JavaScriptAst holding the swc_ecma_ast::Module,
or every error the parser reported. The AST is the language's own shape, not
the uast spine: it keeps swc's spans but not comments or whitespace, so it
does not reconstruct the source.
For JavaScript in the spine (a lossless Tree with the vocabulary the
TypeScript dialect shares), use parse_javascript from
uast-treesitter. The TypeScript
counterpart of this crate is
uast-typescript.
What it reads
- swc_ecma_parser 45 with
EsSyntax { jsx: true }and the parser's other defaults: the latest ECMAScript syntax swc reads, plus JSX. - Always a module (
parse_module), soimportandexportare accepted and the body is read in strict mode. - Any error is an
Err(String): a fatal one alone, or the recoverable errors swc collected, one per line, each in itsDebugform. JavaScriptAstimplements serde'sSerializeandDeserialize(swc'sserde-impl), and round-trips through JSON.
Usage
[]
= "0.1"
use JavaScriptParser;
#
To match on the AST, depend on the same swc_ecma_ast (29) the crate does.
Through uast-grammar
The javascript feature of
uast-grammar, off by default,
re-exports uast_grammar::{JavaScriptAst, JavaScriptParser}. The default
treesitter feature gives the spine reader, uast_grammar::parse_javascript.
License
MIT. See LICENSE.