UNPKG

ecmarkup

Version:

Custom element definitions and core utilities for markup that specifies ECMAScript and related technologies.

43 lines (42 loc) 2.18 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const Builder_1 = require("./Builder"); const Xref_1 = require("./Xref"); // Builds the list of definitions rendered inside an `<emu-concrete-method-dfns>` or // `<emu-internal-method-dfns>` element: a bulleted list of xrefs pointing at each clause which // defines the method named by the `for` attribute. Concrete and internal methods are indexed // together in the biblio (see `byMethodAoid`), so a single builder handles both elements. class MethodDefinitionsList extends Builder_1.default { constructor(spec, node, _for, parentClause) { super(spec, node); this._for = _for; this._parentClause = parentClause; } static async enter({ node, spec, clauseStack }) { const _for = node.getAttribute('for'); const parentClause = clauseStack[clauseStack.length - 1]; spec._methodDefinitionsLists.push(new MethodDefinitionsList(spec, node, _for, parentClause)); } build() { var _a, _b; const { spec, _parentClause: parentClause } = this; const namespace = parentClause ? parentClause.namespace : spec.namespace; const definitions = (_a = spec.biblio.byMethodAoid(this._for, namespace)) !== null && _a !== void 0 ? _a : []; const ul = spec.doc.createElement('ul'); for (const def of definitions) { const id = (_b = def.id) !== null && _b !== void 0 ? _b : def.refId; const declaration = spec.biblio.byId(id); const li = spec.doc.createElement('li'); const xrefNode = spec.doc.createElement('emu-xref'); xrefNode.setAttribute('href', `#${id}`); xrefNode.textContent = `${declaration.number} ${def.for}`; li.appendChild(xrefNode); ul.appendChild(li); const xref = new Xref_1.default(spec, xrefNode, parentClause, namespace, xrefNode.getAttribute('href'), null); spec._xrefs.push(xref); } this.node.appendChild(ul); } } MethodDefinitionsList.elements = ['EMU-CONCRETE-METHOD-DFNS', 'EMU-INTERNAL-METHOD-DFNS']; exports.default = MethodDefinitionsList;