Skip to content
This repository has been archived by the owner on Jan 11, 2023. It is now read-only.

Commit

Permalink
Rename some Position/Location types. (#7364)
Browse files Browse the repository at this point in the history
* Rename Location to SourceLocation.

* Rename Position to PartialPosition.

* Rename Range to PartialRange.

* Rename ColumnRange to Range.

* Rename ColumnPosition to Position.

* Make SourceLocation objects exact.

* Rename more Location to SourceLocation

* Make SourceLocation objects exact.
  • Loading branch information
loganfsmyth committed Nov 29, 2018
1 parent 72e855d commit fcff67b
Show file tree
Hide file tree
Showing 51 changed files with 246 additions and 203 deletions.
22 changes: 13 additions & 9 deletions flow-typed/debugger-html.js
@@ -1,3 +1,7 @@
/* 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

declare module "debugger-html" {
Expand Down Expand Up @@ -31,12 +35,12 @@ declare module "debugger-html" {
* @memberof types
* @static
*/
declare type Location = {
declare type SourceLocation = {|
sourceId: SourceId,
line: number,
column?: number,
sourceUrl?: string
};
|};

/**
* Breakpoint
Expand All @@ -46,7 +50,7 @@ declare module "debugger-html" {
*/
declare type Breakpoint = {
id: BreakpointId,
location: Location,
location: SourceLocation,
loading: boolean,
disabled: boolean,
text: string,
Expand All @@ -61,7 +65,7 @@ declare module "debugger-html" {
*/
declare type BreakpointResult = {
id: ActorId,
actualLocation: Location
actualLocation: SourceLocation
};

/**
Expand Down Expand Up @@ -95,7 +99,7 @@ declare module "debugger-html" {
declare type Frame = {
id: FrameId,
displayName: string,
location: Location,
location: SourceLocation,
source?: Source,
scope: Scope,
// FIXME Define this type more clearly
Expand Down Expand Up @@ -190,10 +194,10 @@ declare module "debugger-html" {
*/
declare type SourceScope = {
type: string,
start: Location,
end: Location,
start: SourceLocation,
end: SourceLocation,
bindings: {
[name: string]: Location[]
[name: string]: SourceLocation[]
}
};

Expand Down Expand Up @@ -240,7 +244,7 @@ declare module "debugger-html" {
actor: ActorId,
class: string,
displayName: string,
location: Location,
location: SourceLocation,
// FIXME Define this type more clearly
parameterNames: Array<Object>
},
Expand Down
18 changes: 9 additions & 9 deletions packages/devtools-source-map/src/source-map.js
Expand Up @@ -29,7 +29,7 @@ const {
} = require("./utils");
const { clearWasmXScopes } = require("./utils/wasmXScopes");

import type { Location, Source, SourceId } from "debugger-html";
import type { SourceLocation, Source, SourceId } from "debugger-html";

async function getOriginalURLs(generatedSource: Source) {
const map = await fetchSourceMap(generatedSource);
Expand Down Expand Up @@ -98,7 +98,7 @@ async function getOriginalRanges(sourceId: SourceId, url: string) {
* are mapped from the original range containing the location.
*/
async function getGeneratedRanges(
location: Location,
location: SourceLocation,
originalSource: Source
): Promise<
Array<{
Expand Down Expand Up @@ -158,9 +158,9 @@ async function getGeneratedRanges(
}

async function getGeneratedLocation(
location: Location,
location: SourceLocation,
originalSource: Source
): Promise<Location> {
): Promise<SourceLocation> {
if (!isOriginalId(location.sourceId)) {
return location;
}
Expand Down Expand Up @@ -205,9 +205,9 @@ async function getGeneratedLocation(
}

async function getAllGeneratedLocations(
location: Location,
location: SourceLocation,
originalSource: Source
): Promise<Array<Location>> {
): Promise<Array<SourceLocation>> {
if (!isOriginalId(location.sourceId)) {
return [];
}
Expand Down Expand Up @@ -235,9 +235,9 @@ type locationOptions = {
search?: "LEAST_UPPER_BOUND" | "GREATEST_LOWER_BOUND"
};
async function getOriginalLocation(
location: Location,
location: SourceLocation,
{ search }: locationOptions = {}
): Promise<Location> {
): Promise<SourceLocation> {
if (!isGeneratedId(location.sourceId)) {
return location;
}
Expand Down Expand Up @@ -306,7 +306,7 @@ async function getOriginalSourceText(originalSource: Source) {
};
}

async function hasMappedSource(location: Location): Promise<boolean> {
async function hasMappedSource(location: SourceLocation): Promise<boolean> {
if (isOriginalId(location.sourceId)) {
return true;
}
Expand Down
Expand Up @@ -4,17 +4,17 @@

// @flow

import type { Location } from "debugger-html";
import type { SourceLocation } from "debugger-html";

const { getWasmXScopes } = require("./wasmXScopes");

// Returns expanded stack frames details based on the generated location.
// The function return null if not information was found.
async function getOriginalStackFrames(
generatedLocation: Location
generatedLocation: SourceLocation
): Promise<?Array<{
displayName: string,
location?: Location
location?: SourceLocation
}>> {
const wasmXScopes = await getWasmXScopes(generatedLocation.sourceId);
if (!wasmXScopes) {
Expand Down
6 changes: 3 additions & 3 deletions packages/devtools-source-map/src/utils/wasmXScopes.js
Expand Up @@ -5,7 +5,7 @@
// @flow
/* eslint camelcase: 0*/

import type { Location, SourceId } from "debugger-html";
import type { SourceLocation, SourceId } from "debugger-html";

const { getSourceMap } = require("./sourceMapRequests");
const { generatedToOriginalId } = require("./index");
Expand Down Expand Up @@ -137,10 +137,10 @@ class XScope {
}

search(
generatedLocation: Location
generatedLocation: SourceLocation
): Array<{
displayName: string,
location?: Location
location?: SourceLocation
}> {
const { code_section_offset, debug_info, sources, idIndex } = this.xScope;
const pc = generatedLocation.line - (code_section_offset || 0);
Expand Down
8 changes: 4 additions & 4 deletions src/actions/breakpoints/addBreakpoint.js
Expand Up @@ -94,7 +94,7 @@ async function addBreakpointPromise(getState, client, sourceMaps, breakpoint) {
* @param location
* @return {function(ThunkArgs)}
*/
export function addHiddenBreakpoint(location: Location) {
export function addHiddenBreakpoint(location: SourceLocation) {
return ({ dispatch }: ThunkArgs) => {
return dispatch(addBreakpoint(location, { hidden: true }));
};
Expand All @@ -106,9 +106,9 @@ export function addHiddenBreakpoint(location: Location) {
*
* @memberof actions/breakpoints
* @static
* @param {Location} $1.location Location value
* @param {SourceLocation} $1.location Location value
*/
export function enableBreakpoint(location: Location) {
export function enableBreakpoint(location: SourceLocation) {
return async ({ dispatch, getState, client, sourceMaps }: ThunkArgs) => {
const breakpoint = getBreakpoint(getState(), location);
if (!breakpoint || breakpoint.loading) {
Expand Down Expand Up @@ -139,7 +139,7 @@ export function enableBreakpoint(location: Location) {
*/

export function addBreakpoint(
location: Location,
location: SourceLocation,
{ condition, hidden }: addBreakpointOptions = {}
) {
const breakpoint = createBreakpoint(location, { condition, hidden });
Expand Down
10 changes: 5 additions & 5 deletions src/actions/breakpoints/index.js
Expand Up @@ -32,7 +32,7 @@ import { isEmptyLineInSource } from "../../reducers/ast";
// this will need to be changed so that addCLientBreakpoint is removed

import type { ThunkArgs, Action } from "../types";
import type { Breakpoint, Location, XHRBreakpoint } from "../../types";
import type { Breakpoint, SourceLocation, XHRBreakpoint } from "../../types";

import { recordEvent } from "../../utils/telemetry";

Expand All @@ -47,7 +47,7 @@ type addBreakpointOptions = {
* @memberof actions/breakpoints
* @static
*/
export function removeBreakpoint(location: Location) {
export function removeBreakpoint(location: SourceLocation) {
return ({ dispatch, getState, client }: ThunkArgs) => {
const bp = getBreakpoint(getState(), location);
if (!bp || bp.loading) {
Expand Down Expand Up @@ -84,7 +84,7 @@ export function removeBreakpoint(location: Location) {
* @memberof actions/breakpoints
* @static
*/
export function disableBreakpoint(location: Location) {
export function disableBreakpoint(location: SourceLocation) {
return async ({ dispatch, getState, client }: ThunkArgs) => {
const bp = getBreakpoint(getState(), location);

Expand Down Expand Up @@ -220,14 +220,14 @@ export function remapBreakpoints(sourceId: string) {
* @throws {Error} "not implemented"
* @memberof actions/breakpoints
* @static
* @param {Location} location
* @param {SourceLocation} location
* @see DebuggerController.Breakpoints.addBreakpoint
* @param {string} condition
* The condition to set on the breakpoint
* @param {Boolean} $1.disabled Disable value for breakpoint value
*/
export function setBreakpointCondition(
location: Location,
location: SourceLocation,
{ condition }: addBreakpointOptions = {}
) {
return async ({ dispatch, getState, client, sourceMaps }: ThunkArgs) => {
Expand Down
12 changes: 6 additions & 6 deletions src/actions/breakpoints/syncBreakpoint.js
Expand Up @@ -18,21 +18,21 @@ import { getSource } from "../../selectors";
import type { ThunkArgs, Action } from "../types";

import type {
Location,
SourceLocation,
ASTLocation,
PendingBreakpoint,
SourceId,
Breakpoint
} from "../../types";

type BreakpointSyncData = {
previousLocation: Location,
previousLocation: SourceLocation,
breakpoint: ?Breakpoint
};

async function makeScopedLocation(
{ name, offset }: ASTLocation,
location: Location,
location: SourceLocation,
source
) {
const scope = await findScopeByName(source, name);
Expand All @@ -51,9 +51,9 @@ async function makeScopedLocation(
function createSyncData(
id: SourceId,
pendingBreakpoint: PendingBreakpoint,
location: Location,
generatedLocation: Location,
previousLocation: Location,
location: SourceLocation,
generatedLocation: SourceLocation,
previousLocation: SourceLocation,
text: string,
originalText: string
): BreakpointSyncData {
Expand Down
4 changes: 2 additions & 2 deletions src/actions/preview.js
Expand Up @@ -22,7 +22,7 @@ import { getMappedExpression } from "./expressions";
import { getExtra } from "./pause";

import type { Action, ThunkArgs } from "./types";
import type { ColumnPosition } from "../types";
import type { Position } from "../types";
import type { AstLocation } from "../workers/parser";

function findExpressionMatch(state, codeMirror, tokenPos) {
Expand Down Expand Up @@ -75,7 +75,7 @@ export function updatePreview(
export function setPreview(
expression: string,
location: AstLocation,
tokenPos: ColumnPosition,
tokenPos: Position,
cursorPos: ClientRect
) {
return async ({ dispatch, getState, client, sourceMaps }: ThunkArgs) => {
Expand Down
7 changes: 6 additions & 1 deletion src/actions/sources/newSources.js
Expand Up @@ -123,7 +123,12 @@ function checkSelectedSource(sourceId: string) {
}

await dispatch(
selectLocation({ ...pendingLocation, sourceId: source.id })
selectLocation({
sourceId: source.id,
line:
typeof pendingLocation.line === "number" ? pendingLocation.line : 0,
column: pendingLocation.column
})
);
}
};
Expand Down
18 changes: 12 additions & 6 deletions src/actions/sources/select.js
Expand Up @@ -34,10 +34,13 @@ import {
getSelectedSource
} from "../../selectors";

import type { Location, Position, Source } from "../../types";
import type { SourceLocation, PartialPosition, Source } from "../../types";
import type { ThunkArgs } from "../types";

export const setSelectedLocation = (source: Source, location: Location) => ({
export const setSelectedLocation = (
source: Source,
location: SourceLocation
) => ({
type: "SET_SELECTED_LOCATION",
source,
location
Expand All @@ -64,7 +67,10 @@ export const clearSelectedLocation = () => ({
* @memberof actions/sources
* @static
*/
export function selectSourceURL(url: string, options: Position = { line: 1 }) {
export function selectSourceURL(
url: string,
options: PartialPosition = { line: 1 }
) {
return async ({ dispatch, getState, sourceMaps }: ThunkArgs) => {
const source = getSourceByURL(getState(), url);
if (!source) {
Expand Down Expand Up @@ -93,7 +99,7 @@ export function selectSource(sourceId: string) {
* @static
*/
export function selectLocation(
location: Location,
location: SourceLocation,
{ keepContext = true }: Object = {}
) {
return async ({ dispatch, getState, sourceMaps, client }: ThunkArgs) => {
Expand Down Expand Up @@ -169,15 +175,15 @@ export function selectLocation(
* @memberof actions/sources
* @static
*/
export function selectSpecificLocation(location: Location) {
export function selectSpecificLocation(location: SourceLocation) {
return selectLocation(location, { keepContext: false });
}

/**
* @memberof actions/sources
* @static
*/
export function jumpToMappedLocation(location: Location) {
export function jumpToMappedLocation(location: SourceLocation) {
return async function({ dispatch, getState, client, sourceMaps }: ThunkArgs) {
if (!client) {
return;
Expand Down

0 comments on commit fcff67b

Please sign in to comment.