1 | "use strict";
|
2 | var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
3 | function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
4 | return new (P || (P = Promise))(function (resolve, reject) {
|
5 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
6 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
7 | function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
8 | step((generator = generator.apply(thisArg, _arguments || [])).next());
|
9 | });
|
10 | };
|
11 | Object.defineProperty(exports, "__esModule", { value: true });
|
12 | const Biblio_1 = require("./Biblio");
|
13 | const Builder_1 = require("./Builder");
|
14 |
|
15 | class Dfn extends Builder_1.default {
|
16 | static enter({ spec, node, clauseStack }) {
|
17 | return __awaiter(this, void 0, void 0, function* () {
|
18 | const parentClause = clauseStack[clauseStack.length - 1];
|
19 | if (!parentClause)
|
20 | return;
|
21 | const entry = {
|
22 | type: 'term',
|
23 | term: node.textContent,
|
24 | refId: parentClause.id,
|
25 | };
|
26 | if (node.hasAttribute('id')) {
|
27 | entry.id = node.id;
|
28 | }
|
29 | if (node.hasAttribute('variants')) {
|
30 | entry.variants = node
|
31 | .getAttribute('variants')
|
32 | .split(',')
|
33 | .map(v => v.trim());
|
34 | }
|
35 | const keys = Biblio_1.getKeys(entry);
|
36 | const existing = spec.biblio.keysForNamespace(parentClause.namespace);
|
37 | for (const [index, key] of keys.entries()) {
|
38 | if (keys.indexOf(key) !== index) {
|
39 | spec.warn({
|
40 | type: 'node',
|
41 | node,
|
42 | ruleId: 'duplicate-definition',
|
43 | message: `${JSON.stringify(key)} is defined more than once in this definition`,
|
44 | });
|
45 | }
|
46 | if (existing.has(key)) {
|
47 | spec.warn({
|
48 | type: 'node',
|
49 | node,
|
50 | ruleId: 'duplicate-definition',
|
51 | message: `duplicate definition ${JSON.stringify(key)}`,
|
52 | });
|
53 | }
|
54 | }
|
55 | spec.biblio.add(entry, parentClause.namespace);
|
56 | });
|
57 | }
|
58 | }
|
59 | exports.default = Dfn;
|
60 | Dfn.elements = ['DFN'];
|