-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathforStatement.ts
17 lines (16 loc) · 974 Bytes
/
forStatement.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import { AST } from "../ast";
import { Chapter, Context } from "../types";
import { Rule } from "./rule";
import { ForStatement, Node } from "estree"
import { DiagnosticSeverity } from "vscode-languageserver";
import { STATEMENTS } from "../types";
export const forStatementRule = new class extends Rule<ForStatement> {
public process(child: ForStatement, parent: Node, context: Context, ast: AST): void {
if (context.chapter < Chapter.SOURCE_3)
ast.addDiagnostic("For statements are not allowed", DiagnosticSeverity.Error, { start: child.loc!.start, end: child.body.loc!.start })
if (child.body.type !== STATEMENTS.BLOCK)
ast.addDiagnostic("Missing curly braces around for", DiagnosticSeverity.Error, { start: child.loc!.start, end: child.body.loc!.start });
if (!(child.init && child.test && child.update))
ast.addDiagnostic("Incomplete for loop", DiagnosticSeverity.Error, { start: child.loc!.start, end: child.body.loc!.start })
}
}();