Struct resw::Writer[][src]

pub struct Writer<T: Write> { /* fields omitted */ }

The writer that will take in RESSA AST and write to the provided impl Write provided

Implementations

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]

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 of format!. If using this in conjunction with ressa you will need to call the AsConcrete trait method as_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]

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]

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]

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]

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]

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]

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]

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]

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]

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]

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]

Write an assignment expression

a = b
b += 8
q **= 100

pub fn write_assignment_operator(
    &mut self,
    op: &AssignOp
) -> Result<(), IoError>
[src]

pub fn write_logical_expr(
    &mut self,
    logical: &LogicalExpr<'_>
) -> Result<(), IoError>
[src]

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]

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]

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]

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

impl<T> Send for Writer<T> where
    T: Send

impl<T> Sync for Writer<T> where
    T: Sync

impl<T> Unpin for Writer<T> where
    T: Unpin

impl<T> UnwindSafe for Writer<T> where
    T: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.