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

Commit 7787bc0

Browse files
committed
Tighten flow types (#5838)
1 parent bee2c76 commit 7787bc0

File tree

7 files changed

+22
-25
lines changed

7 files changed

+22
-25
lines changed

src/actions/preview.js

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

2626
import type { ThunkArgs } from "./types";
27-
import type { Frame, Range, Position } from "../types";
27+
import type { Frame, Range, ColumnPosition } from "../types";
2828

2929
async function getReactProps(evaluate) {
3030
const reactDisplayName = await evaluate(
@@ -160,7 +160,7 @@ export function updatePreview(target: HTMLElement, editor: any) {
160160
export function setPreview(
161161
expression: string,
162162
location: Range,
163-
tokenPos: Position,
163+
tokenPos: ColumnPosition,
164164
cursorPos: any
165165
) {
166166
return async ({ dispatch, getState, client, sourceMaps }: ThunkArgs) => {

src/types.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,13 @@ export type Position = {
6565
column: ?number
6666
};
6767

68+
export type ColumnPosition = {
69+
line: number,
70+
column: number
71+
};
72+
6873
export type Range = { end: Position, start: Position };
74+
export type ColumnRange = { end: ColumnPosition, start: ColumnPosition };
6975

7076
export type PendingLocation = {
7177
line: number,

src/utils/ast.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,20 @@
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-
75
import { without, range } from "lodash";
86

9-
import type { Location, Source, Position } from "../types";
7+
import type { Location, Source, ColumnPosition } from "../types";
108
import type {
119
AstPosition,
1210
AstLocation,
13-
PausePoint,
1411
SymbolDeclarations,
15-
SymbolDeclaration
12+
SymbolDeclaration,
13+
PausePoint
1614
} from "../workers/parser";
1715

1816
export function findBestMatchExpression(
1917
symbols: SymbolDeclarations,
20-
tokenPos: Position
18+
tokenPos: ColumnPosition
2119
) {
2220
const { memberExpressions, identifiers, literals } = symbols;
2321
const { line, column } = tokenPos;

src/utils/editor/get-expression.js

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

55
// @flow
66

7-
import type { Position } from "../../types";
7+
import type { ColumnPosition } from "../../types";
88

99
type Token = {
1010
startColumn: number,
@@ -14,7 +14,7 @@ type Token = {
1414

1515
export function tokenAtTextPosition(
1616
cm: any,
17-
{ line, column }: Position
17+
{ line, column }: ColumnPosition
1818
): Token | null {
1919
if (line < 0 || line >= cm.lineCount()) {
2020
return null;
@@ -30,7 +30,7 @@ export function tokenAtTextPosition(
3030

3131
// The strategy of querying codeMirror tokens was borrowed
3232
// from Chrome's inital implementation in JavaScriptSourceFrame.js#L414
33-
export function getExpressionFromCoords(cm: any, coord: Position) {
33+
export function getExpressionFromCoords(cm: any, coord: ColumnPosition) {
3434
const token = tokenAtTextPosition(cm, coord);
3535
if (!token) {
3636
return null;

src/utils/editor/get-token-location.js

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

55
// @flow
6-
import type { Position } from "../../types";
6+
import type { ColumnPosition } from "../../types";
77

88
export function getTokenLocation(
99
codeMirror: any,
1010
tokenEl: HTMLElement
11-
): Position {
11+
): ColumnPosition {
1212
const { left, top, width, height } = tokenEl.getBoundingClientRect();
1313
const { line, ch } = codeMirror.coordsChar({
1414
left: left + width / 2,

src/workers/parser/index.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,5 @@ export type {
4747
SymbolDeclarations,
4848
AstLocation,
4949
AstPosition,
50-
Scope,
5150
PausePoint
5251
} from "./types";

src/workers/parser/types.js

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,23 @@
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-
import type { BabelLocation } from "@babel/types";
5+
// @flow
66

77
export type AstPosition = { line: number, column: number };
88
export type AstLocation = { end: AstPosition, start: AstPosition };
99

10-
export type Scope = {
11-
location: AstLocation,
12-
parent: Scope,
13-
bindings: Object[]
14-
};
15-
1610
export type ClassDeclaration = {|
1711
name: string,
18-
location: BabelLocation,
12+
location: AstLocation,
1913
parent?: ClassDeclaration
2014
|};
2115

2216
export type SymbolDeclaration = {|
2317
name: string,
2418
expression?: string,
2519
klass?: ?string,
26-
location: BabelLocation,
27-
expressionLocation?: BabelLocation,
20+
location: AstLocation,
21+
expressionLocation?: AstLocation,
2822
parameterNames?: string[],
2923
identifier?: Object,
3024
computed?: Boolean,
@@ -47,6 +41,6 @@ export type SymbolDeclarations = {
4741
};
4842

4943
export type PausePoint = {
50-
location: { line: number, column: number },
44+
location: AstPosition,
5145
types: { breakpoint: boolean, stepOver: boolean }
5246
};

0 commit comments

Comments
 (0)