wikilint 2.9.2 → 2.9.3

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 (99) hide show
  1. package/dist/base.d.ts +9 -3
  2. package/dist/lib/element.js +11 -11
  3. package/dist/lib/node.d.ts +4 -1
  4. package/dist/lib/text.d.ts +1 -1
  5. package/dist/lib/text.js +3 -2
  6. package/dist/parser/table.js +3 -3
  7. package/dist/src/arg.d.ts +1 -1
  8. package/dist/src/arg.js +3 -1
  9. package/dist/src/atom.d.ts +5 -2
  10. package/dist/src/atom.js +25 -1
  11. package/dist/src/attribute.d.ts +1 -1
  12. package/dist/src/attribute.js +5 -1
  13. package/dist/src/attributes.d.ts +2 -1
  14. package/dist/src/attributes.js +5 -1
  15. package/dist/src/converter.d.ts +1 -1
  16. package/dist/src/converter.js +3 -1
  17. package/dist/src/converterFlags.d.ts +1 -1
  18. package/dist/src/converterFlags.js +3 -1
  19. package/dist/src/converterRule.d.ts +1 -1
  20. package/dist/src/converterRule.js +3 -1
  21. package/dist/src/extLink.d.ts +1 -1
  22. package/dist/src/extLink.js +3 -1
  23. package/dist/src/gallery.d.ts +1 -1
  24. package/dist/src/gallery.js +5 -3
  25. package/dist/src/heading.d.ts +1 -1
  26. package/dist/src/heading.js +3 -1
  27. package/dist/src/hidden.d.ts +1 -1
  28. package/dist/src/hidden.js +3 -1
  29. package/dist/src/html.d.ts +1 -1
  30. package/dist/src/html.js +3 -1
  31. package/dist/src/imageParameter.d.ts +1 -1
  32. package/dist/src/imageParameter.js +3 -1
  33. package/dist/src/imagemap.d.ts +1 -1
  34. package/dist/src/imagemap.js +3 -1
  35. package/dist/src/imagemapLink.d.ts +1 -1
  36. package/dist/src/imagemapLink.js +3 -1
  37. package/dist/src/index.d.ts +2 -1
  38. package/dist/src/index.js +7 -1
  39. package/dist/src/link/base.d.ts +1 -1
  40. package/dist/src/link/category.d.ts +1 -1
  41. package/dist/src/link/category.js +3 -1
  42. package/dist/src/link/file.d.ts +1 -1
  43. package/dist/src/link/file.js +3 -1
  44. package/dist/src/link/galleryImage.d.ts +1 -2
  45. package/dist/src/link/galleryImage.js +7 -13
  46. package/dist/src/link/index.d.ts +1 -1
  47. package/dist/src/link/index.js +3 -1
  48. package/dist/src/link/redirectTarget.d.ts +1 -1
  49. package/dist/src/link/redirectTarget.js +3 -1
  50. package/dist/src/magicLink.d.ts +2 -1
  51. package/dist/src/magicLink.js +7 -3
  52. package/dist/src/nested.d.ts +1 -1
  53. package/dist/src/nested.js +3 -1
  54. package/dist/src/nowiki/base.d.ts +1 -1
  55. package/dist/src/nowiki/comment.d.ts +1 -1
  56. package/dist/src/nowiki/comment.js +3 -1
  57. package/dist/src/nowiki/dd.d.ts +1 -1
  58. package/dist/src/nowiki/dd.js +3 -1
  59. package/dist/src/nowiki/doubleUnderscore.d.ts +1 -1
  60. package/dist/src/nowiki/doubleUnderscore.js +3 -1
  61. package/dist/src/nowiki/hr.d.ts +1 -1
  62. package/dist/src/nowiki/hr.js +3 -1
  63. package/dist/src/nowiki/index.d.ts +1 -1
  64. package/dist/src/nowiki/index.js +3 -1
  65. package/dist/src/nowiki/list.d.ts +1 -1
  66. package/dist/src/nowiki/list.js +3 -1
  67. package/dist/src/nowiki/listBase.d.ts +1 -1
  68. package/dist/src/nowiki/noinclude.d.ts +1 -1
  69. package/dist/src/nowiki/noinclude.js +3 -1
  70. package/dist/src/nowiki/quote.d.ts +1 -1
  71. package/dist/src/nowiki/quote.js +3 -1
  72. package/dist/src/onlyinclude.d.ts +1 -1
  73. package/dist/src/onlyinclude.js +3 -1
  74. package/dist/src/paramTag/index.d.ts +1 -1
  75. package/dist/src/paramTag/index.js +3 -1
  76. package/dist/src/parameter.d.ts +1 -2
  77. package/dist/src/parameter.js +3 -2
  78. package/dist/src/pre.d.ts +1 -1
  79. package/dist/src/pre.js +3 -1
  80. package/dist/src/redirect.d.ts +1 -1
  81. package/dist/src/redirect.js +3 -1
  82. package/dist/src/syntax.d.ts +4 -3
  83. package/dist/src/syntax.js +6 -2
  84. package/dist/src/table/base.d.ts +1 -1
  85. package/dist/src/table/index.d.ts +1 -1
  86. package/dist/src/table/index.js +3 -1
  87. package/dist/src/table/td.d.ts +1 -5
  88. package/dist/src/table/td.js +3 -5
  89. package/dist/src/table/tr.d.ts +1 -1
  90. package/dist/src/table/tr.js +3 -1
  91. package/dist/src/table/trBase.d.ts +1 -1
  92. package/dist/src/tagPair/ext.d.ts +1 -1
  93. package/dist/src/tagPair/ext.js +7 -3
  94. package/dist/src/tagPair/include.d.ts +1 -1
  95. package/dist/src/tagPair/include.js +3 -1
  96. package/dist/src/tagPair/index.d.ts +1 -1
  97. package/dist/src/transclude.d.ts +1 -1
  98. package/dist/src/transclude.js +5 -2
  99. package/package.json +1 -1
