Skip to content

Commit 3f8d481

Browse files
darkwingjasonLaster
authored andcommitted
Use isOriginal and isGenerated instead of ID checks (firefox-devtools#6996)
1 parent a3085ae commit 3f8d481

File tree

16 files changed

+55
-53
lines changed

16 files changed

+55
-53
lines changed

src/actions/ast.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,8 @@ import {
2424
} from "../workers/parser";
2525

2626
import { PROMISE } from "./utils/middleware/promise";
27-
import { isGeneratedId } from "devtools-source-map";
2827
import { features } from "../utils/prefs";
29-
import { isLoaded } from "../utils/source";
28+
import { isLoaded, isGenerated } from "../utils/source";
3029

3130
import type { SourceId } from "../types";
3231
import type { ThunkArgs, Action } from "./types";
@@ -128,7 +127,7 @@ export function setPausePoints(sourceId: SourceId) {
128127
const pausePoints = await getPausePoints(sourceId);
129128
const compressed = compressPausePoints(pausePoints);
130129

131-
if (isGeneratedId(sourceId)) {
130+
if (isGenerated(source)) {
132131
await client.setPausePoints(sourceId, compressed);
133132
}
134133

src/actions/expressions.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ import {
1515
getSelectedFrameBindings
1616
} from "../selectors";
1717
import { PROMISE } from "./utils/middleware/promise";
18-
import { isGeneratedId } from "devtools-source-map";
1918
import { wrapExpression } from "../utils/expressions";
2019
import { features } from "../utils/prefs";
20+
import { isOriginal } from "../utils/source";
2121

2222
import * as parser from "../workers/parser";
2323
import type { Expression } from "../types";
@@ -135,15 +135,10 @@ function evaluateExpression(expression: Expression) {
135135
if (frame) {
136136
const { location } = frame;
137137
const source = getSourceFromId(getState(), location.sourceId);
138-
const sourceId = source.id;
139138

140139
const selectedSource = getSelectedSource(getState());
141140

142-
if (
143-
selectedSource &&
144-
!isGeneratedId(sourceId) &&
145-
!isGeneratedId(selectedSource.id)
146-
) {
141+
if (selectedSource && isOriginal(source) && isOriginal(selectedSource)) {
147142
const mapResult = await dispatch(getMappedExpression(input));
148143
if (mapResult) {
149144
input = mapResult.expression || mapResult;

src/actions/pause/mapScopes.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { PROMISE } from "../utils/middleware/promise";
1010

1111
import { features } from "../../utils/prefs";
1212
import { log } from "../../utils/log";
13-
import { isGeneratedId } from "devtools-source-map";
13+
import { isGenerated } from "../../utils/source";
1414
import type { Frame, Scope } from "../../types";
1515

1616
import type { ThunkArgs } from "../types";
@@ -36,7 +36,7 @@ export function mapScopes(scopes: Promise<Scope>, frame: Frame) {
3636
!generatedSource ||
3737
generatedSource.isWasm ||
3838
source.isPrettyPrinted ||
39-
isGeneratedId(frame.location.sourceId)
39+
isGenerated(source)
4040
) {
4141
return null;
4242
}

src/actions/preview.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
// @flow
66
import { isConsole } from "../utils/preview";
77
import { findBestMatchExpression } from "../utils/ast";
8-
import { isGeneratedId } from "devtools-source-map";
98
import { PROMISE } from "./utils/middleware/promise";
109
import { getExpressionFromCoords } from "../utils/editor/get-expression";
10+
import { isOriginal } from "../utils/source";
1111

1212
import {
1313
getPreview,
@@ -87,10 +87,9 @@ export function setPreview(
8787
return;
8888
}
8989

90-
const sourceId = source.id;
9190
const selectedFrame = getSelectedFrame(getState());
9291

93-
if (location && !isGeneratedId(sourceId)) {
92+
if (location && isOriginal(source)) {
9493
const mapResult = await dispatch(getMappedExpression(expression));
9594
if (mapResult) {
9695
expression = mapResult.expression || mapResult;

src/actions/sources/loadSourceText.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,10 @@
44

55
// @flow
66

7-
import { isOriginalId } from "devtools-source-map";
87
import { PROMISE } from "../utils/middleware/promise";
98
import { getGeneratedSource, getSource } from "../../selectors";
109
import * as parser from "../../workers/parser";
11-
import { isLoaded } from "../../utils/source";
10+
import { isLoaded, isOriginal } from "../../utils/source";
1211
import { Telemetry } from "devtools-modules";
1312

1413
import defer from "../../utils/defer";
@@ -23,8 +22,8 @@ const loadSourceHistogram = "DEVTOOLS_DEBUGGER_LOAD_SOURCE_MS";
2322
const telemetry = new Telemetry();
2423

2524
async function loadSource(source: Source, { sourceMaps, client }) {
26-
const id = source.id;
27-
if (isOriginalId(id)) {
25+
const { id } = source;
26+
if (isOriginal(source)) {
2827
return sourceMaps.getOriginalSourceText(source);
2928
}
3029

@@ -79,7 +78,7 @@ export function loadSourceText(source: ?Source) {
7978
return;
8079
}
8180

82-
if (isOriginalId(newSource.id) && !newSource.isWasm) {
81+
if (isOriginal(newSource) && !newSource.isWasm) {
8382
const generatedSource = getGeneratedSource(getState(), source);
8483
await dispatch(loadSourceText(generatedSource));
8584
}

src/actions/sources/newSources.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@
99
* @module actions/sources
1010
*/
1111

12-
import { isGeneratedId, generatedToOriginalId } from "devtools-source-map";
12+
import { generatedToOriginalId } from "devtools-source-map";
1313
import { flatten } from "lodash";
1414

1515
import { toggleBlackBox } from "./blackbox";
1616
import { syncBreakpoint } from "../breakpoints";
1717
import { loadSourceText } from "./loadSourceText";
1818
import { togglePrettyPrint } from "./prettyPrint";
1919
import { selectLocation } from "../sources";
20-
import { getRawSourceURL, isPrettyURL } from "../../utils/source";
20+
import { getRawSourceURL, isPrettyURL, isOriginal } from "../../utils/source";
2121
import {
2222
getBlackBoxList,
2323
getSource,
@@ -69,7 +69,7 @@ function loadSourceMap(sourceId: SourceId) {
6969
return async function({ dispatch, getState, sourceMaps }: ThunkArgs) {
7070
const source = getSource(getState(), sourceId);
7171

72-
if (!source || !isGeneratedId(sourceId) || !source.sourceMapURL) {
72+
if (!source || isOriginal(source) || !source.sourceMapURL) {
7373
return;
7474
}
7575

src/components/Editor/Footer.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
// @flow
66
import React, { PureComponent } from "react";
77
import { connect } from "react-redux";
8-
import { isOriginalId } from "devtools-source-map";
98
import classnames from "classnames";
109

1110
import actions from "../../actions";
@@ -16,7 +15,12 @@ import {
1615
} from "../../selectors";
1716

1817
import { features } from "../../utils/prefs";
19-
import { isPretty, isLoaded, getFilename } from "../../utils/source";
18+
import {
19+
isPretty,
20+
isLoaded,
21+
getFilename,
22+
isOriginal
23+
} from "../../utils/source";
2024
import { getGeneratedSource } from "../../reducers/sources";
2125
import { shouldShowFooter, shouldShowPrettyPrint } from "../../utils/editor";
2226

@@ -158,7 +162,7 @@ class SourceFooter extends PureComponent<Props> {
158162
renderSourceSummary() {
159163
const { mappedSource, jumpToMappedLocation, selectedSource } = this.props;
160164

161-
if (!mappedSource || !isOriginalId(selectedSource.id)) {
165+
if (!mappedSource || !isOriginal(selectedSource)) {
162166
return null;
163167
}
164168

src/components/PrimaryPanes/SourcesTreeItem.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
// @flow
66

7-
import { isOriginalId } from "devtools-source-map";
87
import React, { Component } from "react";
98
import { connect } from "react-redux";
109
import classnames from "classnames";
@@ -16,6 +15,7 @@ import Svg from "../shared/Svg";
1615
import { getSourcesByURL } from "../../selectors";
1716
import actions from "../../actions";
1817

18+
import { isOriginal as isOriginalSource } from "../../utils/source";
1919
import { isDirectory } from "../../utils/sources-tree";
2020
import { copyToTheClipboard } from "../../utils/clipboard";
2121
import { features } from "../../utils/prefs";
@@ -191,7 +191,7 @@ function getHasMatchingGeneratedSource(state, source: ?Source) {
191191
return false;
192192
}
193193

194-
const isOriginal = isOriginalId(source.id);
194+
const isOriginal = isOriginalSource(source);
195195
const sources = getSourcesByURL(state, source.url, isOriginal);
196196
return isOriginal && sources.length > 0;
197197
}

src/components/SecondaryPanes/Breakpoints/Breakpoint.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
import React, { PureComponent } from "react";
88
import { connect } from "react-redux";
9-
import { isGeneratedId } from "devtools-source-map";
109

1110
import classnames from "classnames";
1211

@@ -19,6 +18,7 @@ import { getLocationWithoutColumn } from "../../../utils/breakpoint";
1918

2019
import { features } from "../../../utils/prefs";
2120
import { getEditor } from "../../../utils/editor";
21+
import { isGenerated } from "../../../utils/source";
2222

2323
import type { BreakpointsMap } from "../../../reducers/types";
2424

@@ -53,7 +53,7 @@ type Props = {
5353
};
5454

5555
function getMappedLocation(mappedLocation: MappedLocation, selectedSource) {
56-
return selectedSource && isGeneratedId(selectedSource.id)
56+
return selectedSource && isGenerated(selectedSource)
5757
? mappedLocation.generatedLocation
5858
: mappedLocation.location;
5959
}
@@ -132,7 +132,7 @@ class Breakpoint extends PureComponent<Props> {
132132
return condition;
133133
}
134134

135-
if (selectedSource && isGeneratedId(selectedSource.id)) {
135+
if (selectedSource && isGenerated(selectedSource)) {
136136
return breakpoint.text;
137137
}
138138

src/reducers/pending-breakpoints.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@
99
* @module reducers/pending-breakpoints
1010
*/
1111

12-
import { isGeneratedId } from "devtools-source-map";
1312
import { getSourcesByURL } from "./sources";
1413

1514
import {
1615
createPendingBreakpoint,
1716
makePendingLocationId
1817
} from "../utils/breakpoint";
18+
import { isGenerated } from "../utils/source";
1919

2020
import type { SourcesState } from "./sources";
2121
import type { PendingBreakpoint, Source } from "../types";
@@ -164,7 +164,7 @@ export function getPendingBreakpointsForSource(
164164
source: Source
165165
): PendingBreakpoint[] {
166166
const sources = getSourcesByURL(state, source.url);
167-
if (sources.length > 1 && isGeneratedId(source.id)) {
167+
if (sources.length > 1 && isGenerated(source)) {
168168
// Don't return pending breakpoints for duplicated generated sources
169169
return [];
170170
}

0 commit comments

Comments
 (0)