[−][src]Struct resw::Writer
The writer that will take in
RESSA AST and write to the provided
impl Write
provided
Methods
impl<T: Write> Writer<T>
[src]
pub fn new(out: T) -> Self
[src]
Create a default writer with the provided destination
This will use \n
for new lines, 4 spaces for indenting
and the source text's quote character for quoting
pub fn create(
out: T,
new_line: String,
quote: Option<char>,
indent: String
) -> Self
[src]
out: T,
new_line: String,
quote: Option<char>,
indent: String
) -> Self
Fully customizable constructor
See builder
for a more ergonomic solution
pub fn builder() -> Builder<T>
[src]
Create a Builder
for constructing your writer
pub fn write_program(&mut self, program: &Program) -> Result<(), IoError>
[src]
This will loop over the contents of a Program
and
attempt write them all to the provided impl Write
Note: This will take the concrete version of the
resast
tree to allow for easier mutation of any string contents by enabling the use offormat!
. If using this in conjunction withressa
you will need to call theAsConcrete
trait methodas_concrete
to convert the output into the right type for input here.
pub fn write_part(&mut self, part: &ProgramPart) -> Result<(), IoError>
[src]
This will attempt to write a single ProgramPart
pub fn write_decl(&mut self, decl: &Decl) -> Result<(), IoError>
[src]
Attempt to write a Declaration
to the impl Write
pub fn write_variable_decls(
&mut self,
kind: &VarKind,
decls: &[VarDecl]
) -> Result<(), IoError>
[src]
&mut self,
kind: &VarKind,
decls: &[VarDecl]
) -> Result<(), IoError>
Attempt to write a Declaration::Var
's contents to the impl Write
let a, b, c, d, e = "thing";
const f = "stuff";
var g, h, i, j = "places";
pub fn write_class(&mut self, class: &Class) -> Result<(), IoError>
[src]
Attempt to write a Class
to the impl Write
, used for both
writing the contents of Declaration::Class
and Expr::Class
// class expression
let x = class {
constructor() {
}
method1() {
}
method2() {
}
}
// class declaration
class Y {
constructor() {
}
method1() {
}
method2() {
}
}
pub fn write_export_decl(&mut self, exp: &ModExport) -> Result<(), IoError>
[src]
Attempt to write the contents of Declaration::Export
to the impl Write
export function Thing() {
}
export * from 'module';
export {Stuff} from 'other_module';
pub fn write_all_export(&mut self, exp: &Lit) -> Result<(), IoError>
[src]
Attempt to write the contents ModuleExport::All
to the impl Write
export * from 'module'
pub fn write_default_export(
&mut self,
exp: &DefaultExportDecl
) -> Result<(), IoError>
[src]
&mut self,
exp: &DefaultExportDecl
) -> Result<(), IoError>
Attempt to write the contents ModuleExport::Default
to the impl Write
export default function Thing() {
}
pub fn write_named_export(
&mut self,
exp: &NamedExportDecl
) -> Result<(), IoError>
[src]
&mut self,
exp: &NamedExportDecl
) -> Result<(), IoError>
Attempts to write the contents of ModuleExport::Named
to the impl Write
export function Thing {
}
export {Stuff} from 'module';
pub fn write_export_specifiers(
&mut self,
specifiers: &[ExportSpecifier],
from: &Option<Lit>
) -> Result<(), IoError>
[src]
&mut self,
specifiers: &[ExportSpecifier],
from: &Option<Lit>
) -> Result<(), IoError>
Attempts to write the contents of NamedExportDecl::Specifier
to the impl Write
export {Stuff as Things} from 'module'
export {Places} from 'other_module'
pub fn write_import_decl(&mut self, imp: &ModImport) -> Result<(), IoError>
[src]
Attempts to write the contents of Declaration::Import
to the impl Write
import * as Moment from 'moment';
import {Thing, Place} from 'module';
import Stuff from 'other_module';
pub fn write_import_specificer(
&mut self,
spec: &ImportSpecifier
) -> Result<(), IoError>
[src]
&mut self,
spec: &ImportSpecifier
) -> Result<(), IoError>
Attempts to write a single ImportSpecifier
to the impl Write
import * as Moment from 'moment';
import {Thing, Place} from 'module';
import Stuff from 'other_module';
pub fn write_namespace_import(&mut self, name: &Ident) -> Result<(), IoError>
[src]
Attempts to write the contents ofImportSpecifier::Namespace
to the impl Write
import * as Moment from 'moment';
pub fn write_normal_import(
&mut self,
name: &Ident,
local: &Ident
) -> Result<(), IoError>
[src]
&mut self,
name: &Ident,
local: &Ident
) -> Result<(), IoError>
Attempts to write the contents ofImportSpecifier::Normal
to the impl Write
import {Thing as Stuff} from 'module';
pub fn write_directive(&mut self, dir: &Dir) -> Result<(), IoError>
[src]
Attempts to write a directive to the impl Write
'use strict';
pub fn write_variable_decl(&mut self, decl: &VarDecl) -> Result<(), IoError>
[src]
Attempts to write a variable declaration
let x = function() {
}
var a, b, c, d = 'things';
pub fn write_variable_kind(&mut self, kind: &VarKind) -> Result<(), IoError>
[src]
Attempts to write the variable keyword (var
/let
/const
)
pub fn write_stmt(&mut self, stmt: &Stmt) -> Result<(), IoError>
[src]
Attempts to write the contents of a Stmt
pub fn write_debugger_stmt(&mut self) -> Result<(), IoError>
[src]
Attempts to write a debugger stmt
debugger;
pub fn write_block_stmt(&mut self, block: &[ProgramPart]) -> Result<(), IoError>
[src]
Attempts to write a block statement
{
var x = 0;
}
pub fn write_with_stmt(&mut self, expr: &WithStmt) -> Result<(), IoError>
[src]
Attempts to write a WithStmt
With(Math) {
var y = random() * 100;
}
pub fn write_return_stmt(&mut self, expr: &Option<Expr>) -> Result<(), IoError>
[src]
Attempts to write a ReturnStmt
function one() {
return 'things';
}
function two() {
return;
}
pub fn write_labeled_stmt(&mut self, expr: &LabeledStmt) -> Result<(), IoError>
[src]
Attempts to write a LabeledStmt
label: {
if (true) {
break label;
}
}
pub fn write_break_stmt(&mut self, expr: &Option<Ident>) -> Result<(), IoError>
[src]
Attempts to write a break statement
label: {
if (true) {
break label;
}
}
for (;;) {
break;
}
pub fn write_continue_stmt(
&mut self,
expr: &Option<Ident>
) -> Result<(), IoError>
[src]
&mut self,
expr: &Option<Ident>
) -> Result<(), IoError>
Attempts to write a continue statement
for (;;) continue;
outer: for (;;) {
inner: for (;;) {
if ((Math.random() * 100) > 50) {
continue outer;
} else {
continue inner;
}
}
}
pub fn write_if_stmt(&mut self, expr: &IfStmt) -> Result<(), IoError>
[src]
Attempts to write an IfStmt
if ((Math.random() * 100) > 50) {
} else if ((Math.random() * 100) < 25) {
} else {
}
pub fn write_switch_stmt(&mut self, switch: &SwitchStmt) -> Result<(), IoError>
[src]
Attempts to write a SwitchStmt
switch (Math.floor(Math.random() * 5)) {
case 0:
default:
}
pub fn write_switch_case(&mut self, case: &SwitchCase) -> Result<(), IoError>
[src]
Attempts to write a SwitchCase
switch (Math.floor(Math.random() * 5)) {
case 0:
break;
default:
return 100;
}
pub fn write_throw_stmt(&mut self, expr: &Expr) -> Result<(), IoError>
[src]
Attempts to write a throw statement
function one() {
throw 'Things'
}
function two() {
throw new Error('Things');
}
pub fn write_try_stmt(&mut self, stmt: &TryStmt) -> Result<(), IoError>
[src]
Attempts to write a try statement
try {
} catch (e) {
} finally {
}
pub fn write_while_stmt(&mut self, stmt: &WhileStmt) -> Result<bool, IoError>
[src]
Attempts to write a while statement
while (true) {
}
pub fn write_do_while_stmt(&mut self, stmt: &DoWhileStmt) -> Result<(), IoError>
[src]
Attempts to write a do while statement
do {
} while(true)
pub fn write_for_stmt(&mut self, stmt: &ForStmt) -> Result<bool, IoError>
[src]
Attempts to write a c-style for loop for (var i = 0; i < 100; i++) console.log(i); for (;;) { break; }
pub fn write_loop_init(&mut self, init: &LoopInit) -> Result<(), IoError>
[src]
Attempts to write the first part of a c-style for loop's parenthetical
pub fn write_for_in_stmt(&mut self, stmt: &ForInStmt) -> Result<bool, IoError>
[src]
Attempts to write a for in loop
for (var x in []) {
}
pub fn write_for_of_stmt(&mut self, stmt: &ForOfStmt) -> Result<bool, IoError>
[src]
Attempts to write a for of loop
for (let x of []) {
}
pub fn write_loop_left(&mut self, left: &LoopLeft) -> Result<(), IoError>
[src]
Attempts to write for first part of a for of or for in loop's parenthetical
pub fn write_var_stmt(&mut self, expr: &[VarDecl]) -> Result<(), IoError>
[src]
write a variable statment
var x;
var y = x;
var q, w, e, r = Infinity;
pub fn write_pattern(&mut self, pattern: &Pat) -> Result<(), IoError>
[src]
Write the contents of a pattern
pub fn write_object_pattern(&mut self, obj: &ObjPat) -> Result<(), IoError>
[src]
Write an object pattern
let {x, y} = {x: 100, y: 0};
pub fn write_property(&mut self, prop: &Prop) -> Result<(), IoError>
[src]
Write an object or class property
pub fn write_init_property(&mut self, prop: &Prop) -> Result<(), IoError>
[src]
Write a property that is not a method or constructor
{
a: 100,
}
pub fn write_get_property(&mut self, prop: &Prop) -> Result<(), IoError>
[src]
Write a get property
{
get thing() {
return 'thing'
}
}
pub fn write_set_property(&mut self, prop: &Prop) -> Result<(), IoError>
[src]
Write a get property
class Stuff {
set thing(value) {
this.thing = value;
}
}
pub fn write_property_method(&mut self, prop: &Prop) -> Result<(), IoError>
[src]
Write a property that is a method
{
thing() {
return 'thing'
}
}
pub fn write_function_args(&mut self, args: &[FuncArg]) -> Result<(), IoError>
[src]
Write the arguments of a function or method definition
function(arg1, arg2) {
}
pub fn write_function_arg(&mut self, arg: &FuncArg) -> Result<(), IoError>
[src]
Write a single function arg
pub fn write_function_body(&mut self, body: &FuncBody) -> Result<(), IoError>
[src]
Write the block statement that makes up a function's body
pub fn write_ctor_property(&mut self, prop: &Prop) -> Result<(), IoError>
[src]
Write a property that is a constructor for a class
class Thing {
constructor() {
}
}
pub fn write_property_key(
&mut self,
key: &PropKey,
computed: bool
) -> Result<(), IoError>
[src]
&mut self,
key: &PropKey,
computed: bool
) -> Result<(), IoError>
Write a property key, taking into account of it should be wrapped in [] for "computed" properties
pub fn write_property_value(&mut self, value: &PropValue) -> Result<(), IoError>
[src]
Write the value for a property
pub fn write_rest_pattern_part(&mut self, pat: &Pat) -> Result<(), IoError>
[src]
Writes a rest pattern
let x = [...y];
pub fn write_array_pattern(
&mut self,
arr: &[Option<ArrayPatPart>]
) -> Result<(), IoError>
[src]
&mut self,
arr: &[Option<ArrayPatPart>]
) -> Result<(), IoError>
Writes an array literal from a pattern
let [x, y] = [1, 2];
pub fn write_rest_element(&mut self, pat: &Pat) -> Result<(), IoError>
[src]
Writes a rest pattern
let x = [...y];
pub fn write_assignment_pattern(
&mut self,
assignment: &AssignPat
) -> Result<(), IoError>
[src]
&mut self,
assignment: &AssignPat
) -> Result<(), IoError>
pub fn write_wrapped_expr(&mut self, expr: &Expr) -> Result<(), IoError>
[src]
pub fn write_expr(&mut self, expr: &Expr) -> Result<(), IoError>
[src]
pub fn write_this_expr(&mut self) -> Result<(), IoError>
[src]
Write this
pub fn write_super_expr(&mut self) -> Result<(), IoError>
[src]
Write super
pub fn write_array_expr(&mut self, arr: &ArrayExpr) -> Result<(), IoError>
[src]
write an array literal
[one,,two,,3, null];
pub fn write_object_expr(&mut self, obj: &ObjExpr) -> Result<(), IoError>
[src]
Write an object literal
{
a: b,
c: d,
}
pub fn write_function(&mut self, func: &Func) -> Result<(), IoError>
[src]
Write a function. This is used to write the contents of both a Declaration::Func
and an Expr::Func
pub fn write_unary_expr(&mut self, unary: &UnaryExpr) -> Result<(), IoError>
[src]
Write a unary expression
delete x
typeof y
+9
-10
void 0
~3
!true
pub fn write_unary_operator(&mut self, op: &UnaryOp) -> Result<(), IoError>
[src]
pub fn write_update_expr(&mut self, update: &UpdateExpr) -> Result<(), IoError>
[src]
Write an update expression
a++
--b
pub fn write_update_operator(&mut self, op: &UpdateOp) -> Result<(), IoError>
[src]
pub fn write_binary_expr(&mut self, binary: &BinaryExpr) -> Result<(), IoError>
[src]
Writes a binary expression
a == b
c !== d
x instanceof y
x * 100
pub fn write_binary_side(&mut self, side: &Expr) -> Result<(), IoError>
[src]
pub fn write_binary_operator(&mut self, op: &BinaryOp) -> Result<(), IoError>
[src]
pub fn write_assignment_expr(
&mut self,
assignment: &AssignExpr
) -> Result<(), IoError>
[src]
&mut self,
assignment: &AssignExpr
) -> Result<(), IoError>
Write an assignment expression
a = b
b += 8
q **= 100
pub fn write_assignment_operator(
&mut self,
op: &AssignOp
) -> Result<(), IoError>
[src]
&mut self,
op: &AssignOp
) -> Result<(), IoError>
pub fn write_logical_expr(
&mut self,
logical: &LogicalExpr
) -> Result<(), IoError>
[src]
&mut self,
logical: &LogicalExpr
) -> Result<(), IoError>
Writes a logical expression
a && b
y || q
pub fn write_logical_operator(&mut self, op: &LogicalOp) -> Result<(), IoError>
[src]
pub fn write_member_expr(&mut self, member: &MemberExpr) -> Result<(), IoError>
[src]
Writes a member expression
console.log
console['log']
pub fn write_conditional_expr(
&mut self,
conditional: &ConditionalExpr
) -> Result<(), IoError>
[src]
&mut self,
conditional: &ConditionalExpr
) -> Result<(), IoError>
Writes a conditional expression
let x = isTrue ? 'yes' : 'no';
pub fn write_call_expr(&mut self, call: &CallExpr) -> Result<(), IoError>
[src]
Writes a call expression
console.log()
(function() {
})()
pub fn write_new_expr(&mut self, new: &NewExpr) -> Result<(), IoError>
[src]
Writes a new expression
new Uint8Array(100);
pub fn write_sequence_expr(&mut self, sequence: &[Expr]) -> Result<(), IoError>
[src]
Writes a sequence of sub-expressions
a = b, c = d, q * 100
pub fn write_spread_expr(&mut self, spread: &Expr) -> Result<(), IoError>
[src]
Writes a spread expression
function(...args) {
}
pub fn write_arrow_function_expr(
&mut self,
func: &ArrowFuncExpr
) -> Result<(), IoError>
[src]
&mut self,
func: &ArrowFuncExpr
) -> Result<(), IoError>
Writes and arrow function
x => console.log(x);
(x, y) => {
return x * y;
}
pub fn write_yield_expr(&mut self, expr: &YieldExpr) -> Result<(), IoError>
[src]
Writes a yield expression
function *gen() {
while (true) {
yield 100;
}
}
pub fn write_meta_property(&mut self, meta: &MetaProp) -> Result<(), IoError>
[src]
Writes a meta property
function Thing() {
if (new.target) {
this.stuff = 'things'
} else {
return new Thing;
}
}
pub fn write_await_expr(&mut self, expr: &Expr) -> Result<(), IoError>
[src]
Write an expression preceded by the await keyword
pub fn write_ident(&mut self, ident: &Ident) -> Result<(), IoError>
[src]
Write a plain identifier
pub fn write_tagged_template(
&mut self,
template: &TaggedTemplateExpr
) -> Result<(), IoError>
[src]
&mut self,
template: &TaggedTemplateExpr
) -> Result<(), IoError>
Write a template preceded by an identifier
tag`things ${0} stuff`;
pub fn write_literal(&mut self, lit: &Lit) -> Result<(), IoError>
[src]
Write a literal
null
'string'
"string"
0.1e100
0xff
0o77
0b11
false,
true,
/.+/g
`things`
pub fn write_bool(&mut self, boolean: bool) -> Result<(), IoError>
[src]
Write true or false
pub fn write_string(&mut self, s: &StringLit) -> Result<(), IoError>
[src]
write a string, re-writes the string if quote configuration is set
pub fn write_regex(&mut self, regex: &RegEx) -> Result<(), IoError>
[src]
pub fn write_template(&mut self, template: &TemplateLit) -> Result<(), IoError>
[src]
pub fn write_empty_stmt(&mut self) -> Result<(), IoError>
[src]
pub fn write_open_brace(&mut self) -> Result<(), IoError>
[src]
pub fn write_close_brace(&mut self) -> Result<(), IoError>
[src]
pub fn write_leading_whitespace(&mut self) -> Result<(), IoError>
[src]
pub fn write_new_line(&mut self) -> Result<(), IoError>
[src]
pub fn write_comment(&mut self, comment: Comment<&str>) -> Result<(), IoError>
[src]
Auto Trait Implementations
impl<T> RefUnwindSafe for Writer<T> where
T: RefUnwindSafe,
T: RefUnwindSafe,
impl<T> Send for Writer<T> where
T: Send,
T: Send,
impl<T> Sync for Writer<T> where
T: Sync,
T: Sync,
impl<T> Unpin for Writer<T> where
T: Unpin,
T: Unpin,
impl<T> UnwindSafe for Writer<T> where
T: UnwindSafe,
T: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,