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

Commit ae91179

Browse files
committed
Lock down parser flow type exports (#5674)
1 parent 47dd851 commit ae91179

File tree

17 files changed

+82
-51
lines changed

17 files changed

+82
-51
lines changed

src/actions/preview.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import {
2121
} from "../selectors";
2222

2323
import { getMappedExpression } from "./expressions";
24-
2524
import { isEqual } from "lodash";
2625

2726
import type { ThunkArgs } from "./types";
@@ -91,7 +90,6 @@ function isInvalidTarget(target: HTMLElement) {
9190

9291
export function updatePreview(target: HTMLElement, editor: any) {
9392
return ({ dispatch, getState, client, sourceMaps }: ThunkArgs) => {
94-
const tokenText = target.innerText ? target.innerText.trim() : "";
9593
const tokenPos = getTokenLocation(editor.codeMirror, target);
9694
const cursorPos = target.getBoundingClientRect();
9795
const preview = getPreview(getState());
@@ -126,9 +124,9 @@ export function updatePreview(target: HTMLElement, editor: any) {
126124

127125
let match;
128126
if (!symbols || symbols.loading) {
129-
match = findBestMatchExpression(symbols, tokenPos, tokenText);
130-
} else {
131127
match = getExpressionFromCoords(editor.codeMirror, tokenPos);
128+
} else {
129+
match = findBestMatchExpression(symbols, tokenPos);
132130
}
133131

134132
if (!match || !match.expression) {

src/actions/types.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@ import type {
2424
} from "../reducers/ui";
2525
import type { MatchedLocations } from "../reducers/file-search";
2626

27-
import type { SymbolDeclaration, AstLocation } from "../workers/parser";
27+
import type { AstLocation, SymbolDeclaration } from "../workers/parser";
2828
import type { SourceMetaDataType } from "../reducers/ast.js";
29+
2930
/**
3031
* Flow types
3132
* @module actions/types

src/components/PrimaryPanes/Outline.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ import PreviewFunction from "../shared/PreviewFunction";
1515
import { uniq, sortBy } from "lodash";
1616
import type {
1717
SymbolDeclarations,
18-
SymbolDeclaration
19-
} from "../../workers/parser/getSymbols";
20-
import type { AstLocation } from "../../workers/parser/types";
18+
SymbolDeclaration,
19+
AstLocation
20+
} from "../../workers/parser";
2121
import type { SourceRecord } from "../../reducers/sources";
2222

2323
type Props = {

src/types.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,3 +327,7 @@ export type Worker = {
327327
type: number,
328328
url: string
329329
};
330+
331+
export type Position = { line: number, column: number };
332+
333+
export type Range = { end: Position, start: Position };

src/utils/ast.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,15 @@
22
* License, v. 2.0. If a copy of the MPL was not distributed with this
33
* file, You can obtain one at <http://mozilla.org/MPL/2.0/>. */
44

5-
export function findBestMatchExpression(symbols, tokenPos, token) {
5+
// @flow
6+
7+
import type { Position } from "../types";
8+
import type { SymbolDeclarations } from "../workers/parser";
9+
10+
export function findBestMatchExpression(
11+
symbols: SymbolDeclarations,
12+
tokenPos: Position
13+
) {
614
const { memberExpressions, identifiers } = symbols;
715
const { line, column } = tokenPos;
816
return identifiers.concat(memberExpressions).reduce((found, expression) => {

src/utils/breakpoint/astBreakpointLocation.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,12 @@
66

77
import { getSymbols } from "../../workers/parser";
88

9-
import type { Scope, AstPosition } from "../../workers/parser/types";
10-
import type { SymbolDeclarations } from "../../workers/parser/getSymbols";
9+
import type {
10+
Scope,
11+
AstPosition,
12+
SymbolDeclarations
13+
} from "../../workers/parser";
14+
1115
import type { Location, Source, ASTLocation } from "../../types";
1216

1317
export function containsPosition(a: AstPosition, b: AstPosition) {

src/utils/breakpoint/tests/astBreakpointLocation.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { getASTLocation } from "../astBreakpointLocation.js";
22
import { getSource } from "../../../workers/parser/tests/helpers";
33
import { setSource } from "../../../workers/parser/sources";
4-
import getSymbols from "../../../workers/parser/getSymbols";
4+
import { getSymbols } from "../../../workers/parser/getSymbols";
55
import cases from "jest-in-case";
66

77
async function setup({ fileName, location, functionName }) {

src/utils/editor/source-documents.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { getMode } from "../source";
99
import type { Source } from "../../types";
1010
import { isWasm, getWasmLineNumberFormatter, renderWasmText } from "../wasm";
1111
import { resizeBreakpointGutter, resizeToggleButton } from "../ui";
12-
import type { SymbolDeclarations } from "../../workers/parser/getSymbols";
12+
import type { SymbolDeclarations } from "../../workers/parser";
1313
import type { SourceRecord } from "../../reducers/types";
1414
import SourceEditor from "./source-editor";
1515

src/utils/tests/ast.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { findBestMatchExpression } from "../ast";
22

3-
import getSymbols from "../../workers/parser/getSymbols";
3+
import { getSymbols } from "../../workers/parser/getSymbols";
44
import { getSource } from "../../workers/parser/tests/helpers";
55
import { setSource } from "../../workers/parser/sources";
66

src/utils/tests/function.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { findFunctionText } from "../function";
22

3-
import getSymbols from "../../workers/parser/getSymbols";
3+
import { getSymbols } from "../../workers/parser/getSymbols";
44
import { getOriginalSource } from "../../workers/parser/tests/helpers";
55
import { setSource } from "../../workers/parser/sources";
66

0 commit comments

Comments
 (0)