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.
- package/CHANGELOG.md +13 -0
- package/README.md +26 -19
- package/browser/index.js +331 -272
- package/es6/index.d.ts +21 -4
- package/es6/index.js +21 -5
- package/es6/parser/block-parser.d.ts +18 -2
- package/es6/parser/block-parser.js +12 -12
- package/es6/parser/index.d.ts +4 -4
- package/es6/parser/index.js +25 -26
- package/es6/parser/source-parser.js +13 -15
- package/es6/parser/spec-parser.d.ts +1 -6
- package/es6/parser/spec-parser.js +4 -151
- package/es6/parser/tokenizers/description.d.ts +19 -0
- package/es6/parser/tokenizers/description.js +46 -0
- package/es6/parser/tokenizers/index.d.ts +7 -0
- package/es6/parser/tokenizers/index.js +1 -0
- package/es6/parser/tokenizers/name.d.ts +6 -0
- package/es6/parser/tokenizers/name.js +91 -0
- package/es6/parser/tokenizers/tag.d.ts +6 -0
- package/es6/parser/tokenizers/tag.js +24 -0
- package/es6/parser/tokenizers/type.d.ts +27 -0
- package/es6/parser/tokenizers/type.js +67 -0
- package/es6/stringifier/index.d.ts +2 -1
- package/es6/stringifier/index.js +1 -6
- package/es6/stringifier/inspect.d.ts +2 -0
- package/es6/stringifier/inspect.js +41 -0
- package/es6/transforms/align.js +48 -43
- package/es6/transforms/indent.js +11 -22
- package/es6/transforms/index.d.ts +0 -2
- package/es6/transforms/index.js +2 -10
- package/es6/util.d.ts +11 -0
- package/es6/util.js +25 -25
- package/jest.config.js +12 -11
- package/lib/index.d.ts +21 -4
- package/lib/index.js +24 -6
- package/lib/parser/block-parser.d.ts +18 -2
- package/lib/parser/block-parser.js +12 -12
- package/lib/parser/index.d.ts +4 -4
- package/lib/parser/index.js +26 -27
- package/lib/parser/source-parser.js +14 -16
- package/lib/parser/spec-parser.d.ts +1 -6
- package/lib/parser/spec-parser.js +4 -156
- package/lib/parser/tokenizers/description.d.ts +19 -0
- package/lib/parser/tokenizers/description.js +51 -0
- package/lib/parser/tokenizers/index.d.ts +7 -0
- package/lib/parser/tokenizers/index.js +2 -0
- package/lib/parser/tokenizers/name.d.ts +6 -0
- package/lib/parser/tokenizers/name.js +94 -0
- package/lib/parser/tokenizers/tag.d.ts +6 -0
- package/lib/parser/tokenizers/tag.js +27 -0
- package/lib/parser/tokenizers/type.d.ts +27 -0
- package/lib/parser/tokenizers/type.js +70 -0
- package/lib/stringifier/index.d.ts +2 -1
- package/lib/stringifier/index.js +1 -6
- package/lib/stringifier/inspect.d.ts +2 -0
- package/lib/stringifier/inspect.js +44 -0
- package/lib/transforms/align.js +50 -45
- package/lib/transforms/indent.js +12 -23
- package/lib/transforms/index.d.ts +0 -2
- package/lib/transforms/index.js +3 -13
- package/lib/util.d.ts +11 -0
- package/lib/util.js +27 -26
- package/migrate-1.0.md +7 -7
- package/package.json +1 -1
- package/src/index.ts +20 -2
- package/src/parser/block-parser.ts +19 -1
- package/src/parser/index.ts +22 -21
- package/src/parser/source-parser.ts +2 -2
- package/src/parser/spec-parser.ts +2 -170
- package/src/parser/tokenizers/description.ts +75 -0
- package/src/parser/tokenizers/index.ts +8 -0
- package/src/parser/tokenizers/name.ts +112 -0
- package/src/parser/tokenizers/tag.ts +30 -0
- package/src/parser/tokenizers/type.ts +92 -0
- package/src/stringifier/index.ts +3 -1
- package/src/stringifier/inspect.ts +64 -0
- package/src/transforms/align.ts +37 -12
- package/src/transforms/index.ts +0 -3
- package/src/util.ts +20 -0
- package/tests/e2e/examples.js +39 -2
- package/tests/e2e/examples.spec.js +4 -2
- package/tests/e2e/issue-109.spec.js +49 -0
- package/tests/e2e/issue-112.spec.js +20 -0
- package/tests/e2e/issue-113.spec.js +23 -0
- package/tests/e2e/issue-119.spec.js +29 -0
- package/tests/e2e/issue-120.spec.js +29 -0
- package/tests/e2e/issue-121.spec.js +102 -0
- package/tests/e2e/transforms.spec.js +5 -2
- package/tests/unit/inspect.spec.ts +36 -0
- package/tests/unit/{spacer.spec.ts → spacer-description-joiner.spec.ts} +6 -6
- package/tests/unit/spec-description-tokenizer.spec.ts +100 -7
- package/tests/unit/spec-name-tokenizer.spec.ts +113 -1
- package/tests/unit/spec-parser.spec.ts +6 -9
- package/tests/unit/spec-tag-tokenizer.spec.ts +1 -1
- package/tests/unit/spec-type-tokenizer.spec.ts +121 -1
- package/tests/unit/stringifier.spec.ts +0 -1
- package/tests/unit/transforms-align.spec.ts +80 -16
- package/tests/unit/util-rewire.spec.ts +107 -0
- package/tests/unit/util.spec.ts +0 -48
- package/tsconfig.es6.json +1 -1
- package/tsconfig.node.json +1 -1
- package/es6/parser/spacer.d.ts +0 -3
- package/es6/parser/spacer.js +0 -37
- package/lib/parser/spacer.d.ts +0 -3
- package/lib/parser/spacer.js +0 -40
- 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
|
|
6
|
-
- **no dependencies** – it is compact and environment-agnostic, can be
|
|
7
|
-
- **highly customizable** – with a little
|
|
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
|
-
|
|
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
|
|
33
|
-
* @param
|
|
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
|
|
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
|
-
|
|
|
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
|
|
156
|
-
spacing: 'compact' | 'preserve'
|
|
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('
|
|
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
|