Bug 1529640 - Fix recent flow regresssions.
authorJason Laster <jlaster@mozilla.com>
Fri, 22 Feb 2019 14:15:33 +0000
changeset 518460 f205ebe60fc114e9f47f607e00cd7c509f4dc7d1
parent 518459 268454ace73e27964043baefdf35c22a07adb4b7
child 518461 1e0f74ff709be83c436495745c9adf795306651c
push id10862
push userffxbld-merge
push dateMon, 11 Mar 2019 13:01:11 +0000
treeherdermozilla-beta@a2e7f5c935da [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs1529640
milestone67.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1529640 - Fix recent flow regresssions. Differential Revision: https://phabricator.services.mozilla.com/D20689
devtools/client/debugger/new/src/actions/ast/setPausePoints.js
devtools/client/debugger/new/src/client/firefox/types.js
devtools/client/debugger/new/src/selectors/visiblePausePoints.js
devtools/client/debugger/new/src/utils/pause/pausePoints.js
devtools/client/debugger/new/src/utils/pause/stepping.js
devtools/client/debugger/new/src/workers/parser/pausePoints.js
devtools/client/debugger/new/src/workers/parser/tests/pausePoints.spec.js
deleted file mode 100644
--- a/devtools/client/debugger/new/src/actions/ast/setPausePoints.js
+++ /dev/null
@@ -1,63 +0,0 @@
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at <http://mozilla.org/MPL/2.0/>. */
-
-// @flow
-
-import { getSourceFromId } from "../../selectors";
-import * as parser from "../../workers/parser";
-import { convertToList } from "../../utils/pause/pausePoints";
-import { features } from "../../utils/prefs";
-import { getGeneratedLocation } from "../../utils/source-maps";
-
-import type { SourceId } from "../../types";
-import type { ThunkArgs, Action } from "../types";
-
-async function mapLocations(pausePoints, state, source, sourceMaps) {
-  const pausePointList = convertToList(pausePoints);
-  const sourceId = source.id;
-
-  return Promise.all(
-    pausePointList.map(async ({ types, location }) => {
-      const generatedLocation = await getGeneratedLocation(
-        state,
-        source,
-        {
-          ...location,
-          sourceId
-        },
-        sourceMaps
-      );
-
-      return { types, location, generatedLocation };
-    })
-  );
-}
-export function setPausePoints(sourceId: SourceId) {
-  return async ({ dispatch, getState, client, sourceMaps }: ThunkArgs) => {
-    const source = getSourceFromId(getState(), sourceId);
-    if (!features.pausePoints || !source || !source.text) {
-      return;
-    }
-
-    if (source.isWasm) {
-      return;
-    }
-
-    const pausePoints = await mapLocations(
-      await parser.getPausePoints(sourceId),
-      getState(),
-      source,
-      sourceMaps
-    );
-
-    dispatch(
-      ({
-        type: "SET_PAUSE_POINTS",
-        sourceText: source.text || "",
-        sourceId,
-        pausePoints
-      }: Action)
-    );
-  };
-}
--- a/devtools/client/debugger/new/src/client/firefox/types.js
+++ b/devtools/client/debugger/new/src/client/firefox/types.js
@@ -221,21 +221,19 @@ export type TabTarget = {
       input: string,
       cursor: number,
       func: Function,
       frameId: ?string
     ) => void
   },
   form: { consoleActor: any },
   root: any,
