UNPKG

prepack

Version:

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

120 lines (87 loc) 3.37 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.BreakpointManager = void 0; var _PerFileBreakpointMap = require("./PerFileBreakpointMap.js"); var _Breakpoint = require("./Breakpoint.js"); var _types = require("@babel/types"); /** * 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 */ // Storing BreakpointStores for all source files class BreakpointManager { constructor() { this._breakpointMaps = new Map(); } getStoppableBreakpoint(ast) { if (ast.loc && ast.loc.source !== null) { let location = ast.loc; let filePath = location.source; if (filePath === null) return; let lineNum = location.start.line; let colNum = location.start.column; // Check whether there is a breakpoint we need to stop on here let breakpoint = this._findStoppableBreakpoint(filePath, lineNum, colNum); if (breakpoint === null) return; return breakpoint; } } // Try to find a breakpoint at the given location and check if we should stop on it _findStoppableBreakpoint(filePath, lineNum, colNum) { let breakpoint = this.getBreakpoint(filePath, lineNum, colNum); if (breakpoint && breakpoint.enabled) { return breakpoint; } return null; } addBreakpointMulti(breakpoints) { this._doBreakpointsAction(breakpoints, this._addBreakpoint.bind(this)); } _addBreakpoint(bp) { let breakpointMap = this._breakpointMaps.get(bp.filePath); if (!breakpointMap) { breakpointMap = new _PerFileBreakpointMap.PerFileBreakpointMap(bp.filePath); this._breakpointMaps.set(bp.filePath, breakpointMap); } // Nuclide doesn't support column debugging, so set every breakpoint // to column 0 for consistency. breakpointMap.addBreakpoint(bp.line, 0); } getBreakpoint(filePath, lineNum, columnNum = 0) { let breakpointMap = this._breakpointMaps.get(filePath); if (breakpointMap) return breakpointMap.getBreakpoint(lineNum, columnNum); return undefined; } removeBreakpointMulti(breakpoints) { this._doBreakpointsAction(breakpoints, this._removeBreakpoint.bind(this)); } _removeBreakpoint(bp) { let breakpointMap = this._breakpointMaps.get(bp.filePath); if (breakpointMap) breakpointMap.removeBreakpoint(bp.line, bp.column); } enableBreakpointMulti(breakpoints) { this._doBreakpointsAction(breakpoints, this._enableBreakpoint.bind(this)); } _enableBreakpoint(bp) { let breakpointMap = this._breakpointMaps.get(bp.filePath); if (breakpointMap) breakpointMap.enableBreakpoint(bp.line, bp.column); } disableBreakpointMulti(breakpoints) { this._doBreakpointsAction(breakpoints, this._disableBreakpoint.bind(this)); } _disableBreakpoint(bp) { let breakpointMap = this._breakpointMaps.get(bp.filePath); if (breakpointMap) breakpointMap.disableBreakpoint(bp.line, bp.column); } _doBreakpointsAction(breakpoints, action) { for (let bp of breakpoints) { action(bp); } } } exports.BreakpointManager = BreakpointManager; //# sourceMappingURL=BreakpointManager.js.map