comment-parser 1.0.0 → 1.1.2

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.
Files changed (106) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/README.md +26 -19
  3. package/browser/index.js +331 -272
  4. package/es6/index.d.ts +21 -4
  5. package/es6/index.js +21 -5
  6. package/es6/parser/block-parser.d.ts +18 -2
  7. package/es6/parser/block-parser.js +12 -12
  8. package/es6/parser/index.d.ts +4 -4
  9. package/es6/parser/index.js +25 -26
  10. package/es6/parser/source-parser.js +13 -15
  11. package/es6/parser/spec-parser.d.ts +1 -6
  12. package/es6/parser/spec-parser.js +4 -151
  13. package/es6/parser/tokenizers/description.d.ts +19 -0
  14. package/es6/parser/tokenizers/description.js +46 -0
  15. package/es6/parser/tokenizers/index.d.ts +7 -0
  16. package/es6/parser/tokenizers/index.js +1 -0
  17. package/es6/parser/tokenizers/name.d.ts +6 -0
  18. package/es6/parser/tokenizers/name.js +91 -0
  19. package/es6/parser/tokenizers/tag.d.ts +6 -0
  20. package/es6/parser/tokenizers/tag.js +24 -0
  21. package/es6/parser/tokenizers/type.d.ts +27 -0
  22. package/es6/parser/tokenizers/type.js +67 -0
  23. package/es6/stringifier/index.d.ts +2 -1
  24. package/es6/stringifier/index.js +1 -6
  25. package/es6/stringifier/inspect.d.ts +2 -0
  26. package/es6/stringifier/inspect.js +41 -0
  27. package/es6/transforms/align.js +48 -43
  28. package/es6/transforms/indent.js +11 -22
  29. package/es6/transforms/index.d.ts +0 -2
  30. package/es6/transforms/index.js +2 -10
  31. package/es6/util.d.ts +11 -0
  32. package/es6/util.js +25 -25
  33. package/jest.config.js +12 -11
  34. package/lib/index.d.ts +21 -4
  35. package/lib/index.js +24 -6
  36. package/lib/parser/block-parser.d.ts +18 -2
  37. package/lib/parser/block-parser.js +12 -12
  38. package/lib/parser/index.d.ts +4 -4
  39. package/lib/parser/index.js +26 -27
  40. package/lib/parser/source-parser.js +14 -16
  41. package/lib/parser/spec-parser.d.ts +1 -6
  42. package/lib/parser/spec-parser.js +4 -156
  43. package/lib/parser/tokenizers/description.d.ts +19 -0
  44. package/lib/parser/tokenizers/description.js +51 -0
  45. package/lib/parser/tokenizers/index.d.ts +7 -0
  46. package/lib/parser/tokenizers/index.js +2 -0
  47. package/lib/parser/tokenizers/name.d.ts +6 -0
  48. package/lib/parser/tokenizers/name.js +94 -0
  49. package/lib/parser/tokenizers/tag.d.ts +6 -0
  50. package/lib/parser/tokenizers/tag.js +27 -0
  51. package/lib/parser/tokenizers/type.d.ts +27 -0
  52. package/lib/parser/tokenizers/type.js +70 -0
  53. package/lib/stringifier/index.d.ts +2 -1
  54. package/lib/stringifier/index.js +1 -6
  55. package/lib/stringifier/inspect.d.ts +2 -0
  56. package/lib/stringifier/inspect.js +44 -0
  57. package/lib/transforms/align.js +50 -45
  58. package/lib/transforms/indent.js +12 -23
  59. package/lib/transforms/index.d.ts +0 -2
  60. package/lib/transforms/index.js +3 -13
  61. package/lib/util.d.ts +11 -0
  62. package/lib/util.js +27 -26
  63. package/migrate-1.0.md +7 -7
  64. package/package.json +1 -1
  65. package/src/index.ts +20 -2
  66. package/src/parser/block-parser.ts +19 -1
  67. package/src/parser/index.ts +22 -21
  68. package/src/parser/source-parser.ts +2 -2
  69. package/src/parser/spec-parser.ts +2 -170
  70. package/src/parser/tokenizers/description.ts +75 -0
  71. package/src/parser/tokenizers/index.ts +8 -0
  72. package/src/parser/tokenizers/name.ts +112 -0
  73. package/src/parser/tokenizers/tag.ts +30 -0
  74. package/src/parser/tokenizers/type.ts +92 -0
  75. package/src/stringifier/index.ts +3 -1
  76. package/src/stringifier/inspect.ts +64 -0
  77. package/src/transforms/align.ts +37 -12
  78. package/src/transforms/index.ts +0 -3
  79. package/src/util.ts +20 -0
  80. package/tests/e2e/examples.js +39 -2
  81. package/tests/e2e/examples.spec.js +4 -2
  82. package/tests/e2e/issue-109.spec.js +49 -0
  83. package/tests/e2e/issue-112.spec.js +20 -0
  84. package/tests/e2e/issue-113.spec.js +23 -0
  85. package/tests/e2e/issue-119.spec.js +29 -0
  86. package/tests/e2e/issue-120.spec.js +29 -0
  87. package/tests/e2e/issue-121.spec.js +102 -0
  88. package/tests/e2e/transforms.spec.js +5 -2
  89. package/tests/unit/inspect.spec.ts +36 -0
  90. package/tests/unit/{spacer.spec.ts → spacer-description-joiner.spec.ts} +6 -6
  91. package/tests/unit/spec-description-tokenizer.spec.ts +100 -7
  92. package/tests/unit/spec-name-tokenizer.spec.ts +113 -1
  93. package/tests/unit/spec-parser.spec.ts +6 -9
  94. package/tests/unit/spec-tag-tokenizer.spec.ts +1 -1
  95. package/tests/unit/spec-type-tokenizer.spec.ts +121 -1
  96. package/tests/unit/stringifier.spec.ts +0 -1
  97. package/tests/unit/transforms-align.spec.ts +80 -16
  98. package/tests/unit/util-rewire.spec.ts +107 -0
  99. package/tests/unit/util.spec.ts +0 -48
  100. package/tsconfig.es6.json +1 -1
  101. package/tsconfig.node.json +1 -1
  102. package/es6/parser/spacer.d.ts +0 -3
  103. package/es6/parser/spacer.js +0 -37
  104. package/lib/parser/spacer.d.ts +0 -3
  105. package/lib/parser/spacer.js +0 -40
  106. package/src/parser/spacer.ts +0 -45
