Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

break: Add support for labeled statements, breaks, and continues #2891

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 32 additions & 8 deletions src/ast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -440,9 +440,10 @@ export abstract class Node {

static createBlockStatement(
statements: Statement[],
label: IdentifierExpression | null,
range: Range
): BlockStatement {
return new BlockStatement(statements, range);
return new BlockStatement(statements, label, range);
}

static createBreakStatement(
Expand Down Expand Up @@ -475,9 +476,10 @@ export abstract class Node {
static createDoStatement(
body: Statement,
condition: Expression,
label: IdentifierExpression | null,
range: Range
): DoStatement {
return new DoStatement(body, condition, range);
return new DoStatement(body, condition, label, range);
}

static createEmptyStatement(
Expand Down Expand Up @@ -548,9 +550,10 @@ export abstract class Node {
condition: Expression,
ifTrue: Statement,
ifFalse: Statement | null,
label: IdentifierExpression | null,
range: Range
): IfStatement {
return new IfStatement(condition, ifTrue, ifFalse, range);
return new IfStatement(condition, ifTrue, ifFalse, label, range);
}

static createImportStatement(
Expand Down Expand Up @@ -607,18 +610,20 @@ export abstract class Node {
condition: Expression | null,
incrementor: Expression | null,
body: Statement,
label: IdentifierExpression | null,
range: Range
): ForStatement {
return new ForStatement(initializer, condition, incrementor, body, range);
return new ForStatement(initializer, condition, incrementor, body, label, range);
}

static createForOfStatement(
variable: Statement,
iterable: Expression,
body: Statement,
label: IdentifierExpression | null,
range: Range
): ForOfStatement {
return new ForOfStatement(variable, iterable, body, range);
return new ForOfStatement(variable, iterable, body, label, range);
}

static createFunctionDeclaration(
Expand Down Expand Up @@ -675,9 +680,10 @@ export abstract class Node {
static createSwitchStatement(
condition: Expression,
cases: SwitchCase[],
label: IdentifierExpression | null,
range: Range
): SwitchStatement {
return new SwitchStatement(condition, cases, range);
return new SwitchStatement(condition, cases, label, range);
}

static createSwitchCase(
Expand All @@ -700,9 +706,10 @@ export abstract class Node {
catchVariable: IdentifierExpression | null,
catchStatements: Statement[] | null,
finallyStatements: Statement[] | null,
label: IdentifierExpression | null,
range: Range
): TryStatement {
return new TryStatement(bodyStatements, catchVariable, catchStatements, finallyStatements, range);
return new TryStatement(bodyStatements, catchVariable, catchStatements, finallyStatements, label, range);
}

static createTypeDeclaration(
Expand Down Expand Up @@ -753,9 +760,10 @@ export abstract class Node {
static createWhileStatement(
condition: Expression,
statement: Statement,
label: IdentifierExpression | null,
range: Range
): WhileStatement {
return new WhileStatement(condition, statement, range);
return new WhileStatement(condition, statement, label, range);
}

/** Tests if this node is a literal of the specified kind. */
Expand Down Expand Up @@ -1788,6 +1796,8 @@ export class BlockStatement extends Statement {
constructor(
/** Contained statements. */
public statements: Statement[],
/** Label, if any. */
public label: IdentifierExpression | null,
/** Source range. */
range: Range
) {
Expand Down Expand Up @@ -1858,6 +1868,8 @@ export class DoStatement extends Statement {
public body: Statement,
/** Condition when to repeat. */
public condition: Expression,
/** Label, if any. */
public label: IdentifierExpression | null,
/** Source range. */
range: Range
) {
Expand Down Expand Up @@ -2022,6 +2034,8 @@ export class ForStatement extends Statement {
public incrementor: Expression | null,
/** Body statement being looped over. */
public body: Statement,
/** Label, if any. */
public label: IdentifierExpression | null,
/** Source range. */
range: Range
) {
Expand All @@ -2038,6 +2052,8 @@ export class ForOfStatement extends Statement {
public iterable: Expression,
/** Body statement being looped over. */
public body: Statement,
/** Label, if any. */
public label: IdentifierExpression | null,
/** Source range. */
range: Range
) {
Expand Down Expand Up @@ -2108,6 +2124,8 @@ export class IfStatement extends Statement {
public ifTrue: Statement,
/** Statement executed when condition is `false`. */
public ifFalse: Statement | null,
/** Label, if any. */
public label: IdentifierExpression | null,
/** Source range. */
range: Range
) {
Expand Down Expand Up @@ -2258,6 +2276,8 @@ export class SwitchStatement extends Statement {
public condition: Expression,
/** Contained cases. */
public cases: SwitchCase[],
/** Label, if any. */
public label: IdentifierExpression | null,
/** Source range. */
range: Range
) {
Expand Down Expand Up @@ -2288,6 +2308,8 @@ export class TryStatement extends Statement {
public catchStatements: Statement[] | null,
/** Statements being executed afterwards, if a `finally` clause is present. */
public finallyStatements: Statement[] | null,
/** Label, if any. */
public label: IdentifierExpression | null,
/** Source range. */
range: Range
) {
Expand Down Expand Up @@ -2382,6 +2404,8 @@ export class WhileStatement extends Statement {
public condition: Expression,
/** Body statement being looped over. */
public body: Statement,
/** Label, if any. */
public label: IdentifierExpression | null,
/** Source range. */
range: Range
) {
Expand Down
Loading
Loading