wikilint 2.9.2 → 2.10.0

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 (114) hide show
  1. package/config/.schema.json +5 -0
  2. package/config/enwiki.json +2 -1
  3. package/config/llwiki.json +2 -1
  4. package/config/moegirl.json +2 -1
  5. package/config/zhwiki.json +2 -1
  6. package/dist/base.d.ts +11 -4
  7. package/dist/index.js +3 -4
  8. package/dist/lib/element.js +13 -13
  9. package/dist/lib/node.d.ts +9 -1
  10. package/dist/lib/node.js +7 -0
  11. package/dist/lib/text.d.ts +1 -3
  12. package/dist/lib/text.js +8 -6
  13. package/dist/mixin/hidden.d.ts +1 -0
  14. package/dist/mixin/hidden.js +2 -2
  15. package/dist/parser/list.js +8 -6
  16. package/dist/parser/table.js +5 -5
  17. package/dist/src/arg.d.ts +1 -1
  18. package/dist/src/arg.js +5 -3
  19. package/dist/src/atom.d.ts +5 -2
  20. package/dist/src/atom.js +25 -1
  21. package/dist/src/attribute.d.ts +1 -1
  22. package/dist/src/attribute.js +13 -25
  23. package/dist/src/attributes.d.ts +2 -1
  24. package/dist/src/attributes.js +6 -2
  25. package/dist/src/converter.d.ts +2 -2
  26. package/dist/src/converter.js +7 -4
  27. package/dist/src/converterFlags.d.ts +1 -1
  28. package/dist/src/converterFlags.js +5 -3
  29. package/dist/src/converterRule.d.ts +1 -1
  30. package/dist/src/converterRule.js +12 -14
  31. package/dist/src/extLink.d.ts +1 -1
  32. package/dist/src/extLink.js +6 -4
  33. package/dist/src/gallery.d.ts +1 -1
  34. package/dist/src/gallery.js +7 -5
  35. package/dist/src/heading.d.ts +1 -1
  36. package/dist/src/heading.js +7 -4
  37. package/dist/src/hidden.d.ts +1 -1
  38. package/dist/src/hidden.js +4 -2
  39. package/dist/src/html.d.ts +1 -1
  40. package/dist/src/html.js +5 -3
  41. package/dist/src/imageParameter.d.ts +1 -1
  42. package/dist/src/imageParameter.js +5 -3
  43. package/dist/src/imagemap.d.ts +1 -1
  44. package/dist/src/imagemap.js +5 -3
  45. package/dist/src/imagemapLink.d.ts +1 -1
  46. package/dist/src/imagemapLink.js +3 -1
  47. package/dist/src/index.d.ts +2 -1
  48. package/dist/src/index.js +17 -10
  49. package/dist/src/link/base.d.ts +1 -1
  50. package/dist/src/link/base.js +12 -7
  51. package/dist/src/link/category.d.ts +1 -1
  52. package/dist/src/link/category.js +3 -1
  53. package/dist/src/link/file.d.ts +1 -1
  54. package/dist/src/link/file.js +4 -2
  55. package/dist/src/link/galleryImage.d.ts +1 -2
  56. package/dist/src/link/galleryImage.js +7 -13
  57. package/dist/src/link/index.d.ts +1 -1
  58. package/dist/src/link/index.js +3 -1
  59. package/dist/src/link/redirectTarget.d.ts +2 -2
  60. package/dist/src/link/redirectTarget.js +5 -7
  61. package/dist/src/magicLink.d.ts +4 -1
  62. package/dist/src/magicLink.js +42 -54
  63. package/dist/src/nested.d.ts +1 -1
  64. package/dist/src/nested.js +3 -1
  65. package/dist/src/nowiki/base.d.ts +1 -1
  66. package/dist/src/nowiki/comment.d.ts +1 -1
  67. package/dist/src/nowiki/comment.js +6 -4
  68. package/dist/src/nowiki/dd.d.ts +1 -1
  69. package/dist/src/nowiki/dd.js +3 -1
  70. package/dist/src/nowiki/doubleUnderscore.d.ts +1 -1
  71. package/dist/src/nowiki/doubleUnderscore.js +4 -2
  72. package/dist/src/nowiki/hr.d.ts +1 -1
  73. package/dist/src/nowiki/hr.js +3 -1
  74. package/dist/src/nowiki/index.d.ts +1 -1
  75. package/dist/src/nowiki/index.js +3 -1
  76. package/dist/src/nowiki/list.d.ts +1 -1
  77. package/dist/src/nowiki/list.js +3 -1
  78. package/dist/src/nowiki/listBase.d.ts +1 -1
  79. package/dist/src/nowiki/noinclude.d.ts +1 -1
  80. package/dist/src/nowiki/noinclude.js +8 -2
  81. package/dist/src/nowiki/quote.d.ts +1 -1
  82. package/dist/src/nowiki/quote.js +3 -1
  83. package/dist/src/onlyinclude.d.ts +1 -1
  84. package/dist/src/onlyinclude.js +5 -3
  85. package/dist/src/paramTag/index.d.ts +1 -1
  86. package/dist/src/paramTag/index.js +5 -3
  87. package/dist/src/parameter.d.ts +1 -2
  88. package/dist/src/parameter.js +14 -11
  89. package/dist/src/pre.d.ts +1 -1
  90. package/dist/src/pre.js +3 -1
  91. package/dist/src/redirect.d.ts +1 -1
  92. package/dist/src/redirect.js +6 -4
  93. package/dist/src/syntax.d.ts +5 -4
  94. package/dist/src/syntax.js +8 -4
  95. package/dist/src/table/base.d.ts +1 -1
  96. package/dist/src/table/index.d.ts +1 -1
  97. package/dist/src/table/index.js +3 -1
  98. package/dist/src/table/td.d.ts +1 -5
  99. package/dist/src/table/td.js +5 -7
  100. package/dist/src/table/tr.d.ts +1 -1
  101. package/dist/src/table/tr.js +3 -1
  102. package/dist/src/table/trBase.d.ts +1 -1
  103. package/dist/src/table/trBase.js +3 -4
  104. package/dist/src/tagPair/ext.d.ts +1 -1
  105. package/dist/src/tagPair/ext.js +7 -3
  106. package/dist/src/tagPair/include.d.ts +1 -1
  107. package/dist/src/tagPair/include.js +8 -2
  108. package/dist/src/tagPair/index.d.ts +1 -1
  109. package/dist/src/tagPair/index.js +3 -3
  110. package/dist/src/transclude.d.ts +1 -1
  111. package/dist/src/transclude.js +19 -15
  112. package/dist/util/lint.js +1 -1
  113. package/errors/README +2 -0
  114. package/package.json +1 -1