package/CHANGELOG.md CHANGED
@@ -1,3 +1,16 @@
1
+ # v1.1.0
2
+ - split tokenizers into separate modules
3
+ - allow multiline {type} definitions - issue #109
4
+ - allow using "=>" in [name=default] defaults – issue #112
5
+ - allow using "=" in quoted [name=default] defaults – issue #112
6
+ - add tokenizers usage example - issue #111
7
+
8
+ # v1.1.1
9
+ - add helpers for rewiring Spec.source <-> Spec.tags.source
10
+
11
+ # v1.0.0
12
+ - complete rewrite in TS with more flexible API
13
+
1
14
  # v0.7.6
2
15
  - distinct non-critical errors by providing `err.warning`
3
16
 
package/README.md CHANGED
@@ -2,9 +2,9 @@
2
2
 
3
3
  `comment-parser` is a library helping to handle Generic JSDoc-style comments. It is
4
4
 
5
- - **language-agnostic** – no semantic enforced. You decide what tags are and what they mean. And it can be used with any language supporting `/** */` source comments.
6
- - **no dependencies** – it is compact and environment-agnostic, can be ran on both server and browser sides
7
- - **highly customizable** – with a little of code you can deeply customize how comments are parsed
5
+ - **language-agnostic** – no semantics enforced. You decide what tags are and what they mean. And it can be used with any language supporting `/** */` source comments.
6
+ - **no dependencies** – it is compact and environment-agnostic, can be run on both the server and browser sides
7
+ - **highly customizable** – with a little code you can deeply customize how comments are parsed
8
8
  - **bidirectional** - you can write comment blocks back to the source after updating or formatting
9
9
  - **strictly typed** - comes with generated `d.ts` data definitions since written in TypeScript
10
10
 
