Skip to content

Commit a12b67d

Browse files
ullumullussterb
andauthored
Fix: Handle multiline comments in parseWithComments (#12845)
Co-authored-by: Sven Sterbling <[email protected]>
1 parent 3f78547 commit a12b67d

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
### Fixes
88

99
- `[jest-worker]` Make `JestWorkerFarm` helper type to include methods of worker module that take more than one argument ([#12839](https://github.com/facebook/jest/pull/12839))
10+
- `[jest-docblock]` Handle multiline comments in parseWithComments ([#12845](https://github.com/facebook/jest/pull/12845))
1011

1112
### Chore & Maintenance
1213

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ describe('docblock', () => {
3131
expect(docblock.extract(code)).toBe(`/*${EOL} * @team foo${EOL}*/`);
3232
});
3333

34+
it('extracts from invalid docblock singleline', () => {
35+
const code = `/* some comment @team foo */${EOL}const x = foo;`;
36+
expect(docblock.extract(code)).toBe('/* some comment @team foo */');
37+
});
38+
3439
it('returns extract and parsedocblock', () => {
3540
const code = `/** @provides module-name */${EOL}${EOL}.dummy {}${EOL}`;
3641

@@ -204,6 +209,22 @@ describe('docblock', () => {
204209
});
205210
});
206211

212+
it('extract from invalid docblock', () => {
213+
const code = `/* @format: everything${EOL}// keep me */`;
214+
expect(docblock.parseWithComments(code)).toEqual({
215+
comments: '// keep me',
216+
pragmas: {'format:': 'everything'},
217+
});
218+
});
219+
220+
it('extract from invalid docblock singleline', () => {
221+
const code = '/* some test */';
222+
expect(docblock.parseWithComments(code)).toEqual({
223+
comments: ' some test',
224+
pragmas: {},
225+
});
226+
});
227+
207228
it('extracts docblock comments as CRLF when docblock contains CRLF', () => {
208229
const code = '/**\r\n * foo\r\n * bar\r\n*/';
209230
expect(docblock.parseWithComments(code)).toEqual({

packages/jest-docblock/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import detectNewline = require('detect-newline');
1111
type Pragmas = Record<string, string | Array<string>>;
1212

1313
const commentEndRe = /\*\/$/;
14-
const commentStartRe = /^\/\*\*/;
14+
const commentStartRe = /^\/\*\*?/;
1515
const docblockRe = /^\s*(\/\*\*?(.|\r?\n)*?\*\/)/;
1616
const lineCommentRe = /(^|\s+)\/\/([^\r\n]*)/g;
1717
const ltrimNewlineRe = /^(\r?\n)+/;

0 commit comments

Comments
 (0)