pub enum Stmt<'a> {
Show 19 variants Expr { expr: Expr<'a>, semi_colon: Option<Slice<'a>>, }, Block(BlockStmt<'a>), Empty(Slice<'a>), Debugger { keyword: Slice<'a>, semi_colon: Option<Slice<'a>>, }, With(WithStmt<'a>), Return { keyword: Slice<'a>, value: Option<Expr<'a>>, semi_colon: Option<Slice<'a>>, }, Labeled(LabeledStmt<'a>), Break { keyword: Slice<'a>, label: Option<Ident<'a>>, semi_colon: Option<Slice<'a>>, }, Continue { keyword: Slice<'a>, label: Option<Ident<'a>>, semi_colon: Option<Slice<'a>>, }, If(IfStmt<'a>), Switch(SwitchStmt<'a>), Throw { keyword: Slice<'a>, expr: Expr<'a>, semi_colon: Option<Slice<'a>>, }, Try(TryStmt<'a>), While(WhileStmt<'a>), DoWhile(DoWhileStmt<'a>), For(ForStmt<'a>), ForIn(ForInStmt<'a>), ForOf(ForOfStmt<'a>), Var { decls: VarDecls<'a>, semi_colon: Option<Slice<'a>>, },
}
Expand description

A slightly more granular part of an es program than ProgramPart

Variants

Expr

Fields

expr: Expr<'a>
semi_colon: Option<Slice<'a>>

Any expression

Block(BlockStmt<'a>)

A collection of program parts wrapped in curly braces

Empty(Slice<'a>)

A single semi-colon

Debugger

Fields

keyword: Slice<'a>
semi_colon: Option<Slice<'a>>

The contextual keyword debugger

With(WithStmt<'a>)

A with statement, this puts one object at the top of the identifier search tree.

note: this cannot be used in a strict context

function random() {
    return 0;
}
let rand;
with (Math) {
    rand = floor(random() * 100) + 1;
}
//rand !== 0

Return

Fields

keyword: Slice<'a>
value: Option<Expr<'a>>
semi_colon: Option<Slice<'a>>

A return statement

function thing() {
    return 'stuff';
}
function stuff() {
    return;
}

Labeled(LabeledStmt<'a>)

A labeled statement

label: {
    break label;
}

Break

Fields

keyword: Slice<'a>
label: Option<Ident<'a>>
semi_colon: Option<Slice<'a>>

A break statement

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

Continue

Fields

keyword: Slice<'a>
label: Option<Ident<'a>>
semi_colon: Option<Slice<'a>>

A short circuit continuation of a loop

label: while (true) {
    if (Math.floor(Math.random() * 100) > 50) {
        continue;
    } else {
        console.log('too low')
    }
}

If(IfStmt<'a>)

An if statement

if (1 < 2) {
    console.log('Always true');
} else {
    console.log('Never true');
}

Switch(SwitchStmt<'a>)

A switch statement

switch (Math.floor(Math.random()) * 10) {
    case 1:

    break;
    case 2:
    case 3:
    case 4:
        return false;
    default:
        return true;
}

Throw

Fields

keyword: Slice<'a>
expr: Expr<'a>
semi_colon: Option<Slice<'a>>

A statement that throws an error

function error() {
    throw 'hahahaha';
}

function newError() {
    throw new Error('hohoho');
}

Try(TryStmt<'a>)

A try/catch block

try {

} catch (e) {

} finally {

}

While(WhileStmt<'a>)

A while loop

while (false) {

}
var i = 0;
while (i < 100) {
    if (Math.floor(Math.random() * 100) > 50) {
        i--;
    } else {
        i += 5;
    }
}

DoWhile(DoWhileStmt<'a>)

A while loop that executes its body first

do {
    console.log('at least once')
} while (Math.floor(Math.random() * 100) < 75)

For(ForStmt<'a>)

A “c-style” for loop

for (var i = 0; i < 100; i++) console.log(i);
for (;;) {
    console.log('forever!');
}

ForIn(ForInStmt<'a>)

A for in statement, this kind of for statement will extract each key from an indexable thing

for (var i in [2,3,4,5,6]) {
    console.log(i);
}
//prints 0, 1, 2, 3, 4
for (var k in {a: 'b', c: 'd'}) {
    console.log(k);
}
//prints a, b

ForOf(ForOfStmt<'a>)

A for of statement, this kind of for statement will extract the value from a generator or iterator

for (var k of [2, 3, 4, 5, 6]) {
    console.log(k);
}
//prints 2, 3, 4, 5, 6

Var

Fields

decls: VarDecls<'a>
semi_colon: Option<Slice<'a>>

A var statement

var x;
var x, y = 'huh?';

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Converts to this type from the input type.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.