#deno #ast #text

deno_ast

Source text parsing, lexing, and AST related functionality for Deno

16 releases (8 breaking)

0.9.0 Jan 13, 2022
0.7.0 Dec 8, 2021
0.5.0 Oct 29, 2021
Download history 2142/week @ 2021-10-02 2307/week @ 2021-10-09 2445/week @ 2021-10-16 1967/week @ 2021-10-23 1831/week @ 2021-10-30 1416/week @ 2021-11-06 1211/week @ 2021-11-13 1076/week @ 2021-11-20 1443/week @ 2021-11-27 1297/week @ 2021-12-04 1568/week @ 2021-12-11 1131/week @ 2021-12-18 860/week @ 2021-12-25 1654/week @ 2022-01-01 2096/week @ 2022-01-08 1686/week @ 2022-01-15

6,450 downloads per month
Used in 9 crates (8 directly)

MIT license

135KB
3.5K SLoC

Rust 3.5K SLoC // 0.0% comments TypeScript 395 SLoC // 0.1% comments

deno_ast

Discord Chat

Source text parsing, lexing, and AST related functionality for Deno.

use deno_ast::parse_module;
use deno_ast::MediaType;
use deno_ast::ParseParams;
use deno_ast::SourceTextInfo;
use std::sync::Arc;

let source_text = Arc::new("class MyClass {}");
let source_text_info = SourceTextInfo::new(source_text);
let parsed_source = parse_module(ParseParams {
  specifier: "file:///my_file.ts".to_string(),
  media_type: MediaType::TypeScript,
  source: source_text_info,
  capture_tokens: true,
  maybe_syntax: None,
  scope_analysis: false,
}).expect("should parse");

// returns the comments
parsed_source.comments();
// returns the tokens if captured
parsed_source.tokens();
// returns the module (AST)
parsed_source.module();
// returns the `SourceTextInfo`
parsed_source.source();

Dependencies

~5.5–9MB
~206K SLoC

XFa