wikiparser-node 1.9.2 → 1.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 (110) hide show
  1. package/dist/base.d.ts +9 -3
  2. package/dist/index.js +0 -1
  3. package/dist/lib/element.d.ts +1 -0
  4. package/dist/lib/element.js +23 -249
  5. package/dist/lib/node.d.ts +3 -1
  6. package/dist/lib/range.js +12 -12
  7. package/dist/lib/text.d.ts +2 -1
  8. package/dist/lib/text.js +8 -2
  9. package/dist/mixin/hidden.js +5 -0
  10. package/dist/mixin/syntax.js +2 -1
  11. package/dist/parser/selector.js +223 -20
  12. package/dist/parser/table.js +3 -3
  13. package/dist/src/arg.d.ts +1 -2
  14. package/dist/src/arg.js +3 -2
  15. package/dist/src/atom.d.ts +5 -3
  16. package/dist/src/atom.js +28 -2
  17. package/dist/src/attribute.d.ts +1 -2
  18. package/dist/src/attribute.js +5 -2
  19. package/dist/src/attributes.d.ts +1 -2
  20. package/dist/src/attributes.js +7 -2
  21. package/dist/src/converter.d.ts +1 -2
  22. package/dist/src/converter.js +5 -2
  23. package/dist/src/converterFlags.d.ts +1 -2
  24. package/dist/src/converterFlags.js +5 -2
  25. package/dist/src/converterRule.d.ts +1 -3
  26. package/dist/src/converterRule.js +5 -3
  27. package/dist/src/extLink.d.ts +1 -2
  28. package/dist/src/extLink.js +5 -2
  29. package/dist/src/gallery.d.ts +1 -2
  30. package/dist/src/gallery.js +7 -4
  31. package/dist/src/heading.d.ts +1 -2
  32. package/dist/src/heading.js +3 -2
  33. package/dist/src/hidden.d.ts +1 -2
  34. package/dist/src/hidden.js +3 -2
  35. package/dist/src/html.d.ts +1 -2
  36. package/dist/src/html.js +3 -2
  37. package/dist/src/imageParameter.d.ts +1 -2
  38. package/dist/src/imageParameter.js +3 -2
  39. package/dist/src/imagemap.d.ts +1 -2
  40. package/dist/src/imagemap.js +3 -2
  41. package/dist/src/imagemapLink.d.ts +1 -1
  42. package/dist/src/imagemapLink.js +5 -1
  43. package/dist/src/index.d.ts +2 -1
  44. package/dist/src/index.js +26 -1
  45. package/dist/src/link/base.d.ts +1 -2
  46. package/dist/src/link/base.js +5 -3
  47. package/dist/src/link/category.d.ts +1 -1
  48. package/dist/src/link/category.js +5 -1
  49. package/dist/src/link/file.d.ts +1 -1
  50. package/dist/src/link/file.js +3 -1
  51. package/dist/src/link/galleryImage.d.ts +1 -2
  52. package/dist/src/link/galleryImage.js +7 -33
  53. package/dist/src/link/index.d.ts +1 -2
  54. package/dist/src/link/index.js +5 -2
  55. package/dist/src/link/redirectTarget.d.ts +1 -2
  56. package/dist/src/link/redirectTarget.js +5 -2
  57. package/dist/src/magicLink.d.ts +2 -2
  58. package/dist/src/magicLink.js +8 -5
  59. package/dist/src/nested.d.ts +1 -2
  60. package/dist/src/nested.js +3 -2
  61. package/dist/src/nowiki/base.d.ts +1 -2
  62. package/dist/src/nowiki/base.js +1 -3
  63. package/dist/src/nowiki/comment.d.ts +1 -2
  64. package/dist/src/nowiki/comment.js +3 -2
  65. package/dist/src/nowiki/dd.d.ts +1 -1
  66. package/dist/src/nowiki/dd.js +3 -1
  67. package/dist/src/nowiki/doubleUnderscore.d.ts +1 -2
  68. package/dist/src/nowiki/doubleUnderscore.js +3 -2
  69. package/dist/src/nowiki/hr.d.ts +1 -1
  70. package/dist/src/nowiki/hr.js +3 -1
  71. package/dist/src/nowiki/index.d.ts +1 -1
  72. package/dist/src/nowiki/index.js +3 -1
  73. package/dist/src/nowiki/list.d.ts +1 -1
  74. package/dist/src/nowiki/list.js +3 -1
  75. package/dist/src/nowiki/listBase.d.ts +1 -1
  76. package/dist/src/nowiki/noinclude.d.ts +1 -5
  77. package/dist/src/nowiki/noinclude.js +3 -5
  78. package/dist/src/nowiki/quote.d.ts +1 -4
  79. package/dist/src/nowiki/quote.js +3 -4
  80. package/dist/src/onlyinclude.d.ts +1 -2
  81. package/dist/src/onlyinclude.js +3 -2
  82. package/dist/src/paramTag/index.d.ts +1 -2
  83. package/dist/src/paramTag/index.js +3 -2
  84. package/dist/src/parameter.d.ts +1 -7
  85. package/dist/src/parameter.js +3 -7
  86. package/dist/src/pre.d.ts +1 -2
  87. package/dist/src/pre.js +3 -2
  88. package/dist/src/redirect.d.ts +1 -2
  89. package/dist/src/redirect.js +3 -2
  90. package/dist/src/syntax.d.ts +4 -4
  91. package/dist/src/syntax.js +6 -3
  92. package/dist/src/table/base.d.ts +1 -2
  93. package/dist/src/table/base.js +0 -1
  94. package/dist/src/table/index.d.ts +1 -10
  95. package/dist/src/table/index.js +3 -10
  96. package/dist/src/table/td.d.ts +1 -7
  97. package/dist/src/table/td.js +3 -7
  98. package/dist/src/table/tr.d.ts +1 -1
  99. package/dist/src/table/tr.js +3 -1
  100. package/dist/src/table/trBase.d.ts +1 -1
  101. package/dist/src/tagPair/ext.d.ts +1 -2
  102. package/dist/src/tagPair/ext.js +7 -4
  103. package/dist/src/tagPair/include.d.ts +1 -3
  104. package/dist/src/tagPair/include.js +5 -3
  105. package/dist/src/tagPair/index.d.ts +1 -1
  106. package/dist/src/transclude.d.ts +1 -2
  107. package/dist/src/transclude.js +8 -5
  108. package/dist/util/constants.js +2 -2
  109. package/dist/util/debug.js +0 -2
  110. package/package.json +1 -1
