Skip to content

Commit

Permalink
chore: migrate jest-docblock to TypeScript (jestjs#7836)
Browse files Browse the repository at this point in the history
  • Loading branch information
SimenB authored and captain-yossarian committed Jul 18, 2019
1 parent 85bc5ee commit 3e8aabd
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 15 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -17,6 +17,7 @@
- `[jest-leak-detector]`: Migrate to TypeScript ([#7825](https://github.com/facebook/jest/pull/7825))
- `[jest-changed-files]`: Migrate to TypeScript ([#7827](https://github.com/facebook/jest/pull/7827))
- `[jest-matcher-utils]`: Migrate to TypeScript ([#7835](https://github.com/facebook/jest/pull/7835))
- `[jest-docblock]`: Migrate to TypeScript ([#7836](https://github.com/facebook/jest/pull/7836))

### Performance

Expand Down
Expand Up @@ -4,12 +4,8 @@
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
*/

'use strict';

import os from 'os';
import * as docblock from '..';

Expand Down
Expand Up @@ -3,14 +3,12 @@
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
*/

import detectNewline from 'detect-newline';
import {EOL} from 'os';
import detectNewline from 'detect-newline';

type Pragmas = {[key: string]: string | string[], __proto__: null};
type Pragmas = {[key: string]: string | string[]};

const commentEndRe = /\*\/$/;
const commentStartRe = /^\/\*\*/;
Expand All @@ -37,7 +35,7 @@ export function parse(docblock: string): Pragmas {

export function parseWithComments(
docblock: string,
): {comments: string, pragmas: Pragmas} {
): {comments: string; pragmas: Pragmas} {
const line = detectNewline(docblock) || EOL;

docblock = docblock
Expand Down Expand Up @@ -67,7 +65,7 @@ export function parseWithComments(
typeof result[match[1]] === 'string' ||
Array.isArray(result[match[1]])
) {
result[match[1]] = [].concat(result[match[1]], nextPragma);
result[match[1]] = ([] as string[]).concat(result[match[1]], nextPragma);
} else {
result[match[1]] = nextPragma;
}
Expand All @@ -79,9 +77,8 @@ export function print({
comments = '',
pragmas = {},
}: {
comments?: string,
pragmas?: Pragmas,
__proto__: null,
comments?: string;
pragmas?: Pragmas;
}): string {
const line = detectNewline(comments) || EOL;
const head = '/**';
Expand Down Expand Up @@ -122,6 +119,8 @@ export function print({
);
}

function printKeyValues(key, valueOrArray) {
return [].concat(valueOrArray).map(value => `@${key} ${value}`.trim());
function printKeyValues(key: string, valueOrArray: string | string[]) {
return ([] as string[])
.concat(valueOrArray)
.map(value => `@${key} ${value}`.trim());
}
7 changes: 7 additions & 0 deletions packages/jest-docblock/tsconfig.json
@@ -0,0 +1,7 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"rootDir": "src",
"outDir": "build"
}
}

0 comments on commit 3e8aabd

Please sign in to comment.