Skip to content

Commit e58ac7f

Browse files
committed
chore: fix types
1 parent cd2ce61 commit e58ac7f

3 files changed

Lines changed: 29 additions & 7 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
* `[babel-jest]` Revert "Remove retainLines from babel-jest"
66
([#5496](https://github.com/facebook/jest/pull/5496))
7+
* `[jest-docblock]` Support multiple of the same `@pragma`.
8+
([#5154](https://github.com/facebook/jest/pull/5502))
79

810
### Features
911

packages/jest-docblock/src/__tests__/index.test.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,26 @@ describe('docblock', () => {
140140
});
141141
});
142142

143+
it('parses >=3 of the same directives out of a docblock', () => {
144+
const code =
145+
'/**' +
146+
os.EOL +
147+
'' +
148+
' * @x foo' +
149+
os.EOL +
150+
'' +
151+
' * @x bar' +
152+
os.EOL +
153+
'' +
154+
' * @x baz' +
155+
os.EOL +
156+
'' +
157+
' */';
158+
expect(docblock.parse(code)).toEqual({
159+
x: ['foo', 'bar', 'baz'],
160+
});
161+
});
162+
143163
it('parses directives out of a docblock with comments', () => {
144164
const code =
145165
'/**' +
@@ -433,7 +453,6 @@ describe('docblock', () => {
433453
' */',
434454
);
435455
});
436-
437456
it('prints docblocks with pragmas', () => {
438457
const pragmas = {
439458
flow: 'foo',

packages/jest-docblock/src/index.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
import detectNewline from 'detect-newline';
1111
import {EOL} from 'os';
1212

13+
type Pragmas = {[key: string]: string | string[], __proto__: null};
14+
1315
const commentEndRe = /\*\/$/;
1416
const commentStartRe = /^\/\*\*/;
1517
const docblockRe = /^\s*(\/\*\*?(.|\r?\n)*?\*\/)/;
@@ -31,15 +33,13 @@ export function strip(contents: string) {
3133
return match && match[0] ? contents.substring(match[0].length) : contents;
3234
}
3335

34-
export function parse(
35-
docblock: string,
36-
): {[key: string]: string, __proto__: null} {
36+
export function parse(docblock: string): Pragmas {
3737
return parseWithComments(docblock).pragmas;
3838
}
3939

4040
export function parseWithComments(
4141
docblock: string,
42-
): {comments: string, pragmas: {[key: string]: string, __proto__: null}} {
42+
): {comments: string, pragmas: Pragmas} {
4343
const line = detectNewline(docblock) || EOL;
4444

4545
docblock = docblock
@@ -82,7 +82,7 @@ export function print({
8282
pragmas = {},
8383
}: {
8484
comments?: string,
85-
pragmas?: {[key: string]: string, __proto__: null},
85+
pragmas?: Pragmas,
8686
__proto__: null,
8787
}): string {
8888
const line = detectNewline(comments) || EOL;
@@ -103,7 +103,8 @@ export function print({
103103
return '';
104104
}
105105
if (keys.length === 1 && !Array.isArray(pragmas[keys[0]])) {
106-
return `${head} ${printKeyValues(keys[0], pragmas[keys[0]])}${tail}`;
106+
const value = pragmas[keys[0]];
107+
return `${head} ${printKeyValues(keys[0], value)[0]}${tail}`;
107108
}
108109
}
109110

0 commit comments

Comments
 (0)