comment-parser 0.7.5 → 0.7.6

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.
@@ -0,0 +1,24 @@
1
+ name: test
2
+
3
+ on:
4
+ push:
5
+ pull_request:
6
+ branches: [ master ]
7
+
8
+ jobs:
9
+ build:
10
+
11
+ runs-on: ubuntu-latest
12
+
13
+ strategy:
14
+ matrix:
15
+ node-version: [8.x, 10.x, 12.x, 14.x]
16
+
17
+ steps:
18
+ - uses: actions/checkout@v2
19
+ - name: Use Node.js ${{ matrix.node-version }}
20
+ uses: actions/setup-node@v1
21
+ with:
22
+ node-version: ${{ matrix.node-version }}
23
+ - run: npm ci
24
+ - run: npm test
package/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ # v0.7.6
2
+ - distinct non-critical errors by providing `err.warning`
3
+
1
4
  # v0.7.5
2
5
  - name parsing fixes
3
6
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "comment-parser",
3
- "version": "0.7.5",
3
+ "version": "0.7.6",
4
4
  "description": "Generic JSDoc-like comment parser. ",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
package/parser.js CHANGED
@@ -33,11 +33,16 @@ function find (list, filter) {
33
33
  * @returns {object} parsed tag node
34
34
  */
35
35
  function parse_tag (str, parsers) {
36
- const data = parsers.reduce(function (state, parser) {
36
+ const { data } = parsers.reduce(function (state, parser) {
37
37
  let result
38
38
 
39
39
  try {
40
40
  result = parser(state.source, Object.assign({}, state.data))
41
+ if (result && result.data && result.data.warning) {
42
+ state.data.warnings = (state.data.warnings || [])
43
+ .concat(parser.name + ': ' + result.data.warning)
44
+ delete result.data.warning
45
+ }
41
46
  } catch (err) {
42
47
  state.data.errors = (state.data.errors || [])
43
48
  .concat(parser.name + ': ' + err.message)
@@ -52,7 +57,7 @@ function parse_tag (str, parsers) {
52
57
  }, {
53
58
  source: str,
54
59
  data: {}
55
- }).data
60
+ })
56
61
 
57
62
  data.optional = !!data.optional
58
63
  data.type = data.type === undefined ? '' : data.type
@@ -177,6 +182,13 @@ function parse_block (source, opts) {
177
182
  return tags.concat(tag_node)
178
183
  }, [])
179
184
 
185
+ for (const tag of tags) {
186
+ if (!tag.errors && tag.warnings) {
187
+ tag.errors = [...tag.warnings]
188
+ delete tag.warnings
189
+ }
190
+ }
191
+
180
192
  return {
181
193
  tags,
182
194
  line: start,
@@ -215,7 +227,7 @@ function mkextract (opts) {
215
227
  const endPos = line.indexOf(MARKER_END)
216
228
 
217
229
  // if open marker detected and it's not, skip one
218
- if (startPos !== -1 && line.indexOf(MARKER_START_SKIP) !== startPos) {
230
+ if (!chunk && startPos !== -1 && line.indexOf(MARKER_START_SKIP) !== startPos) {
219
231
  chunk = []
220
232
  indent = startPos + MARKER_START.length
221
233
  }
package/parsers.js CHANGED
@@ -77,13 +77,19 @@ PARSERS.parse_name = function parse_name (str, data) {
77
77
  name = name.slice(1, -1)
78
78
 
79
79
  const match = name.match(
80
- /^\s*([^=]+?)(?:\s*=\s*(.+?))?\s*(?=$)/
80
+ /^\s*([^=]+?)(?:\s*=\s*(.*?))?\s*(?=$)/
81
81
  )
82
82
 
83
83
  if (!match) throw new SyntaxError('Invalid `name`, bad syntax')
84
84
 
85
85
  name = match[1]
86
86
  if (match[2]) res.default = match[2]
87
+ // We will throw this later after processing other tags (so we
88
+ // will collect enough data for the user to be able to fully recover)
89
+ else if (match[2] === '') {
90
+ res.default = match[2]
91
+ res.warning = 'Empty `name`, bad syntax'
92
+ }
87
93
  }
88
94
  }
89
95
 
package/stringifier.js CHANGED
@@ -57,7 +57,7 @@ const stringifyTag = exports.stringifyTag = function stringifyTag (
57
57
  (type ? ` {${type}}` : '') +
58
58
  (name.trim() ? ` ${
59
59
  optional ? '[' : ''
60
- }${name.trimRight()}${deflt ? `=${deflt}` : ''}${
60
+ }${name.trimRight()}${deflt !== undefined ? `=${deflt}` : ''}${
61
61
  optional ? ']' : ''
62
62
  }` : '') +
63
63
  (description ? ` ${description.replace(/\n/g, '\n' + indnt + '* ')}` : '') + '\n'