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.
- package/CHANGELOG.md +13 -0
- package/README.md +30 -21
- package/browser/index.js +301 -261
- 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 +2 -3
- 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.js +1 -6
- package/es6/stringifier/inspect.d.ts +2 -0
- package/es6/stringifier/inspect.js +41 -0
- package/es6/transforms/align.js +18 -32
- 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 +2 -3
- 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.js +1 -6
- package/lib/stringifier/inspect.d.ts +2 -0
- package/lib/stringifier/inspect.js +44 -0
- package/lib/transforms/align.js +20 -34
- 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 +19 -20
- 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/inspect.ts +64 -0
- 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/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 +135 -1
- package/tests/unit/stringifier.spec.ts +0 -1
- package/tests/unit/transforms-align.spec.ts +1 -1
- 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
|
|
|
@@ -12,23 +12,25 @@
|
|
|
12
12
|
npm install comment-parser
|
|
13
13
|
```
|
|
14
14
|
|
|
15
|
-
|
|
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
|
-
|
|
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
|
|
31
|
-
* @param
|
|
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
|
|
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
|
-
|
|
|
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
|
|
154
|
-
spacing: 'compact' | 'preserve'
|
|
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
|
|
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('
|
|
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
|