swc_ecma_codegen/
macros.rs#![allow(unused)]
macro_rules! opt_leading_space {
($emitter:expr, $e:expr) => {
if let Some(ref e) = $e {
formatting_space!($emitter);
emit!($emitter, e);
}
};
}
macro_rules! opt {
($emitter:expr, $e:expr) => {{
if let Some(ref expr) = $e {
emit!($emitter, expr);
}
}};
($emitter:expr, $e:expr,) => {{
opt!($emitter, $e)
}};
}
macro_rules! emit {
($emitter:expr, $e:expr) => {{
crate::Node::emit_with(&$e, $emitter)?;
}};
}
macro_rules! keyword {
($emitter:expr, $span:expr, $s:expr) => {
$emitter.wr.write_keyword(Some($span), $s)?
};
($emitter:expr, $s:expr) => {
$emitter.wr.write_keyword(None, $s)?
};
}
macro_rules! punct {
($emitter:expr, $sp:expr, ";") => {
$emitter.wr.write_semi(Some($sp))?;
};
($emitter:expr, $sp:expr, $s:expr) => {
$emitter.wr.write_punct(Some($sp), $s)?;
};
($emitter:expr, ";") => {
$emitter.wr.write_semi(None)?
};
($emitter:expr, $s:expr) => {
$emitter.wr.write_punct(None, $s)?
};
}
macro_rules! operator {
($emitter:expr, $sp:expr, $s:expr) => {
$emitter.wr.write_operator(Some($sp), $s)?;
};
($emitter:expr, $s:expr) => {
$emitter.wr.write_operator(None, $s)?;
};
}
macro_rules! space {
($emitter:expr) => {
$emitter.wr.write_space()?
};
($emitter:expr,) => {
space!($emitter)
};
}
macro_rules! formatting_space {
($emitter:expr) => {
if !$emitter.cfg.minify {
$emitter.wr.write_space()?;
}
};
($emitter:expr,) => {
formatting_space!($emitter)
};
}
macro_rules! formatting_semi {
($emitter:expr) => {
punct!($emitter, ";")
};
($emitter:expr, ) => {
punct!($emitter, ";")
};
}
macro_rules! semi {
($emitter:expr, $sp:expr) => {
$emitter.wr.write_semi(Some($sp))?;
};
($emitter:expr) => {
$emitter.wr.write_semi(None)?;
};
}
macro_rules! srcmap {
($emitter:expr, $n:expr, true) => {{
let lo = $n.span_lo();
if !lo.is_dummy() {
$emitter.wr.add_srcmap(lo)?;
}
}};
($emitter:expr, $n:expr, false) => {
srcmap!($emitter, $n, false, false)
};
($emitter:expr, $n:expr, false, $subtract:expr) => {
let hi = $n.span_hi();
if !hi.is_dummy() {
if $subtract {
$emitter.wr.add_srcmap(hi - swc_common::BytePos(1))?;
} else {
$emitter.wr.add_srcmap(hi)?;
}
}
};
}