source: frontend/node_modules/sucrase/dist/parser/tokenizer/state.js

Last change on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 2 weeks ago

Fix frontend appearance

  • Property mode set to 100644
File size: 3.9 KB
RevLine 
[9af201e]1"use strict";Object.defineProperty(exports, "__esModule", {value: true});
2var _keywords = require('./keywords');
3var _types = require('./types');
4
5 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} exports.Scope = Scope;
16
17 class StateSnapshot {
18 constructor(
19 potentialArrowAt,
20 noAnonFunctionType,
21 inDisallowConditionalTypesContext,
22 tokensLength,
23 scopesLength,
24 pos,
25 type,
26 contextualKeyword,
27 start,
28 end,
29 isType,
30 scopeDepth,
31 error,
32 ) {;this.potentialArrowAt = potentialArrowAt;this.noAnonFunctionType = noAnonFunctionType;this.inDisallowConditionalTypesContext = inDisallowConditionalTypesContext;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;}
33} exports.StateSnapshot = StateSnapshot;
34
35 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);State.prototype.__init13.call(this); }
36 // Used to signify the start of a potential arrow function
37 __init() {this.potentialArrowAt = -1}
38
39 // Used by Flow to handle an edge case involving function type parsing.
40 __init2() {this.noAnonFunctionType = false}
41
42 // Used by TypeScript to handle ambiguities when parsing conditional types.
43 __init3() {this.inDisallowConditionalTypesContext = false}
44
45 // Token store.
46 __init4() {this.tokens = []}
47
48 // Array of all observed scopes, ordered by their ending position.
49 __init5() {this.scopes = []}
50
51 // The current position of the tokenizer in the input.
52 __init6() {this.pos = 0}
53
54 // Information about the current token.
55 __init7() {this.type = _types.TokenType.eof}
56 __init8() {this.contextualKeyword = _keywords.ContextualKeyword.NONE}
57 __init9() {this.start = 0}
58 __init10() {this.end = 0}
59
60 __init11() {this.isType = false}
61 __init12() {this.scopeDepth = 0}
62
63 /**
64 * If the parser is in an error state, then the token is always tt.eof and all functions can
65 * keep executing but should be written so they don't get into an infinite loop in this situation.
66 *
67 * This approach, combined with the ability to snapshot and restore state, allows us to implement
68 * backtracking without exceptions and without needing to explicitly propagate error states
69 * everywhere.
70 */
71 __init13() {this.error = null}
72
73 snapshot() {
74 return new StateSnapshot(
75 this.potentialArrowAt,
76 this.noAnonFunctionType,
77 this.inDisallowConditionalTypesContext,
78 this.tokens.length,
79 this.scopes.length,
80 this.pos,
81 this.type,
82 this.contextualKeyword,
83 this.start,
84 this.end,
85 this.isType,
86 this.scopeDepth,
87 this.error,
88 );
89 }
90
91 restoreFromSnapshot(snapshot) {
92 this.potentialArrowAt = snapshot.potentialArrowAt;
93 this.noAnonFunctionType = snapshot.noAnonFunctionType;
94 this.inDisallowConditionalTypesContext = snapshot.inDisallowConditionalTypesContext;
95 this.tokens.length = snapshot.tokensLength;
96 this.scopes.length = snapshot.scopesLength;
97 this.pos = snapshot.pos;
98 this.type = snapshot.type;
99 this.contextualKeyword = snapshot.contextualKeyword;
100 this.start = snapshot.start;
101 this.end = snapshot.end;
102 this.isType = snapshot.isType;
103 this.scopeDepth = snapshot.scopeDepth;
104 this.error = snapshot.error;
105 }
106} exports.default = State;
Note: See TracBrowser for help on using the repository browser.