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

Commit 1e31650

Browse files
y9127jasonLaster
authored andcommitted
Add flow coverage to parser/types.js (#5772)
1 parent 0eaa82f commit 1e31650

File tree

17 files changed

+816
-800
lines changed

17 files changed

+816
-800
lines changed

src/actions/preview.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ import { getMappedExpression } from "./expressions";
2424
import { isEqual } from "lodash";
2525

2626
import type { ThunkArgs } from "./types";
27-
import type { Frame, Range, ColumnPosition } from "../types";
27+
import type { Frame, ColumnPosition } from "../types";
28+
import type { AstLocation } from "../workers/parser";
2829

2930
async function getReactProps(evaluate) {
3031
const reactDisplayName = await evaluate(
@@ -159,7 +160,7 @@ export function updatePreview(target: HTMLElement, editor: any) {
159160

160161
export function setPreview(
161162
expression: string,
162-
location: Range,
163+
location: AstLocation,
163164
tokenPos: ColumnPosition,
164165
cursorPos: any
165166
) {

src/actions/types.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,13 @@ import type {
2525
} from "../reducers/ui";
2626

2727
import type { MatchedLocations } from "../reducers/file-search";
28+
2829
import type {
29-
SymbolDeclaration,
30+
SymbolDeclarations,
3031
AstLocation,
3132
PausePoint
3233
} from "../workers/parser";
34+
3335
import type { SourceMetaDataType } from "../reducers/ast.js";
3436

3537
/**
@@ -326,7 +328,7 @@ type ASTAction =
326328
| {
327329
type: "SET_SYMBOLS",
328330
source: Source,
329-
value: SymbolDeclaration[]
331+
value: SymbolDeclarations
330332
}
331333
| {
332334
type: "SET_PAUSE_POINTS",

src/components/Editor/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ import EmptyLines from "./EmptyLines";
4141
import GutterMenu from "./GutterMenu";
4242
import EditorMenu from "./EditorMenu";
4343
import ConditionalPanel from "./ConditionalPanel";
44-
import type { SymbolDeclarations } from "../../workers/parser";
4544

4645
import {
4746
showSourceText,
@@ -66,6 +65,7 @@ import "./Editor.css";
6665
import "./Highlight.css";
6766

6867
import type SourceEditor from "../../utils/editor/source-editor";
68+
import type { SymbolDeclarations } from "../../workers/parser";
6969

7070
const cssVars = {
7171
searchbarHeight: "var(--editor-searchbar-height)",

src/components/PrimaryPanes/Outline.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,12 @@ import {
2222
import "./Outline.css";
2323
import PreviewFunction from "../shared/PreviewFunction";
2424
import { uniq, sortBy } from "lodash";
25+
2526
import type {
27+
AstLocation,
2628
SymbolDeclarations,
2729
SymbolDeclaration,
28-
AstLocation
30+
FunctionDeclaration
2931
} from "../../workers/parser";
3032
import type { SourceRecord } from "../../types";
3133

@@ -104,7 +106,7 @@ export class Outline extends Component<Props> {
104106
);
105107
}
106108

107-
renderFunction(func: SymbolDeclaration) {
109+
renderFunction(func: FunctionDeclaration) {
108110
const { name, location, parameterNames } = func;
109111

110112
return (
@@ -120,7 +122,7 @@ export class Outline extends Component<Props> {
120122
);
121123
}
122124

123-
renderClassFunctions(klass: string, functions: SymbolDeclaration[]) {
125+
renderClassFunctions(klass: string, functions: FunctionDeclaration[]) {
124126
if (klass == null || functions.length == 0) {
125127
return null;
126128
}
@@ -149,7 +151,7 @@ export class Outline extends Component<Props> {
149151
);
150152
}
151153

152-
renderFunctions(functions: Array<SymbolDeclaration>) {
154+
renderFunctions(functions: Array<FunctionDeclaration>) {
153155
let classes = uniq(functions.map(func => func.klass));
154156
let namedFunctions = functions.filter(
155157
func =>

src/reducers/ast.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ import makeRecord from "../utils/makeRecord";
1515
import { findEmptyLines } from "../utils/ast";
1616

1717
import type {
18-
SymbolDeclarations,
1918
AstLocation,
20-
PausePoint
19+
PausePoint,
20+
SymbolDeclarations
2121
} from "../workers/parser";
2222

2323
import type { Map } from "immutable";
@@ -26,6 +26,7 @@ import type { Action } from "../actions/types";
2626
import type { Record } from "../utils/makeRecord";
2727

2828
type EmptyLinesType = number[];
29+
2930
export type Symbols = SymbolDeclarations | {| loading: true |};
3031
export type SymbolsMap = Map<string, Symbols>;
3132
export type EmptyLinesMap = Map<string, EmptyLinesType>;

src/utils/ast.js

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,34 @@
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+
// @flow
6+
57
import { without, range } from "lodash";
68

79
import type { Location, Source, ColumnPosition } from "../types";
10+
11+
import type { AstPosition, AstLocation, PausePoint } from "../workers/parser";
812
import type {
9-
AstPosition,
10-
AstLocation,
1113
SymbolDeclarations,
12-
SymbolDeclaration,
13-
PausePoint
14-
} from "../workers/parser";
14+
FunctionDeclaration
15+
} from "../workers/parser/getSymbols";
1516

1617
export function findBestMatchExpression(
1718
symbols: SymbolDeclarations,
1819
tokenPos: ColumnPosition
1920
) {
2021
const { memberExpressions, identifiers, literals } = symbols;
2122
const { line, column } = tokenPos;
22-
return identifiers
23-
.concat(memberExpressions, literals)
23+
24+
const members = memberExpressions.filter(({ computed }) => !computed);
25+
26+
return []
27+
.concat(identifiers, members, literals)
2428
.reduce((found, expression) => {
2529
const overlaps =
2630
expression.location.start.line == line &&
2731
expression.location.start.column <= column &&
28-
expression.location.end.column >= column &&
29-
!expression.computed;
32+
expression.location.end.column >= column;
3033

3134
if (overlaps) {
3235
return expression;
@@ -66,7 +69,7 @@ export function containsPosition(a: AstLocation, b: AstPosition) {
6669
}
6770

6871
export function findClosestFunction(
69-
functions: SymbolDeclaration[],
72+
functions: FunctionDeclaration[],
7073
location: Location
7174
) {
7275
return functions.reduce((found, currNode) => {

src/utils/editor/get-expression.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ export function getExpressionFromCoords(cm: any, coord: ColumnPosition) {
5252

5353
startHighlight = tokenBefore.startColumn;
5454
}
55-
const expression = line.substring(startHighlight, endHighlight);
55+
56+
const expression = line.substring(startHighlight, endHighlight) || "";
5657

5758
if (!expression) {
5859
return null;

src/utils/editor/source-documents.js

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

77
import { getMode } from "../source";
88

9-
import type { Source, SourceRecord } from "../../types";
109
import { isWasm, getWasmLineNumberFormatter, renderWasmText } from "../wasm";
1110
import { resizeBreakpointGutter, resizeToggleButton } from "../ui";
12-
import type { SymbolDeclarations } from "../../workers/parser";
1311
import SourceEditor from "./source-editor";
1412

13+
import type { Source, SourceRecord } from "../../types";
14+
import type { SymbolDeclarations } from "../../workers/parser";
15+
1516
let sourceDocs = {};
1617

1718
function getDocument(key: string) {

src/utils/quick-open.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@
33
* file, You can obtain one at <http://mozilla.org/MPL/2.0/>. */
44

55
// @flow
6+
67
import { endTruncateStr } from "./utils";
78
import { isPretty, getFilename } from "./source";
89

910
import type { Location as BabelLocation } from "@babel/types";
1011
import type { Symbols } from "../reducers/ast";
1112
import type { QuickOpenType } from "../reducers/quick-open";
12-
import type { SymbolDeclaration } from "../workers/parser";
1313
import type { RelativeSource } from "../selectors/getRelativeSources";
14+
import type { SymbolDeclaration } from "../workers/parser";
1415

1516
export const MODIFIERS = {
1617
"@": "functions",

src/utils/tests/__snapshots__/ast.spec.js.snap

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,6 @@ exports[`find the best expression for the token should find the expression for t
44
Object {
55
"computed": false,
66
"expression": "obj.b",
7-
"expressionLocation": SourceLocation {
8-
"end": Position {
9-
"column": 17,
10-
"line": 6,
11-
},
12-
"start": Position {
13-
"column": 12,
14-
"line": 6,
15-
},
16-
},
177
"location": Object {
188
"end": Position {
199
"column": 17,

0 commit comments

Comments
 (0)