comment-parser 1.0.0-beta.2 → 1.1.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.
Files changed (99) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/README.md +30 -21
  3. package/browser/index.js +301 -261
  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 +2 -3
  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.js +1 -6
  24. package/es6/stringifier/inspect.d.ts +2 -0
  25. package/es6/stringifier/inspect.js +41 -0
  26. package/es6/transforms/align.js +18 -32
  27. package/es6/transforms/indent.js +11 -22
  28. package/es6/transforms/index.d.ts +0 -2
  29. package/es6/transforms/index.js +2 -10
  30. package/es6/util.d.ts +11 -0
  31. package/es6/util.js +25 -25
  32. package/jest.config.js +12 -11
  33. package/lib/index.d.ts +21 -4
  34. package/lib/index.js +24 -6
  35. package/lib/parser/block-parser.d.ts +18 -2
  36. package/lib/parser/block-parser.js +12 -12
  37. package/lib/parser/index.d.ts +2 -3
  38. package/lib/parser/index.js +26 -27
  39. package/lib/parser/source-parser.js +14 -16
  40. package/lib/parser/spec-parser.d.ts +1 -6
  41. package/lib/parser/spec-parser.js +4 -156
  42. package/lib/parser/tokenizers/description.d.ts +19 -0
  43. package/lib/parser/tokenizers/description.js +51 -0
  44. package/lib/parser/tokenizers/index.d.ts +7 -0
  45. package/lib/parser/tokenizers/index.js +2 -0
  46. package/lib/parser/tokenizers/name.d.ts +6 -0
  47. package/lib/parser/tokenizers/name.js +94 -0
  48. package/lib/parser/tokenizers/tag.d.ts +6 -0
  49. package/lib/parser/tokenizers/tag.js +27 -0
  50. package/lib/parser/tokenizers/type.d.ts +27 -0
  51. package/lib/parser/tokenizers/type.js +70 -0
  52. package/lib/stringifier/index.js +1 -6
  53. package/lib/stringifier/inspect.d.ts +2 -0
  54. package/lib/stringifier/inspect.js +44 -0
  55. package/lib/transforms/align.js +20 -34
  56. package/lib/transforms/indent.js +12 -23
  57. package/lib/transforms/index.d.ts +0 -2
  58. package/lib/transforms/index.js +3 -13
  59. package/lib/util.d.ts +11 -0
  60. package/lib/util.js +27 -26
  61. package/migrate-1.0.md +7 -7
  62. package/package.json +1 -1
  63. package/src/index.ts +20 -2
  64. package/src/parser/block-parser.ts +19 -1
  65. package/src/parser/index.ts +19 -20
  66. package/src/parser/source-parser.ts +2 -2
  67. package/src/parser/spec-parser.ts +2 -170
  68. package/src/parser/tokenizers/description.ts +75 -0
  69. package/src/parser/tokenizers/index.ts +8 -0
  70. package/src/parser/tokenizers/name.ts +112 -0
  71. package/src/parser/tokenizers/tag.ts +30 -0
  72. package/src/parser/tokenizers/type.ts +92 -0
  73. package/src/stringifier/inspect.ts +64 -0
  74. package/src/transforms/index.ts +0 -3
  75. package/src/util.ts +20 -0
  76. package/tests/e2e/examples.js +39 -2
  77. package/tests/e2e/examples.spec.js +4 -2
  78. package/tests/e2e/issue-109.spec.js +49 -0
  79. package/tests/e2e/issue-112.spec.js +20 -0
  80. package/tests/e2e/issue-113.spec.js +23 -0
  81. package/tests/e2e/transforms.spec.js +5 -2
  82. package/tests/unit/inspect.spec.ts +36 -0
  83. package/tests/unit/{spacer.spec.ts → spacer-description-joiner.spec.ts} +6 -6
  84. package/tests/unit/spec-description-tokenizer.spec.ts +100 -7
  85. package/tests/unit/spec-name-tokenizer.spec.ts +113 -1
  86. package/tests/unit/spec-parser.spec.ts +6 -9
  87. package/tests/unit/spec-tag-tokenizer.spec.ts +1 -1
  88. package/tests/unit/spec-type-tokenizer.spec.ts +135 -1
  89. package/tests/unit/stringifier.spec.ts +0 -1
  90. package/tests/unit/transforms-align.spec.ts +1 -1
  91. package/tests/unit/util-rewire.spec.ts +107 -0
  92. package/tests/unit/util.spec.ts +0 -48
  93. package/tsconfig.es6.json +1 -1
  94. package/tsconfig.node.json +1 -1
  95. package/es6/parser/spacer.d.ts +0 -3
  96. package/es6/parser/spacer.js +0 -37
  97. package/lib/parser/spacer.d.ts +0 -3
  98. package/lib/parser/spacer.js +0 -40
  99. 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 may use it anywhere as long as `/** */` comments are supported.
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
 