@@ -1,8 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parseSelector = void 0;
3
+ exports.checkToken = void 0;
4
4
  const constants_1 = require("../util/constants");
5
5
  const string_1 = require("../util/string");
6
+ const ranges_1 = require("../lib/ranges");
7
+ const title_1 = require("../lib/title");
6
8
  const simplePseudos = new Set([
7
9
  'root',
8
10
  'first-child',
@@ -22,8 +24,7 @@ const simplePseudos = new Set([
22
24
  'invalid',
23
25
  'required',
24
26
  'optional',
25
- ]);
26
- const complexPseudos = new Set([
27
+ ]), complexPseudos = new Set([
27
28
  'is',
28
29
  'not',
29
30
  'nth-child',
@@ -34,8 +35,7 @@ const complexPseudos = new Set([
34
35
  'has',
35
36
  'lang',
36
37
  'regex',
37
- ]);
38
- const specialChars = [
38
+ ]), specialChars = [
39
39
  ['[', '['],
40
40
  [']', ']'],
41
41
  ['(', '('],
@@ -45,17 +45,218 @@ const specialChars = [
45
45
  [':', ':'],
46
46
  ['\\', '\'],
47
47
  ['&', '&'],
48
- ];
49
- const regularRegex = /[[(,>+~]|\s+/u, attributeRegex = /^\s*(\w+)\s*(?:([~|^$*!]?=)\s*("[^"]*"|'[^']*'|[^\s[\]]+)(?:\s+(i))?\s*)?\]/u, functionRegex = /^(\s*"[^"]*"\s*|\s*'[^']*'\s*|[^()]*)\)/u, grouping = new Set([',', '>', '+', '~']), combinator = new Set(['>', '+', '~', '']), sanitizeRegex = specialChars.map(([c, escaped]) => [new RegExp((0, string_1.escapeRegExp)(`\\${c}`), 'gu'), escaped]), desanitizeRegex = specialChars.map(([c, escaped]) => [c, new RegExp(escaped, 'gu')]);
48
+ ], regularRegex = /[[(,>+~]|\s+/u, attributeRegex = /^\s*(\w+)\s*(?:([~|^$*!]?=)\s*("[^"]*"|'[^']*'|[^\s[\]]+)(?:\s+(i))?\s*)?\]/u, functionRegex = /^(\s*"[^"]*"\s*|\s*'[^']*'\s*|[^()]*)\)/u, grouping = new Set([',', '>', '+', '~']), combinator = new Set(['>', '+', '~', '']), sanitizeRegex = specialChars.map(([c, escaped]) => [new RegExp((0, string_1.escapeRegExp)(`\\${c}`), 'gu'), escaped]), desanitizeRegex = specialChars.map(([c, escaped]) => [c, new RegExp(escaped, 'gu')]), primitives = new Set(['string', 'number', 'boolean', 'undefined']);
50
49
  /**
51
- * 清理转义符号
52
- * @param selector
50
+ * optionally convert to lower cases
51
+ * @param val 属性值
52
+ * @param i 是否对大小写不敏感
53
53
  */
54
- const sanitize = (selector) => {
55
- for (const [re, escaped] of sanitizeRegex) {
56
- selector = selector.replace(re, escaped);
54
+ const toCase = (val, i) => i ? val.toLowerCase() : val;
55
+ /**
56
+ * 检查某个下标是否符合表达式
57
+ * @param str 表达式
58
+ * @param i 待检查的下标
59
+ */
60
+ const nth = (str, i) => new ranges_1.Ranges(str).applyTo(i + 1).includes(i);
61
+ /**
62
+ * 是否受保护。保护条件来自Token,这里仅提前用于:required和:optional伪选择器。
63
+ * @param token 节点
64
+ */
65
+ const isProtected = (token) => {
66
+ const { parentNode } = token;
67
+ if (!parentNode) {
68
+ return undefined;
69
+ }
70
+ const { childNodes, fixed } = parentNode;
71
+ return fixed
72
+ || parentNode.getAttribute('protectedChildren').applyTo(childNodes).includes(childNodes.indexOf(token));
73
+ };
74
+ /**
75
+ * 获取属性
76
+ * @param token 节点
77
+ * @param key 属性键
78
+ */
79
+ const getAttr = (token, key) => {
80
+ if (typeof token.getAttr === 'function') {
81
+ const attr = token.getAttr(key);
82
+ if (attr !== undefined) {
83
+ return attr;
84
+ }
57
85
  }
58
- return selector;
86
+ const val = token[key];
87
+ return val instanceof RegExp ? val.source : val;
88
+ };
89
+ /**
90
+ * 检查是否符合解析后的选择器,不含节点关系
91
+ * @param token 节点
92
+ * @param step 解析后的选择器
93
+ * @throws `SyntaxError` 错误的正则伪选择器
94
+ * @throws `SyntaxError` 未定义的伪选择器
95
+ */
96
+ const matches = (token, step) => {
97
+ const { parentNode, type, name, childNodes, link } = token, children = parentNode?.children, childrenOfType = children?.filter(({ type: t }) => t === type), siblingsCount = children?.length ?? 1, siblingsCountOfType = childrenOfType?.length ?? 1, index = (children?.indexOf(token) ?? 0) + 1, indexOfType = (childrenOfType?.indexOf(token) ?? 0) + 1, lastIndex = siblingsCount - index + 1, lastIndexOfType = siblingsCountOfType - indexOfType + 1;
98
+ return step.every(selector => {
99
+ if (typeof selector === 'string') {
100
+ switch (selector) { // 情形1:简单伪选择器、type和name
101
+ case '*':
102
+ return true;
103
+ case ':root':
104
+ return !parentNode;
105
+ case ':first-child':
106
+ return index === 1;
107
+ case ':first-of-type':
108
+ return indexOfType === 1;
109
+ case ':last-child':
110
+ return lastIndex === 1;
111
+ case ':last-of-type':
112
+ return lastIndexOfType === 1;
113
+ case ':only-child':
114
+ return siblingsCount === 1;
115
+ case ':only-of-type':
116
+ return siblingsCountOfType === 1;
117
+ case ':empty':
118
+ return !childNodes.some(({ type: t, data }) => t !== 'text' || data);
119
+ case ':parent':
120
+ return childNodes.some(({ type: t, data }) => t !== 'text' || data);
121
+ case ':header':
122
+ return type === 'heading';
123
+ case ':hidden':
124
+ return token.text() === '';
125
+ case ':visible':
126
+ return token.text() !== '';
127
+ case ':only-whitespace':
128
+ return token.text().trim() === '';
129
+ case ':any-link':
130
+ return type === 'link'
131
+ || type === 'free-ext-link'
132
+ || type === 'magic-link'
133
+ || type === 'ext-link'
134
+ || (type === 'file' || type === 'gallery-image') && link;
135
+ case ':local-link':
136
+ return (type === 'link' || type === 'file' || type === 'gallery-image')
137
+ && link instanceof title_1.Title
138
+ && link.title === '';
139
+ case ':invalid':
140
+ return type === 'table-inter' || type === 'image-parameter' && name === 'invalid';
141
+ case ':required':
142
+ return isProtected(token) === true;
143
+ case ':optional':
144
+ return isProtected(token) === false;
145
+ default: {
146
+ const [t, n] = selector.split('#');
147
+ return (!t || t === type) && (!n || n === name);
148
+ }
149
+ }
150
+ }
151
+ else if (selector.length === 4) { // 情形2:属性选择器
152
+ const [key, equal, val = '', i] = selector, isAttr = typeof token.hasAttr === 'function' && typeof token.getAttr === 'function';
153
+ if (!(key in token) && (!isAttr || !token.hasAttr(key))) {
154
+ return equal === '!=';
155
+ }
156
+ const v = toCase(val, i), thisVal = getAttr(token, key);
157
+ if (!equal) {
158
+ return thisVal !== undefined && thisVal !== false;
159
+ }
160
+ if (equal === '~=') {
161
+ const thisVals = typeof thisVal === 'string' ? thisVal.split(/\s/u) : thisVal;
162
+ return Boolean(thisVals?.[Symbol.iterator])
163
+ && [...thisVals].some(w => typeof w === 'string' && toCase(w, i) === v);
164
+ }
165
+ else if (!primitives.has(typeof thisVal) && !(thisVal instanceof title_1.Title)) {
166
+ throw new RangeError(`The complex attribute ${key} cannot be used in a selector!`);
167
+ }
168
+ const stringVal = toCase(String(thisVal), i);
169
+ switch (equal) {
170
+ case '|=':
171
+ return stringVal === v || stringVal.startsWith(`${v}-`);
172
+ case '^=':
173
+ return stringVal.startsWith(v);
174
+ case '$=':
175
+ return stringVal.endsWith(v);
176
+ case '*=':
177
+ return stringVal.includes(v);
178
+ case '!=':
179
+ return stringVal !== v;
180
+ default: // `=`
181
+ return stringVal === v;
182
+ }
183
+ }
184
+ const [s, pseudo] = selector; // 情形3:复杂伪选择器
185
+ switch (pseudo) {
186
+ case 'is':
187
+ return token.matches(s);
188
+ case 'not':
189
+ return !token.matches(s);
190
+ case 'nth-child':
191
+ return nth(s, index);
192
+ case 'nth-of-type':
193
+ return nth(s, indexOfType);
194
+ case 'nth-last-child':
195
+ return nth(s, lastIndex);
196
+ case 'nth-last-of-type':
197
+ return nth(s, lastIndexOfType);
198
+ case 'contains':
199
+ return token.text().includes(s);
200
+ case 'has':
201
+ return Boolean(token.querySelector(s));
202
+ case 'lang': {
203
+ // eslint-disable-next-line @typescript-eslint/no-unused-expressions
204
+ /^zh(?:-|$)/iu;
205
+ const regex = new RegExp(`^${s}(?:-|$)`, 'iu');
206
+ let node = token;
207
+ for (; node; node = node.parentNode) {
208
+ const lang = node.attributes?.['lang'];
209
+ if (lang !== undefined) {
210
+ return typeof lang === 'string' && regex.test(lang);
211
+ }
212
+ }
213
+ return false;
214
+ }
215
+ case 'regex': {
216
+ const mt = /^([^,]+),\s*\/(.+)\/([a-z]*)$/u.exec(s);
217
+ if (!mt) {
218
+ throw new SyntaxError(`Wrong usage of the regex pseudo-selector. Use ":regex('attr, /re/i')" format.`);
219
+ }
220
+ try {
221
+ return new RegExp(mt[2], mt[3]).test(String(getAttr(token, mt[1].trim())));
222
+ }
223
+ catch {
224
+ throw new SyntaxError(`Invalid regular expression: /${mt[2]}/${mt[3]}`);
225
+ }
226
+ }
227
+ default:
228
+ throw new SyntaxError(`Undefined pseudo-selector: ${pseudo}`);
229
+ }
230
+ });
231
+ };
232
+ /**
233
+ * 检查是否符合解析后的选择器
234
+ * @param token 节点
235
+ * @param copy 解析后的选择器
236
+ */
237
+ const matchesArray = (token, copy) => {
238
+ const condition = [...copy];
239
+ if (matches(token, condition.pop())) {
240
+ const { parentNode, previousElementSibling } = token;
241
+ switch (condition[condition.length - 1]?.relation) {
242
+ case undefined:
243
+ return true;
244
+ case '>':
245
+ return Boolean(parentNode && matchesArray(parentNode, condition));
246
+ case '+':
247
+ return Boolean(previousElementSibling && matchesArray(previousElementSibling, condition));
248
+ case '~': {
249
+ if (!parentNode) {
250
+ return false;
251
+ }
252
+ const { children } = parentNode;
253
+ return children.slice(0, children.indexOf(token)).some(child => matchesArray(child, condition));
254
+ }
255
+ default: // ' '
256
+ return token.getAncestors().some(ancestor => matchesArray(ancestor, condition));
257
+ }
258
+ }
259
+ return false;
59
260
  };
60
261
  /**
61
262
  * 还原转义符号
@@ -73,14 +274,16 @@ const desanitize = (selector) => {
73
274
  */
74
275
  const deQuote = (val) => /^(["']).*\1$/u.test(val) ? val.slice(1, -1) : val.trim();
75
276
  /**
76
- * 解析选择器
277
+ * 检查节点是否符合选择器
77
278
  * @param selector
78
- * @throws `SyntaxError` 非法的选择器
79
279
  */
80
- const parseSelector = (selector) => {
81
- selector = selector.trim();
280
+ const checkToken = (selector) => (token) => {
281
+ let sanitized = selector.trim();
282
+ for (const [re, escaped] of sanitizeRegex) {
283
+ sanitized = sanitized.replace(re, escaped);
284
+ }
82
285
  const stack = [[[]]];
83
- let sanitized = sanitize(selector), regex = regularRegex, mt = regex.exec(sanitized), [condition] = stack, [step] = condition;
286
+ let regex = regularRegex, mt = regex.exec(sanitized), [condition] = stack, [step] = condition;
84
287
  /**
85
288
  * 解析简单伪选择器
86
289
  * @param index 伪选择器的终点位置
@@ -182,9 +385,9 @@ const parseSelector = (selector) => {
182
385
  if (regex === regularRegex) {
183
386
  pushSimple();
184
387
  needUniversal();
185
- return stack;
388
+ return stack.some(copy => matchesArray(token, copy));
186
389
  }
187
390
  throw new SyntaxError(`Unclosed '${regex === attributeRegex ? '[' : '('}' in the selector!\n${desanitize(sanitized)}`);
188
391
  };
189
- exports.parseSelector = parseSelector;
392
+ exports.checkToken = checkToken;
190
393
  constants_1.parsers['parseSelector'] = __filename;
@@ -102,19 +102,19 @@ const parseTable = ({ firstChild: { data }, type, name }, config, accum) => {
102
102
  * 创建表格单元格
103
103
  * @param tr 当前表格行
104
104
  */
105
- const createTd = (tr) => {
105
+ const newTd = (tr) => {
106
106
  // @ts-expect-error abstract class
107
107
  const td = new td_1.TdToken(lastSyntax, attr.slice(lastIndex, mt?.index), config, accum);
108
108
  tr.insertAt(td);
109
109
  return td;
110
110
  };
111
111
  while (mt) {
112
- createTd(top);
112
+ newTd(top);
113
113
  ({ lastIndex } = regex);
114
114
  [lastSyntax] = mt;
115
115
  mt = regex.exec(attr);
116
116
  }
117
- stack.push(top, createTd(top));
117
+ stack.push(top, newTd(top));
118
118
  }
119
119
  }
120
120
  return out.slice(1);
package/dist/src/arg.d.ts CHANGED
@@ -9,7 +9,6 @@ import type { LintError, AST } from '../base';
9
9
  */
10
10
  export declare abstract class ArgToken extends Token {
11
11
  #private;
12
- readonly type = "arg";
13
12
  readonly name: string;
14
13
  readonly childNodes: readonly [AtomToken] | readonly [AtomToken, Token, ...HiddenToken[]];
15
14
  abstract get firstChild(): AtomToken;
@@ -17,6 +16,7 @@ export declare abstract class ArgToken extends Token {
17
16
  abstract get children(): [AtomToken] | [AtomToken, Token, ...HiddenToken[]];
18
17
  abstract get firstElementChild(): AtomToken;
19
18
  abstract get lastElementChild(): Token;
19
+ get type(): 'arg';
20
20
  /** 预设值 */
21
21
  get default(): string | false;
22
22
  set default(value: string | false);
@@ -24,7 +24,6 @@ export declare abstract class ArgToken extends Token {
24
24
  constructor(parts: readonly string[], config?: Parser.Config, accum?: Token[]);
25
25
  /** @override */
26
26
  json(): AST;
27
- /** @override */
28
27
  cloneNode(): this;
29
28
  /** 移除无效部分 */
30
29
  removeRedundant(): void;
package/dist/src/arg.js CHANGED
@@ -15,8 +15,10 @@ const hidden_1 = require("./hidden");
15
15
  * @classdesc `{childNodes: [AtomToken, ?Token, ...HiddenToken]}`
16
16
  */
17
17
  class ArgToken extends index_2.Token {
18
- type = 'arg';
19
18
  /* NOT FOR BROWSER END */
19
+ get type() {
20
+ return 'arg';
21
+ }
20
22
  /** 预设值 */
21
23
  get default() {
22
24
  return this.childNodes[1]?.text() ?? false;
@@ -119,7 +121,6 @@ class ArgToken extends index_2.Token {
119
121
  return json;
120
122
  }
121
123
  /* NOT FOR BROWSER */
122
- /** @override */
123
124
  cloneNode() {
124
125
  const [name, ...cloned] = this.cloneChildNodes();
125
126
  return debug_1.Shadow.run(() => {
@@ -1,12 +1,14 @@
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
- /** @override */
10
12
  cloneNode(): this;
11
13
  }
12
14
  export {};
package/dist/src/atom.js CHANGED
@@ -4,15 +4,41 @@ exports.AtomToken = void 0;
4
4
  const debug_1 = require("../util/debug");
5
5
  const constants_1 = require("../util/constants");
6
6
  const index_1 = require("./index");
7
+ const atomTypes = [
8
+ 'arg-name',
9
+ 'attr-key',
10
+ 'attr-value',
11
+ 'ext-attr-dirty',
12
+ 'html-attr-dirty',
13
+ 'table-attr-dirty',
14
+ 'converter-flag',
15
+ 'converter-rule-variant',
16
+ 'converter-rule-to',
17
+ 'converter-rule-from',
18
+ 'invoke-function',
19
+ 'invoke-module',
20
+ 'template-name',
21
+ 'link-target',
22
+ 'param-line',
23
+ ];
7
24
  /** 不会被继续解析的plain Token */
8
25
  class AtomToken extends index_1.Token {
26
+ #type;
27
+ get type() {
28
+ return this.#type;
29
+ }
30
+ set type(value) {
31
+ if (!atomTypes.includes(value)) {
32
+ throw new RangeError(`"${value}" is not a valid type for AtomToken!`);
33
+ }
34
+ this.#type = value;
35
+ }
9
36
  /** @class */
10
37
  constructor(wikitext, type, config, accum, acceptable) {
11
38
  super(wikitext, config, accum, acceptable);
12
- this.type = type;
39
+ this.#type = type;
13
40
  }
14
41
  /* NOT FOR BROWSER */
15
- /** @override */
16
42
  cloneNode() {
17
43
  const cloned = this.cloneChildNodes(), config = this.getAttribute('config'), acceptable = this.getAcceptable();
18
44
  return debug_1.Shadow.run(() => {
@@ -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;
@@ -24,6 +23,7 @@ export declare abstract class AttributeToken extends Token {
24
23
  abstract get parentElement(): AttributesToken | undefined;
25
24
  abstract get nextElementSibling(): AtomToken | this | undefined;
26
25
  abstract get previousElementSibling(): AtomToken | this | undefined;
26
+ get type(): AttributeTypes;
27
27
  /** 标签名 */
28
28
  get tag(): string;
29
29
  /** 引号是否匹配 */
@@ -43,7 +43,6 @@ export declare abstract class AttributeToken extends Token {
43
43
  constructor(type: AttributeTypes, tag: string, key: string, equal?: string, value?: string, quotes?: readonly [string?, string?], config?: Parser.Config, accum?: Token[]);
44
44
  /** 获取属性值 */
45
45
  getValue(): string | true;
46
- /** @override */
47
46
  cloneNode(): this;
48
47
  /** 转义等号 */
49
48
  escape(): void;
@@ -223,10 +223,14 @@ let AttributeToken = (() => {
223
223
  if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
224
224
  __runInitializers(_classThis, _classExtraInitializers);
225
225
  }
226
+ #type;
226
227
  #tag;
227
228
  #equal;
228
229
  #quotes;
229
230
  /* NOT FOR BROWSER END */
231
+ get type() {
232
+ return this.#type;
233
+ }
230
234
  /** 标签名 */
231
235
  get tag() {
232
236
  return this.#tag;
@@ -305,7 +309,7 @@ let AttributeToken = (() => {
305
309
  });
306
310
  }
307
311
  super(undefined, config, accum);
308
- this.type = type;
312
+ this.#type = type;
309
313
  this.append(keyToken, valueToken);
310
314
  this.#equal = equal;
311
315
  this.#quotes = [...quotes];
@@ -409,7 +413,6 @@ let AttributeToken = (() => {
409
413
  return this.#equal ? super.print({ sep: (0, string_1.escape)(this.#equal) + quoteStart, post: quoteEnd }) : super.print();
410
414
  }
411
415
  /* NOT FOR BROWSER */
412
- /** @override */
413
416
  cloneNode() {
414
417
  const [key, value] = this.cloneChildNodes(), config = this.getAttribute('config');
415
418
  return debug_1.Shadow.run(() => {
@@ -12,7 +12,6 @@ declare type AttributesTypes = `${AttributeTypes}s`;
12
12
  */
13
13
  export declare abstract class AttributesToken extends Token {
14
14
  #private;
15
- type: AttributesTypes;
16
15
  readonly name: string;
17
16
  readonly childNodes: readonly (AtomToken | AttributeToken)[];
18
17
  abstract get firstChild(): AtomToken | AttributeToken | undefined;
@@ -22,6 +21,7 @@ export declare abstract class AttributesToken extends Token {
22
21
  abstract get firstElementChild(): AtomToken | AttributeToken | undefined;
23
22
  abstract get lastElementChild(): AtomToken | AttributeToken | undefined;
24
23
  abstract get parentElement(): ExtToken | HtmlToken | TableToken | TrToken | TdToken | undefined;
24
+ get type(): AttributesTypes;
25
25
  /** getAttrs()方法的getter写法 */
26
26
  get attributes(): Record<string, string | true>;
27
27
  set attributes(attrs: Record<string, string | true>);
@@ -60,7 +60,6 @@ export declare abstract class AttributesToken extends Token {
60
60
  getAttr(key: string): string | true | undefined;
61
61
  /** 清理无效属性 */
62
62
  sanitize(): void;
63
- /** @override */
64
63
  cloneNode(): this;
65
64
  /**
66
65
  * @override
@@ -29,6 +29,12 @@ const toDirty = (type) => `${toAttributeType(type)}-dirty`;
29
29
  * @classdesc `{childNodes: ...AtomToken|AttributeToken}`
30
30
  */
31
31
  class AttributesToken extends index_2.Token {
32
+ #type;
33
+ /* NOT FOR BROWSER END */
34
+ get type() {
35
+ return this.#type;
36
+ }
37
+ /* NOT FOR BROWSER */
32
38
  /** getAttrs()方法的getter写法 */
33
39
  get attributes() {
34
40
  return this.getAttrs();
@@ -79,7 +85,7 @@ class AttributesToken extends index_2.Token {
79
85
  super(undefined, config, accum, {
80
86
  AtomToken: ':', AttributeToken: ':',
81
87
  });
82
- this.type = type;
88
+ this.#type = type;
83
89
  this.setAttribute('name', name);
84
90
  if (attr) {
85
91
  regex.lastIndex = 0;
@@ -202,7 +208,6 @@ class AttributesToken extends index_2.Token {
202
208
  index_1.default.warn('AttributesToken.sanitize will remove invalid attributes!');
203
209
  }
204
210
  }
205
- /** @override */
206
211
  cloneNode() {
207
212
  const cloned = this.cloneChildNodes();
208
213
  return debug_1.Shadow.run(() => {
@@ -10,13 +10,13 @@ export interface ConverterToken extends FlagsParentBase {
10
10
  * @classdesc `{childNodes: [ConverterFlagsToken, ...ConverterRuleToken]}`
11
11
  */
12
12
  export declare abstract class ConverterToken extends Token {
13
- readonly type = "converter";
14
13
  readonly childNodes: readonly [ConverterFlagsToken, ...ConverterRuleToken[]];
15
14
  abstract get firstChild(): ConverterFlagsToken;
16
15
  abstract get lastChild(): ConverterFlagsToken | ConverterRuleToken;
17
16
  abstract get children(): [ConverterFlagsToken, ...ConverterRuleToken[]];
18
17
  abstract get firstElementChild(): ConverterFlagsToken;
19
18
  abstract get lastElementChild(): ConverterFlagsToken | ConverterRuleToken;
19
+ get type(): 'converter';
20
20
  /** 是否不转换 */
21
21
  get noConvert(): boolean;
22
22
  /**
@@ -24,6 +24,5 @@ export declare abstract class ConverterToken extends Token {
24
24
  * @param rules 转换规则
25
25
  */
26
26
  constructor(flags: readonly string[], rules: readonly [string, ...string[]], config?: Parser.Config, accum?: Token[]);
27
- /** @override */
28
27
  cloneNode(): this;
29
28
  }
@@ -62,7 +62,11 @@ let ConverterToken = (() => {
62
62
  if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
63
63
  __runInitializers(_classThis, _classExtraInitializers);
64
64
  }
65
- type = 'converter';
65
+ /* NOT FOR BROWSER END */
66
+ get type() {
67
+ return 'converter';
68
+ }
69
+ /* NOT FOR BROWSER */
66
70
  /** 是否不转换 */
67
71
  get noConvert() {
68
72
  return this.hasFlag('R') || this.length === 2 && this.lastChild.length === 1;
@@ -115,7 +119,6 @@ let ConverterToken = (() => {
115
119
  return `<span class="wpb-converter">-{${flags.print()}${flags.length > 0 ? '|' : ''}${(0, string_1.print)(rules, { sep: ';' })}}-</span>`;
116
120
  }
117
121
  /* NOT FOR BROWSER */
118
- /** @override */
119
122
  cloneNode() {
120
123
  const [flags, ...rules] = this.cloneChildNodes();
121
124
  return debug_1.Shadow.run(() => {
@@ -9,7 +9,6 @@ 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;
@@ -22,6 +21,7 @@ export declare abstract class ConverterFlagsToken extends Token {
22
21
  abstract get parentElement(): ConverterToken | undefined;
23
22
  abstract get previousElementSibling(): undefined;
24
23
  abstract get nextElementSibling(): ConverterRuleToken | undefined;
24
+ get type(): 'converter-flags';
25
25
  /** 所有转换类型标记 */
26
26
  get flags(): Set<string>;
27
27
  set flags(value: Set<string>);
@@ -31,7 +31,6 @@ export declare abstract class ConverterFlagsToken extends Token {
31
31
  getUnknownFlags(): Set<string>;
32
32
  /** 获取指定语言变体的转换标记 */
33
33
  getVariantFlags(): Set<string>;
34
- /** @override */
35
34
  cloneNode(): this;
36
35
  /**
37
36
  * @override
@@ -14,8 +14,12 @@ const definedFlags = new Set(['A', 'T', 'R', 'D', '-', 'H', 'N']);
14
14
  * @classdesc `{childNodes: ...AtomToken}`
15
15
  */
16
16
  class ConverterFlagsToken extends index_2.Token {
17
- type = 'converter-flags';
18
17
  #flags;
18
+ /* NOT FOR BROWSER END */
19
+ get type() {
20
+ return 'converter-flags';
21
+ }
22
+ /* NOT FOR BROWSER */
19
23
  /** 所有转换类型标记 */
20
24
  get flags() {
21
25
  return this.getAllFlags();
@@ -106,7 +110,6 @@ class ConverterFlagsToken extends index_2.Token {
106
110
  return super.print({ sep: ';' });
107
111
  }
108
112
  /* NOT FOR BROWSER */
109
- /** @override */
110
113
  cloneNode() {
111
114
  const cloned = this.cloneChildNodes();
112
115
  return debug_1.Shadow.run(() => {
@@ -7,7 +7,6 @@ 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;
@@ -20,6 +19,7 @@ export declare abstract class ConverterRuleToken extends Token {
20
19
  abstract get parentElement(): ConverterToken | undefined;
21
20
  abstract get previousElementSibling(): ConverterFlagsToken | this;
22
21
  abstract get nextElementSibling(): this | undefined;
22
+ get type(): 'converter-rule';
23
23
  /** 语言变体 */
24
24
  get variant(): string;
25
25
  set variant(variant: string);
@@ -36,14 +36,12 @@ export declare abstract class ConverterRuleToken extends Token {
36
36
  * @param hasColon 是否带有":"
37
37
  */
38
38
  constructor(rule: string, hasColon?: boolean, config?: Parser.Config, accum?: Token[]);
39
- /** @override */
40
39
  cloneNode(): this;
41
40
  /**
42
41
  * @override
43
42
  * @param i 移除位置
44
43
  */
45
44
  removeAt(i: number): AtomToken;
46
- /** @override */
47
45
  insertAt(): never;
48
46
  /** 修改为不转换 */
49
47
  noConvert(): void;