Skip to content

Commit e8f5d62

Browse files
lorenzorapettiSimenB
authored andcommitted
Migrate diff-sequences to Typescript (#7820)
1 parent d4018a8 commit e8f5d62

6 files changed

Lines changed: 30 additions & 23 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
- `[*]`: Setup building, linting and testing of TypeScript ([#7808](https://github.com/facebook/jest/pull/7808))
1010
- `[pretty-format]`: Migrate to TypeScript ([#7809](https://github.com/facebook/jest/pull/7809))
11+
- `[diff-sequences]`: Migrate to Typescript ([#7820](https://github.com/facebook/jest/pull/7820))
1112

1213
### Performance
1314

packages/diff-sequences/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"node": ">= 6"
2020
},
2121
"main": "build/index.js",
22+
"types": "build/index.d.ts",
2223
"scripts": {
2324
"perf": "node --expose-gc perf/index.js"
2425
},

packages/diff-sequences/src/__tests__/__snapshots__/index.test.js.snap renamed to packages/diff-sequences/src/__tests__/__snapshots__/index.test.ts.snap

File renamed without changes.

packages/diff-sequences/src/__tests__/index.test.js renamed to packages/diff-sequences/src/__tests__/index.test.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7-
* @flow
87
*/
98

109
import diff from '../';
@@ -16,7 +15,7 @@ describe('invalid arg', () => {
1615
describe('length', () => {
1716
test('is not a number', () => {
1817
expect(() => {
19-
diff(('0': any), 0, isCommon, foundSubsequence);
18+
diff('0' as any, 0, isCommon, foundSubsequence);
2019
}).toThrow(/aLength/);
2120
});
2221
test('Infinity is not a safe integer', () => {
@@ -50,12 +49,12 @@ describe('invalid arg', () => {
5049
describe('callback', () => {
5150
test('null is not a function', () => {
5251
expect(() => {
53-
diff(0, 0, (null: any), foundSubsequence);
52+
diff(0, 0, null as any, foundSubsequence);
5453
}).toThrow(/isCommon/);
5554
});
5655
test('undefined is not a function', () => {
5756
expect(() => {
58-
diff(0, 0, isCommon, (undefined: any));
57+
diff(0, 0, isCommon, undefined as any);
5958
}).toThrow(/foundSubsequence/);
6059
});
6160
});
Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7-
* @flow
87
*/
98

109
// This diff-sequences package implements the linear space variation in
@@ -66,10 +65,10 @@ type FoundSubsequence = (
6665
) => void;
6766

6867
// Either original functions or wrapped to swap indexes if graph is transposed.
69-
type Callbacks = {|
70-
foundSubsequence: FoundSubsequence,
71-
isCommon: IsCommon,
72-
|};
68+
type Callbacks = {
69+
foundSubsequence: FoundSubsequence;
70+
isCommon: IsCommon;
71+
};
7372

7473
// Indexes in sequence a of last point of forward or reverse paths in graph.
7574
// Myers algorithm indexes by diagonal k which for negative is bad deopt in V8.
@@ -81,25 +80,25 @@ type Indexes = Array<number>;
8180

8281
// Division of index intervals in sequences a and b at the middle change.
8382
// Invariant: intervals do not have common items at the start or end.
84-
type Division = {|
83+
type Division = {
8584
// The end of interval preceding division is open like array slice method.
86-
nChangePreceding: number, // number of change items
87-
aEndPreceding: number,
88-
bEndPreceding: number,
85+
nChangePreceding: number; // number of change items
86+
aEndPreceding: number;
87+
bEndPreceding: number;
8988

90-
nCommonPreceding: number, // 0 if no common items preceding middle change
91-
aCommonPreceding: number, // ignore prop value if nCommonPreceding === 0
92-
bCommonPreceding: number, // ignore prop value if nCommonPreceding === 0
89+
nCommonPreceding: number; // 0 if no common items preceding middle change
90+
aCommonPreceding: number; // ignore prop value if nCommonPreceding === 0
91+
bCommonPreceding: number; // ignore prop value if nCommonPreceding === 0
9392

94-
nCommonFollowing: number, // 0 if no common items following middle change
95-
aCommonFollowing: number, // ignore prop value if nCommonFollowing === 0
96-
bCommonFollowing: number, // ignore prop value if nCommonFollowing === 0
93+
nCommonFollowing: number; // 0 if no common items following middle change
94+
aCommonFollowing: number; // ignore prop value if nCommonFollowing === 0
95+
bCommonFollowing: number; // ignore prop value if nCommonFollowing === 0
9796

9897
// The start of interval following division is closed like array slice method.
99-
nChangeFollowing: number, // number of change items
100-
aStartFollowing: number,
101-
bStartFollowing: number,
102-
|};
98+
nChangeFollowing: number; // number of change items
99+
aStartFollowing: number;
100+
bStartFollowing: number;
101+
};
103102

104103
const pkg = 'diff-sequences'; // for error messages
105104
const NOT_YET_SET = 0; // small int instead of undefined to avoid deopt in V8
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"extends": "../../tsconfig.json",
3+
"compilerOptions": {
4+
"rootDir": "src",
5+
"outDir": "build"
6+
}
7+
}

0 commit comments

Comments
 (0)