package/dist/base.d.ts CHANGED
@@ -43,8 +43,14 @@ export interface AstNode {
43
43
  /** Linter */
44
44
  lint(): LintError[];
45
45
  }
46
- /** 类似HTMLElement */
47
- interface AstElement extends AstNode {
46
+ /** 所有节点的基类 */
47
+ interface Token extends AstNode {
48
+ readonly name?: string;
49
+ /**
50
+ * 符合选择器的所有后代节点
51
+ * @param selector 选择器
52
+ */
53
+ querySelectorAll<T = Token>(selector: string): T[];
48
54
  }
49
55
  export interface Parser {
50
56
  config: Config | string;
@@ -56,6 +62,6 @@ export interface Parser {
56
62
  * @param include 是否嵌入
57
63
  * @param maxStage 最大解析层级
58
64
  */
59
- parse(wikitext: string, include?: boolean, maxStage?: number, config?: Config): AstElement;
65
+ parse(wikitext: string, include?: boolean, maxStage?: number, config?: Config): Token;
60
66
  }
61
67
  export {};
@@ -4,6 +4,14 @@ exports.AstElement = void 0;
4
4
  const string_1 = require("../util/string");
5
5
  const debug_1 = require("../util/debug");
6
6
  const node_1 = require("./node");
7
+ /**
8
+ * 将选择器转化为类型谓词
9
+ * @param selector 选择器
10
+ */
11
+ const getCondition = (selector) => {
12
+ const types = new Set(selector.split(',').map(str => str.trim()));
13
+ return (({ type }) => types.has(type));
14
+ };
7
15
  /** 类似HTMLElement */
8
16
  class AstElement extends node_1.AstNode {
9
17
  /** 子节点总数 */
@@ -51,20 +59,12 @@ class AstElement extends node_1.AstNode {
51
59
  (0, debug_1.setChildNodes)(this, i, 0, [node]);
52
60
  return node;
53
61
  }
54
- /**
55
- * 将选择器转化为类型谓词
56
- * @param selector 选择器
57
- */
58
- #getCondition(selector) {
59
- const types = new Set(selector.split(',').map(str => str.trim()));
60
- return (({ type }) => types.has(type));
61
- }
62
62
  /**
63
63
  * 最近的祖先节点
64
64
  * @param selector 选择器
65
65
  */
66
66
  closest(selector) {
67
- const condition = this.#getCondition(selector);
67
+ const condition = getCondition(selector);
68
68
  let { parentNode } = this;
69
69
  while (parentNode) {
70
70
  if (condition(parentNode)) {
@@ -98,7 +98,7 @@ class AstElement extends node_1.AstNode {
98
98
  * @param selector 选择器
99
99
  */
100
100
  querySelector(selector) {
101
- const condition = this.#getCondition(selector);
101
+ const condition = getCondition(selector);
102
102
  return this.#getElementBy(condition);
103
103
  }
104
104
  /**
@@ -123,7 +123,7 @@ class AstElement extends node_1.AstNode {
123
123
  * @param selector 选择器
124
124
  */
125
125
  querySelectorAll(selector) {
126
- const condition = this.#getCondition(selector);
126
+ const condition = getCondition(selector);
127
127
  return this.#getElementsBy(condition);
128
128
  }
129
129
  /**
@@ -16,9 +16,12 @@ export interface CaretPosition {
16
16
  /** 类似Node */
17
17
  export declare abstract class AstNode implements AstNodeBase {
18
18
  #private;
19
- type: TokenTypes | 'text';
20
19
  data?: string | undefined;
21
20
  readonly childNodes: readonly AstNodes[];
21
+ /** 节点类型 */
22
+ abstract get type(): TokenTypes | 'text';
23
+ abstract set type(value: TokenTypes | 'text');
24
+ text(): string;
22
25
  lint(): LintError[];
23
26
  /** 首位子节点 */
24
27
  get firstChild(): AstNodes | undefined;
@@ -3,9 +3,9 @@ import type { LintError } from '../base';
3
3
  /** 文本节点 */
4
4
  export declare class AstText extends AstNode {
5
5
  #private;
6
- readonly type = "text";
7
6
  readonly name: undefined;
8
7
  readonly data: string;
8
+ get type(): 'text';
9
9
  /** @param text 包含文本 */
10
10
  constructor(text: string);
11
11
  /** 可见部分 */
package/dist/lib/text.js CHANGED
@@ -45,14 +45,15 @@ const source = String.raw `<\s*(?:/\s*)?([a-z]\w*)|\{+|\}+|\[{2,}|\[(?![^[]*?\])
45
45
  ];
46
46
  /** 文本节点 */
47
47
  class AstText extends node_1.AstNode {
48
- type = 'text';
49
48
  data = '';
49
+ get type() {
50
+ return 'text';
51
+ }
50
52
  /** @param text 包含文本 */
51
53
  constructor(text) {
52
54
  super();
53
55
  Object.defineProperties(this, {
54
56
  childNodes: { enumerable: false, configurable: false },
55
- type: { enumerable: false, writable: false },
56
57
  data: {
57
58
  value: text,
58
59
  },
@@ -101,19 +101,19 @@ const parseTable = ({ firstChild: { data }, type, name }, config, accum) => {
101
101
  * 创建表格单元格
102
102
  * @param tr 当前表格行
103
103
  */
104
- const createTd = (tr) => {
104
+ const newTd = (tr) => {
105
105
  // @ts-expect-error abstract class
106
106
  const td = new td_1.TdToken(lastSyntax, attr.slice(lastIndex, mt?.index), config, accum);
107
107
  tr.insertAt(td);
108
108
  return td;
109
109
  };
110
110
  while (mt) {
111
- createTd(top);
111
+ newTd(top);
112
112
  ({ lastIndex } = regex);
113
113
  [lastSyntax] = mt;
114
114
  mt = regex.exec(attr);
115
115
  }
116
- stack.push(top, createTd(top));
116
+ stack.push(top, newTd(top));
117
117
  }
118
118
  }
119
119
  return out.slice(1);
package/dist/src/arg.d.ts CHANGED
@@ -8,10 +8,10 @@ import type { LintError } from '../base';
8
8
  * @classdesc `{childNodes: [AtomToken, ?Token, ...HiddenToken]}`
9
9
  */
10
10
  export declare abstract class ArgToken extends Token {
11
- readonly type = "arg";
12
11
  readonly childNodes: readonly [AtomToken] | readonly [AtomToken, Token, ...HiddenToken[]];
13
12
  abstract get firstChild(): AtomToken;
14
13
  abstract get lastChild(): Token;
14
+ get type(): 'arg';
15
15
  /** 预设值 */
16
16
  get default(): string | false;
17
17
  /** @param parts 以'|'分隔的各部分 */
package/dist/src/arg.js CHANGED
@@ -13,7 +13,9 @@ const hidden_1 = require("./hidden");
13
13
  * @classdesc `{childNodes: [AtomToken, ?Token, ...HiddenToken]}`
14
14
  */
15
15
  class ArgToken extends index_2.Token {
16
- type = 'arg';
16
+ get type() {
17
+ return 'arg';
18
+ }
17
19
  /** 预设值 */
18
20
  get default() {
19
21
  return this.childNodes[1]?.text() ?? false;
@@ -1,9 +1,12 @@
1
1
  import { Token } from './index';
2
2
  import type { Config } from '../base';
3
- declare type AtomTypes = 'arg-name' | 'attr-key' | 'attr-value' | 'ext-attr-dirty' | 'html-attr-dirty' | 'table-attr-dirty' | 'converter-flag' | 'converter-rule-variant' | 'converter-rule-to' | 'converter-rule-from' | 'invoke-function' | 'invoke-module' | 'template-name' | 'link-target' | 'param-line';
3
+ declare const atomTypes: readonly ["arg-name", "attr-key", "attr-value", "ext-attr-dirty", "html-attr-dirty", "table-attr-dirty", "converter-flag", "converter-rule-variant", "converter-rule-to", "converter-rule-from", "invoke-function", "invoke-module", "template-name", "link-target", "param-line"];
4
+ declare type AtomTypes = typeof atomTypes[number];
4
5
  /** 不会被继续解析的plain Token */
5
6
  export declare class AtomToken extends Token {
6
- type: AtomTypes;
7
+ #private;
8
+ get type(): AtomTypes;
9
+ set type(value: AtomTypes);
7
10
  /** @class */
8
11
  constructor(wikitext: string | undefined, type: AtomTypes, config?: Config, accum?: Token[], acceptable?: Acceptable);
9
12
  }
package/dist/src/atom.js CHANGED
@@ -2,12 +2,36 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.AtomToken = void 0;
4
4
  const index_1 = require("./index");
5
+ const atomTypes = [
6
+ 'arg-name',
7
+ 'attr-key',
8
+ 'attr-value',
9
+ 'ext-attr-dirty',
10
+ 'html-attr-dirty',
11
+ 'table-attr-dirty',
12
+ 'converter-flag',
13
+ 'converter-rule-variant',
14
+ 'converter-rule-to',
15
+ 'converter-rule-from',
16
+ 'invoke-function',
17
+ 'invoke-module',
18
+ 'template-name',
19
+ 'link-target',
20
+ 'param-line',
21
+ ];
5
22
  /** 不会被继续解析的plain Token */
6
23
  class AtomToken extends index_1.Token {
24
+ #type;
25
+ get type() {
26
+ return this.#type;
27
+ }
28
+ set type(value) {
29
+ this.#type = value;
30
+ }
7
31
  /** @class */
8
32
  constructor(wikitext, type, config, accum, acceptable) {
9
33
  super(wikitext, config, accum, acceptable);
10
- this.type = type;
34
+ this.#type = type;
11
35
  }
12
36
  }
13
37
  exports.AtomToken = AtomToken;
@@ -10,7 +10,6 @@ export type AttributeTypes = 'ext-attr' | 'html-attr' | 'table-attr';
10
10
  */
11
11
  export declare abstract class AttributeToken extends Token {
12
12
  #private;
13
- type: AttributeTypes;
14
13
  readonly name: string;
15
14
  readonly childNodes: readonly [AtomToken, Token];
16
15
  abstract get firstChild(): AtomToken;
@@ -18,6 +17,7 @@ export declare abstract class AttributeToken extends Token {
18
17
  abstract get parentNode(): AttributesToken | undefined;
19
18
  abstract get nextSibling(): AtomToken | this | undefined;
20
19
  abstract get previousSibling(): AtomToken | this | undefined;
20
+ get type(): AttributeTypes;
21
21
  /** 标签名 */
22
22
  get tag(): string;
23
23
  /** 引号是否匹配 */
@@ -170,9 +170,13 @@ const commonHtmlAttrs = new Set([
170
170
  * @classdesc `{childNodes: [AtomToken, Token|AtomToken]}`
171
171
  */
172
172
  class AttributeToken extends index_2.Token {
173
+ #type;
173
174
  #tag;
174
175
  #equal;
175
176
  #quotes;
177
+ get type() {
178
+ return this.#type;
179
+ }
176
180
  /** 标签名 */
177
181
  get tag() {
178
182
  return this.#tag;
@@ -219,7 +223,7 @@ class AttributeToken extends index_2.Token {
219
223
  valueToken = new atom_1.AtomToken(value, 'attr-value', config, accum, {});
220
224
  }
221
225
  super(undefined, config, accum);
222
- this.type = type;
226
+ this.#type = type;
223
227
  this.append(keyToken, valueToken);
224
228
  this.#equal = equal;
225
229
  this.#quotes = [...quotes];
@@ -11,12 +11,13 @@ declare type AttributesTypes = `${AttributeTypes}s`;
11
11
  * @classdesc `{childNodes: ...AtomToken|AttributeToken}`
12
12
  */
13
13
  export declare abstract class AttributesToken extends Token {
14
- type: AttributesTypes;
14
+ #private;
15
15
  readonly name: string;
16
16
  readonly childNodes: readonly (AtomToken | AttributeToken)[];
17
17
  abstract get firstChild(): AtomToken | AttributeToken | undefined;
18
18
  abstract get lastChild(): AtomToken | AttributeToken | undefined;
19
19
  abstract get parentNode(): ExtToken | HtmlToken | TableToken | TrToken | TdToken | undefined;
20
+ get type(): AttributesTypes;
20
21
  /**
21
22
  * @param attr 标签属性
22
23
  * @param type 标签类型
@@ -24,6 +24,10 @@ const toDirty = (type) => `${toAttributeType(type)}-dirty`;
24
24
  * @classdesc `{childNodes: ...AtomToken|AttributeToken}`
25
25
  */
26
26
  class AttributesToken extends index_2.Token {
27
+ #type;
28
+ get type() {
29
+ return this.#type;
30
+ }
27
31
  /**
28
32
  * @param attr 标签属性
29
33
  * @param type 标签类型
@@ -31,7 +35,7 @@ class AttributesToken extends index_2.Token {
31
35
  */
32
36
  constructor(attr, type, name, config = index_1.default.getConfig(), accum = []) {
33
37
  super(undefined, config, accum, {});
34
- this.type = type;
38
+ this.#type = type;
35
39
  this.setAttribute('name', name);
36
40
  if (attr) {
37
41
  regex.lastIndex = 0;
@@ -7,10 +7,10 @@ import { ConverterRuleToken } from './converterRule';
7
7
  * @classdesc `{childNodes: [ConverterFlagsToken, ...ConverterRuleToken]}`
8
8
  */
9
9
  export declare abstract class ConverterToken extends Token {
10
- readonly type = "converter";
11
10
  readonly childNodes: readonly [ConverterFlagsToken, ...ConverterRuleToken[]];
12
11
  abstract get firstChild(): ConverterFlagsToken;
13
12
  abstract get lastChild(): ConverterFlagsToken | ConverterRuleToken;
13
+ get type(): 'converter';
14
14
  /**
15
15
  * @param flags 转换类型标记
16
16
  * @param rules 转换规则
@@ -11,7 +11,9 @@ const converterRule_1 = require("./converterRule");
11
11
  * @classdesc `{childNodes: [ConverterFlagsToken, ...ConverterRuleToken]}`
12
12
  */
13
13
  class ConverterToken extends index_2.Token {
14
- type = 'converter';
14
+ get type() {
15
+ return 'converter';
16
+ }
15
17
  /**
16
18
  * @param flags 转换类型标记
17
19
  * @param rules 转换规则
@@ -9,13 +9,13 @@ import type { ConverterToken, ConverterRuleToken } from '../internal';
9
9
  */
10
10
  export declare abstract class ConverterFlagsToken extends Token {
11
11
  #private;
12
- readonly type = "converter-flags";
13
12
  readonly childNodes: readonly AtomToken[];
14
13
  abstract get firstChild(): AtomToken | undefined;
15
14
  abstract get lastChild(): AtomToken | undefined;
16
15
  abstract get parentNode(): ConverterToken | undefined;
17
16
  abstract get previousSibling(): undefined;
18
17
  abstract get nextSibling(): ConverterRuleToken | undefined;
18
+ get type(): 'converter-flags';
19
19
  /** @param flags 转换类型标记 */
20
20
  constructor(flags: readonly string[], config?: Parser.Config, accum?: Token[]);
21
21
  /** 获取未知的转换类型标记 */
@@ -12,8 +12,10 @@ const definedFlags = new Set(['A', 'T', 'R', 'D', '-', 'H', 'N']);
12
12
  * @classdesc `{childNodes: ...AtomToken}`
13
13
  */
14
14
  class ConverterFlagsToken extends index_2.Token {
15
- type = 'converter-flags';
16
15
  #flags;
16
+ get type() {
17
+ return 'converter-flags';
18
+ }
17
19
  /** @param flags 转换类型标记 */
18
20
  constructor(flags, config = index_1.default.getConfig(), accum = []) {
19
21
  super(undefined, config, accum, {});
@@ -7,13 +7,13 @@ import type { ConverterToken, ConverterFlagsToken } from '../internal';
7
7
  * @classdesc `{childNodes: ...AtomToken}`
8
8
  */
9
9
  export declare abstract class ConverterRuleToken extends Token {
10
- readonly type = "converter-rule";
11
10
  readonly childNodes: readonly [AtomToken] | readonly [AtomToken, AtomToken] | readonly [AtomToken, AtomToken, AtomToken];
12
11
  abstract get firstChild(): AtomToken;
13
12
  abstract get lastChild(): AtomToken;
14
13
  abstract get parentNode(): ConverterToken | undefined;
15
14
  abstract get previousSibling(): ConverterFlagsToken | this;
16
15
  abstract get nextSibling(): this | undefined;
16
+ get type(): 'converter-rule';
17
17
  /**
18
18
  * @param rule 转换规则
19
19
  * @param hasColon 是否带有":"
@@ -9,7 +9,9 @@ const atom_1 = require("./atom");
9
9
  * @classdesc `{childNodes: ...AtomToken}`
10
10
  */
11
11
  class ConverterRuleToken extends index_2.Token {
12
- type = 'converter-rule';
12
+ get type() {
13
+ return 'converter-rule';
14
+ }
13
15
  /**
14
16
  * @param rule 转换规则
15
17
  * @param hasColon 是否带有":"
@@ -8,10 +8,10 @@ import type { LintError } from '../base';
8
8
  */
9
9
  export declare abstract class ExtLinkToken extends Token {
10
10
  #private;
11
- readonly type = "ext-link";
12
11
  readonly childNodes: readonly [MagicLinkToken] | readonly [MagicLinkToken, Token];
13
12
  abstract get firstChild(): MagicLinkToken;
14
13
  abstract get lastChild(): Token;
14
+ get type(): 'ext-link';
15
15
  /**
16
16
  * @param url 网址
17
17
  * @param space 空白字符
@@ -11,8 +11,10 @@ const magicLink_1 = require("./magicLink");
11
11
  * @classdesc `{childNodes: [MagicLinkToken, ?Token]}`
12
12
  */
13
13
  class ExtLinkToken extends index_2.Token {
14
- type = 'ext-link';
15
14
  #space;
15
+ get type() {
16
+ return 'ext-link';
17
+ }
16
18
  /**
17
19
  * @param url 网址
18
20
  * @param space 空白字符
@@ -10,7 +10,6 @@ import type { AstText, AttributesToken, ExtToken } from '../internal';
10
10
  */
11
11
  export declare abstract class GalleryToken extends Token {
12
12
  #private;
13
- readonly type = "ext-inner";
14
13
  readonly name: 'gallery';
15
14
  readonly childNodes: readonly (GalleryImageToken | NoincludeToken | AstText)[];
16
15
  abstract get firstChild(): GalleryImageToken | NoincludeToken | AstText | undefined;
@@ -18,6 +17,7 @@ export declare abstract class GalleryToken extends Token {
18
17
  abstract get nextSibling(): undefined;
19
18
  abstract get previousSibling(): AttributesToken;
20
19
  abstract get parentNode(): ExtToken | undefined;
20
+ get type(): 'ext-inner';
21
21
  /** @param inner 标签内部wikitext */
22
22
  constructor(inner?: string, config?: Parser.Config, accum?: Token[]);
23
23
  }
@@ -10,7 +10,9 @@ const noinclude_1 = require("./nowiki/noinclude");
10
10
  * @classdesc `{childNodes: ...(GalleryImageToken|NoincludeToken|AstText)}`
11
11
  */
12
12
  class GalleryToken extends index_2.Token {
13
- type = 'ext-inner';
13
+ get type() {
14
+ return 'ext-inner';
15
+ }
14
16
  /** @param inner 标签内部wikitext */
15
17
  constructor(inner, config = index_1.default.getConfig(), accum = []) {
16
18
  super(undefined, config, accum, {});
@@ -18,7 +20,7 @@ class GalleryToken extends index_2.Token {
18
20
  const matches = /^([^|]+)(?:\|(.*))?/u.exec(line);
19
21
  if (!matches) {
20
22
  // @ts-expect-error abstract class
21
- super.insertAt((line.trim() ? new noinclude_1.NoincludeToken(line, config) : line));
23
+ super.insertAt((line.trim() ? new noinclude_1.NoincludeToken(line, config, accum) : line));
22
24
  continue;
23
25
  }
24
26
  const [, file, alt] = matches;
@@ -28,7 +30,7 @@ class GalleryToken extends index_2.Token {
28
30
  }
29
31
  else {
30
32
  // @ts-expect-error abstract class
31
- super.insertAt(new noinclude_1.NoincludeToken(line, config));
33
+ super.insertAt(new noinclude_1.NoincludeToken(line, config, accum));
32
34
  }
33
35
  }
34
36
  }
@@ -8,10 +8,10 @@ import type { LintError } from '../base';
8
8
  */
9
9
  export declare abstract class HeadingToken extends Token {
10
10
  #private;
11
- readonly type = "heading";
12
11
  readonly childNodes: readonly [Token, SyntaxToken];
13
12
  abstract get firstChild(): Token;
14
13
  abstract get lastChild(): SyntaxToken;
14
+ get type(): 'heading';
15
15
  /** 标题层级 */
16
16
  get level(): number;
17
17
  /**
@@ -11,8 +11,10 @@ const syntax_1 = require("./syntax");
11
11
  * @classdesc `{childNodes: [Token, SyntaxToken]}`
12
12
  */
13
13
  class HeadingToken extends index_2.Token {
14
- type = 'heading';
15
14
  #level;
15
+ get type() {
16
+ return 'heading';
17
+ }
16
18
  /** 标题格式的等号 */
17
19
  get #equals() {
18
20
  return '='.repeat(this.level);
@@ -1,5 +1,5 @@
1
1
  import { Token } from './index';
2
2
  /** 不可见的节点 */
3
3
  export declare class HiddenToken extends Token {
4
- readonly type = "hidden";
4
+ get type(): 'hidden';
5
5
  }
@@ -53,7 +53,9 @@ let HiddenToken = (() => {
53
53
  if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
54
54
  __runInitializers(_classThis, _classExtraInitializers);
55
55
  }
56
- type = 'hidden';
56
+ get type() {
57
+ return 'hidden';
58
+ }
57
59
  };
58
60
  return HiddenToken = _classThis;
59
61
  })();
@@ -7,11 +7,11 @@ import type { AttributesToken } from '../internal';
7
7
  */
8
8
  export declare abstract class HtmlToken extends Token {
9
9
  #private;
10
- readonly type = "html";
11
10
  readonly name: string;
12
11
  readonly childNodes: readonly [AttributesToken];
13
12
  abstract get firstChild(): AttributesToken;
14
13
  abstract get lastChild(): AttributesToken;
14
+ get type(): 'html';
15
15
  /** 是否自封闭 */
16
16
  get selfClosing(): boolean;
17
17
  /** 是否是闭合标签 */
package/dist/src/html.js CHANGED
@@ -37,10 +37,12 @@ const magicWords = new Set(['if', 'ifeq', 'ifexpr', 'ifexist', 'iferror', 'switc
37
37
  * @classdesc `{childNodes: [AttributesToken]}`
38
38
  */
39
39
  class HtmlToken extends index_1.Token {
40
- type = 'html';
41
40
  #closing;
42
41
  #selfClosing;
43
42
  #tag;
43
+ get type() {
44
+ return 'html';
45
+ }
44
46
  /** 是否自封闭 */
45
47
  get selfClosing() {
46
48
  return this.#selfClosing;
@@ -7,11 +7,11 @@ export declare const galleryParams: Set<string>;
7
7
  /** 图片参数 */
8
8
  export declare abstract class ImageParameterToken extends Token {
9
9
  #private;
10
- readonly type = "image-parameter";
11
10
  readonly name: string;
12
11
  abstract get parentNode(): FileToken | undefined;
13
12
  abstract get nextSibling(): this | undefined;
14
13
  abstract get previousSibling(): AtomToken | this;
14
+ get type(): 'image-parameter';
15
15
  /** 图片链接 */
16
16
  get link(): string | Title | undefined;
17
17
  /** @param str 图片参数 */
@@ -40,8 +40,10 @@ function validate(key, val, config, halfParsed, ext) {
40
40
  }
41
41
  /** 图片参数 */
42
42
  class ImageParameterToken extends index_2.Token {
43
- type = 'image-parameter';
44
43
  #syntax = '';
44
+ get type() {
45
+ return 'image-parameter';
46
+ }
45
47
  /** 图片链接 */
46
48
  get link() {
47
49
  return this.name === 'link' ? validate('link', super.text(), this.getAttribute('config')) : undefined;
@@ -10,7 +10,6 @@ import type { AstText, AttributesToken, ExtToken } from '../internal';
10
10
  * @classdesc `{childNodes: ...NoincludeToken, GalleryImageToken, ...(NoincludeToken|ImagemapLinkToken|AstText)}`
11
11
  */
12
12
  export declare abstract class ImagemapToken extends Token {
13
- readonly type = "ext-inner";
14
13
  readonly name: 'imagemap';
15
14
  readonly childNodes: readonly (GalleryImageToken | NoincludeToken | ImagemapLinkToken | AstText)[];
16
15
  abstract get firstChild(): NoincludeToken | GalleryImageToken | undefined;
@@ -18,6 +17,7 @@ export declare abstract class ImagemapToken extends Token {
18
17
  abstract get nextSibling(): undefined;
19
18
  abstract get previousSibling(): AttributesToken;
20
19
  abstract get parentNode(): ExtToken | undefined;
20
+ get type(): 'ext-inner';
21
21
  /** 图片 */
22
22
  get image(): GalleryImageToken | undefined;
23
23
  /** @param inner 标签内部wikitext */
@@ -14,7 +14,9 @@ const imagemapLink_1 = require("./imagemapLink");
14
14
  * @classdesc `{childNodes: ...NoincludeToken, GalleryImageToken, ...(NoincludeToken|ImagemapLinkToken|AstText)}`
15
15
  */
16
16
  class ImagemapToken extends index_2.Token {
17
- type = 'ext-inner';
17
+ get type() {
18
+ return 'ext-inner';
19
+ }
18
20
  /** 图片 */
19
21
  get image() {
20
22
  return this.childNodes.find((0, debug_1.isToken)('imagemap-image'));
@@ -9,11 +9,11 @@ import type { AstText, ImagemapToken } from '../internal';
9
9
  * @classdesc `{childNodes: [AstText, LinkToken|ExtLinkToken, NoincludeToken]}`
10
10
  */
11
11
  export declare abstract class ImagemapLinkToken extends Token {
12
- readonly type = "imagemap-link";
13
12
  readonly childNodes: readonly [AstText, LinkToken | ExtLinkToken, NoincludeToken];
14
13
  abstract get firstChild(): AstText;
15
14
  abstract get lastChild(): NoincludeToken;
16
15
  abstract get parentNode(): ImagemapToken | undefined;
16
+ get type(): 'imagemap-link';
17
17
  /**
18
18
  * @param pre 链接前的文本
19
19
  * @param linkStuff 内外链接
@@ -11,7 +11,9 @@ const extLink_1 = require("./extLink");
11
11
  * @classdesc `{childNodes: [AstText, LinkToken|ExtLinkToken, NoincludeToken]}`
12
12
  */
13
13
  class ImagemapLinkToken extends index_2.Token {
14
- type = 'imagemap-link';
14
+ get type() {
15
+ return 'imagemap-link';
16
+ }
15
17
  /**
16
18
  * @param pre 链接前的文本
17
19
  * @param linkStuff 内外链接
@@ -10,7 +10,8 @@ import type { AstNodes } from '../internal';
10
10
  */
11
11
  export declare class Token extends AstElement {
12
12
  #private;
13
- type: TokenTypes;
13
+ get type(): TokenTypes;
14
+ set type(value: TokenTypes);
14
15
  /** @class */
15
16
  constructor(wikitext?: string, config?: Parser.Config, accum?: Token[], acceptable?: Acceptable);
16
17
  /**
package/dist/src/index.js CHANGED
@@ -53,7 +53,7 @@ const text_1 = require("../lib/text");
53
53
  * @classdesc `{childNodes: ...(AstText|Token)}`
54
54
  */
55
55
  class Token extends element_1.AstElement {
56
- type = 'plain';
56
+ #type = 'plain';
57
57
  /** 解析阶段,参见顶部注释。只对plain Token有意义。 */
58
58
  #stage = 0;
59
59
  #config;
@@ -62,6 +62,12 @@ class Token extends element_1.AstElement {
62
62
  #include;
63
63
  #built = false;
64
64
  #string;
65
+ get type() {
66
+ return this.#type;
67
+ }
68
+ set type(value) {
69
+ this.#type = value;
70
+ }
65
71
  /** @class */
66
72
  constructor(wikitext, config = index_1.default.getConfig(), accum = [], acceptable) {
67
73
  super();