• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

RauliL / juokse / 4489861679

pending completion
4489861679

push

github

GitHub
Merge pull request #2 from RauliL/typescript-rewrite

83 of 152 branches covered (54.61%)

Branch coverage included in aggregate %.

366 of 366 new or added lines in 12 files covered. (100.0%)

242 of 366 relevant lines covered (66.12%)

11.87 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

11.11
/src/ast/statement.ts
1
import { JuokseError } from "../error";
1✔
2
import { Position } from "./position";
3
import { Word } from "./token";
4

5
export type StatementType =
6
  | "Assignment"
7
  | "Block"
8
  | "Command"
9
  | "For"
10
  | "If"
11
  | "Pass"
12
  | "While";
13

14
export type Statement = {
15
  position: Position;
16
  type: StatementType;
17
};
18

19
export type AssignmentStatement = Statement & {
20
  type: "Assignment";
21
  variable: string;
22
  value: Word;
23
};
24

25
export type BlockStatement = Statement & {
26
  type: "Block";
27
  body: Statement[];
28
};
29

30
export type CommandStatement = Statement & {
31
  type: "Command";
32
  command: Word;
33
  args: Word[];
34
};
35

36
export type ForStatement = Statement & {
37
  type: "For";
38
  variable: string;
39
  subjects: Word[];
40
  body: Statement;
41
};
42

43
export type IfStatement = Statement & {
44
  type: "If";
45
  test: CommandStatement;
46
  then: Statement;
47
  else?: Statement;
48
};
49

50
export type PassStatement = Statement & {
51
  type: "Pass";
52
};
53

54
export type WhileStatement = Statement & {
55
  type: "While";
56
  test: CommandStatement;
57
  body: Statement;
58
};
59

60
export type StatementVisitor<R, A = undefined> = {
61
  visitAssignment: (statement: AssignmentStatement, arg: A) => R;
62
  visitBlock: (statement: BlockStatement, arg: A) => R;
63
  visitCommand: (statement: CommandStatement, arg: A) => R;
64
  visitFor: (statement: ForStatement, arg: A) => R;
65
  visitIf: (statement: IfStatement, arg: A) => R;
66
  visitPass: (statement: PassStatement, arg: A) => R;
67
  visitWhile: (statement: WhileStatement, arg: A) => R;
68
};
69

70
export const visitStatement = <R, A = undefined>(
1✔
71
  visitor: StatementVisitor<R, A>,
72
  statement: Statement,
73
  arg: A
74
): R => {
75
  switch (statement.type) {
×
76
    case "Assignment":
77
      return visitor.visitAssignment(statement as AssignmentStatement, arg);
×
78

79
    case "Block":
80
      return visitor.visitBlock(statement as BlockStatement, arg);
×
81

82
    case "Command":
83
      return visitor.visitCommand(statement as CommandStatement, arg);
×
84

85
    case "For":
86
      return visitor.visitFor(statement as ForStatement, arg);
×
87

88
    case "If":
89
      return visitor.visitIf(statement as IfStatement, arg);
×
90

91
    case "Pass":
92
      return visitor.visitPass(statement as PassStatement, arg);
×
93

94
    case "While":
95
      return visitor.visitWhile(statement as WhileStatement, arg);
×
96
  }
97

98
  throw new JuokseError(
×
99
    `Unrecognized statement type: ${statement.type}`,
100
    statement.position
101
  );
102
};
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc