[][src]Struct resw::Writer

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

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]

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

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: &Declaration) -> Result<(), IoError>
[src]

Attempt to write a Declaration to the impl Write

pub fn write_variable_decls(
    &mut self,
    kind: &VariableKind,
    decls: &[VariableDecl]
) -> Result<(), IoError>
[src]

Attempt to write a Declaration::Variable'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 Expression::Class

// class expression
let x = class {
    constructor() {
    }
    method1() {
    }
    method2() {
    }
}
// class declaration
class Y {
    constructor() {
    }
    method1() {
    }
    method2() {
    }
}

pub fn write_export_decl(&mut self, exp: &ModuleExport) -> 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: &Literal) -> 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<Literal>
) -> 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: &ModuleImport) -> 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: &Identifier
) -> 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: &Identifier,
    local: &Option<Identifier>
) -> 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: &Directive) -> Result<(), IoError>
[src]

Attempts to write a directive to the impl Write

'use strict';

pub fn write_variable_decl(
    &mut self,
    decl: &VariableDecl
) -> Result<bool, 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: &VariableKind
) -> Result<(), IoError>
[src]

Attempts to write the variable keyword (var/let/const)

pub fn write_stmt(&mut self, stmt: &Statement) -> Result<(), IoError>
[src]

Attempts to write the contents of a Statement

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: &WithStatement) -> Result<(), IoError>
[src]

Attempts to write a WithStatement

With(Math) {
    var y = random() * 100;
}

pub fn write_return_stmt(
    &mut self,
    expr: &Option<Expression>
) -> Result<(), IoError>
[src]

Attempts to write a ReturnStatement

function one() {
    return 'things';
}
function two() {
    return;
}

pub fn write_labeled_stmt(
    &mut self,
    expr: &LabeledStatement
) -> Result<(), IoError>
[src]

Attempts to write a LabeledStatement

label: {
    if (true) {
        break label;
    }
}

pub fn write_break_stmt(
    &mut self,
    expr: &Option<Identifier>
) -> 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<Identifier>
) -> 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: &IfStatement) -> Result<(), IoError>
[src]

Attempts to write an IfStatement

if ((Math.random() * 100) > 50) {

} else if ((Math.random() * 100) < 25) {

} else {

}

pub fn write_switch_stmt(
    &mut self,
    switch: &SwitchStatement
) -> Result<(), IoError>
[src]

Attempts to write a SwitchStatement

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: &Expression) -> 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: &TryStatement) -> Result<(), IoError>
[src]

Attempts to write a try statement

try {

} catch (e) {

} finally {

}

pub fn write_while_stmt(
    &mut self,
    stmt: &WhileStatement
) -> Result<bool, IoError>
[src]

Attempts to write a while statement

while (true) {
}

pub fn write_do_while_stmt(
    &mut self,
    stmt: &DoWhileStatement
) -> Result<(), IoError>
[src]

Attempts to write a do while statement

do {

} while(true)

pub fn write_for_stmt(&mut self, stmt: &ForStatement) -> 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: &ForInStatement
) -> Result<bool, IoError>
[src]

Attempts to write a for in loop

for (var x in []) {

}

pub fn write_for_of_stmt(
    &mut self,
    stmt: &ForOfStatement
) -> 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: &[VariableDecl]) -> 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: &Pattern) -> Result<(), IoError>
[src]

Write the contents of a pattern

pub fn write_object_pattern(
    &mut self,
    obj: &ObjectPattern
) -> Result<(), IoError>
[src]

Write an object pattern

let {x, y} = {x: 100, y: 0};

pub fn write_property(&mut self, prop: &Property) -> Result<(), IoError>
[src]

Write an object or class property

pub fn write_init_property(&mut self, prop: &Property) -> Result<(), IoError>
[src]

Write a property that is not a method or constructor

{
    a: 100,
}

pub fn write_get_property(&mut self, prop: &Property) -> Result<(), IoError>
[src]

Write a get property

{
    get thing() {
        return 'thing'
    }
}

pub fn write_set_property(&mut self, prop: &Property) -> Result<(), IoError>
[src]

Write a get property

class Stuff {
    set thing(value) {
        this.thing = value;
    }
}

pub fn write_property_method(&mut self, prop: &Property) -> Result<(), IoError>
[src]

Write a property that is a method

{
    thing() {
        return 'thing'
    }
}

pub fn write_function_args(
    &mut self,
    args: &[FunctionArg]
) -> Result<(), IoError>
[src]

Write the arguments of a function or method definition

function(arg1, arg2) {
}

pub fn write_function_arg(&mut self, arg: &FunctionArg) -> Result<(), IoError>
[src]

Write a single function arg

pub fn write_function_body(
    &mut self,
    body: &FunctionBody
) -> Result<(), IoError>
[src]

