-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctionDeclaration.ts
More file actions
23 lines (20 loc) · 985 Bytes
/
functionDeclaration.ts
File metadata and controls
23 lines (20 loc) · 985 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import { AST } from "../ast";
import { Rule } from "./rule";
import { FunctionDeclaration, Identifier, Node } from "estree"
import { DiagnosticSeverity } from "vscode-languageserver";
import { NODES } from "../types";
import { Context } from "../types";
export const functionDeclarationRule = new class extends Rule<FunctionDeclaration> {
public process(child: FunctionDeclaration, parent: Node, context: Context, ast: AST): void {
if (child.id !== null && ast.isDummy(child.id))
ast.addDiagnostic("Missing function name", DiagnosticSeverity.Error, child.loc!)
let hasRestElement = false;
for (const param of child.params) {
if (hasRestElement) {
ast.addDiagnostic("No params allowed after rest element", DiagnosticSeverity.Error, { start: param.loc!.start, end: child.params[child.params.length - 1].loc!.end });
break;
}
hasRestElement = param.type === "RestElement";
}
}
}();