@@ -12,23 +12,25 @@
12
12
  npm install comment-parser
13
13
  ```
14
14
 
15
- ### 💡 Check out the [Playground](https://syavorsky.github.io/comment-parser)
15
+ > 💡 Check out the [Playground](https://syavorsky.github.io/comment-parser)
16
+
17
+ > 💡 Previous version lives in [0.x](https://github.com/syavorsky/comment-parser/tree/0.x) branch
16
18
 
17
19
  Lib mainly provides two pieces [Parser](#Parser) and [Stringifier](#Stringifier).
18
20
 
19
21
  ## Parser
20
22
 
21
- Lets go over string parsing
23
+ Let's go over string parsing:
22
24
 
23
- ```
25
+ ```js
24
26
  const { parse } = require('comment-parser/lib')
25
27
 
26
28
  const source = `
27
29
  /**
28
30
  * Description may go
29
31
  * over few lines followed by @tags
30
- * @param name {string} name parameter
31
- * @param value {any} value of any type
32
+ * @param {string} name the name parameter
33
+ * @param {any} value the value of any type
32
34
  */`
33
35
 
34
36
  const parsed = parse(source)
@@ -36,11 +38,11 @@ const parsed = parse(source)
36
38
 
37
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)
38
40
 
39
- 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
40
42
 
41
43
  ### Block
42
44
 
43
- ```
45
+ ```js
44
46
  /**
45
47
  * Description may go
46
48
  * over multiple lines followed by @tags
@@ -51,7 +53,7 @@ The input source is fist parsed into lines, then lines split into tokens, and fi
51
53
 
52
54
  ### Description
53
55
 
54
- ```
56
+ ```js
55
57
  /**
56
58
  * Description may go
57
59
  * over multiple lines followed by @tags
@@ -59,11 +61,11 @@ The input source is fist parsed into lines, then lines split into tokens, and fi
59
61
 
60
62
  ### Tags
61
63
 
62
- ```
64
+ ```js
63
65
  * @param {string} name the name parameter
64
66
  ```
65
67
 
66
- ```
68
+ ```js
67
69
  * @param {any} value the value parameter
68
70
  */
69
71
  ```
@@ -71,7 +73,14 @@ The input source is fist parsed into lines, then lines split into tokens, and fi
71
73
  ### Tokens
72
74
 
73
75
  ```
74
- | ... | * | ... | @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} | | | | | | | | | |*/ |
75
84
  ```
76
85
 
77
86
  ### Result
@@ -150,14 +159,14 @@ interface Options {
150
159
  startLine: number;
151
160
  // escaping chars sequence marking wrapped content literal for the parser
152
161
  fence: string;
153
- // block and comment description compaction strategy, see Spacer
154
- spacing: 'compact' | 'preserve' | Spacer;
162
+ // block and comment description compaction strategy
163
+ spacing: 'compact' | 'preserve';
155
164
  // tokenizer functions extracting name, type, and description out of tag, see Tokenizer
156
165
  tokenizers: Tokenizer[];
157
166
  }
158
167
  ```
159
168
 
160
- examples
169
+ examples
161
170
  - [default config](https://syavorsky.github.io/comment-parser/#parse-defaults)
162
171
  - [line numbers control](https://syavorsky.github.io/comment-parser/#parse-line-numbering)
163
172
  - [description spacing](https://syavorsky.github.io/comment-parser/#parse-spacing)
@@ -168,16 +177,16 @@ examples
168
177
 
169
178
  ## Stringifier
170
179
 
171
- The stringifier is an important piece used by other tools updating the source code. It goes over `Block.source[].tokens` and assembles them back to a string. It might be used with various transforms applied to the parsed data before stringifying.
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.
172
181
 
173
182
  ```js
174
- const { parse, stringify, transforms: {flow, align, indent} } = require('./lib/');
183
+ const { parse, stringify, transforms: {flow, align, indent} } = require('comment-parser');
175
184
 
176
185
  const source = `
177
186
  /**
178
187
  * Description may go
179
188
  * over multiple lines followed by @tags
180
- *
189
+ *
181
190
  * @my-tag {my.type} my-name description line 1
182
191
  description line 2
183
192
  * description line 3
@@ -190,7 +199,7 @@ console.log(stringify(transform(parsed[0])));
190
199
 
191
200
  ### Result
192
201
 
193
- ```
202
+ ```js
194
203
  /**
195
204
  * Description may go
196
205
  * over multiple lines followed by @tags