Skip to content
For the complete documentation index, see llms.txt. This page is also available as Markdown.

Ensure Block Statements

Example Visitor: Ensuring Block Statements

JavaScript allows concise one-liners like:

jsCopyEditif (x) doSomething();
while (y) doSomethingElse();

While valid, these can be fragile during code generation or transformation. The BlockStatementInsertVisitor ensures that all control structures (if, while, for, etc.) consistently use {} blocks—even if they originally had a single statement.

🔍 What It Does

Transforms:

if (x) y;
while(x) y;
for(;;) y;

Into:

if (x) {
  y;
}
while (x) {
  y;
}
for (;;) {
  y;
}

🧪 How to Use

Last updated