Struct deno_ast::ParsedSource

source ·
pub struct ParsedSource { /* private fields */ }
Expand description

A parsed source containing an AST, comments, and possibly tokens.

Note: This struct is cheap to clone.

Implementations§

source§

impl ParsedSource

source

pub fn analyze_cjs(&self) -> CjsAnalysis

Analyzes the script for CommonJS exports and re-exports based on similar functionality to cjs-module-lexer (https://github.com/nodejs/cjs-module-lexer).

Note: This will panic if called on a non-script.

source§

impl ParsedSource

source

pub fn specifier(&self) -> &str

Gets the module specifier of the module.

source

pub fn media_type(&self) -> MediaType

Gets the media type of the module.

source

pub fn text_info(&self) -> &SourceTextInfo

Gets the text content of the module.

source

pub fn program(&self) -> Arc<Program>

Gets the parsed program.

source

pub fn program_ref(&self) -> &Program

Gets the parsed program as a reference.

source

pub fn module(&self) -> &Module

Gets the parsed module.

This will panic if the source is not a module.

source

pub fn script(&self) -> &Script

Gets the parsed script.

This will panic if the source is not a script.

source

pub fn comments(&self) -> &MultiThreadedComments

Gets the comments found in the source file.

source

pub fn get_leading_comments(&self) -> Vec<Comment>

Get the source’s leading comments, where triple slash directives might be located.

source

pub fn tokens(&self) -> &[TokenAndSpan]

Gets the tokens found in the source file.

This will panic if tokens were not captured during parsing.

source

pub fn top_level_context(&self) -> SyntaxContext

Gets the top level context used when parsing with scope analysis.

This will panic if the source was not parsed with scope analysis.

source

pub fn unresolved_context(&self) -> SyntaxContext

Gets the unresolved context used when parsing with scope analysis.

This will panic if the source was not parsed with scope analysis.

source

pub fn diagnostics(&self) -> &Vec<Diagnostic>

Gets extra non-fatal diagnostics found while parsing.

source

pub fn is_module(&self) -> bool

Gets if this source is a module.

source

pub fn is_script(&self) -> bool

Gets if this source is a script.

source§

impl ParsedSource

source

pub fn with_view<'a, T>(&self, with_view: impl FnOnce(Program<'a>) -> T) -> T

Gets a dprint-swc-ext view of the module.

This provides a closure to examine an “ast view” of the swc AST which has more helper methods and allows for going up the ancestors of a node.

Read more: https://github.com/dprint/dprint-swc-ext

source§

impl ParsedSource

source

pub fn transpile(&self, options: &EmitOptions) -> Result<TranspiledSource>

Transform a TypeScript file into a JavaScript file.

Trait Implementations§

source§

impl Clone for ParsedSource

source§

fn clone(&self) -> ParsedSource

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for ParsedSource

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
source§

impl<T> Send for T
where T: ?Sized,

source§

impl<T> Sync for T
where T: ?Sized,