@@ -20,17 +20,17 @@ Lib mainly provides two pieces [Parser](#Parser) and [Stringifier](#Stringifier)
20
20
 
21
21
  ## Parser
22
22
 
23
- Lets go over string parsing
23
+ Let's go over string parsing:
24
24
 
25
- ```
25
+ ```js
26
26
  const { parse } = require('comment-parser/lib')
27
27
 
28
28
  const source = `
29
29
  /**
30
30
  * Description may go
31
31
  * over few lines followed by @tags
32
- * @param name {string} name parameter
33
- * @param value {any} value of any type
32
+ * @param {string} name the name parameter
33
+ * @param {any} value the value of any type
34
34
  */`
35
35
 
36
36
  const parsed = parse(source)
@@ -38,11 +38,11 @@ const parsed = parse(source)
38
38
 
39
39
  Lib source code is written in TypeScript and all data shapes are conveniently available for your IDE of choice. All types described below can be found in [primitives.ts](src/primitives.ts)
40
40
 
41
- The input source is fist parsed into lines, then lines split into tokens, and finally, tokens are processed into blocks of tags
41
+ The input source is first parsed into lines, then lines split into tokens, and finally, tokens are processed into blocks of tags
42
42
 
43
43
  ### Block
44
44
 
45
- ```
45
+ ```js
46
46
  /**
47
47
  * Description may go
48
48
  * over multiple lines followed by @tags
@@ -53,7 +53,7 @@ The input source is fist parsed into lines, then lines split into tokens, and fi
53
53
 
54
54
  ### Description
55
55
 
56
- ```
56
+ ```js
57
57
  /**
58
58
  * Description may go
59
59
  * over multiple lines followed by @tags
@@ -61,11 +61,11 @@ The input source is fist parsed into lines, then lines split into tokens, and fi
61
61
 
62
62
  ### Tags
63
63
 
64
- ```
64
+ ```js
65
65
  * @param {string} name the name parameter
66
66
  ```
67
67
 
68
- ```
68
+ ```js
69
69
  * @param {any} value the value parameter
70
70
  */
71
71
  ```
@@ -73,7 +73,14 @@ The input source is fist parsed into lines, then lines split into tokens, and fi
73
73
  ### Tokens
74
74
 
75
75
  ```
76
- | ... | * | ... | @param | ... | value | ... | {any} | ... | value of any type
76
+ |line|start|delimiter|postDelimiter|tag |postTag|name |postName|type |postType|description |end|
77
+ |----|-----|---------|-------------|------|-------|-----|--------|--------|--------|--------------------------------|---|
78
+ | 0|{2} |/** | | | | | | | | | |
79
+ | 1|{3} |* |{1} | | | | | | |Description may go | |
80
+ | 2|{3} |* |{1} | | | | | | |over few lines followed by @tags| |
81
+ | 3|{3} |* |{1} |@param|{1} |name |{1} |{string}|{1} |the name parameter | |
82
+ | 4|{3} |* |{1} |@param|{1} |value|{1} |{any} |{1} |the value of any type | |
83
+ | 5|{3} | | | | | | | | | |*/ |
77
84
  ```
78
85
 
79
86
  ### Result
@@ -152,14 +159,14 @@ interface Options {
152
159
  startLine: number;
153
160
  // escaping chars sequence marking wrapped content literal for the parser
154
161
  fence: string;
155
- // block and comment description compaction strategy, see Spacer
156
- spacing: 'compact' | 'preserve' | Spacer;
162
+ // block and comment description compaction strategy
163
+ spacing: 'compact' | 'preserve';
157
164
  // tokenizer functions extracting name, type, and description out of tag, see Tokenizer
158
165
  tokenizers: Tokenizer[];
159
166
  }
160
167
  ```
161
168
 
162
- examples
169
+ examples
163
170
  - [default config](https://syavorsky.github.io/comment-parser/#parse-defaults)
164
171
  - [line numbers control](https://syavorsky.github.io/comment-parser/#parse-line-numbering)
165
172
  - [description spacing](https://syavorsky.github.io/comment-parser/#parse-spacing)
@@ -173,13 +180,13 @@ examples
173
180
  The stringifier is an important piece used by other tools updating the source code. It goes over `Block.source[].tokens` items and assembles them back to the string. It might be used with various transforms applied before stringifying.
174
181
 
175
182
  ```js
176
- const { parse, stringify, transforms: {flow, align, indent} } = require('./lib/');
183
+ const { parse, stringify, transforms: {flow, align, indent} } = require('comment-parser');
177
184
 
178
185
  const source = `
179
186
  /**
180
187
  * Description may go
181
188
  * over multiple lines followed by @tags
182
- *
189
+ *
183
190
  * @my-tag {my.type} my-name description line 1
184
191
  description line 2
185
192
  * description line 3
@@ -192,7 +199,7 @@ console.log(stringify(transform(parsed[0])));
192
199
 
193
200
  ### Result
194
201
 
195
- ```
202
+ ```js
196
203
  /**
197
204
  * Description may go
198
205
  * over multiple lines followed by @tags