UNPKG

wikiparser-node

Version:

A Node.js parser for MediaWiki markup with AST

143 lines (142 loc) 7.62 kB
"use strict"; var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) { var useValue = arguments.length > 2; for (var i = 0; i < initializers.length; i++) { value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg); } return useValue ? value : void 0; }; var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) { function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; } var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value"; var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null; var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {}); var _, done = false; for (var i = decorators.length - 1; i >= 0; i--) { var context = {}; for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p]; for (var p in contextIn.access) context.access[p] = contextIn.access[p]; context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); }; var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context); if (kind === "accessor") { if (result === void 0) continue; if (result === null || typeof result !== "object") throw new TypeError("Object expected"); if (_ = accept(result.get)) descriptor.get = _; if (_ = accept(result.set)) descriptor.set = _; if (_ = accept(result.init)) initializers.unshift(_); } else if (_ = accept(result)) { if (kind === "field") initializers.unshift(_); else descriptor[key] = _; } } if (target) Object.defineProperty(target, contextIn.name, descriptor); done = true; }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.ParamTagToken = void 0; const lint_1 = require("../../util/lint"); const rect_1 = require("../../lib/rect"); const commentAndExt_1 = require("../../parser/commentAndExt"); const multiLine_1 = require("../../mixin/multiLine"); const index_1 = __importDefault(require("../../index")); const index_2 = require("../index"); const atom_1 = require("../atom"); /* NOT FOR BROWSER */ const constants_1 = require("../../util/constants"); const clone_1 = require("../../mixin/clone"); const singleLine_1 = require("../../mixin/singleLine"); /* NOT FOR BROWSER END */ /** * `<dynamicpagelist>` * @classdesc `{childNodes: AtomToken[]}` */ let ParamTagToken = (() => { let _classDecorators = [multiLine_1.multiLine]; let _classDescriptor; let _classExtraInitializers = []; let _classThis; let _classSuper = index_2.Token; let _instanceExtraInitializers = []; let _cloneNode_decorators; var ParamTagToken = class extends _classSuper { static { _classThis = this; } static { const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0; _cloneNode_decorators = [clone_1.clone]; __esDecorate(this, null, _cloneNode_decorators, { kind: "method", name: "cloneNode", static: false, private: false, access: { has: obj => "cloneNode" in obj, get: obj => obj.cloneNode }, metadata: _metadata }, null, _instanceExtraInitializers); __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers); ParamTagToken = _classThis = _classDescriptor.value; if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata }); __runInitializers(_classThis, _classExtraInitializers); } /* NOT FOR BROWSER END */ get type() { return 'ext-inner'; } /** @class */ constructor(include, wikitext, config = index_1.default.getConfig(), accum = [], acceptable) { super(undefined, config, accum, { AtomToken: ':', }); __runInitializers(this, _instanceExtraInitializers); if (wikitext) { const SingleLineAtomToken = (0, singleLine_1.singleLine)(!acceptable)(atom_1.AtomToken); this.append(...wikitext.split('\n') .map(line => acceptable ? line : (0, commentAndExt_1.parseCommentAndExt)(line, config, accum, include)) .map(line => new SingleLineAtomToken(line, 'param-line', config, accum, { 'Stage-1': ':', ...acceptable, }))); } accum.splice(accum.indexOf(this), 1); accum.push(this); } /** @private */ lint(start = this.getAbsoluteIndex()) { LINT: { // eslint-disable-line no-unused-labels const rule = 'no-ignored', { lintConfig } = index_1.default, s = lintConfig.getSeverity(rule, this.name); if (!s) { return []; } const rect = new rect_1.BoundingRect(this, start), msg = index_1.default.msg('invalid-parameter', this.name), errors = []; for (const child of this.childNodes) { child.setAttribute('aIndex', start); const grandChildren = child.childNodes .filter(({ type }) => type !== 'comment' && type !== 'include' && type !== 'noinclude'); if (grandChildren.some(({ type }) => type === 'ext')) { errors.push((0, lint_1.generateForChild)(child, rect, rule, msg, s)); } else { const i = grandChildren.findIndex(({ type }) => type !== 'text'), str = grandChildren.slice(0, i === -1 ? undefined : i).map(String).join(''); if (str && !(i === -1 ? /^[a-z]+(?:\[\])?\s*=/iu : /^[a-z]+(?:\[\])?\s*(?:=|$)/iu).test(str)) { const e = (0, lint_1.generateForChild)(child, rect, rule, msg, s); if (lintConfig.computeEditInfo) { e.suggestions = [(0, lint_1.fixByRemove)(e)]; } errors.push(e); } else { const childErrors = child.lint(start, false); if (childErrors.length > 0) { errors.push(...childErrors); } } } start += child.toString().length + 1; } return errors; } } /* NOT FOR BROWSER */ cloneNode() { const C = this.constructor; return new C(this.getAttribute('include'), undefined, this.getAttribute('config')); } }; return ParamTagToken = _classThis; })(); exports.ParamTagToken = ParamTagToken; constants_1.classes['ParamTagToken'] = __filename;