ah-yu / deno_ast

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

Home Page:https://crates.io/crates/deno_ast

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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();

About

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

https://crates.io/crates/deno_ast

License:MIT License


Languages

Language:Rust 95.9%Language:TypeScript 4.1%