jest-docblock
Advanced tools
Comparing version 30.0.0-alpha.2 to 30.0.0-alpha.3
@@ -50,6 +50,6 @@ /*! | ||
const docblockRe = /^\s*(\/\*\*?(.|\r?\n)*?\*\/)/; | ||
const lineCommentRe = /(^|\s+)\/\/([^\r\n]*)/g; | ||
const lineCommentRe = /(^|\s+)\/\/([^\n\r]*)/g; | ||
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 multilineRe = /(?:^|\r?\n) *(@[^\n\r]*?) *\r?\n *(?![^\n\r@]*\/\/[^]*)([^\s@][^\n\r@]+?) *\r?\n/g; | ||
const propertyRe = /(?:^|\r?\n) *@(\S+) *([^\n\r]*)/g; | ||
const stringStartRe = /(\r?\n|^) *\* ?/g; | ||
@@ -59,7 +59,8 @@ const STRING_ARRAY = []; | ||
const match = contents.match(docblockRe); | ||
return match ? match[0].trimLeft() : ''; | ||
return match ? match[0].trimStart() : ''; | ||
} | ||
function strip(contents) { | ||
const match = contents.match(docblockRe); | ||
return match && match[0] ? contents.substring(match[0].length) : contents; | ||
const matchResult = contents.match(docblockRe); | ||
const match = matchResult?.[0]; | ||
return match == null ? contents : contents.slice(match.length); | ||
} | ||
@@ -71,3 +72,3 @@ function parse(docblock) { | ||
const line = (0, _detectNewline().default)(docblock) ?? _os().EOL; | ||
docblock = docblock.replace(commentStartRe, '').replace(commentEndRe, '').replace(stringStartRe, '$1'); | ||
docblock = docblock.replace(commentStartRe, '').replace(commentEndRe, '').replaceAll(stringStartRe, '$1'); | ||
@@ -78,13 +79,14 @@ // Normalize multi-line directives | ||
prev = docblock; | ||
docblock = docblock.replace(multilineRe, `${line}$1 $2${line}`); | ||
docblock = docblock.replaceAll(multilineRe, `${line}$1 $2${line}`); | ||
} | ||
docblock = docblock.replace(ltrimNewlineRe, '').trimRight(); | ||
docblock = docblock.replace(ltrimNewlineRe, '').trimEnd(); | ||
const result = Object.create(null); | ||
const comments = docblock.replace(propertyRe, '').replace(ltrimNewlineRe, '').trimRight(); | ||
const comments = docblock.replaceAll(propertyRe, '').replace(ltrimNewlineRe, '').trimEnd(); | ||
let match; | ||
while (match = propertyRe.exec(docblock)) { | ||
// strip linecomments from pragmas | ||
const nextPragma = match[2].replace(lineCommentRe, ''); | ||
const nextPragma = match[2].replaceAll(lineCommentRe, ''); | ||
if (typeof result[match[1]] === 'string' || Array.isArray(result[match[1]])) { | ||
result[match[1]] = STRING_ARRAY.concat(result[match[1]], nextPragma); | ||
const resultElement = result[match[1]]; | ||
result[match[1]] = [...STRING_ARRAY, ...(Array.isArray(resultElement) ? resultElement : [resultElement]), nextPragma]; | ||
} else { | ||
@@ -122,3 +124,3 @@ result[match[1]] = nextPragma; | ||
function printKeyValues(key, valueOrArray) { | ||
return STRING_ARRAY.concat(valueOrArray).map(value => `@${key} ${value}`.trim()); | ||
return [...STRING_ARRAY, ...(Array.isArray(valueOrArray) ? valueOrArray : [valueOrArray])].map(value => `@${key} ${value}`.trim()); | ||
} | ||
@@ -125,0 +127,0 @@ })(); |
{ | ||
"name": "jest-docblock", | ||
"version": "30.0.0-alpha.2", | ||
"version": "30.0.0-alpha.3", | ||
"repository": { | ||
@@ -33,3 +33,3 @@ "type": "git", | ||
}, | ||
"gitHead": "c04d13d7abd22e47b0997f6027886aed225c9ce4" | ||
"gitHead": "e267aff33d105399f2134bad7c8f82285104f3da" | ||
} |
9897
149