Expand description
All methods accept Handler, which is a storage for errors.
The caller should check if the handler contains any errors after calling method.
Fields
cm: Arc<SourceMap>
CodeMap
Implementations
sourceimpl Compiler
impl Compiler
These are low-level apis.
pub fn globals(&self) -> &Globals
pub fn comments(&self) -> &SwcComments
sourcepub fn run<R, F>(&self, op: F) -> R where
F: FnOnce() -> R,
pub fn run<R, F>(&self, op: F) -> R where
F: FnOnce() -> R,
Runs op
in current compiler’s context.
Note: Other methods of Compiler
already uses this internally.
sourcepub fn parse_js(
&self,
fm: Arc<SourceFile>,
handler: &Handler,
target: EsVersion,
syntax: Syntax,
is_module: IsModule,
comments: Option<&dyn Comments>
) -> Result<Program, Error>
pub fn parse_js(
&self,
fm: Arc<SourceFile>,
handler: &Handler,
target: EsVersion,
syntax: Syntax,
is_module: IsModule,
comments: Option<&dyn Comments>
) -> Result<Program, Error>
This method parses a javascript / typescript file
sourcepub fn print<T>(
&self,
node: &T,
source_file_name: Option<&str>,
output_path: Option<PathBuf>,
inline_sources_content: bool,
target: EsVersion,
source_map: SourceMapsConfig,
source_map_names: &AHashMap<BytePos, JsWord>,
orig: Option<&SourceMap>,
minify: bool,
comments: Option<&dyn Comments>
) -> Result<TransformOutput, Error> where
T: Node + VisitWith<IdentCollector>,
pub fn print<T>(
&self,
node: &T,
source_file_name: Option<&str>,
output_path: Option<PathBuf>,
inline_sources_content: bool,
target: EsVersion,
source_map: SourceMapsConfig,
source_map_names: &AHashMap<BytePos, JsWord>,
orig: Option<&SourceMap>,
minify: bool,
comments: Option<&dyn Comments>
) -> Result<TransformOutput, Error> where
T: Node + VisitWith<IdentCollector>,
Converts ast node to source string and sourcemap.
This method receives target file path, but does not write file to the path. See: https://github.com/swc-project/swc/issues/1255
sourceimpl Compiler
impl Compiler
High-level apis.
pub fn new(cm: Arc<SourceMap>) -> Self
pub fn read_config(
&self,
opts: &Options,
name: &FileName
) -> Result<Option<Config>, Error>
sourcepub fn parse_js_as_input<'a, P>(
&'a self,
fm: Lrc<SourceFile>,
program: Option<Program>,
handler: &'a Handler,
opts: &Options,
name: &FileName,
comments: Option<&'a SingleThreadedComments>,
before_pass: impl 'a + FnOnce(&Program) -> P
) -> Result<Option<BuiltInput<impl 'a + Fold>>, Error> where
P: 'a + Fold,
pub fn parse_js_as_input<'a, P>(
&'a self,
fm: Lrc<SourceFile>,
program: Option<Program>,
handler: &'a Handler,
opts: &Options,
name: &FileName,
comments: Option<&'a SingleThreadedComments>,
before_pass: impl 'a + FnOnce(&Program) -> P
) -> Result<Option<BuiltInput<impl 'a + Fold>>, Error> where
P: 'a + Fold,
This method returns None if a file should be skipped.
This method handles merging of config.
This method does not parse module.
pub fn run_transform<F, Ret>(
&self,
handler: &Handler,
external_helpers: bool,
op: F
) -> Ret where
F: FnOnce() -> Ret,
pub fn transform(
&self,
handler: &Handler,
program: Program,
external_helpers: bool,
pass: impl Fold
) -> Program
sourcepub fn process_js_with_custom_pass<P1, P2>(
&self,
fm: Arc<SourceFile>,
program: Option<Program>,
handler: &Handler,
opts: &Options,
custom_before_pass: impl FnOnce(&Program) -> P1,
custom_after_pass: impl FnOnce(&Program) -> P2
) -> Result<TransformOutput, Error> where
P1: Fold,
P2: Fold,
pub fn process_js_with_custom_pass<P1, P2>(
&self,
fm: Arc<SourceFile>,
program: Option<Program>,
handler: &Handler,
opts: &Options,
custom_before_pass: impl FnOnce(&Program) -> P1,
custom_after_pass: impl FnOnce(&Program) -> P2
) -> Result<TransformOutput, Error> where
P1: Fold,
P2: Fold,
custom_after_pass
is applied after swc transforms are applied.
program
: If you already parsed Program
, you can pass it.
Guarantee
swc
invokes custom_before_pass
after
- Handling decorators, if configured
- Applying
resolver
- Stripping typescript nodes
This means, you can use noop_visit_type
, noop_fold_type
and
noop_visit_mut_type
in your visitor to reduce the binary size.
pub fn process_js_file(
&self,
fm: Arc<SourceFile>,
handler: &Handler,
opts: &Options
) -> Result<TransformOutput, Error>
pub fn minify(
&self,
fm: Arc<SourceFile>,
handler: &Handler,
opts: &JsMinifyOptions
) -> Result<TransformOutput, Error>
sourcepub fn process_js(
&self,
handler: &Handler,
program: Program,
opts: &Options
) -> Result<TransformOutput, Error>
pub fn process_js(
&self,
handler: &Handler,
program: Program,
opts: &Options
) -> Result<TransformOutput, Error>
You can use custom pass with this method.
There exists a PassBuilder to help building custom passes.
Auto Trait Implementations
impl !RefUnwindSafe for Compiler
impl Send for Compiler
impl Sync for Compiler
impl Unpin for Compiler
impl !UnwindSafe for Compiler
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
impl<T> Pointable for T
impl<T> Pointable for T
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
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
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more