UNPKG

sucrase

Version:

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

78 lines (60 loc) 2.62 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var N = _interopRequireWildcard(require("../types")); var _location = require("../util/location"); var _context = require("./context"); var _types2 = require("./types"); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } } class State { init(options, input) { this.strict = options.strictMode === false ? false : options.sourceType === "module"; this.input = input; this.potentialArrowAt = -1; this.noArrowAt = []; this.noArrowParamsConversionAt = []; // eslint-disable-next-line max-len this.inMethod = this.inFunction = this.inParameters = this.maybeInArrowParameters = this.inGenerator = this.inAsync = this.inPropertyName = this.inType = this.inClassProperty = this.noAnonFunctionType = false; this.classLevel = 0; this.labels = []; this.decoratorStack = [[]]; this.yieldInPossibleArrowParameters = null; this.tokens = []; this.comments = []; this.trailingComments = []; this.leadingComments = []; this.commentStack = []; // $FlowIgnore this.commentPreviousNode = null; this.pos = this.lineStart = 0; this.curLine = options.startLine; this.type = _types2.types.eof; this.value = null; this.start = this.end = this.pos; this.startLoc = this.endLoc = this.curPosition(); // $FlowIgnore this.lastTokEndLoc = this.lastTokStartLoc = null; this.lastTokStart = this.lastTokEnd = this.pos; this.context = [_context.types.braceStatement]; this.exprAllowed = true; this.containsEsc = this.containsOctal = false; this.octalPosition = null; this.invalidTemplateEscapePosition = null; this.exportedIdentifiers = []; } // TODO curPosition() { return new _location.Position(this.curLine, this.pos - this.lineStart); } clone(skipArrays) { const state = new State(); Object.keys(this).forEach(key => { // $FlowIgnore let val = this[key]; if ((!skipArrays || key === "context") && Array.isArray(val)) { val = val.slice(); } // $FlowIgnore state[key] = val; }); return state; } } exports.default = State;