wikiparser-node 1.0.0-beta.2 → 1.0.0-beta.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.
package/dist/src/arg.js CHANGED
@@ -168,12 +168,12 @@ class ArgToken extends _1.Token {
168
168
  */
169
169
  setName(name) {
170
170
  const root = index_1.default.parse(`{{{${name}}}}`, this.getAttribute('include'), 2, this.getAttribute('config')), { length, firstChild: arg } = root;
171
- if (length === 1 && arg instanceof ArgToken && arg.length === 1) {
172
- const { firstChild } = arg;
173
- arg.destroy();
174
- this.firstChild.safeReplaceWith(firstChild);
171
+ if (length !== 1 || !(arg instanceof ArgToken) || arg.length !== 1) {
172
+ throw new SyntaxError(`非法的参数名称:${(0, string_1.noWrap)(name)}`);
175
173
  }
176
- throw new SyntaxError(`非法的参数名称:${(0, string_1.noWrap)(name)}`);
174
+ const { firstChild } = arg;
175
+ arg.destroy();
176
+ this.firstChild.safeReplaceWith(firstChild);
177
177
  }
178
178
  /**
179
179
  * 设置预设值
@@ -424,12 +424,12 @@ class AttributeToken extends (0, fixed_1.fixed)(_1.Token) {
424
424
  attrs = tag.firstChild;
425
425
  }
426
426
  const { firstChild: attr } = attrs;
427
- if (attrs.length === 1 && attr.type === this.type && attr.value === true) {
428
- const { firstChild } = attr;
429
- attr.destroy();
430
- this.firstChild.safeReplaceWith(firstChild);
427
+ if (attrs.length !== 1 || attr.type !== this.type || attr.value !== true) {
428
+ throw new SyntaxError(`非法的标签属性名:${(0, string_1.noWrap)(key)}`);
431
429
  }
432
- throw new SyntaxError(`非法的标签属性名:${(0, string_1.noWrap)(key)}`);
430
+ const { firstChild } = attr;
431
+ attr.destroy();
432
+ this.firstChild.safeReplaceWith(firstChild);
433
433
  }
434
434
  }
435
435
  exports.AttributeToken = AttributeToken;
@@ -187,12 +187,12 @@ class ConverterRuleToken extends _1.Token {
187
187
  throw new SyntaxError(`非法的转换目标:${(0, string_1.noWrap)(to)}`);
188
188
  }
189
189
  const { lastChild: converterRule } = converter;
190
- if (converter.length === 2 && converterRule.length === 2) {
191
- const { lastChild } = converterRule;
192
- converterRule.destroy();
193
- this.lastChild.safeReplaceWith(lastChild);
190
+ if (converter.length !== 2 || converterRule.length !== 2) {
191
+ throw new SyntaxError(`非法的转换目标:${(0, string_1.noWrap)(to)}`);
194
192
  }
195
- throw new SyntaxError(`非法的转换目标:${(0, string_1.noWrap)(to)}`);
193
+ const { lastChild } = converterRule;
194
+ converterRule.destroy();
195
+ this.lastChild.safeReplaceWith(lastChild);
196
196
  }
197
197
  /**
198
198
  * 设置语言变体
@@ -126,12 +126,12 @@ class ExtLinkToken extends _1.Token {
126
126
  */
127
127
  setTarget(url) {
128
128
  const strUrl = String(url), root = index_1.default.parse(`[${strUrl}]`, this.getAttribute('include'), 8, this.getAttribute('config')), { length, firstChild: extLink } = root;
129
- if (length === 1 && extLink instanceof ExtLinkToken && extLink.length === 1) {
130
- const { firstChild } = extLink;
131
- extLink.destroy();
132
- this.firstChild.safeReplaceWith(firstChild);
129
+ if (length !== 1 || !(extLink instanceof ExtLinkToken) || extLink.length !== 1) {
130
+ throw new SyntaxError(`非法的外链目标:${strUrl}`);
133
131
  }
134
- throw new SyntaxError(`非法的外链目标:${strUrl}`);
132
+ const { firstChild } = extLink;
133
+ extLink.destroy();
134
+ this.firstChild.safeReplaceWith(firstChild);
135
135
  }
136
136
  /**
137
137
  * 设置链接显示文字
@@ -246,10 +246,10 @@ class ImageParameterToken extends _1.Token {
246
246
  throw new SyntaxError(`非法的 ${this.name} 参数:${(0, string_1.noWrap)(value)}`);
247
247
  }
248
248
  const { lastChild: imageParameter, name } = file;
249
- if (name === 'File:F' && imageParameter.name === this.name) {
250
- this.replaceChildren(...imageParameter.childNodes);
249
+ if (name !== 'File:F' || imageParameter.name !== this.name) {
250
+ throw new SyntaxError(`非法的 ${this.name} 参数:${(0, string_1.noWrap)(value)}`);
251
251
  }
252
- throw new SyntaxError(`非法的 ${this.name} 参数:${(0, string_1.noWrap)(value)}`);
252
+ this.replaceChildren(...imageParameter.childNodes);
253
253
  }
254
254
  }
255
255
  exports.ImageParameterToken = ImageParameterToken;
package/dist/src/index.js CHANGED
@@ -806,8 +806,11 @@ class Token extends element_1.AstElement {
806
806
  if (transclusion) {
807
807
  continue;
808
808
  }
809
- target.replaceWith(replace);
810
809
  }
810
+ else {
811
+ continue;
812
+ }
813
+ target.replaceWith(replace);
811
814
  }
812
815
  }
813
816
  }
@@ -192,13 +192,13 @@ class LinkBaseToken extends __1.Token {
192
192
  strLink = `:${strLink}`;
193
193
  }
194
194
  const root = index_1.default.parse(`[[${strLink}]]`, this.getAttribute('include'), 6, this.getAttribute('config')), { length, firstChild: wikiLink } = root;
195
- if (length === 1 && wikiLink?.type === this.type && wikiLink.length === 1) {
196
- const { firstChild } = wikiLink;
197
- wikiLink.destroy();
198
- this.firstChild.safeReplaceWith(firstChild);
195
+ if (length !== 1 || wikiLink?.type !== this.type || wikiLink.length !== 1) {
196
+ const msgs = { link: '内链', file: '文件链接', category: '分类' };
197
+ throw new SyntaxError(`非法的${msgs[this.type]}目标:${strLink}`);
199
198
  }
200
- const msgs = { link: '内链', file: '文件链接', category: '分类' };
201
- throw new SyntaxError(`非法的${msgs[this.type]}目标:${strLink}`);
199
+ const { firstChild } = wikiLink;
200
+ wikiLink.destroy();
201
+ this.firstChild.safeReplaceWith(firstChild);
202
202
  }
203
203
  /**
204
204
  * 设置链接显示文字
@@ -259,10 +259,10 @@ class FileToken extends base_1.LinkBaseToken {
259
259
  throw new SyntaxError(`非法的 ${key} 参数:${(0, string_1.noWrap)(value)}`);
260
260
  }
261
261
  const { name, lastChild: imageParameter } = file;
262
- if (name === 'File:F' && imageParameter.name === key) {
263
- this.insertAt(imageParameter);
262
+ if (name !== 'File:F' || imageParameter.name !== key) {
263
+ throw new SyntaxError(`非法的 ${key} 参数:${(0, string_1.noWrap)(value)}`);
264
264
  }
265
- throw new SyntaxError(`非法的 ${key} 参数:${(0, string_1.noWrap)(value)}`);
265
+ this.insertAt(imageParameter);
266
266
  }
267
267
  }
268
268
  exports.FileToken = FileToken;
@@ -88,12 +88,12 @@ class GalleryImageToken extends (0, singleLine_1.singleLine)(file_1.FileToken) {
88
88
  throw new SyntaxError(`非法的图库文件名:${link}`);
89
89
  }
90
90
  const { lastChild: gallery } = ext, { firstChild: image } = gallery;
91
- if (gallery.length === 1 && image.type === 'gallery-image') {
92
- const { firstChild } = image;
93
- image.destroy();
94
- this.firstChild.safeReplaceWith(firstChild);
91
+ if (gallery.length !== 1 || image.type !== 'gallery-image') {
92
+ throw new SyntaxError(`非法的图库文件名:${link}`);
95
93
  }
96
- throw new SyntaxError(`非法的图库文件名:${link}`);
94
+ const { firstChild } = image;
95
+ image.destroy();
96
+ this.firstChild.safeReplaceWith(firstChild);
97
97
  }
98
98
  }
99
99
  exports.GalleryImageToken = GalleryImageToken;
@@ -116,10 +116,10 @@ class MagicLinkToken extends _1.Token {
116
116
  */
117
117
  setTarget(url) {
118
118
  const strUrl = String(url), root = index_1.default.parse(strUrl, this.getAttribute('include'), 9, this.getAttribute('config')), { length, firstChild: freeExtLink } = root;
119
- if (length === 1 && freeExtLink.type === 'free-ext-link') {
120
- this.replaceChildren(...freeExtLink.childNodes);
119
+ if (length !== 1 || freeExtLink.type !== 'free-ext-link') {
120
+ throw new SyntaxError(`非法的自由外链目标:${strUrl}`);
121
121
  }
122
- throw new SyntaxError(`非法的自由外链目标:${strUrl}`);
122
+ this.replaceChildren(...freeExtLink.childNodes);
123
123
  }
124
124
  /** 是否是模板或魔术字参数 */
125
125
  isParamValue() {
@@ -159,12 +159,12 @@ class ParameterToken extends (0, fixed_1.fixed)(_1.Token) {
159
159
  throw new SyntaxError(`非法的模板参数:${(0, string_1.noWrap)(value)}`);
160
160
  }
161
161
  const { lastChild: parameter, name } = transclude, targetName = templateLike ? 'T' : 'lc';
162
- if (name === targetName && transclude.length === 2 && parameter.anon === this.anon && parameter.name === '1') {
163
- const { lastChild } = parameter;
164
- parameter.destroy();
165
- this.lastChild.safeReplaceWith(lastChild);
162
+ if (name !== targetName || transclude.length !== 2 || parameter.anon !== this.anon || parameter.name !== '1') {
163
+ throw new SyntaxError(`非法的模板参数:${(0, string_1.noWrap)(value)}`);
166
164
  }
167
- throw new SyntaxError(`非法的模板参数:${(0, string_1.noWrap)(value)}`);
165
+ const { lastChild } = parameter;
166
+ parameter.destroy();
167
+ this.lastChild.safeReplaceWith(lastChild);
168
168
  }
169
169
  /**
170
170
  * 修改参数名
@@ -527,10 +527,10 @@ class TranscludeToken extends _1.Token {
527
527
  throw new SyntaxError(`非法的命名参数:${key}=${(0, string_1.noWrap)(value)}`);
528
528
  }
529
529
  const { name, lastChild: parameter } = template;
530
- if (name === 'T' && parameter.name === key) {
531
- this.insertAt(parameter);
530
+ if (name !== 'T' || parameter.name !== key) {
531
+ throw new SyntaxError(`非法的命名参数:${key}=${(0, string_1.noWrap)(value)}`);
532
532
  }
533
- throw new SyntaxError(`非法的命名参数:${key}=${(0, string_1.noWrap)(value)}`);
533
+ this.insertAt(parameter);
534
534
  }
535
535
  /**
536
536
  * 将匿名参数改写为命名参数
@@ -555,10 +555,10 @@ class TranscludeToken extends _1.Token {
555
555
  throw new Error(`${this.constructor.name}.replaceTemplate 方法仅用于更换模板!`);
556
556
  }
557
557
  const root = index_1.default.parse(`{{${title}}}`, this.getAttribute('include'), 2, this.getAttribute('config')), { length, firstChild: template } = root;
558
- if (length === 1 && template.type === 'template' && template.length === 1) {
559
- this.firstChild.replaceChildren(...template.firstChild.childNodes);
558
+ if (length !== 1 || template.type !== 'template' || template.length !== 1) {
559
+ throw new SyntaxError(`非法的模板名称:${title}`);
560
560
  }
561
- throw new SyntaxError(`非法的模板名称:${title}`);
561
+ this.firstChild.replaceChildren(...template.firstChild.childNodes);
562
562
  }
563
563
  /**
564
564
  * 替换模块名
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wikiparser-node",
3
- "version": "1.0.0-beta.2",
3
+ "version": "1.0.0-beta.3",
4
4
  "description": "A Node.js parser for MediaWiki markup with AST",
5
5
  "keywords": [
6
6
  "mediawiki",