sucrase
Version:
Super-fast alternative to Babel for when you can target modern JS runtimes
66 lines (65 loc) • 2.28 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const context_1 = require("./context");
const types_1 = require("./types");
class State {
init(options, input) {
this.input = input;
this.potentialArrowAt = -1;
this.inGenerator = false;
this.inPropertyName = false;
this.inType = false;
this.noAnonFunctionType = false;
this.tokens = [];
this.scopes = [];
this.pos = 0;
this.type = types_1.types.eof;
this.value = null;
this.start = this.pos;
this.end = this.pos;
this.isType = false;
this.lastTokEnd = this.pos;
this.context = [context_1.types.braceStatement];
this.exprAllowed = true;
}
snapshot() {
return {
potentialArrowAt: this.potentialArrowAt,
inGenerator: this.inGenerator,
inType: this.inType,
noAnonFunctionType: this.noAnonFunctionType,
inPropertyName: this.inPropertyName,
tokensLength: this.tokens.length,
scopesLength: this.scopes.length,
pos: this.pos,
type: this.type,
// tslint:disable-next-line: no-any
value: this.value,
start: this.start,
end: this.end,
isType: this.isType,
lastTokEnd: this.lastTokEnd,
context: this.context.slice(),
exprAllowed: this.exprAllowed,
};
}
restoreFromSnapshot(snapshot) {
this.potentialArrowAt = snapshot.potentialArrowAt;
this.inGenerator = snapshot.inGenerator;
this.inType = snapshot.inType;
this.noAnonFunctionType = snapshot.noAnonFunctionType;
this.inPropertyName = snapshot.inPropertyName;
this.tokens.length = snapshot.tokensLength;
this.scopes.length = snapshot.scopesLength;
this.pos = snapshot.pos;
this.type = snapshot.type;
this.value = snapshot.value;
this.start = snapshot.start;
this.end = snapshot.end;
this.isType = snapshot.isType;
this.lastTokEnd = snapshot.lastTokEnd;
this.context = snapshot.context;
this.exprAllowed = snapshot.exprAllowed;
}
}
exports.default = State;