jest-docblock
Advanced tools
Comparing version 29.0.0 to 29.2.0
@@ -11,27 +11,19 @@ 'use strict'; | ||
exports.strip = strip; | ||
function _os() { | ||
const data = require('os'); | ||
_os = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function _detectNewline() { | ||
const data = _interopRequireDefault(require('detect-newline')); | ||
_detectNewline = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function _interopRequireDefault(obj) { | ||
return obj && obj.__esModule ? obj : {default: obj}; | ||
} | ||
/** | ||
@@ -43,2 +35,3 @@ * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. | ||
*/ | ||
const commentEndRe = /\*\/$/; | ||
@@ -54,3 +47,2 @@ const commentStartRe = /^\/\*\*?/; | ||
const STRING_ARRAY = []; | ||
function extract(contents) { | ||
@@ -60,3 +52,2 @@ const match = contents.match(docblockRe); | ||
} | ||
function strip(contents) { | ||
@@ -66,17 +57,14 @@ const match = contents.match(docblockRe); | ||
} | ||
function parse(docblock) { | ||
return parseWithComments(docblock).pragmas; | ||
} | ||
function parseWithComments(docblock) { | ||
const line = (0, _detectNewline().default)(docblock) || _os().EOL; | ||
const line = (0, _detectNewline().default)(docblock) ?? _os().EOL; | ||
docblock = docblock | ||
.replace(commentStartRe, '') | ||
.replace(commentEndRe, '') | ||
.replace(stringStartRe, '$1'); // Normalize multi-line directives | ||
.replace(stringStartRe, '$1'); | ||
// Normalize multi-line directives | ||
let prev = ''; | ||
while (prev !== docblock) { | ||
@@ -86,3 +74,2 @@ prev = docblock; | ||
} | ||
docblock = docblock.replace(ltrimNewlineRe, '').trimRight(); | ||
@@ -95,7 +82,5 @@ const result = Object.create(null); | ||
let match; | ||
while ((match = propertyRe.exec(docblock))) { | ||
// strip linecomments from pragmas | ||
const nextPragma = match[2].replace(lineCommentRe, ''); | ||
if ( | ||
@@ -110,3 +95,2 @@ typeof result[match[1]] === 'string' || | ||
} | ||
return { | ||
@@ -117,6 +101,4 @@ comments, | ||
} | ||
function print({comments = '', pragmas = {}}) { | ||
const line = (0, _detectNewline().default)(comments) || _os().EOL; | ||
const line = (0, _detectNewline().default)(comments) ?? _os().EOL; | ||
const head = '/**'; | ||
@@ -131,3 +113,2 @@ const start = ' *'; | ||
.join(''); | ||
if (!comments) { | ||
@@ -137,3 +118,2 @@ if (keys.length === 0) { | ||
} | ||
if (keys.length === 1 && !Array.isArray(pragmas[keys[0]])) { | ||
@@ -144,3 +124,2 @@ const value = pragmas[keys[0]]; | ||
} | ||
const printedComments = | ||
@@ -160,3 +139,2 @@ comments | ||
} | ||
function printKeyValues(key, valueOrArray) { | ||
@@ -163,0 +141,0 @@ return STRING_ARRAY.concat(valueOrArray).map(value => |
{ | ||
"name": "jest-docblock", | ||
"version": "29.0.0", | ||
"version": "29.2.0", | ||
"repository": { | ||
@@ -31,3 +31,3 @@ "type": "git", | ||
}, | ||
"gitHead": "75006e46c76f6fda14bbc0548f86edb2ba087cd2" | ||
"gitHead": "ee5b37a4f4433afcfffb0356cea47739d8092287" | ||
} |
151
9072