UNPKG

prepack

Version:

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

95 lines (79 loc) 2.65 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.StepOverStepper = exports.StepIntoStepper = exports.Stepper = undefined; var _is = require("./../../methods/is.js"); var _babelTypes = require("babel-types"); var _invariant = require("./../common/invariant.js"); var _invariant2 = _interopRequireDefault(_invariant); 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. */ class Stepper { constructor(filePath, line, column) { this._stepStartData = { filePath: filePath, line: line, column: column }; } isComplete(ast, currentStackSize) { (0, _invariant2.default)(false, "Abstract method, please override"); } isAstLocationChanged(ast) { // we should only step to statements if (!(0, _is.IsStatement)(ast)) return false; let loc = ast.loc; if (!loc) return false; let filePath = loc.source; let line = loc.start.line; let column = loc.start.column; if (!filePath) return false; if (this._stepStartData) { if (filePath === this._stepStartData.filePath && line === this._stepStartData.line && column === this._stepStartData.column) { return false; } } else { return false; } return true; } } exports.Stepper = Stepper; class StepIntoStepper extends Stepper { constructor(filePath, line, column) { super(filePath, line, column); } // Override isComplete(ast, currentStackSize) { return this.isAstLocationChanged(ast); } } exports.StepIntoStepper = StepIntoStepper; class StepOverStepper extends Stepper { constructor(filePath, line, column, stackSize) { super(filePath, line, column); this._startStackSize = stackSize; } isComplete(ast, currentStackSize) { if (!this.isAstLocationChanged(ast)) return false; if (currentStackSize <= this._startStackSize) { // two cases here: // if current stack length < starting stack length, the program must have // hit an exception so this stepper is no longer relevant // if current stack length === starting stack length, the program returned // to the same stack depth, so a step over is complete return true; } return false; } } exports.StepOverStepper = StepOverStepper; //# sourceMappingURL=Stepper.js.map