Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate diff-sequences to Typescript #7820

Merged
merged 3 commits into from Feb 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
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
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
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
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
@@ -0,0 +1,7 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"rootDir": "src",
"outDir": "build"
}
}