Write the block statement that makes up a function's body

pub fn write_ctor_property(&mut self, prop: &Property) -> Result<(), IoError>
[src]

Write a property that is a constructor for a class

class Thing {
    constructor() {
    }
}

pub fn write_property_key(
    &mut self,
    key: &PropertyKey,
    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: &PropertyValue
) -> Result<(), IoError>
[src]

Write the value for a property

pub fn write_rest_pattern_part(&mut self, pat: &Pattern) -> Result<(), IoError>
[src]

Writes a rest pattern

let x = [...y];

pub fn write_array_pattern(
    &mut self,
    arr: &[Option<Pattern>]
) -> Result<(), IoError>
[src]

Writes an array literal from a pattern

let [x, y] = [1, 2];

pub fn write_rest_element(&mut self, pat: &Pattern) -> Result<(), IoError>
[src]

pub fn write_assignment_pattern(
    &mut self,
    assignment: &AssignmentPattern
) -> Result<(), IoError>
[src]

Writes a rest pattern

let x = [...y];

pub fn write_wrapped_expr(&mut self, expr: &Expression) -> Result<(), IoError>
[src]

pub fn write_expr(&mut self, expr: &Expression) -> 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: &ArrayExpression) -> Result<(), IoError>
[src]

write an array literal

[one,,two,,3, null];

pub fn write_object_expr(
    &mut self,
    obj: &ObjectExpression
) -> Result<(), IoError>
[src]

Write an object literal

{
    a: b,
    c: d,
}

pub fn write_function(&mut self, func: &Function) -> Result<(), IoError>
[src]

Write a function. This is used to write the contents of both a Declaration::Function and an Expression::Function

pub fn write_unary_expr(
    &mut self,
    unary: &UnaryExpression
) -> 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: &UnaryOperator
) -> Result<(), IoError>
[src]

pub fn write_update_expr(
    &mut self,
    update: &UpdateExpression
) -> Result<(), IoError>
[src]

Write an update expression

a++
--b

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

pub fn write_binary_expr(
    &mut self,
    binary: &BinaryExpression
) -> Result<(), IoError>
[src]

Writes a binary expression

a == b
c !== d
x instanceof y
x * 100

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

pub fn write_assignment_expr(
    &mut self,
    assignment: &AssignmentExpression
) -> Result<(), IoError>
[src]

Write an assignment expression

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

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

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

Writes a logical expression

a && b
y || q

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

pub fn write_member_expr(
    &mut self,
    member: &MemberExpression
) -> Result<(), IoError>
[src]

Writes a member expression

console.log
console['log']

pub fn write_conditional_expr(
    &mut self,
    conditional: &ConditionalExpression
) -> Result<(), IoError>
[src]

Writes a conditional expression

let x = isTrue ? 'yes' : 'no';

pub fn write_call_expr(&mut self, call: &CallExpression) -> Result<(), IoError>
[src]

Writes a call expression

console.log()
(function() {
})()

pub fn write_new_expr(&mut self, new: &NewExpression) -> Result<(), IoError>
[src]

Writes a new expression

new Uint8Array(100);

pub fn write_sequence_expr(
    &mut self,
    sequence: &[Expression]
) -> Result<(), IoError>
[src]

Writes a sequence of sub-expressions

a = b, c = d, q * 100

pub fn write_spread_expr(&mut self, spread: &Expression) -> Result<(), IoError>
[src]

Writes a spread expression

function(...args) {
}

pub fn write_arrow_function_expr(
    &mut self,
    func: &ArrowFunctionExpression
) -> Result<(), IoError>
[src]

Writes and arrow function

x => console.log(x);
(x, y) => {
    return x * y;
}

pub fn write_yield_expr(
    &mut self,
    expr: &YieldExpression
) -> Result<(), IoError>
[src]

Writes a yield expression

function *gen() {
    while (true) {
        yield 100;
    }
}

pub fn write_meta_property(
    &mut self,
    meta: &MetaProperty
) -> 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: &Expression) -> Result<(), IoError>
[src]

Write an expression preceded by the await keyword

pub fn write_ident(&mut self, ident: &str) -> Result<(), IoError>
[src]

Write a plain identifier

pub fn write_tagged_template(
    &mut self,
    template: &TaggedTemplateExpression
) -> Result<(), IoError>
[src]

Write a template preceded by an identifier

tag`things ${0} stuff`;

pub fn write_literal(&mut self, lit: &Literal) -> 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: &str) -> 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: &TemplateLiteral
) -> 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) -> Result<(), IoError>
[src]

Auto Trait Implementations

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

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

Blanket Implementations

impl<T> From for T
[src]

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

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

type Error = !

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

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

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

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

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

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

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