wikiparser-node 1.35.0 → 1.35.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 (71) hide show
  1. package/README.md +29 -28
  2. package/bundle/bundle-es8.min.js +29 -29
  3. package/bundle/bundle-lsp.min.js +34 -34
  4. package/bundle/bundle.min.js +24 -24
  5. package/config/default.json +3 -0
  6. package/config/enwiki.json +3 -0
  7. package/config/jawiki.json +3 -0
  8. package/config/minimum.json +1 -0
  9. package/config/zhwiki.json +3 -0
  10. package/coverage/badge.svg +1 -1
  11. package/data/signatures.json +13 -0
  12. package/dist/addon/attribute.js +13 -12
  13. package/dist/addon/link.js +3 -3
  14. package/dist/addon/token.js +4 -4
  15. package/dist/addon/transclude.js +8 -8
  16. package/dist/base.d.mts +3 -1
  17. package/dist/base.d.ts +3 -1
  18. package/dist/bin/config.js +3 -3
  19. package/dist/index.js +21 -13
  20. package/dist/lib/document.js +14 -12
  21. package/dist/lib/element.d.ts +2 -1
  22. package/dist/lib/element.js +17 -13
  23. package/dist/lib/lintConfig.js +7 -6
  24. package/dist/lib/lsp.js +10 -8
  25. package/dist/lib/node.js +8 -6
  26. package/dist/lib/range.js +17 -13
  27. package/dist/lib/ranges.js +25 -26
  28. package/dist/lib/text.js +14 -13
  29. package/dist/lib/title.js +7 -6
  30. package/dist/parser/braces.js +5 -7
  31. package/dist/parser/hrAndDoubleUnderscore.js +2 -2
  32. package/dist/parser/list.js +1 -1
  33. package/dist/parser/magicLinks.js +2 -1
  34. package/dist/parser/selector.js +15 -15
  35. package/dist/src/arg.js +4 -4
  36. package/dist/src/atom.js +1 -1
  37. package/dist/src/attribute.js +5 -4
  38. package/dist/src/attributes.js +10 -7
  39. package/dist/src/converter.js +4 -4
  40. package/dist/src/converterRule.js +2 -2
  41. package/dist/src/heading.js +2 -2
  42. package/dist/src/imageParameter.js +12 -3
  43. package/dist/src/index.js +15 -10
  44. package/dist/src/link/base.js +10 -7
  45. package/dist/src/link/category.js +3 -3
  46. package/dist/src/link/file.js +6 -5
  47. package/dist/src/link/index.js +5 -3
  48. package/dist/src/multiLine/gallery.js +2 -2
  49. package/dist/src/nowiki/comment.js +4 -3
  50. package/dist/src/nowiki/doubleUnderscore.js +1 -1
  51. package/dist/src/nowiki/listBase.js +2 -2
  52. package/dist/src/nowiki/noinclude.js +1 -1
  53. package/dist/src/nowiki/quote.js +3 -3
  54. package/dist/src/onlyinclude.js +1 -1
  55. package/dist/src/parameter.js +2 -2
  56. package/dist/src/table/index.js +9 -8
  57. package/dist/src/table/td.js +5 -5
  58. package/dist/src/table/trBase.js +4 -4
  59. package/dist/src/tag/html.js +9 -9
  60. package/dist/src/tag/index.js +6 -5
  61. package/dist/src/tag/tvar.js +4 -3
  62. package/dist/src/tagPair/index.js +6 -4
  63. package/dist/src/transclude.js +3 -3
  64. package/dist/util/debug.js +3 -2
  65. package/dist/util/diff.js +11 -6
  66. package/dist/util/selector.js +1 -1
  67. package/dist/util/string.js +2 -2
  68. package/extensions/dist/base.js +12 -4
  69. package/extensions/dist/codejar.js +1 -1
  70. package/package.json +27 -27
  71. package/logo.png +0 -0
