From ab46da32ca503204d88cf538fe83dbd01883f124 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Fri, 8 Feb 2019 12:04:44 +0100 Subject: [PATCH 1/2] chore: migrate jest-docblock to TypeScript --- CHANGELOG.md | 1 + .../{index.test.js => index.test.ts} | 4 ---- .../jest-docblock/src/{index.js => index.ts} | 21 +++++++++---------- packages/jest-docblock/tsconfig.json | 7 +++++++ 4 files changed, 18 insertions(+), 15 deletions(-) rename packages/jest-docblock/src/__tests__/{index.test.js => index.test.ts} (99%) rename packages/jest-docblock/src/{index.js => index.ts} (89%) create mode 100644 packages/jest-docblock/tsconfig.json diff --git a/CHANGELOG.md b/CHANGELOG.md index 0050a9f04365..4fb53e9eb963 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/packages/jest-docblock/src/__tests__/index.test.js b/packages/jest-docblock/src/__tests__/index.test.ts similarity index 99% rename from packages/jest-docblock/src/__tests__/index.test.js rename to packages/jest-docblock/src/__tests__/index.test.ts index aba7bf160607..5df6ce09c552 100644 --- a/packages/jest-docblock/src/__tests__/index.test.js +++ b/packages/jest-docblock/src/__tests__/index.test.ts @@ -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 '..'; diff --git a/packages/jest-docblock/src/index.js b/packages/jest-docblock/src/index.ts similarity index 89% rename from packages/jest-docblock/src/index.js rename to packages/jest-docblock/src/index.ts index 408f790d765c..6f6f59c9d2d1 100644 --- a/packages/jest-docblock/src/index.js +++ b/packages/jest-docblock/src/index.ts @@ -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 = /^\/\*\*/; @@ -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 @@ -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; } @@ -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 = '/**'; @@ -122,6 +119,8 @@ export function print({ ); } -function printKeyValues(key, valueOrArray) { - return [].concat(valueOrArray).map(value => `@${key} ${value}`.trim()); +function printKeyValues(key: string, valueOrArray: T | T[]) { + return ([] as T[]) + .concat(valueOrArray) + .map(value => `@${key} ${value}`.trim()); } diff --git a/packages/jest-docblock/tsconfig.json b/packages/jest-docblock/tsconfig.json new file mode 100644 index 000000000000..7bb06bce6d20 --- /dev/null +++ b/packages/jest-docblock/tsconfig.json @@ -0,0 +1,7 @@ +{ + "extends": "../../tsconfig.json", + "compilerOptions": { + "rootDir": "src", + "outDir": "build" + } +} From 53f9d2f010cf4f058c6f6a4a140a6b58a5ecef28 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Fri, 8 Feb 2019 12:08:56 +0100 Subject: [PATCH 2/2] string, not generic --- packages/jest-docblock/src/index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/jest-docblock/src/index.ts b/packages/jest-docblock/src/index.ts index 6f6f59c9d2d1..892a8a32cac3 100644 --- a/packages/jest-docblock/src/index.ts +++ b/packages/jest-docblock/src/index.ts @@ -119,8 +119,8 @@ export function print({ ); } -function printKeyValues(key: string, valueOrArray: T | T[]) { - return ([] as T[]) +function printKeyValues(key: string, valueOrArray: string | string[]) { + return ([] as string[]) .concat(valueOrArray) .map(value => `@${key} ${value}`.trim()); }