-  activeTab: {
-    navigateTo: ({ url: string }) => Promise<*>,
-    listWorkers: () => Promise<*>,
-    reload: () => Promise<*>
-  },
+  navigateTo: ({ url: string }) => Promise<*>,
+  listWorkers: () => Promise<*>,
+  reload: () => Promise<*>,
   destroy: () => void,
   isBrowsingContext: boolean,
   isContentProcess: boolean
 };
 
 /**
  * Clients for accessing the Firefox debug server and browser
  * @memberof firefox/clients
deleted file mode 100644
--- a/devtools/client/debugger/new/src/selectors/visiblePausePoints.js
+++ /dev/null
@@ -1,19 +0,0 @@
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at <http://mozilla.org/MPL/2.0/>. */
-
-// @flow
-
-import { getSelectedSource } from "../reducers/sources";
-import { getPausePoints } from "../reducers/ast";
-
-import type { State } from "../reducers/types";
-
-export function getVisiblePausePoints(state: State) {
-  const source = getSelectedSource(state);
-  if (!source) {
-    return null;
-  }
-
-  return getPausePoints(state, source.id);
-}
deleted file mode 100644
--- a/devtools/client/debugger/new/src/utils/pause/pausePoints.js
+++ /dev/null
@@ -1,37 +0,0 @@
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at <http://mozilla.org/MPL/2.0/>. */
-
-// @flow
-import { reverse } from "lodash";
-
-import type { PausePoints, PausePointsMap } from "../../reducers/types";
-
-function insertStrtAt(string, index, newString) {
-  const start = string.slice(0, index);
-  const end = string.slice(index);
-  return `${start}${newString}${end}`;
-}
-
-export function convertToList(pausePoints: PausePointsMap): PausePoints {
-  const list = [];
-  for (const line in pausePoints) {
-    for (const column in pausePoints[line]) {
-      list.push(pausePoints[line][column]);
-    }
-  }
-  return list;
-}
-
-export function formatPausePoints(text: string, pausePoints: PausePoints) {
-  const nodes = reverse(pausePoints);
-  const lines = text.split("\n");
-  nodes.forEach((node, index) => {
-    const { line, column } = node.location;
-    const { break: breakPoint, step } = node.types;
-    const types = `${breakPoint ? "b" : ""}${step ? "s" : ""}`;
-    lines[line - 1] = insertStrtAt(lines[line - 1], column, `/*${types}*/`);
-  });
-
-  return lines.join("\n");
-}
deleted file mode 100644
--- a/devtools/client/debugger/new/src/utils/pause/stepping.js
+++ /dev/null
@@ -1,48 +0,0 @@
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at <http://mozilla.org/MPL/2.0/>. */
-
-// @flow
-
-import { isEqual } from "lodash";
-import { isGeneratedId } from "devtools-source-map";
-import type { Frame, MappedLocation } from "../../types";
-import type { State } from "../../reducers/types";
-import { isOriginal } from "../../utils/source";
-
-import {
-  getSelectedSource,
-  getPreviousPauseFrameLocation,
-  getPausePoint
-} from "../../selectors";
-
-function getFrameLocation(source, frame: ?MappedLocation) {
-  if (!frame) {
-    return null;
-  }
-
-  return isOriginal(source) ? frame.location : frame.generatedLocation;
-}
-
-export function shouldStep(rootFrame: ?Frame, state: State, sourceMaps: any) {
-  const selectedSource = getSelectedSource(state);
-  const previousFrameInfo = getPreviousPauseFrameLocation(state);
-
-  if (!rootFrame || !selectedSource) {
-    return false;
-  }
-
-  const previousFrameLoc = getFrameLocation(selectedSource, previousFrameInfo);
-  const frameLoc = getFrameLocation(selectedSource, rootFrame);
-
-  const sameLocation = previousFrameLoc && isEqual(previousFrameLoc, frameLoc);
-  const pausePoint = getPausePoint(state, frameLoc);
-  const invalidPauseLocation = pausePoint && !pausePoint.types.step;
-
-  // We always want to pause in generated locations
-  if (!frameLoc || isGeneratedId(frameLoc.sourceId)) {
-    return false;
-  }
-
-  return sameLocation || invalidPauseLocation;
-}
deleted file mode 100644
--- a/devtools/client/debugger/new/src/workers/parser/pausePoints.js
+++ /dev/null
@@ -1,199 +0,0 @@
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at <http://mozilla.org/MPL/2.0/>. */
-
-// @flow
-
-import { traverseAst } from "./utils/ast";
-import * as t from "@babel/types";
-import isEqual from "lodash/isEqual";
-
-import type { BabelNode } from "@babel/types";
-import type { SimplePath } from "./utils/simple-path";
-import type { PausePointsMap } from "./types";
-
-const isForStatement = node =>
-  t.isForStatement(node) || t.isForOfStatement(node);
-
-const isControlFlow = node =>
-  isForStatement(node) ||
-  t.isWhileStatement(node) ||
-  t.isIfStatement(node) ||
-  t.isSwitchCase(node) ||
-  t.isSwitchStatement(node) ||
-  t.isTryStatement(node) ||
-  t.isWithStatement(node);
-
-const isAssignment = node =>
-  t.isVariableDeclarator(node) ||
-  t.isAssignmentExpression(node) ||
-  t.isAssignmentPattern(node);
-
-const isImport = node => t.isImport(node) || t.isImportDeclaration(node);
-const isCall = node => t.isCallExpression(node) || t.isJSXElement(node);
-
-const inStepExpression = parent =>
-  t.isArrayExpression(parent) ||
-  t.isObjectProperty(parent) ||
-  t.isCallExpression(parent) ||
-  t.isJSXElement(parent) ||
-  t.isSequenceExpression(parent);
-
-const inExpression = (parent, grandParent) =>
-  inStepExpression(parent) ||
-  t.isJSXAttribute(grandParent) ||
-  t.isTemplateLiteral(parent);
-
-const isExport = node =>
-  t.isExportNamedDeclaration(node) || t.isExportDefaultDeclaration(node);
-
-// Finds the first call item in a step expression so that we can step
-// to the beginning of the list and either step in or over. e.g. [], x(), { }
-function isFirstCall(node, parentNode, grandParentNode) {
-  let children = [];
-  if (t.isArrayExpression(parentNode)) {
-    children = parentNode.elements;
-  }
-
-  if (t.isObjectProperty(parentNode)) {
-    children = grandParentNode.properties.map(({ value }) => value);
-  }
-
-  if (t.isSequenceExpression(parentNode)) {
-    children = parentNode.expressions;
-  }
-
-  if (t.isCallExpression(parentNode)) {
-    children = parentNode.arguments;
-  }
-
-  return children.find(child => isCall(child)) === node;
-}
-
-export function getPausePoints(sourceId: string): PausePointsMap {
-  const state = {};
-  traverseAst(sourceId, { enter: onEnter }, state);
-  return state;
-}
-
-/* eslint-disable complexity */
-function onEnter(node: BabelNode, ancestors: SimplePath[], state) {
-  const parent = ancestors[ancestors.length - 1];
-  const parentNode = parent && parent.node;
-  const grandParent = ancestors[ancestors.length - 2];
-  const grandParentNode = grandParent && grandParent.node;
-  const startLocation = node.loc.start;
-
-  if (
-    isImport(node) ||
-    t.isClassDeclaration(node) ||
-    isExport(node) ||
-    t.isDebuggerStatement(node) ||
-    t.isThrowStatement(node) ||
-    t.isBreakStatement(node) ||
-    t.isContinueStatement(node) ||
-    t.isReturnStatement(node)
-  ) {
-    return addStopPoint(state, startLocation);
-  }
-
-  if (isControlFlow(node)) {
-    addStopPoint(state, startLocation);
-
-    // We want to pause at tests so that we can pause at each iteration
-    // e.g `while (i++ < 3) { }`
-    const test = node.test || node.discriminant;
-    if (test) {
-      addStopPoint(state, test.loc.start);
-    }
-    return;
-  }
-
-  if (t.isBlockStatement(node) || t.isArrayExpression(node)) {
-    return addEmptyPoint(state, startLocation);
-  }
-
-  if (isAssignment(node)) {
-    // step at assignments unless the right side is a default assignment
-    // e.g. `( b = 2 ) => {}`
-    const defaultAssignment =
-      t.isFunction(parentNode) && parent.key === "params";
-
-    return addPoint(state, startLocation, !defaultAssignment);
-  }
-
-  if (isCall(node)) {
-    let location = startLocation;
-
-    // When functions are chained, we want to use the property location
-    // e.g `foo().bar()`
-    if (t.isMemberExpression(node.callee)) {
-      location = node.callee.property.loc.start;
-    }
-
-    // NOTE: We want to skip all nested calls in expressions except for the
-    // first call in arrays and objects expression e.g. [], {}, call
-    const step =
-      isFirstCall(node, parentNode, grandParentNode) ||
-      !inExpression(parentNode, grandParentNode);
-
-    // NOTE: we add a point at the beginning of the expression
-    // and each of the calls because the engine does not support
-    // column-based member expression calls.
-    addPoint(state, startLocation, { break: true, step });
-
-    if (location && !isEqual(location, startLocation)) {
-      addPoint(state, location, { break: true, step });
-    }
-
-    return;
-  }
-
-  if (t.isClassProperty(node)) {
-    return addBreakPoint(state, startLocation);
-  }
-
-  if (t.isFunction(node)) {
-    const { line, column } = node.loc.end;
-    addBreakPoint(state, startLocation);
-    return addEmptyPoint(state, { line, column: column - 1 });
-  }
-
-  if (!hasPoint(state, startLocation) && inStepExpression(parentNode)) {
-    return addEmptyPoint(state, startLocation);
-  }
-}
-
-function hasPoint(state, { line, column }) {
-  return state[line] && state[line][column];
-}
-
-function addPoint(
-  state,
-  location,
-  types: boolean | { break?: boolean, step?: boolean }
-) {
-  if (typeof types === "boolean") {
-    types = { step: types, break: types };
-  }
-
-  const { line, column } = location;
-
-  if (!state[line]) {
-    state[line] = {};
-  }
-  state[line][column] = { types, location };
-  return state;
-}
-
-function addStopPoint(state, location) {
-  return addPoint(state, location, { break: true, step: true });
-}
-
-function addEmptyPoint(state, location) {
-  return addPoint(state, location, {});
-}
-
-function addBreakPoint(state, location) {
-  return addPoint(state, location, { break: true });
-}
deleted file mode 100644
--- a/devtools/client/debugger/new/src/workers/parser/tests/pausePoints.spec.js
+++ /dev/null
@@ -1,43 +0,0 @@
-/* eslint max-nested-callbacks: ["error", 4]*/
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at <http://mozilla.org/MPL/2.0/>. */
-
-// @flow
-
-import cases from "jest-in-case";
-import {
-  formatPausePoints,
-  convertToList
-} from "../../../utils/pause/pausePoints";
-
-import { getPausePoints } from "../pausePoints";
-import { getSource, getOriginalSource } from "./helpers";
-import { setSource } from "../sources";
-
-cases(
-  "Parser.pausePoints",
-  ({ name, file, original, type }) => {
-    const source = original
-      ? getOriginalSource(file, type)
-      : getSource(file, type);
-
-    setSource(source);
-
-    // The coercion here is needed because getPausePoints and convertToList
-    // operate on two incompatible definitions of PausePointsMap
-    const nodes = convertToList((getPausePoints(source.id): any));
-    expect(formatPausePoints(source.text || "", nodes)).toMatchSnapshot();
-  },
-  [
-    { name: "control-flow", file: "control-flow" },
-    { name: "flow", file: "flow", original: true },
-    { name: "calls", file: "calls" },
-    { name: "statements", file: "statements" },
-    { name: "modules", file: "modules", original: true },
-    { name: "jsx", file: "jsx", original: true },
-    { name: "func", file: "func", original: true },
-    { name: "decorators", file: "decorators", original: true },
-    { name: "html", file: "parseScriptTags", type: "html" }
-  ]
-);