@@ -152,11 +152,11 @@ let AstElement = (() => {
152
152
  */
153
153
  insertAt(node, i = this.length) {
154
154
  /* NOT FOR BROWSER */
155
- /* istanbul ignore next */
155
+ /* c8 ignore next 6 */
156
156
  if (node.contains(this)) {
157
157
  throw new RangeError('Cannot insert an ancestor node!');
158
158
  }
159
- else if (node.parentNode === this) {
159
+ if (node.parentNode === this) {
160
160
  throw new RangeError('Cannot insert its own child node!');
161
161
  }
162
162
  this.verifyChild(i, 1);
@@ -230,7 +230,7 @@ let AstElement = (() => {
230
230
  return data;
231
231
  }
232
232
  /* NOT FOR BROWSER */
233
- /* istanbul ignore next */
233
+ /* c8 ignore next */
234
234
  throw new RangeError(`The child node at position ${i} is ${oldText.constructor.name}!`);
235
235
  }
236
236
  /** @private */
@@ -337,9 +337,10 @@ let AstElement = (() => {
337
337
  *
338
338
  * 保存为JSON
339
339
  * @param file file name / 文件名
340
+ * @param depth depth of the node / 节点深度
340
341
  * @param start
341
342
  */
342
- json(file, start = this.getAbsoluteIndex()) {
343
+ json(file, depth = Infinity, start = this.getAbsoluteIndex()) {
343
344
  LSP: {
344
345
  const json = {
345
346
  ...this, // eslint-disable-line @typescript-eslint/no-misused-spread
@@ -347,19 +348,22 @@ let AstElement = (() => {
347
348
  range: [start, start + this.toString().length],
348
349
  childNodes: [],
349
350
  };
350
- for (let i = 0, cur = start + this.getAttribute('padding'); i < this.length; i++) {
351
- const child = this.childNodes[i], { length } = child.toString();
352
- child.setAttribute('aIndex', cur);
353
- json.childNodes.push(child.type === 'text'
354
- ? { data: child.data, range: [cur, cur + length] }
355
- : child.json(undefined, cur));
356
- cur += length + this.getGaps(i);
351
+ if (depth >= 1) {
352
+ for (let i = 0, cur = start + this.getAttribute('padding'); i < this.length; i++) {
353
+ const child = this.childNodes[i], { length } = child.toString();
354
+ child.setAttribute('aIndex', cur);
355
+ json.childNodes.push(child.type === 'text'
356
+ ? { data: child.data, range: [cur, cur + length] }
357
+ : child.json(undefined, depth - 1, cur));
358
+ cur += length + this.getGaps(i);
359
+ }
357
360
  }
358
361
  /* NOT FOR BROWSER */
359
- /* istanbul ignore if */
362
+ /* c8 ignore start */
360
363
  if (typeof file === 'string') {
361
364
  fs_1.default.writeFileSync(path_1.default.join(__dirname, '..', '..', 'printed', file + (file.endsWith('.json') ? '' : '.json')), JSON.stringify(json, null, 2));
362
365
  }
366
+ /* c8 ignore stop */
363
367
  /* NOT FOR BROWSER END */
364
368
  return json;
365
369
  }
@@ -427,7 +431,7 @@ let AstElement = (() => {
427
431
  */
428
432
  #getChildIndex(node) {
429
433
  const i = this.childNodes.indexOf(node);
430
- /* istanbul ignore if */
434
+ /* c8 ignore next 3 */
431
435
  if (i === -1) {
432
436
  throw new RangeError('Not a child node!');
433
437
  }
@@ -266,23 +266,23 @@ const validateConfigValue = (value) => validateSeverity(value)
266
266
  * @throws `RangeError` 未知的规则或无效的值
267
267
  */
268
268
  const set = (obj, key, value) => {
269
- /* istanbul ignore if */
269
+ /* c8 ignore next 6 */
270
270
  if (!base_1.rules.includes(key)) {
271
271
  throw new RangeError(`Unknown lint rule: ${key}`);
272
272
  }
273
- else /* istanbul ignore if */ if (value === undefined) {
273
+ if (value === undefined) {
274
274
  return false;
275
275
  }
276
- else if (validateConfigValue(value)) {
276
+ if (validateConfigValue(value)) {
277
277
  obj[key] = value;
278
278
  return true;
279
279
  }
280
- /* istanbul ignore next */
280
+ /* c8 ignore next */
281
281
  throw new RangeError(`Invalid lint config for ${key}: ${JSON.stringify(value)}`);
282
282
  };
283
283
  const clone = typeof structuredClone === 'function'
284
284
  ? structuredClone
285
- : /* istanbul ignore next */ (obj) => JSON.parse(JSON.stringify(obj));
285
+ : /* c8 ignore next */ (obj) => JSON.parse(JSON.stringify(obj));
286
286
  /** 语法规则设置 */
287
287
  class LintRuleConfiguration {
288
288
  /** @param config 语法规则设置 */
@@ -314,11 +314,12 @@ class LintConfiguration {
314
314
  set rules(config) {
315
315
  this.#rules = new Proxy(new LintRuleConfiguration(config), {
316
316
  set,
317
- /* istanbul ignore next */
317
+ /* c8 ignore start */
318
318
  /** @ignore */
319
319
  deleteProperty() {
320
320
  return false;
321
321
  },
322
+ /* c8 ignore stop */
322
323
  });
323
324
  }
324
325
  /** @param config 语法检查设置 */
package/dist/lib/lsp.js CHANGED
@@ -237,7 +237,7 @@ const getFixAll = (root, rule) => {
237
237
  * @param config
238
238
  */
239
239
  const partialParse = async (wikitext, watch, include, config = index_1.default.getConfig()) => {
240
- const set = typeof setImmediate === 'function' ? setImmediate : /* istanbul ignore next */ setTimeout, { running } = debug_1.Shadow;
240
+ const set = typeof setImmediate === 'function' ? setImmediate : /* c8 ignore next */ setTimeout, { running } = debug_1.Shadow;
241
241
  debug_1.Shadow.running = true;
242
242
  /* PRINT ONLY */
243
243
  const { internal } = index_1.default;
@@ -276,10 +276,11 @@ const partialParse = async (wikitext, watch, include, config = index_1.default.g
276
276
  set(parseOnce, 0);
277
277
  });
278
278
  }
279
- catch (e) /* istanbul ignore next */ {
279
+ catch (e) /* c8 ignore start */ {
280
280
  finish();
281
281
  throw e;
282
282
  }
283
+ /* c8 ignore stop */
283
284
  finish();
284
285
  return token;
285
286
  };
@@ -443,10 +444,10 @@ class LanguageService {
443
444
  this.#running = undefined;
444
445
  return root;
445
446
  }
446
- /* istanbul ignore next */
447
+ /* c8 ignore start */
447
448
  this.#running = this.#parse();
448
- /* istanbul ignore next */
449
449
  return this.#running;
450
+ /* c8 ignore stop */
450
451
  }
451
452
  /**
452
453
  * 提交签名解析任务
@@ -481,10 +482,10 @@ class LanguageService {
481
482
  this.#running2 = undefined;
482
483
  return root;
483
484
  }
484
- /* istanbul ignore next */
485
+ /* c8 ignore start */
485
486
  this.#running2 = this.#parseSignature();
486
- /* istanbul ignore next */
487
487
  return this.#running2;
488
+ /* c8 ignore stop */
488
489
  }
489
490
  /**
490
491
  * Provide color decorators
@@ -948,6 +949,7 @@ class LanguageService {
948
949
  const file = path_1.default.join(dir, `${hash.digest('hex')}.ly`);
949
950
  fs_1.default.writeFileSync(file, score);
950
951
  try {
952
+ // eslint-disable-next-line @typescript-eslint/strict-void-return
951
953
  await util_1.default.promisify(child_process_1.execFile)(this.lilypond, ['-s', '-o', dir, file]);
952
954
  scores.set(score, []);
953
955
  }
@@ -1277,7 +1279,7 @@ class LanguageService {
1277
1279
  * @param position position / 位置
1278
1280
  */
1279
1281
  async provideHover(text, position) {
1280
- /* istanbul ignore next */
1282
+ /* c8 ignore next 3 */
1281
1283
  if (!this.data) {
1282
1284
  return undefined;
1283
1285
  }
@@ -1375,7 +1377,7 @@ class LanguageService {
1375
1377
  * @param position position / 位置
1376
1378
  */
1377
1379
  async provideSignatureHelp(text, position) {
1378
- /* istanbul ignore next */
1380
+ /* c8 ignore next 3 */
1379
1381
  if (!this.data) {
1380
1382
  return undefined;
1381
1383
  }
package/dist/lib/node.js CHANGED
@@ -204,7 +204,7 @@ let AstNode = (() => {
204
204
  }
205
205
  /** @private */
206
206
  getAttribute(key) {
207
- return (key === 'padding' ? 0 : /* istanbul ignore next */ this[key]);
207
+ return (key === 'padding' ? 0 : /* c8 ignore next */ this[key]);
208
208
  }
209
209
  /** @private */
210
210
  setAttribute(key, value) {
@@ -410,11 +410,12 @@ let AstNode = (() => {
410
410
  }
411
411
  /* PRINT ONLY END */
412
412
  /* NOT FOR BROWSER */
413
- /* istanbul ignore next */
413
+ /* c8 ignore start */
414
414
  /** @private */
415
415
  typeError(method, ...types) {
416
416
  throw new TypeError(`${this.constructor.name}.${method} method only accepts ${types.join(', ')} as input parameters!`);
417
417
  }
418
+ /* c8 ignore stop */
418
419
  /** @private */
419
420
  constructorError(msg) {
420
421
  throw new Error(`${this.constructor.name} ${msg}!`);
@@ -434,7 +435,7 @@ let AstNode = (() => {
434
435
  if (e instanceof strict_1.default.AssertionError) {
435
436
  return false;
436
437
  }
437
- /* istanbul ignore next */
438
+ /* c8 ignore next 2 */
438
439
  throw e;
439
440
  }
440
441
  return true;
@@ -442,7 +443,7 @@ let AstNode = (() => {
442
443
  /** @private */
443
444
  insertAdjacent(nodes, offset) {
444
445
  const { parentNode } = this;
445
- /* istanbul ignore if */
446
+ /* c8 ignore next 3 */
446
447
  if (!parentNode) {
447
448
  throw new Error('There is no parent node!');
448
449
  }
@@ -511,7 +512,7 @@ let AstNode = (() => {
511
512
  /** @private */
512
513
  verifyChild(i, addition = 0) {
513
514
  const { length } = this.childNodes;
514
- /* istanbul ignore if */
515
+ /* c8 ignore next 3 */
515
516
  if (i < -length || i >= length + addition) {
516
517
  throw new RangeError(`The child node at position ${i} does not exist!`);
517
518
  }
@@ -628,7 +629,8 @@ let AstNode = (() => {
628
629
  else if (other.contains(this)) {
629
630
  return 1;
630
631
  }
631
- else /* istanbul ignore if */ if (this.getRootNode() !== other.getRootNode()) {
632
+ /* c8 ignore next 3 */
633
+ if (this.getRootNode() !== other.getRootNode()) {
632
634
  throw new RangeError('Nodes to be compared are not in the same document!');
633
635
  }
634
636
  const aAncestors = [...this.getAncestors().reverse(), this], bAncestors = [...other.getAncestors().reverse(), other], depth = aAncestors.findIndex((ancestor, i) => bAncestors[i] !== ancestor), { childNodes } = aAncestors[depth - 1];
package/dist/lib/range.js CHANGED
@@ -59,10 +59,10 @@ const getParent = (node) => {
59
59
  if (parentNode) {
60
60
  return parentNode;
61
61
  }
62
- /* istanbul ignore next */
62
+ /* c8 ignore next */
63
63
  throw new RangeError('The reference node has no parent node!');
64
64
  };
65
- /* istanbul ignore next */
65
+ /* c8 ignore start */
66
66
  /**
67
67
  * 未初始化时抛出错误
68
68
  * @param start 是否未初始化起点
@@ -71,6 +71,7 @@ const getParent = (node) => {
71
71
  const notInit = (start) => {
72
72
  throw new Error(`Please set the ${start ? 'start' : 'end'} position first!`);
73
73
  };
74
+ /* c8 ignore stop */
74
75
  /**
75
76
  * Range-like
76
77
  *
@@ -96,11 +97,11 @@ let AstRange = (() => {
96
97
  #endOffset;
97
98
  /** start container / 起点容器 */
98
99
  get startContainer() {
99
- return this.#startContainer ?? /* istanbul ignore next */ notInit(true);
100
+ return this.#startContainer ?? /* c8 ignore next */ notInit(true);
100
101
  }
101
102
  /** start offset / 起点位置 */
102
103
  get startOffset() {
103
- return this.#startOffset ?? /* istanbul ignore next */ notInit(true);
104
+ return this.#startOffset ?? /* c8 ignore next */ notInit(true);
104
105
  }
105
106
  /** start character index / 起点绝对位置 */
106
107
  get startIndex() {
@@ -112,11 +113,11 @@ let AstRange = (() => {
112
113
  }
113
114
  /** end container / 终点容器 */
114
115
  get endContainer() {
115
- return this.#endContainer ?? /* istanbul ignore next */ notInit(false);
116
+ return this.#endContainer ?? /* c8 ignore next */ notInit(false);
116
117
  }
117
118
  /** end offset / 终点位置 */
118
119
  get endOffset() {
119
- return this.#endOffset ?? /* istanbul ignore next */ notInit(false);
120
+ return this.#endOffset ?? /* c8 ignore next */ notInit(false);
120
121
  }
121
122
  /** end character index / 终点绝对位置 */
122
123
  get endIndex() {
@@ -153,14 +154,14 @@ let AstRange = (() => {
153
154
  #check() {
154
155
  const { startContainer, startOffset, endContainer, endOffset } = this, msg1 = 'The start and end positions are not siblings!', msg2 = 'The start position cannot be after the end position!';
155
156
  if (startContainer === endContainer) {
156
- /* istanbul ignore if */
157
+ /* c8 ignore next 3 */
157
158
  if (startOffset > endOffset) {
158
159
  throw new RangeError(msg2);
159
160
  }
160
161
  return;
161
162
  }
162
163
  const { type: startType, parentNode: startParent } = startContainer, { type: endType, parentNode: endParent } = endContainer;
163
- /* istanbul ignore next */
164
+ /* c8 ignore start */
164
165
  if (startType !== 'text') {
165
166
  if (endType !== 'text' || startContainer !== endParent) {
166
167
  throw new RangeError(msg1);
@@ -184,6 +185,7 @@ let AstRange = (() => {
184
185
  else if (endOffset <= startParent.childNodes.indexOf(startContainer)) {
185
186
  throw new RangeError(msg2);
186
187
  }
188
+ /* c8 ignore stop */
187
189
  }
188
190
  /**
189
191
  * Set the start
@@ -195,7 +197,7 @@ let AstRange = (() => {
195
197
  */
196
198
  setStart(startNode, offset) {
197
199
  const { length } = startNode;
198
- /* istanbul ignore if */
200
+ /* c8 ignore next 3 */
199
201
  if (offset < 0 || offset > length) {
200
202
  throw new RangeError(`The range of startOffset should be 0 ~ ${length}`);
201
203
  }
@@ -206,11 +208,12 @@ let AstRange = (() => {
206
208
  try {
207
209
  this.#check();
208
210
  }
209
- catch (e) /* istanbul ignore next */ {
211
+ catch (e) /* c8 ignore start */ {
210
212
  this.#startContainer = startContainer;
211
213
  this.#startOffset = startOffset;
212
214
  throw e;
213
215
  }
216
+ /* c8 ignore stop */
214
217
  }
215
218
  }
216
219
  /**
@@ -223,7 +226,7 @@ let AstRange = (() => {
223
226
  */
224
227
  setEnd(endNode, offset) {
225
228
  const { length } = endNode;
226
- /* istanbul ignore if */
229
+ /* c8 ignore next 3 */
227
230
  if (offset < 0 || offset > length) {
228
231
  throw new RangeError(`The range of endOffset should be 0 ~ ${length}`);
229
232
  }
@@ -234,11 +237,12 @@ let AstRange = (() => {
234
237
  try {
235
238
  this.#check();
236
239
  }
237
- catch (e) /* istanbul ignore next */ {
240
+ catch (e) /* c8 ignore start */ {
238
241
  this.#endContainer = endContainer;
239
242
  this.#endOffset = endOffset;
240
243
  throw e;
241
244
  }
245
+ /* c8 ignore stop */
242
246
  }
243
247
  }
244
248
  /**
@@ -346,7 +350,7 @@ let AstRange = (() => {
346
350
  */
347
351
  comparePoint(referenceNode, offset) {
348
352
  const { startContainer, startIndex, endContainer, endIndex } = this;
349
- /* istanbul ignore if */
353
+ /* c8 ignore next 3 */
350
354
  if (startContainer.getRootNode() !== referenceNode.getRootNode()) {
351
355
  throw new RangeError('The point to be compared is not in the same document!');
352
356
  }
@@ -28,44 +28,42 @@ class Range {
28
28
  this.start = Number(start);
29
29
  this.end = Number(end?.trim() || Infinity);
30
30
  this.step = Math.max(Number(step), 1);
31
- /* istanbul ignore next */
31
+ /* c8 ignore next 9 */
32
32
  if (!Number.isInteger(this.start)) {
33
33
  throw new RangeError(`The start of a range, \`${start}\`, should be an integer!`);
34
34
  }
35
- else if (this.end !== Infinity && !Number.isInteger(this.end)) {
35
+ if (this.end !== Infinity && !Number.isInteger(this.end)) {
36
36
  throw new RangeError(`The end of a range, \`${end}\`, should be an integer!`);
37
37
  }
38
- else if (!Number.isInteger(this.step)) {
38
+ if (!Number.isInteger(this.step)) {
39
39
  throw new RangeError(`The step of a range, \`${step}\`, should be an integer!`);
40
40
  }
41
41
  }
42
42
  else {
43
43
  const mt = /^([+-])?(\d+)?n(?:\s*([+-])\s*(\d+))?$/u
44
44
  .exec(str);
45
- /* istanbul ignore else */
46
- if (mt) {
47
- const [, sgnA = '+', a = 1, sgnB = '+'] = mt, b = Number(mt[4] ?? 0);
48
- this.step = Number(a);
49
- /* istanbul ignore if */
50
- if (this.step === 0) {
51
- throw new RangeError(`In the argument \`${str}\`, the coefficient of "n" must not be 0!`);
52
- }
53
- else if (sgnA === '+') { // `an+b` or `an-b`
54
- this.start = sgnB === '+' || b === 0 ? b : this.step - 1 - (b - 1) % this.step;
55
- this.end = Infinity;
56
- }
57
- else if (sgnB === '-') { // `-an-b`
58
- this.start = 0;
59
- this.end = b > 0 ? 0 : this.step;
60
- }
61
- else { // `-an+b`
62
- this.start = b % this.step;
63
- this.end = this.step + b;
64
- }
65
- }
66
- else {
45
+ /* c8 ignore next 3 */
46
+ if (!mt) {
67
47
  throw new RangeError(`The argument \`${str}\` should be either in the form of "an+b" as in CSS selectors or Python slices!`);
68
48
  }
49
+ const [, sgnA = '+', a = 1, sgnB = '+'] = mt, b = Number(mt[4] ?? 0);
50
+ this.step = Number(a);
51
+ /* c8 ignore next 3 */
52
+ if (this.step === 0) {
53
+ throw new RangeError(`In the argument \`${str}\`, the coefficient of "n" must not be 0!`);
54
+ }
55
+ else if (sgnA === '+') { // `an+b` or `an-b`
56
+ this.start = sgnB === '+' || b === 0 ? b : this.step - 1 - (b - 1) % this.step;
57
+ this.end = Infinity;
58
+ }
59
+ else if (sgnB === '-') { // `-an-b`
60
+ this.start = 0;
61
+ this.end = b > 0 ? 0 : this.step;
62
+ }
63
+ else { // `-an+b`
64
+ this.start = b % this.step;
65
+ this.end = this.step + b;
66
+ }
69
67
  }
70
68
  }
71
69
  /** @private */
@@ -101,11 +99,12 @@ class Ranges extends Array {
101
99
  try {
102
100
  this.push(new Range(ele));
103
101
  }
104
- catch (e) /* istanbul ignore next */ {
102
+ catch (e) /* c8 ignore start */ {
105
103
  if (e instanceof RangeError) {
106
104
  (0, diff_1.error)(e.message);
107
105
  }
108
106
  }
107
+ /* c8 ignore stop */
109
108
  }
110
109
  }
111
110
  }
package/dist/lib/text.js CHANGED
@@ -121,9 +121,10 @@ const wordRegex = /* #__PURE__ */ (() => {
121
121
  // eslint-disable-next-line prefer-regex-literals
122
122
  return new RegExp(String.raw `[\p{L}\p{N}_]`, 'u');
123
123
  }
124
- catch /* istanbul ignore next */ {
124
+ catch /* c8 ignore start */ {
125
125
  return /\w/u;
126
126
  }
127
+ /* c8 ignore stop */
127
128
  })();
128
129
  /**
129
130
  * text node
@@ -198,7 +199,7 @@ let AstText = (() => {
198
199
  return [];
199
200
  }
200
201
  const { data, parentNode, nextSibling, previousSibling } = this;
201
- /* istanbul ignore if */
202
+ /* c8 ignore next 3 */
202
203
  if (!parentNode) {
203
204
  throw new Error('An isolated text node cannot be linted!');
204
205
  }
@@ -232,17 +233,17 @@ let AstText = (() => {
232
233
  for (let mt = errorRegex.exec(data); mt; mt = errorRegex.exec(data)) {
233
234
  let { index, 0: error } = mt;
234
235
  const [, tag, prefix] = mt, lbrackInExtLinkText = error === '[' && type === 'ext-link-text';
235
- if (error.startsWith('<') && !tags.has(tag.toLowerCase())
236
+ if (prefix && prefix !== ']') {
237
+ const { length } = prefix;
238
+ index += length;
239
+ error = error.slice(length);
240
+ }
241
+ else if (error.startsWith('<') && !tags.has(tag.toLowerCase())
236
242
  || lbrackInExtLinkText && (/&(?:rbrack|#93|#x5[Dd];);/u.test(data.slice(index + 1))
237
243
  || nextSibling?.is('ext') && nextName === 'nowiki'
238
244
  && nextSibling.innerText?.includes(']'))) {
239
245
  continue;
240
246
  }
241
- else if (prefix && prefix !== ']') {
242
- const { length } = prefix;
243
- index += length;
244
- error = error.slice(length);
245
- }
246
247
  else if (error.startsWith('\n==')) {
247
248
  index++;
248
249
  error = error.slice(1);
@@ -437,13 +438,13 @@ let AstText = (() => {
437
438
  splitText(offset) {
438
439
  LSP: {
439
440
  /* NOT FOR BROWSER */
440
- /* istanbul ignore if */
441
+ /* c8 ignore next 3 */
441
442
  if (offset > this.length || offset < -this.length) {
442
443
  throw new RangeError(`Wrong offset to split: ${offset}`);
443
444
  }
444
445
  /* NOT FOR BROWSER END */
445
446
  const { parentNode, data } = this;
446
- /* istanbul ignore if */
447
+ /* c8 ignore next 3 */
447
448
  if (!parentNode) {
448
449
  throw new Error('The text node to be split has no parent node!');
449
450
  }
@@ -463,7 +464,7 @@ let AstText = (() => {
463
464
  escape() {
464
465
  LSP: {
465
466
  const { parentNode } = this;
466
- /* istanbul ignore if */
467
+ /* c8 ignore next 3 */
467
468
  if (!parentNode) {
468
469
  throw new Error('The text node to be escaped has no parent node!');
469
470
  }
@@ -542,11 +543,11 @@ let AstText = (() => {
542
543
  }
543
544
  /** @private */
544
545
  getRelativeIndex(j) {
545
- /* istanbul ignore else */
546
546
  if (j === undefined) {
547
547
  return super.getRelativeIndex();
548
548
  }
549
- else if (j < 0 || j > this.length) {
549
+ /* c8 ignore next 3 */
550
+ if (j < 0 || j > this.length) {
550
551
  throw new RangeError('Exceeding the text length range!');
551
552
  }
552
553
  return j;
package/dist/lib/title.js CHANGED
@@ -80,7 +80,7 @@ class Title {
80
80
  }
81
81
  /** @throws `RangeError` undefined namespace */
82
82
  set ns(ns) {
83
- /* istanbul ignore if */
83
+ /* c8 ignore next 3 */
84
84
  if (!(this.ns in this.#namespaces)) {
85
85
  throw new RangeError('Undefined namespace!');
86
86
  }
@@ -95,7 +95,7 @@ class Title {
95
95
  try {
96
96
  fragment = (0, common_1.rawurldecode)(fragment);
97
97
  }
98
- catch { }
98
+ catch /* c8 ignore next */ { }
99
99
  }
100
100
  this.#fragment = (0, string_1.decodeHtml)(fragment).replace(/[_ ]+/gu, ' ').trimEnd()
101
101
  .replaceAll(' ', '_');
@@ -132,7 +132,7 @@ class Title {
132
132
  title = (0, common_1.rawurldecode)(title);
133
133
  this.encoded = encoded;
134
134
  }
135
- catch { }
135
+ catch /* c8 ignore next */ { }
136
136
  }
137
137
  title = (0, string_1.decodeHtml)(title).replace(/[_ ]+/gu, ' ').trim();
138
138
  if (subpage || page && trimmed.startsWith('/')) {
@@ -168,7 +168,7 @@ class Title {
168
168
  try {
169
169
  fragment = (0, common_1.rawurldecode)(fragment);
170
170
  }
171
- catch { }
171
+ catch /* c8 ignore next */ { }
172
172
  }
173
173
  this.#fragment = fragment.replace(/ /gu, '_');
174
174
  title = title.slice(0, i).trim();
@@ -261,7 +261,7 @@ class Title {
261
261
  LSP: {
262
262
  if (typeof articlePath === 'string') {
263
263
  this.#path = articlePath;
264
- /* istanbul ignore if */
264
+ /* c8 ignore next 3 */
265
265
  if (!this.#path.includes('$1')) {
266
266
  this.#path += `${this.#path.endsWith('/') ? '' : '/'}$1`;
267
267
  }
@@ -290,11 +290,12 @@ class Title {
290
290
  * @throws `Error` not a file
291
291
  */
292
292
  getFileUrl(width, height) {
293
- /* istanbul ignore if */
293
+ /* c8 ignore start */
294
294
  if (typeof width === 'number' && (width <= 0 || !Number.isInteger(width))
295
295
  || typeof height === 'number' && (height <= 0 || !Number.isInteger(height))) {
296
296
  throw new RangeError('Width and height must be positive integers or omitted!');
297
297
  }
298
+ /* c8 ignore stop */
298
299
  const { main, valid, ns, interwiki } = this;
299
300
  if (!valid || ns !== 6 || interwiki) {
300
301
  throw new Error('Title.getFileUrl method is only for files!');
@@ -64,7 +64,7 @@ const getSymbol = (s) => {
64
64
  * @throws `TranscludeToken.constructor()`
65
65
  */
66
66
  const parseBraces = (wikitext, config, accum) => {
67
- const source = String.raw `${config.excludes.includes('heading') ? '' : String.raw `^((?:\0\d+[cno]\x7F)*)={1,6}|`}\[\[|-\{(?!\{)`, { parserFunction: [, , , subst] } = config, stack = [], linkStack = [];
67
+ const source = String.raw `${config.excludes.includes('heading') ? '' : String.raw `^((?:\0\d+[cno]\x7F)*)={1,6}|`}\[\[|-\{(?!\{)`, [, , , subst] = config.parserFunction, stack = [], linkStack = [];
68
68
  /**
69
69
  * 填入模板内容
70
70
  * @param text wikitext全文
@@ -93,7 +93,7 @@ const parseBraces = (wikitext, config, accum) => {
93
93
  return `\0${length}${getSymbol(parts[0])}\x7F`;
94
94
  }
95
95
  catch (e) {
96
- /* istanbul ignore if */
96
+ /* c8 ignore next 3 */
97
97
  if (!(e instanceof SyntaxError) || e.message !== 'Invalid template name') {
98
98
  throw e;
99
99
  }
@@ -174,13 +174,11 @@ const parseBraces = (wikitext, config, accum) => {
174
174
  ch = getSymbol(parts[0][0]);
175
175
  }
176
176
  catch (e) {
177
- /* istanbul ignore else */
178
- if (e instanceof SyntaxError && e.message === 'Invalid template name') {
179
- skip = true;
180
- }
181
- else {
177
+ /* c8 ignore next 3 */
178
+ if (!(e instanceof SyntaxError && e.message === 'Invalid template name')) {
182
179
  throw e;
183
180
  }
181
+ skip = true;
184
182
  }
185
183
  }
186
184
  if (!skip) {
@@ -15,7 +15,7 @@ const constants_1 = require("../util/constants");
15
15
  * @param accum
16
16
  */
17
17
  const parseHrAndDoubleUnderscore = ({ firstChild: { data }, type, name }, config, accum) => {
18
- const { doubleUnderscore: [insensitive, sensitive, aliases] } = config, all = [...insensitive, ...sensitive];
18
+ const [insensitive, sensitive, aliases] = config.doubleUnderscore, all = [...insensitive, ...sensitive];
19
19
  config.insensitiveDoubleUnderscore ??= new Set(insensitive.filter(cm_util_1.isUnderscore));
20
20
  config.sensitiveDoubleUnderscore ??= new Set(sensitive.filter(cm_util_1.isUnderscore));
21
21
  // eslint-disable-next-line @typescript-eslint/no-unused-expressions
@@ -34,7 +34,7 @@ const parseHrAndDoubleUnderscore = ({ firstChild: { data }, type, name }, config
34
34
  if (caseSensitive || caseInsensitive) {
35
35
  // @ts-expect-error abstract class
36
36
  new doubleUnderscore_1.DoubleUnderscoreToken(key, caseSensitive, Boolean(p4), config, accum);
37
- return `\0${accum.length - 1}${caseInsensitive && (aliases?.[lc] ?? /* istanbul ignore next */ lc) === 'toc' ? 'u' : 'n'}\x7F`;
37
+ return `\0${accum.length - 1}${caseInsensitive && (aliases?.[lc] ?? /* c8 ignore next */ lc) === 'toc' ? 'u' : 'n'}\x7F`;
38
38
  }
39
39
  return m;
40
40
  });
@@ -46,7 +46,7 @@ const parseList = (wikitext, state, config, accum) => {
46
46
  if (!dt) {
47
47
  return text;
48
48
  }
49
- const { html: [normalTags, , voidTags] } = config, fullRegex = /:+|-\{|\0\d+[xq]\x7F/gu;
49
+ const [normalTags, , voidTags] = config.html, fullRegex = /:+|-\{|\0\d+[xq]\x7F/gu;
50
50
  let regex = fullRegex, ex = regex.exec(text), lt = 0, lb = false, li = false, lc = 0;
51
51
  /**
52
52
  * 创建`DdToken`