pub enum Stmt<'a> {
Show 19 variants
Expr(Expr<'a>),
Block(BlockStmt<'a>),
Empty,
Debugger,
With(WithStmt<'a>),
Return(Option<Expr<'a>>),
Labeled(LabeledStmt<'a>),
Break(Option<Ident<'a>>),
Continue(Option<Ident<'a>>),
If(IfStmt<'a>),
Switch(SwitchStmt<'a>),
Throw(Expr<'a>),
Try(TryStmt<'a>),
While(WhileStmt<'a>),
DoWhile(DoWhileStmt<'a>),
For(ForStmt<'a>),
ForIn(ForInStmt<'a>),
ForOf(ForOfStmt<'a>),
Var(Vec<VarDecl<'a>>),
}
Expand description
A slightly more granular part of an es program than ProgramPart
Variants
Expr(Expr<'a>)
Any expression
Block(BlockStmt<'a>)
A collection of program parts wrapped in curly braces
Empty
A single semi-colon
Debugger
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(Option<Expr<'a>>)
A return statement
function thing() {
return 'stuff';
}
function stuff() {
return;
}
Labeled(LabeledStmt<'a>)
A labeled statement
label: {
break label;
}
Break(Option<Ident<'a>>)
A break statement
label: {
break label;
}
while (true) {
break;
}
Continue(Option<Ident<'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(Expr<'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(Vec<VarDecl<'a>>)
A var statement
var x;
var x, y = 'huh?';
Trait Implementations
sourceimpl<'a> PartialEq<Stmt<'a>> for Stmt<'a>
impl<'a> PartialEq<Stmt<'a>> for Stmt<'a>
impl<'a> StructuralPartialEq for Stmt<'a>
Auto Trait Implementations
impl<'a> RefUnwindSafe for Stmt<'a>
impl<'a> Send for Stmt<'a>
impl<'a> Sync for Stmt<'a>
impl<'a> Unpin for Stmt<'a>
impl<'a> UnwindSafe for Stmt<'a>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more