-
-
Notifications
You must be signed in to change notification settings - Fork 6.6k
[jest-docblock] add docblock.print() #4517
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
9828730
17d8f0f
130628f
66fdd4a
c0b6a97
854afa6
dc34f5d
a13f950
12a25b5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,6 +8,8 @@ | |
| * @flow | ||
| */ | ||
|
|
||
| const os = require('os'); | ||
|
||
|
|
||
| const commentEndRe = /\*\/$/; | ||
| const commentStartRe = /^\/\*\*/; | ||
| const docblockRe = /^\s*(\/\*\*?(.|\r?\n)*?\*\/)/; | ||
|
|
@@ -47,5 +49,50 @@ function parse(docblock: string): {[key: string]: string} { | |
| return result; | ||
| } | ||
|
|
||
| function print( | ||
| object: {[key: string]: string} = {}, | ||
| comments: string = '', | ||
| ): string { | ||
| const head = '/**'; | ||
| const start = ' *'; | ||
| const tail = ' */'; | ||
|
|
||
| const keys = Object.keys(object); | ||
| const line = os.EOL; | ||
|
|
||
| const printedObject = keys | ||
| .map(key => start + ' ' + printKeyValue(key, object[key]) + line) | ||
| .join(''); | ||
|
|
||
| if (!comments) { | ||
| if (keys.length === 0) { | ||
| return ''; | ||
| } | ||
| if (keys.length === 1) { | ||
| return `${head} ${printKeyValue(keys[0], object[keys[0]])}${tail}`; | ||
| } | ||
| } | ||
|
|
||
| const printedComments = | ||
| comments | ||
| .split(os.EOL) | ||
|
||
| .map(textLine => `${start} ${textLine}`) | ||
| .join(os.EOL) + os.EOL; | ||
|
|
||
| return ( | ||
| head + | ||
| line + | ||
| (comments ? printedComments : '') + | ||
| (comments && keys.length ? start + line : '') + | ||
| printedObject + | ||
| tail | ||
| ); | ||
| } | ||
|
|
||
| function printKeyValue(key, value) { | ||
| return `@${key} ${value}`.trim(); | ||
| } | ||
|
|
||
| exports.extract = extract; | ||
| exports.parse = parse; | ||
| exports.print = print; | ||
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be