Skip to content

Commit

Permalink
Use native trimLeft, trimRight instead of regexp (#5570)
Browse files Browse the repository at this point in the history
  • Loading branch information
Connormiha authored and cpojer committed Feb 15, 2018
1 parent 9d11ec4 commit 71795a5
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions packages/jest-docblock/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,14 @@ const commentEndRe = /\*\/$/;
const commentStartRe = /^\/\*\*/;
const docblockRe = /^\s*(\/\*\*?(.|\r?\n)*?\*\/)/;
const lineCommentRe = /(^|\s+)\/\/([^\r\n]*)/g;
const ltrimRe = /^\s*/;
const rtrimRe = /\s*$/;
const ltrimNewlineRe = /^(\r?\n)+/;
const multilineRe = /(?:^|\r?\n) *(@[^\r\n]*?) *\r?\n *(?![^@\r\n]*\/\/[^]*)([^@\r\n\s][^@\r\n]+?) *\r?\n/g;
const propertyRe = /(?:^|\r?\n) *@(\S+) *([^\r\n]*)/g;
const stringStartRe = /(\r?\n|^) *\* ?/g;

export function extract(contents: string): string {
const match = contents.match(docblockRe);
return match ? match[0].replace(ltrimRe, '') || '' : '';
return match ? match[0].trimLeft() : '';
}

export function strip(contents: string) {
Expand Down Expand Up @@ -53,13 +51,13 @@ export function parseWithComments(
prev = docblock;
docblock = docblock.replace(multilineRe, `${line}$1 $2${line}`);
}
docblock = docblock.replace(ltrimNewlineRe, '').replace(rtrimRe, '');
docblock = docblock.replace(ltrimNewlineRe, '').trimRight();

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

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

0 comments on commit 71795a5

Please sign in to comment.