UNPKG

prepack

Version:

Execute a JS bundle, serialize global state and side effects to a snapshot that can be quickly restored.

99 lines (75 loc) 2.71 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.SteppingManager = void 0; var _types = require("@babel/types"); var _invariant = _interopRequireDefault(require("./../common/invariant.js")); var _Stepper = require("./Stepper.js"); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } /** * Copyright (c) 2017-present, Facebook, Inc. * All rights reserved. * * This source code is licensed under the BSD-style license found in the * LICENSE file in the root directory of this source tree. An additional grant * of patent rights can be found in the PATENTS file in the same directory. */ /* strict-local */ class SteppingManager { constructor(realm, keepOldSteppers) { this._realm = realm; this._steppers = []; this._keepOldSteppers = false; if (keepOldSteppers === true) this._keepOldSteppers = true; } processStepCommand(kind, currentNodeLocation) { if (kind === "in") { this._processStepIn(currentNodeLocation); } else if (kind === "over") { this._processStepOver(currentNodeLocation); } else if (kind === "out") { this._processStepOut(currentNodeLocation); } else { (0, _invariant.default)(false, `Invalid step type: ${kind}`); } } _processStepIn(loc) { (0, _invariant.default)(loc && loc.source !== null); if (!this._keepOldSteppers) { this._steppers = []; } this._steppers.push(new _Stepper.StepIntoStepper(loc.source, loc.start.line, loc.start.column, this._realm.contextStack.length)); } _processStepOver(loc) { (0, _invariant.default)(loc && loc.source !== null); if (!this._keepOldSteppers) { this._steppers = []; } this._steppers.push(new _Stepper.StepOverStepper(loc.source, loc.start.line, loc.start.column, this._realm.contextStack.length)); } _processStepOut(loc) { (0, _invariant.default)(loc && loc.source !== null); if (!this._keepOldSteppers) { this._steppers = []; } this._steppers.push(new _Stepper.StepOutStepper(loc.source, loc.start.line, loc.start.column, this._realm.contextStack.length)); } getAndDeleteCompletedSteppers(ast) { (0, _invariant.default)(ast.loc && ast.loc.source); let i = 0; let completedSteppers = []; while (i < this._steppers.length) { let stepper = this._steppers[i]; if (stepper.isComplete(ast, this._realm.contextStack.length)) { completedSteppers.push(stepper); this._steppers.splice(i, 1); } else { i++; } } return completedSteppers; } } exports.SteppingManager = SteppingManager; //# sourceMappingURL=SteppingManager.js.map