UNPKG

2.93 kBJavaScriptView Raw
1/* @flow */
2
3"use strict";
4
5var _classCallCheck = require("babel-runtime/helpers/class-call-check")["default"];
6
7exports.__esModule = true;
8
9var _utilLocation = require("../util/location");
10
11var _context = require("./context");
12
13var _types = require("./types");
14
15/*:: import type { TokContext } from "./context";*/
16/*:: import type { Token } from "./index";*/
17var State = (function () {
18 function State() {
19 _classCallCheck(this, State);
20 }
21
22 State.prototype.init = function init(options /*: Object*/, input /*: string*/) {
23 this.strict = options.strictMode === false ? false : options.sourceType === "module";
24
25 this.input = input;
26
27 this.potentialArrowAt = -1;
28
29 this.inMethod = this.inFunction = this.inGenerator = this.inAsync = false;
30
31 this.labels = [];
32
33 this.decorators = [];
34
35 this.tokens = [];
36
37 this.comments = [];
38
39 this.trailingComments = [];
40 this.leadingComments = [];
41 this.commentStack = [];
42
43 this.pos = this.lineStart = 0;
44 this.curLine = 1;
45
46 this.type = _types.types.eof;
47 this.value = null;
48 this.start = this.end = this.pos;
49 this.startLoc = this.endLoc = this.curPosition();
50
51 this.lastTokEndLoc = this.lastTokStartLoc = null;
52 this.lastTokStart = this.lastTokEnd = this.pos;
53
54 this.context = [_context.types.b_stat];
55 this.exprAllowed = true;
56
57 this.containsEsc = this.containsOctal = false;
58 this.octalPosition = null;
59
60 return this;
61 };
62
63 // TODO
64
65 State.prototype.curPosition = function curPosition() {
66 return new _utilLocation.Position(this.curLine, this.pos - this.lineStart);
67 };
68
69 State.prototype.clone = function clone(skipArrays /*:: ?*/) {
70 var state = new State();
71 for (var key in this) {
72 var val = this[key];
73
74 if ((!skipArrays || key === "context") && Array.isArray(val)) {
75 val = val.slice();
76 }
77
78 state[key] = val;
79 }
80 return state;
81 };
82
83 return State;
84})();
85
86exports["default"] = State;
87module.exports = exports["default"];
88
89// TODO
90
91// Used to signify the start of a potential arrow function
92
93// Flags to track whether we are in a function, a generator.
94
95// Labels in scope.
96
97// Leading decorators.
98
99// Token store.
100
101// Comment store.
102
103// Comment attachment store
104
105// The current position of the tokenizer in the input.
106
107// Properties of the current token:
108// Its type
109
110// For tokens that include more information than their type, the value
111
112// Its start and end offset
113
114// And, if locations are used, the {line, column} object
115// corresponding to those offsets
116
117// Position information for the previous token
118
119// The context stack is used to superficially track syntactic
120// context to predict whether a regular expression is allowed in a
121// given position.
122
123// Used to signal to callers of `readWord1` whether the word
124// contained any escape sequences. This is needed because words with
125// escape sequences must not be interpreted as keywords.
126
127// TODO
\No newline at end of file