Skip to content

Commit

Permalink
[jest-docblock] remove leading newlines from parswWithComments().comm…
Browse files Browse the repository at this point in the history
…ents (#4610)
  • Loading branch information
samouri authored and cpojer committed Oct 6, 2017
1 parent 087281a commit c44d2c6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
15 changes: 15 additions & 0 deletions packages/jest-docblock/src/__tests__/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,21 @@ describe('docblock', () => {
);
});

it('removes leading newlines in multiline comments from docblock', () => {
const code =
'/**' +
os.EOL +
' * @snailcode' +
os.EOL +
' *' +
os.EOL +
' * hello world' +
os.EOL +
' */';

expect(docblock.parseWithComments(code).comments).toEqual(' hello world');
});

it('extracts comments from beginning and end of docblock', () => {
const code =
'/**' +
Expand Down
5 changes: 4 additions & 1 deletion packages/jest-docblock/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,10 @@ export function parseWithComments(
docblock = docblock.replace(ltrimNewlineRe, '').replace(rtrimRe, '');

const result = Object.create(null);
const comments = docblock.replace(propertyRe, '');
const comments = docblock
.replace(propertyRe, '')
.replace(ltrimNewlineRe, '')
.replace(rtrimRe, '');

let match;
while ((match = propertyRe.exec(docblock))) {
Expand Down

0 comments on commit c44d2c6

Please sign in to comment.