Skip to content
This repository was archived by the owner on Jan 11, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 additions & 5 deletions flow-typed/debugger-html.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,13 @@ declare module "debugger-html" {
sourceUrl?: string
};

declare type ASTLocation = {
declare type ASTLocation = {|
name: ?string,
column: ?number,
line: number
};
offset: {
column: ?number,
line: number
}
|};

/**
* Breakpoint
Expand All @@ -68,6 +70,17 @@ declare module "debugger-html" {
condition: ?string
};

/**
* Breakpoint sync data
*
* @memberof types
* @static
*/
declare type BreakpointSyncData = {
previousLocation: Location | null,
breakpoint: Breakpoint
};

/**
* Breakpoint Result is the return from an add/modify Breakpoint request
*
Expand All @@ -87,7 +100,7 @@ declare module "debugger-html" {
*/
declare type PendingBreakpoint = {
location: PendingLocation,
astLocaton: ASTLocation,
astLocation: ASTLocation,
generatedLocation: PendingLocation,
loading: boolean,
disabled: boolean,
Expand Down
46 changes: 31 additions & 15 deletions src/actions/breakpoints/syncBreakpoint.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @flow
import {
locationMoved,
createBreakpoint,
Expand All @@ -9,8 +10,19 @@ import {
import { getGeneratedLocation } from "../../utils/source-maps";
import { originalToGeneratedId } from "devtools-source-map";
import { getSource } from "../../selectors";

async function makeScopedLocation({ name, offset }, location, source) {
import type {
BreakpointSyncData,
Location,
ASTLocation,
PendingBreakpoint,
SourceId
} from "debugger-html";

async function makeScopedLocation(
{ name, offset }: ASTLocation,
location: Location,
source
) {
const scope = await findScopeByName(source, name);
// fallback onto the location line, if the scope is not found
// note: we may at some point want to delete the breakpoint if the scope
Expand All @@ -25,12 +37,13 @@ async function makeScopedLocation({ name, offset }, location, source) {
}

function createSyncData(
pendingBreakpoint,
location,
generatedLocation,
previousLocation = null
) {
const overrides = { ...pendingBreakpoint, generatedLocation };
id: SourceId,
pendingBreakpoint: PendingBreakpoint,
location: Location,
generatedLocation: Location,
previousLocation: Location | null = null
): BreakpointSyncData {
const overrides = { ...pendingBreakpoint, generatedLocation, id };
const breakpoint = createBreakpoint(location, overrides);

assertBreakpoint(breakpoint);
Expand All @@ -40,12 +53,12 @@ function createSyncData(
// we have three forms of syncing: disabled syncing, existing server syncing
// and adding a new breakpoint
export async function syncClientBreakpoint(
getState,
client,
sourceMaps,
sourceId,
getState: Function,
client: Object,
sourceMaps: Object,
sourceId: SourceId,
pendingBreakpoint: PendingBreakpoint
) {
): Promise<BreakpointSyncData> {
assertPendingBreakpoint(pendingBreakpoint);

const source = getSource(getState(), sourceId).toJS();
Expand Down Expand Up @@ -87,7 +100,9 @@ export async function syncClientBreakpoint(
// early return if breakpoint is disabled or we are in the sameLocation
// send update only to redux
if (pendingBreakpoint.disabled || (existingClient && isSameLocation)) {
const id = pendingBreakpoint.disabled ? "" : existingClient.id;
return createSyncData(
id,
pendingBreakpoint,
scopedLocation,
scopedGeneratedLocation
Expand All @@ -102,20 +117,21 @@ export async function syncClientBreakpoint(
/** ******* Case 2: Add New Breakpoint ***********/
// If we are not disabled, set the breakpoint on the server and get
// that info so we can set it on our breakpoints.
const clientBreakpoint = await client.setBreakpoint(
const { id, actualLocation } = await client.setBreakpoint(
scopedGeneratedLocation,
pendingBreakpoint.condition,
sourceMaps.isOriginalId(sourceId)
);

// the breakpoint might have slid server side, so we want to get the location
// based on the server's return value
const newGeneratedLocation = clientBreakpoint.actualLocation;
const newGeneratedLocation = actualLocation;
const newLocation = await sourceMaps.getOriginalLocation(
newGeneratedLocation
);

return createSyncData(
id,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we are missing this change on line 92 of this file

pendingBreakpoint,
newLocation,
newGeneratedLocation,
Expand Down
12 changes: 12 additions & 0 deletions src/actions/breakpoints/tests/__snapshots__/syncing.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,15 @@ Object {
"sourceUrl": "http://localhost:8000/gen.js",
},
"hidden": false,
"id": "foo",
"loading": false,
"location": Object {
"column": undefined,
"line": 3,
"sourceId": "magic.js",
"sourceUrl": "http://localhost:8000/examples/magic.js",
},
"text": "",
},
"previousLocation": null,
}
Expand All @@ -47,12 +50,15 @@ Object {
"sourceUrl": "http://localhost:8000/gen.js",
},
"hidden": false,
"id": "foo",
"loading": false,
"location": Object {
"column": undefined,
"line": 12,
"sourceId": "magic.js",
"sourceUrl": "http://localhost:8000/examples/magic.js",
},
"text": "",
},
"previousLocation": null,
}
Expand All @@ -76,12 +82,15 @@ Object {
"sourceUrl": "http://localhost:8000/gen.js",
},
"hidden": false,
"id": "foo",
"loading": false,
"location": Object {
"column": undefined,
"line": 3,
"sourceId": "magic.js",
"sourceUrl": "http://localhost:8000/examples/magic.js",
},
"text": "",
},
"previousLocation": null,
}
Expand All @@ -105,12 +114,15 @@ Object {
"sourceUrl": "http://localhost:8000/gen.js",
},
"hidden": false,
"id": "gen.js:5:",
"loading": false,
"location": Object {
"column": undefined,
"line": 3,
"sourceId": "magic.js",
"sourceUrl": "http://localhost:8000/magic.js",
},
"text": "",
},
"previousLocation": Object {
"column": undefined,
Expand Down
1 change: 1 addition & 0 deletions src/actions/breakpoints/tests/syncing.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ function setBreakpoint(location, condition) {
}

const clientBreakpoint = {
id: "foo",
actualLocation: {
sourceUrl: "http://localhost:8000/gen.js",
sourceId: "gen.js",
Expand Down
12 changes: 4 additions & 8 deletions src/components/SecondaryPanes/Breakpoints.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ type Props = {
toggleAllBreakpoints: boolean => void,
toggleDisabledBreakpoint: number => void,
setBreakpointCondition: Location => void,
toggleConditionalBreakpointPanel: number => void
openConditionalPanel: number => void
};

function isCurrentlyPausedAtBreakpoint(pause, breakpoint) {
Expand Down Expand Up @@ -107,7 +107,7 @@ class Breakpoints extends PureComponent<Props> {
toggleAllBreakpoints,
toggleDisabledBreakpoint,
setBreakpointCondition,
toggleConditionalBreakpointPanel,
openConditionalPanel,
breakpoints
} = this.props;

Expand Down Expand Up @@ -268,7 +268,7 @@ class Breakpoints extends PureComponent<Props> {
accesskey: addConditionKey,
click: () => {
this.selectBreakpoint(breakpoint);
toggleConditionalBreakpointPanel(breakpoint.location.line);
openConditionalPanel(breakpoint.location.line);
}
};

Expand All @@ -278,7 +278,7 @@ class Breakpoints extends PureComponent<Props> {
accesskey: editConditionKey,
click: () => {
this.selectBreakpoint(breakpoint);
toggleConditionalBreakpointPanel(breakpoint.location.line);
openConditionalPanel(breakpoint.location.line);
}
};

Expand Down Expand Up @@ -339,10 +339,6 @@ class Breakpoints extends PureComponent<Props> {
this.props.removeBreakpoint(breakpoint.location);
}

toggleConditionalBreakpointPanel(line) {
this.props.toggleConditionalBreakpointPanel(line);
}

renderBreakpoint(breakpoint) {
const snippet = breakpoint.text || "";
const locationId = breakpoint.locationId;
Expand Down
11 changes: 7 additions & 4 deletions src/utils/breakpoint/astBreakpointLocation.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { getSymbols } from "../../workers/parser";

import type { Scope, AstPosition } from "../../workers/parser/types";
import type { Location, Source } from "debugger-html";
import type { Location, Source, ASTLocation } from "debugger-html";

export function containsPosition(a: AstPosition, b: AstPosition) {
const startsBefore =
Expand Down Expand Up @@ -42,7 +42,10 @@ export function findClosestScope(functions: Scope[], location: Location) {
}, null);
}

export async function getASTLocation(source: Source, location: Location) {
export async function getASTLocation(
source: Source,
location: Location
): Promise<ASTLocation> {
const symbols = await getSymbols(source);
const functions = [...symbols.functions];

Expand All @@ -53,13 +56,13 @@ export async function getASTLocation(source: Source, location: Location) {
const line = location.line - scope.location.start.line;
return {
name: scope.name,
offset: { line }
offset: { line, column: undefined }
};
}
return { name: undefined, offset: location };
}

export async function findScopeByName(source: Source, name: String) {
export async function findScopeByName(source: Source, name: ?string) {
const symbols = await getSymbols(source);
const functions = symbols.functions;

Expand Down
14 changes: 11 additions & 3 deletions src/utils/breakpoint/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,20 +103,28 @@ export function breakpointExists(state: State, location: Location) {
return currentBp && !currentBp.disabled;
}

export function createBreakpoint(location: Location, overrides: Object = {}) {
export function createBreakpoint(
location: Location,
overrides: Object = {}
): Breakpoint {
const {
condition,
disabled,
hidden,
generatedLocation,
astLocation
astLocation,
id
} = overrides;

const defaultASTLocation = { name: undefined, offset: location };
const properties = {
id,
condition: condition || null,
disabled: disabled || false,
hidden: hidden || false,
astLocation: astLocation || { offset: location },
loading: false,
text: "",
astLocation: astLocation || defaultASTLocation,
generatedLocation: generatedLocation || location,
location
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ exports[`ast valid location returns name for a nested anon fn as the parent func
Object {
"name": "outer",
"offset": Object {
"column": undefined,
"line": 22,
},
}
Expand All @@ -33,6 +34,7 @@ exports[`ast valid location returns name for a nested named fn 1`] = `
Object {
"name": "inner",
"offset": Object {
"column": undefined,
"line": 1,
},
}
Expand All @@ -42,6 +44,7 @@ exports[`ast valid location returns name for an anon fn with a named variable 1`
Object {
"name": "globalDeclaration",
"offset": Object {
"column": undefined,
"line": 1,
},
}
Expand All @@ -51,6 +54,7 @@ exports[`ast valid location returns the scope and offset 1`] = `
Object {
"name": "math",
"offset": Object {
"column": undefined,
"line": 5,
},
}
Expand Down