1 |
|
2 | import {ContextualKeyword} from "./keywords";
|
3 | import { TokenType as tt} from "./types";
|
4 |
|
5 | export class Scope {
|
6 |
|
7 |
|
8 |
|
9 |
|
10 | constructor(startTokenIndex, endTokenIndex, isFunctionScope) {
|
11 | this.startTokenIndex = startTokenIndex;
|
12 | this.endTokenIndex = endTokenIndex;
|
13 | this.isFunctionScope = isFunctionScope;
|
14 | }
|
15 | }
|
16 |
|
17 | export class StateSnapshot {
|
18 | constructor(
|
19 | potentialArrowAt,
|
20 | noAnonFunctionType,
|
21 | tokensLength,
|
22 | scopesLength,
|
23 | pos,
|
24 | type,
|
25 | contextualKeyword,
|
26 | start,
|
27 | end,
|
28 | isType,
|
29 | scopeDepth,
|
30 | error,
|
31 | ) {;this.potentialArrowAt = potentialArrowAt;this.noAnonFunctionType = noAnonFunctionType;this.tokensLength = tokensLength;this.scopesLength = scopesLength;this.pos = pos;this.type = type;this.contextualKeyword = contextualKeyword;this.start = start;this.end = end;this.isType = isType;this.scopeDepth = scopeDepth;this.error = error;}
|
32 | }
|
33 |
|
34 | export default class State {constructor() { State.prototype.__init.call(this);State.prototype.__init2.call(this);State.prototype.__init3.call(this);State.prototype.__init4.call(this);State.prototype.__init5.call(this);State.prototype.__init6.call(this);State.prototype.__init7.call(this);State.prototype.__init8.call(this);State.prototype.__init9.call(this);State.prototype.__init10.call(this);State.prototype.__init11.call(this);State.prototype.__init12.call(this); }
|
35 |
|
36 | __init() {this.potentialArrowAt = -1}
|
37 |
|
38 |
|
39 | __init2() {this.noAnonFunctionType = false}
|
40 |
|
41 |
|
42 | __init3() {this.tokens = []}
|
43 |
|
44 |
|
45 | __init4() {this.scopes = []}
|
46 |
|
47 |
|
48 | __init5() {this.pos = 0}
|
49 |
|
50 |
|
51 | __init6() {this.type = tt.eof}
|
52 | __init7() {this.contextualKeyword = ContextualKeyword.NONE}
|
53 | __init8() {this.start = 0}
|
54 | __init9() {this.end = 0}
|
55 |
|
56 | __init10() {this.isType = false}
|
57 | __init11() {this.scopeDepth = 0}
|
58 |
|
59 | |
60 |
|
61 |
|
62 |
|
63 |
|
64 |
|
65 |
|
66 |
|
67 | __init12() {this.error = null}
|
68 |
|
69 | snapshot() {
|
70 | return new StateSnapshot(
|
71 | this.potentialArrowAt,
|
72 | this.noAnonFunctionType,
|
73 | this.tokens.length,
|
74 | this.scopes.length,
|
75 | this.pos,
|
76 | this.type,
|
77 | this.contextualKeyword,
|
78 | this.start,
|
79 | this.end,
|
80 | this.isType,
|
81 | this.scopeDepth,
|
82 | this.error,
|
83 | );
|
84 | }
|
85 |
|
86 | restoreFromSnapshot(snapshot) {
|
87 | this.potentialArrowAt = snapshot.potentialArrowAt;
|
88 | this.noAnonFunctionType = snapshot.noAnonFunctionType;
|
89 | this.tokens.length = snapshot.tokensLength;
|
90 | this.scopes.length = snapshot.scopesLength;
|
91 | this.pos = snapshot.pos;
|
92 | this.type = snapshot.type;
|
93 | this.contextualKeyword = snapshot.contextualKeyword;
|
94 | this.start = snapshot.start;
|
95 | this.end = snapshot.end;
|
96 | this.isType = snapshot.isType;
|
97 | this.scopeDepth = snapshot.scopeDepth;
|
98 | this.error = snapshot.error;
|
99 | }
|
100 | }
|