Skip to content

Commit

Permalink
Migrate diff-sequences to Typescript (#7820)
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzorapetti authored and SimenB committed Feb 6, 2019
1 parent d4018a8 commit e8f5d62
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 23 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

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

### Performance

Expand Down
1 change: 1 addition & 0 deletions packages/diff-sequences/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"node": ">= 6"
},
"main": "build/index.js",
"types": "build/index.d.ts",
"scripts": {
"perf": "node --expose-gc perf/index.js"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
*/

import diff from '../';
Expand All @@ -16,7 +15,7 @@ describe('invalid arg', () => {
describe('length', () => {
test('is not a number', () => {
expect(() => {
diff(('0': any), 0, isCommon, foundSubsequence);
diff('0' as any, 0, isCommon, foundSubsequence);
}).toThrow(/aLength/);
});
test('Infinity is not a safe integer', () => {
Expand Down Expand Up @@ -50,12 +49,12 @@ describe('invalid arg', () => {
describe('callback', () => {
test('null is not a function', () => {
expect(() => {
diff(0, 0, (null: any), foundSubsequence);
diff(0, 0, null as any, foundSubsequence);
}).toThrow(/isCommon/);
});
test('undefined is not a function', () => {
expect(() => {
diff(0, 0, isCommon, (undefined: any));
diff(0, 0, isCommon, undefined as any);
}).toThrow(/foundSubsequence/);
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
*/

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

// Either original functions or wrapped to swap indexes if graph is transposed.
type Callbacks = {|
foundSubsequence: FoundSubsequence,
isCommon: IsCommon,
|};
type Callbacks = {
foundSubsequence: FoundSubsequence;
isCommon: IsCommon;
};

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

// Division of index intervals in sequences a and b at the middle change.
// Invariant: intervals do not have common items at the start or end.
type Division = {|
type Division = {
// The end of interval preceding division is open like array slice method.
nChangePreceding: number, // number of change items
aEndPreceding: number,
bEndPreceding: number,
nChangePreceding: number; // number of change items
aEndPreceding: number;
bEndPreceding: number;

nCommonPreceding: number, // 0 if no common items preceding middle change
aCommonPreceding: number, // ignore prop value if nCommonPreceding === 0
bCommonPreceding: number, // ignore prop value if nCommonPreceding === 0
nCommonPreceding: number; // 0 if no common items preceding middle change
aCommonPreceding: number; // ignore prop value if nCommonPreceding === 0
bCommonPreceding: number; // ignore prop value if nCommonPreceding === 0

nCommonFollowing: number, // 0 if no common items following middle change
aCommonFollowing: number, // ignore prop value if nCommonFollowing === 0
bCommonFollowing: number, // ignore prop value if nCommonFollowing === 0
nCommonFollowing: number; // 0 if no common items following middle change
aCommonFollowing: number; // ignore prop value if nCommonFollowing === 0
bCommonFollowing: number; // ignore prop value if nCommonFollowing === 0

// The start of interval following division is closed like array slice method.
nChangeFollowing: number, // number of change items
aStartFollowing: number,
bStartFollowing: number,
|};
nChangeFollowing: number; // number of change items
aStartFollowing: number;
bStartFollowing: number;
};

const pkg = 'diff-sequences'; // for error messages
const NOT_YET_SET = 0; // small int instead of undefined to avoid deopt in V8
Expand Down
7 changes: 7 additions & 0 deletions packages/diff-sequences/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"rootDir": "src",
"outDir": "build"
}
}

0 comments on commit e8f5d62

Please sign in to comment.