comment-parser 1.4.0 → 1.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ # v1.4.1
2
+ - fix .prettierignore
3
+ - add source trasformation example
4
+
1
5
  # v1.4.0
2
6
  - ESM compatibility improvements; fixes #159, #161
3
7
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "comment-parser",
3
- "version": "1.4.0",
3
+ "version": "1.4.1",
4
4
  "description": "Generic JSDoc-like comment parser",
5
5
  "type": "module",
6
6
  "main": "lib/index.cjs",
@@ -192,6 +192,46 @@ function parse_advanced_parsing(source, parse, _, _, tokenizers) {
192
192
  .join('\n');
193
193
  }
194
194
 
195
+ function stringify_rename(source, parse, stringify, transforms) {
196
+ // You can do any manipulations with the parsed result
197
+ // See how each block is being mapped. If you are updating a Block.source
198
+ // then rewireSource(block) should be called on each changed block.
199
+ // If changes were made to Block.tags[].source then call rewireSpecs(block).
200
+ // This example shows how you can "rename" @param tags: value1 -> value11, value2 -> value22
201
+
202
+ /**
203
+ * Description may go
204
+ * over multiple lines followed by @tags
205
+ * @param {string} name the name parameter
206
+ * @param {any} value1 first value parameter
207
+ * with a multipline description
208
+ * @param {any} value2 second value parameter
209
+ */
210
+
211
+ function renameParam(from, to) {
212
+ return (block) => {
213
+ for (const tag of block.tags) {
214
+ if (tag.tag === 'param' && tag.name === from) {
215
+ tag.name = to;
216
+ for (const line of tag.source) {
217
+ if (line.tokens.name === from) line.tokens.name = to;
218
+ }
219
+ }
220
+ }
221
+ return block;
222
+ };
223
+ }
224
+
225
+ const transform = transforms.flow(
226
+ renameParam('value1', 'value11'),
227
+ renameParam('value2', 'value22'),
228
+ stringify
229
+ );
230
+
231
+ const parsed = parse(source);
232
+ const stringified = parsed.map(transform);
233
+ }
234
+
195
235
  (typeof window === 'undefined' ? module.exports : window).examples = [
196
236
  parse_defaults,
197
237
  parse_line_numbering,
@@ -200,4 +240,5 @@ function parse_advanced_parsing(source, parse, _, _, tokenizers) {
200
240
  parse_source_exploration,
201
241
  parse_advanced_parsing,
202
242
  stringify_formatting,
243
+ stringify_rename,
203
244
  ];