@@ -5,18 +5,15 @@ const string_1 = require("../util/string");
5
5
  const lint_1 = require("../util/lint");
6
6
  const index_1 = require("../index");
7
7
  const index_2 = require("./index");
8
- /**
9
- * 准确获取参数名
10
- * @param name 预定的参数名
11
- */
12
- const getName = (name) => name.text().replace(/^[ \t\n\0\v]+|([^ \t\n\0\v])[ \t\n\0\v]+$/gu, '$1');
13
8
  const linkRegex = new RegExp(`https?://${string_1.extUrlCharFirst}${string_1.extUrlChar}$`, 'iu');
14
9
  /**
15
10
  * 模板或魔术字参数
16
11
  * @classdesc `{childNodes: [Token, Token]}`
17
12
  */
18
13
  class ParameterToken extends index_2.Token {
19
- type = 'parameter';
14
+ get type() {
15
+ return 'parameter';
16
+ }
20
17
  /** 是否是匿名参数 */
21
18
  get anon() {
22
19
  return this.firstChild.length === 0;
@@ -29,15 +26,22 @@ class ParameterToken extends index_2.Token {
29
26
  super(undefined, config, accum);
30
27
  const keyToken = new index_2.Token(typeof key === 'number' ? undefined : key, config, accum, {}), token = new index_2.Token(value, config, accum);
31
28
  keyToken.type = 'parameter-key';
29
+ keyToken.setAttribute('stage', 2);
32
30
  token.type = 'parameter-value';
33
31
  token.setAttribute('stage', 2);
34
32
  this.append(keyToken, token);
35
33
  }
36
34
  /** @private */
35
+ trimName(name, set = true) {
36
+ const trimmed = (typeof name === 'string' ? name : name.toString(true))
37
+ .replace(/^[ \t\n\0\v]+|([^ \t\n\0\v])[ \t\n\0\v]+$/gu, '$1');
38
+ this.setAttribute('name', trimmed);
39
+ return trimmed;
40
+ }
41
+ /** @private */
37
42
  afterBuild() {
38
43
  if (!this.anon) {
39
- const { parentNode, firstChild } = this, name = getName(firstChild);
40
- this.setAttribute('name', name);
44
+ const { parentNode, firstChild } = this, name = this.trimName(firstChild);
41
45
  if (parentNode) {
42
46
  parentNode.getArgs(name, false, false).add(this);
43
47
  }
@@ -45,10 +49,9 @@ class ParameterToken extends index_2.Token {
45
49
  super.afterBuild();
46
50
  }
47
51
  /** @private */
48
- toString() {
49
- return this.anon ? this.lastChild.toString() : super.toString('=');
52
+ toString(skip) {
53
+ return this.anon ? this.lastChild.toString(skip) : super.toString(skip, '=');
50
54
  }
51
- /** @override */
52
55
  text() {
53
56
  return this.anon ? this.lastChild.text() : super.text('=');
54
57
  }
package/dist/src/pre.d.ts CHANGED
@@ -8,7 +8,6 @@ import type { AstText, AttributesToken, ExtToken, ConverterToken } from '../inte
8
8
  * @classdesc `{childNodes: [...AstText|NoincludeToken|ConverterToken]}`
9
9
  */
10
10
  export declare abstract class PreToken extends Token {
11
- readonly type = "ext-inner";
12
11
  readonly name: 'pre';
13
12
  readonly childNodes: readonly (AstText | NoincludeToken | ConverterToken)[];
14
13
  abstract get firstChild(): AstText | NoincludeToken | ConverterToken | undefined;
@@ -16,6 +15,7 @@ export declare abstract class PreToken extends Token {
16
15
  abstract get nextSibling(): undefined;
17
16
  abstract get previousSibling(): AttributesToken;
18
17
  abstract get parentNode(): ExtToken | undefined;
18
+ get type(): 'ext-inner';
19
19
  /** @class */
20
20
  constructor(wikitext?: string, config?: Parser.Config, accum?: Token[]);
21
21
  }
package/dist/src/pre.js CHANGED
@@ -10,7 +10,9 @@ const noinclude_1 = require("./nowiki/noinclude");
10
10
  * @classdesc `{childNodes: [...AstText|NoincludeToken|ConverterToken]}`
11
11
  */
12
12
  class PreToken extends index_2.Token {
13
- type = 'ext-inner';
13
+ get type() {
14
+ return 'ext-inner';
15
+ }
14
16
  /** @class */
15
17
  constructor(wikitext, config = index_1.default.getConfig(), accum = []) {
16
18
  if (wikitext) {
@@ -9,11 +9,11 @@ import type { LintError } from '../base';
9
9
  */
10
10
  export declare abstract class RedirectToken extends Token {
11
11
  #private;
12
- readonly type = "redirect";
13
12
  readonly childNodes: readonly [SyntaxToken, RedirectTargetToken];
14
13
  abstract get firstChild(): SyntaxToken;
15
14
  abstract get lastChild(): RedirectTargetToken;
16
15
  abstract get previousSibling(): undefined;
16
+ get type(): 'redirect';
17
17
  /**
18
18
  * @param pre leading whitespace
19
19
  * @param syntax 重定向魔术字
@@ -45,7 +45,7 @@ const redirectTarget_1 = require("./link/redirectTarget");
45
45
  * @classdesc `{childNodes: [SyntaxToken, LinkToken]}`
46
46
  */
47
47
  let RedirectToken = (() => {
48
- let _classDecorators = [(0, hidden_1.hiddenToken)()];
48
+ let _classDecorators = [(0, hidden_1.hiddenToken)(false, false)];
49
49
  let _classDescriptor;
50
50
  let _classExtraInitializers = [];
51
51
  let _classThis;
@@ -59,9 +59,11 @@ let RedirectToken = (() => {
59
59
  if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
60
60
  __runInitializers(_classThis, _classExtraInitializers);
61
61
  }
62
- type = 'redirect';
63
62
  #pre;
64
63
  #post;
64
+ get type() {
65
+ return 'redirect';
66
+ }
65
67
  /**
66
68
  * @param pre leading whitespace
67
69
  * @param syntax 重定向魔术字
@@ -83,8 +85,8 @@ let RedirectToken = (() => {
83
85
  return key === 'padding' ? this.#pre.length : super.getAttribute(key);
84
86
  }
85
87
  /** @private */
86
- toString() {
87
- return this.#pre + super.toString() + this.#post;
88
+ toString(skip) {
89
+ return this.#pre + super.toString(skip) + this.#post;
88
90
  }
89
91
  /** @private */
90
92
  lint(start = this.getAbsoluteIndex()) {
@@ -1,10 +1,11 @@
1
1
  import { Token } from './index';
2
- import type { Config } from '../base';
3
- declare type SyntaxTypes = 'plain' | 'heading-trail' | 'magic-word-name' | 'table-syntax' | 'redirect-syntax';
2
+ import type { Config, LintError } from '../base';
3
+ declare type SyntaxTypes = 'heading-trail' | 'magic-word-name' | 'table-syntax' | 'redirect-syntax';
4
4
  /** 满足特定语法格式的plain Token */
5
5
  export declare class SyntaxToken extends Token {
6
- type: SyntaxTypes;
6
+ #private;
7
+ get type(): SyntaxTypes;
7
8
  /** @param pattern 语法正则 */
8
- constructor(wikitext: string | undefined, pattern: RegExp, type?: SyntaxTypes, config?: Config, accum?: Token[], acceptable?: Acceptable);
9
+ constructor(wikitext: string | undefined, pattern: RegExp, type: SyntaxTypes, config?: Config, accum?: Token[], acceptable?: Acceptable);
9
10
  }
10
11
  export {};
@@ -4,14 +4,18 @@ exports.SyntaxToken = void 0;
4
4
  const index_1 = require("./index");
5
5
  /** 满足特定语法格式的plain Token */
6
6
  class SyntaxToken extends index_1.Token {
7
+ #type;
8
+ get type() {
9
+ return this.#type;
10
+ }
7
11
  /** @param pattern 语法正则 */
8
- constructor(wikitext, pattern, type = 'plain', config, accum, acceptable) {
12
+ constructor(wikitext, pattern, type, config, accum, acceptable) {
9
13
  super(wikitext, config, accum, acceptable);
10
- this.type = type;
14
+ this.#type = type;
11
15
  }
12
16
  /** @private */
13
- lint() {
14
- return [];
17
+ lint(start = this.getAbsoluteIndex()) {
18
+ return super.lint(start, false);
15
19
  }
16
20
  }
17
21
  exports.SyntaxToken = SyntaxToken;
@@ -7,7 +7,7 @@ declare type TableTypes = 'table' | 'tr' | 'td';
7
7
  export interface TableBaseToken extends AttributesParentBase {
8
8
  }
9
9
  export declare abstract class TableBaseToken extends Token {
10
- type: TableTypes;
10
+ abstract get type(): TableTypes;
11
11
  readonly childNodes: readonly [SyntaxToken, AttributesToken, ...Token[]];
12
12
  abstract get firstChild(): SyntaxToken;
13
13
  abstract get lastChild(): Token;
@@ -16,9 +16,9 @@ export declare class Layout extends Array<TableCoords[]> {
16
16
  * @classdesc `{childNodes: [SyntaxToken, AttributesToken, ?Token, ...TdToken, ...TrToken, ?SyntaxToken]}`
17
17
  */
18
18
  export declare abstract class TableToken extends TrBaseToken {
19
- readonly type = "table";
20
19
  readonly childNodes: readonly [SyntaxToken, AttributesToken, ...(TdToken | TrToken)[], SyntaxToken] | readonly [SyntaxToken, AttributesToken, ...(TdToken | TrToken)[]];
21
20
  abstract get lastChild(): AttributesToken | TdToken | TrToken | SyntaxToken;
21
+ get type(): 'table';
22
22
  /** 表格是否闭合 */
23
23
  get closed(): boolean;
24
24
  /**
@@ -23,7 +23,9 @@ exports.Layout = Layout;
23
23
  * @classdesc `{childNodes: [SyntaxToken, AttributesToken, ?Token, ...TdToken, ...TrToken, ?SyntaxToken]}`
24
24
  */
25
25
  class TableToken extends trBase_1.TrBaseToken {
26
- type = 'table';
26
+ get type() {
27
+ return 'table';
28
+ }
27
29
  /** 表格是否闭合 */
28
30
  get closed() {
29
31
  return this.lastChild.type === 'table-syntax';
@@ -15,11 +15,11 @@ declare type TdAttrGetter<T extends string> = T extends keyof TdSpanAttrs ? numb
15
15
  */
16
16
  export declare abstract class TdToken extends TableBaseToken {
17
17
  #private;
18
- readonly type = "td";
19
18
  readonly childNodes: readonly [SyntaxToken, AttributesToken, Token];
20
19
  abstract get parentNode(): TrToken | TableToken | undefined;
21
20
  abstract get nextSibling(): this | TrToken | SyntaxToken | undefined;
22
21
  abstract get previousSibling(): Token | undefined;
22
+ get type(): 'td';
23
23
  /** rowspan */
24
24
  get rowspan(): number;
25
25
  /** colspan */
@@ -33,10 +33,6 @@ export declare abstract class TdToken extends TableBaseToken {
33
33
  constructor(syntax: string, inner?: string, config?: Parser.Config, accum?: Token[]);
34
34
  /** 是否位于行首 */
35
35
  isIndependent(): boolean;
36
- /**
37
- * @override
38
- * @param key 属性键
39
- */
40
36
  getAttr<T extends string>(key: T): TdAttrGetter<T>;
41
37
  }
42
38
  export {};
@@ -13,9 +13,11 @@ const base_1 = require("./base");
13
13
  * @classdesc `{childNodes: [SyntaxToken, AttributesToken, Token]}`
14
14
  */
15
15
  class TdToken extends base_1.TableBaseToken {
16
- type = 'td';
17
16
  #innerSyntax = '';
18
17
  #syntax;
18
+ get type() {
19
+ return 'td';
20
+ }
19
21
  /** rowspan */
20
22
  get rowspan() {
21
23
  return this.getAttr('rowspan');
@@ -80,9 +82,9 @@ class TdToken extends base_1.TableBaseToken {
80
82
  super.afterBuild();
81
83
  }
82
84
  /** @private */
83
- toString() {
85
+ toString(skip) {
84
86
  const { childNodes: [syntax, attr, inner] } = this;
85
- return syntax.toString() + attr.toString() + this.#innerSyntax + inner.toString();
87
+ return syntax.toString(skip) + attr.toString(skip) + this.#innerSyntax + inner.toString(skip);
86
88
  }
87
89
  /** @private */
88
90
  text() {
@@ -130,10 +132,6 @@ class TdToken extends base_1.TableBaseToken {
130
132
  isIndependent() {
131
133
  return this.firstChild.text().startsWith('\n');
132
134
  }
133
- /**
134
- * @override
135
- * @param key 属性键
136
- */
137
135
  getAttr(key) {
138
136
  const value = super.getAttr(key);
139
137
  return (key === 'rowspan' || key === 'colspan' ? parseInt(value) || 1 : value);
@@ -6,12 +6,12 @@ import type { Token, TdToken, TableToken, SyntaxToken, AttributesToken } from '.
6
6
  * @classdesc `{childNodes: [SyntaxToken, AttributesToken, ?Token, ...TdToken]}`
7
7
  */
8
8
  export declare abstract class TrToken extends TrBaseToken {
9
- readonly type = "tr";
10
9
  readonly childNodes: readonly [SyntaxToken, AttributesToken, ...TdToken[]];
11
10
  abstract get lastChild(): AttributesToken | TdToken;
12
11
  abstract get parentNode(): TableToken | undefined;
13
12
  abstract get nextSibling(): this | SyntaxToken | undefined;
14
13
  abstract get previousSibling(): Token;
14
+ get type(): 'tr';
15
15
  /**
16
16
  * @param syntax 表格语法
17
17
  * @param attr 表格属性
@@ -7,7 +7,9 @@ const trBase_1 = require("./trBase");
7
7
  * @classdesc `{childNodes: [SyntaxToken, AttributesToken, ?Token, ...TdToken]}`
8
8
  */
9
9
  class TrToken extends trBase_1.TrBaseToken {
10
- type = 'tr';
10
+ get type() {
11
+ return 'tr';
12
+ }
11
13
  /**
12
14
  * @param syntax 表格语法
13
15
  * @param attr 表格属性
@@ -10,7 +10,7 @@ export interface TableCoords {
10
10
  }
11
11
  /** 表格行或表格 */
12
12
  export declare abstract class TrBaseToken extends TableBaseToken {
13
- type: 'table' | 'tr';
13
+ abstract get type(): 'table' | 'tr';
14
14
  /** 获取行数 */
15
15
  getRowCount(): number;
16
16
  /**
@@ -2,7 +2,6 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.TrBaseToken = void 0;
4
4
  const lint_1 = require("../../util/lint");
5
- const debug_1 = require("../../util/debug");
6
5
  const base_1 = require("./base");
7
6
  const td_1 = require("./td");
8
7
  /** 表格行或表格 */
@@ -13,13 +12,13 @@ class TrBaseToken extends base_1.TableBaseToken {
13
12
  if (!inter) {
14
13
  return errors;
15
14
  }
16
- const first = inter.childNodes.find(child => child.text().trim()), tdPattern = /^\s*(?:!|\{\{\s*![!-]?\s*\}\})/u, isArg = (0, debug_1.isToken)('arg'), isTransclude = (0, debug_1.isToken)('magic-word');
15
+ const first = inter.childNodes.find(child => child.text().trim()), tdPattern = /^\s*(?:!|\{\{\s*![!-]?\s*\}\})/u;
17
16
  if (!first
18
17
  || tdPattern.test(first.toString())
19
- || isArg(first) && tdPattern.test(first.default || '')) {
18
+ || first.is('arg') && tdPattern.test(first.default || '')) {
20
19
  return errors;
21
20
  }
22
- else if (isTransclude(first)) {
21
+ else if (first.is('magic-word')) {
23
22
  try {
24
23
  if (first.getPossibleValues().every(token => tdPattern.test(token.text()))) {
25
24
  return errors;
@@ -8,11 +8,11 @@ import type { LintError } from '../../base';
8
8
  * @classdesc `{childNodes: [AttributesToken, Token]}`
9
9
  */
10
10
  export declare abstract class ExtToken extends TagPairToken {
11
- readonly type = "ext";
12
11
  closed: true;
13
12
  readonly childNodes: readonly [AttributesToken, Token];
14
13
  abstract get firstChild(): AttributesToken;
15
14
  abstract get lastChild(): Token;
15
+ get type(): 'ext';
16
16
  /**
17
17
  * @param name 标签名
18
18
  * @param attr 标签属性
@@ -22,7 +22,9 @@ const del = (arr, ele) => {
22
22
  * @classdesc `{childNodes: [AttributesToken, Token]}`
23
23
  */
24
24
  class ExtToken extends index_3.TagPairToken {
25
- type = 'ext';
25
+ get type() {
26
+ return 'ext';
27
+ }
26
28
  /**
27
29
  * @param name 标签名
28
30
  * @param attr 标签属性
@@ -111,11 +113,13 @@ class ExtToken extends index_3.TagPairToken {
111
113
  default: {
112
114
  const { NowikiToken } = require('../nowiki/index');
113
115
  // @ts-expect-error abstract class
114
- innerToken = new NowikiToken(inner, newConfig);
116
+ innerToken = new NowikiToken(inner, newConfig, accum);
115
117
  }
116
118
  }
117
119
  innerToken.setAttribute('name', lcName);
118
- innerToken.type = 'ext-inner';
120
+ if (innerToken.type === 'plain') {
121
+ innerToken.type = 'ext-inner';
122
+ }
119
123
  super(name, attrToken, innerToken, closed, config, accum);
120
124
  this.seal('closed', true);
121
125
  }
@@ -6,10 +6,10 @@ import type { AstText, Token } from '../../internal';
6
6
  * @classdesc `{childNodes: [AstText, AstText]}`
7
7
  */
8
8
  export declare abstract class IncludeToken extends TagPairToken {
9
- readonly type = "include";
10
9
  readonly childNodes: readonly [AstText, AstText];
11
10
  abstract get firstChild(): AstText;
12
11
  abstract get lastChild(): AstText;
12
+ get type(): 'include';
13
13
  /**
14
14
  * @param name 标签名
15
15
  * @param attr 标签属性
@@ -44,7 +44,7 @@ const index_2 = require("./index");
44
44
  * @classdesc `{childNodes: [AstText, AstText]}`
45
45
  */
46
46
  let IncludeToken = (() => {
47
- let _classDecorators = [(0, hidden_1.hiddenToken)()];
47
+ let _classDecorators = [(0, hidden_1.hiddenToken)(false)];
48
48
  let _classDescriptor;
49
49
  let _classExtraInitializers = [];
50
50
  let _classThis;
@@ -58,7 +58,9 @@ let IncludeToken = (() => {
58
58
  if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
59
59
  __runInitializers(_classThis, _classExtraInitializers);
60
60
  }
61
- type = 'include';
61
+ get type() {
62
+ return 'include';
63
+ }
62
64
  /**
63
65
  * @param name 标签名
64
66
  * @param attr 标签属性
@@ -69,6 +71,10 @@ let IncludeToken = (() => {
69
71
  super(name, attr, inner ?? '', inner === undefined ? closed : closed ?? '', config, accum);
70
72
  }
71
73
  /** @private */
74
+ toString(skip) {
75
+ return skip ? '' : super.toString();
76
+ }
77
+ /** @private */
72
78
  lint(start = this.getAbsoluteIndex()) {
73
79
  if (this.closed) {
74
80
  return [];
@@ -4,10 +4,10 @@ import type { AstNodes } from '../../lib/node';
4
4
  /** 成对标签 */
5
5
  export declare abstract class TagPairToken extends Token {
6
6
  #private;
7
- type: 'ext' | 'include';
8
7
  readonly name: string;
9
8
  closed: boolean;
10
9
  selfClosing: boolean;
10
+ abstract get type(): 'ext' | 'include';
11
11
  readonly childNodes: readonly [AstNodes, AstNodes];
12
12
  abstract get firstChild(): AstNodes;
13
13
  abstract get lastChild(): AstNodes;
@@ -28,11 +28,11 @@ class TagPairToken extends index_1.Token {
28
28
  accum.splice(index === -1 ? Infinity : index, 0, this);
29
29
  }
30
30
  /** @private */
31
- toString() {
31
+ toString(skip) {
32
32
  const { selfClosing, firstChild, lastChild, } = this, [opening, closing] = this.#tags;
33
33
  return selfClosing
34
- ? `<${opening}${firstChild.toString()}/>`
35
- : `<${opening}${firstChild.toString()}>${lastChild.toString()}${this.closed ? `</${closing}>` : ''}`;
34
+ ? `<${opening}${firstChild.toString(skip)}/>`
35
+ : `<${opening}${firstChild.toString(skip)}>${lastChild.toString(skip)}${this.closed ? `</${closing}>` : ''}`;
36
36
  }
37
37
  /** @private */
38
38
  text() {
@@ -10,11 +10,11 @@ import type { LintError } from '../base';
10
10
  */
11
11
  export declare abstract class TranscludeToken extends Token {
12
12
  #private;
13
- type: 'template' | 'magic-word';
14
13
  readonly modifier: string;
15
14
  readonly childNodes: readonly [AtomToken | SyntaxToken, ...ParameterToken[]] | readonly [SyntaxToken, AtomToken, AtomToken, ...ParameterToken[]];
16
15
  abstract get firstChild(): AtomToken | SyntaxToken;
17
16
  abstract get lastChild(): AtomToken | SyntaxToken | ParameterToken;
17
+ get type(): 'template' | 'magic-word';
18
18
  /**
19
19
  * @param title 模板标题或魔术字
20
20
  * @param parts 参数各部分
@@ -24,10 +24,13 @@ const insensitiveVars = new Set([
24
24
  * @classdesc `{childNodes: [AtomToken|SyntaxToken, ...AtomToken, ...ParameterToken]}`
25
25
  */
26
26
  class TranscludeToken extends index_2.Token {
27
- type = 'template';
28
27
  modifier = '';
28
+ #type = 'template';
29
29
  #raw = false;
30
30
  #args = new Map();
31
+ get type() {
32
+ return this.#type;
33
+ }
31
34
  /**
32
35
  * @param title 模板标题或魔术字
33
36
  * @param parts 参数各部分
@@ -51,7 +54,7 @@ class TranscludeToken extends index_2.Token {
51
54
  const [magicWord, ...arg] = title.split(':'), cleaned = (0, string_1.removeComment)(magicWord), name = cleaned[arg.length > 0 ? 'trimStart' : 'trim'](), lcName = name.toLowerCase(), canonicalName = insensitive[lcName], isSensitive = sensitive.includes(name), isVar = isSensitive || insensitiveVars.has(canonicalName);
52
55
  if (isVar || isFunction && canonicalName) {
53
56
  this.setAttribute('name', canonicalName ?? lcName);
54
- this.type = 'magic-word';
57
+ this.#type = 'magic-word';
55
58
  const pattern = new RegExp(String.raw `^\s*${name}\s*$`, isSensitive ? 'u' : 'iu'), token = new syntax_1.SyntaxToken(magicWord, pattern, 'magic-word-name', config, accum, {});
56
59
  super.insertAt(token);
57
60
  if (arg.length > 0) {
@@ -121,7 +124,7 @@ class TranscludeToken extends index_2.Token {
121
124
  /** 获取模板或模块名 */
122
125
  #getTitle() {
123
126
  const isTemplate = this.type === 'template', child = this.childNodes[isTemplate ? 0 : 1];
124
- return this.normalizeTitle(child.text(), isTemplate ? 10 : 828);
127
+ return this.normalizeTitle(child.toString(true), isTemplate ? 10 : 828);
125
128
  }
126
129
  /** @private */
127
130
  afterBuild() {
@@ -131,10 +134,10 @@ class TranscludeToken extends index_2.Token {
131
134
  super.afterBuild();
132
135
  }
133
136
  /** @private */
134
- toString() {
137
+ toString(skip) {
135
138
  return `{{${this.modifier}${this.type === 'magic-word'
136
- ? `${this.firstChild.toString()}${this.length === 1 ? '' : ':'}${this.childNodes.slice(1).map(String).join('|')}`
137
- : super.toString('|')}}}`;
139
+ ? `${this.firstChild.toString(skip)}${this.length === 1 ? '' : ':'}${this.childNodes.slice(1).map(child => child.toString(skip)).join('|')}`
140
+ : super.toString(skip, '|')}}}`;
138
141
  }
139
142
  /** @private */
140
143
  text() {
@@ -160,25 +163,26 @@ class TranscludeToken extends index_2.Token {
160
163
  }
161
164
  /** @private */
162
165
  lint(start = this.getAbsoluteIndex(), re) {
163
- const errors = super.lint(start, re), { type, childNodes, length } = this, rect = new rect_1.BoundingRect(this, start);
166
+ const errors = super.lint(start, re);
164
167
  if (!this.isTemplate()) {
165
168
  return errors;
166
169
  }
167
- const title = this.#getTitle();
168
- if (title.fragment !== undefined) {
169
- const child = childNodes[type === 'template' ? 0 : 1], e = (0, lint_1.generateForChild)(child, rect, 'no-ignored', 'useless fragment'), textNode = child.childNodes.find((c) => c.type === 'text' && c.data.includes('#'));
170
+ const { type, childNodes, length } = this, rect = new rect_1.BoundingRect(this, start), invoke = type === 'magic-word';
171
+ if (invoke && !this.#getTitle().valid) {
172
+ errors.push((0, lint_1.generateForChild)(childNodes[1], rect, 'invalid-invoke', 'illegal module name'));
173
+ }
174
+ else {
175
+ const child = childNodes[invoke ? 1 : 0], textNode = child.childNodes.find((c) => c.type === 'text' && c.data.includes('#'));
170
176
  if (textNode) {
177
+ const e = (0, lint_1.generateForChild)(child, rect, 'no-ignored', 'useless fragment');
171
178
  e.fix = {
172
179
  range: [e.startIndex + textNode.getRelativeIndex() + textNode.data.indexOf('#'), e.endIndex],
173
180
  text: '',
174
181
  };
182
+ errors.push(e);
175
183
  }
176
- errors.push(e);
177
- }
178
- if (!title.valid) {
179
- errors.push((0, lint_1.generateForChild)(childNodes[1], rect, 'invalid-invoke', 'illegal module name'));
180
184
  }
181
- if (type === 'magic-word' && length === 2) {
185
+ if (invoke && length === 2) {
182
186
  errors.push((0, lint_1.generateForSelf)(this, rect, 'invalid-invoke', 'missing module function'));
183
187
  return errors;
184
188
  }
package/dist/util/lint.js CHANGED
@@ -8,7 +8,7 @@ const index_1 = require("../index");
8
8
  * @param func lint函数
9
9
  */
10
10
  const factory = (func) => (token, rect, rule, msg, severity = 'error') => {
11
- const { start } = rect, { top, left } = 'top' in rect ? rect : new rect_1.BoundingRect(token, start), { offsetHeight, offsetWidth } = token, { startIndex, startLine, startCol } = func(token, start, top, left);
11
+ const { start } = rect, { top, left } = rect instanceof rect_1.BoundingRect ? rect : new rect_1.BoundingRect(token, start), { offsetHeight, offsetWidth } = token, { startIndex, startLine, startCol } = func(token, start, top, left);
12
12
  return {
13
13
  rule,
14
14
  message: index_1.default.msg(msg),
package/errors/README CHANGED
@@ -1 +1,3 @@
1
1
  这里记录解析失败时处于半解析状态的维基文本以及错误信息。
2
+
3
+ When parsing fails, the half-parsed wikitext and the error message are recorded here.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wikilint",
3
- "version": "2.9.2",
3
+ "version": "2.10.0",
4
4
  "description": "A Node.js linter for MediaWiki markup",
5
5
  "keywords": [
6
6
  "mediawiki",