UNPKG

sucrase

Version:

Super-fast alternative to Babel for when you can target modern JS runtimes

63 lines (62 loc) 2.17 kB
import { types as ct } from "./context"; import { types as tt } from "./types"; export default 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 = tt.eof; this.value = null; this.start = this.pos; this.end = this.pos; this.isType = false; this.lastTokEnd = this.pos; this.context = [ct.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; } }