oden/third-party/vendor/deno_ast
2024-03-08 11:03:01 -08:00
..
scripts Vendor things 2024-03-08 11:03:01 -08:00
src Vendor things 2024-03-08 11:03:01 -08:00
.cargo-checksum.json Vendor things 2024-03-08 11:03:01 -08:00
Cargo.toml Vendor things 2024-03-08 11:03:01 -08:00
deno.json Vendor things 2024-03-08 11:03:01 -08:00
LICENSE Vendor things 2024-03-08 11:03:01 -08:00
README.md Vendor things 2024-03-08 11:03:01 -08:00
rust-toolchain.toml Vendor things 2024-03-08 11:03:01 -08:00

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;

let source_text = "class MyClass {}";
let text_info = SourceTextInfo::new(source_text.into());
let parsed_source = parse_module(ParseParams {
  specifier: "file:///my_file.ts".to_string(),
  media_type: MediaType::TypeScript,
  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.text_info();