reffy 8.0.4 → 9.0.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "reffy",
3
- "version": "8.0.4",
3
+ "version": "9.0.0",
4
4
  "description": "W3C/WHATWG spec dependencies exploration companion. Features a short set of tools to study spec references as well as WebIDL term definitions and references found in W3C specifications.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -34,18 +34,18 @@
34
34
  "abortcontroller-polyfill": "1.7.3",
35
35
  "commander": "9.4.0",
36
36
  "fetch-filecache-for-crawling": "4.1.0",
37
- "puppeteer": "15.5.0",
37
+ "puppeteer": "16.1.1",
38
38
  "semver": "^7.3.5",
39
- "web-specs": "2.18.0",
39
+ "web-specs": "2.19.0",
40
40
  "webidl2": "24.2.2"
41
41
  },
42
42
  "devDependencies": {
43
43
  "chai": "4.3.6",
44
44
  "mocha": "10.0.0",
45
45
  "nock": "13.2.9",
46
- "respec": "32.2.1",
46
+ "respec": "32.2.3",
47
47
  "respec-hljs": "2.1.1",
48
- "rollup": "2.77.2"
48
+ "rollup": "2.78.0"
49
49
  },
50
50
  "scripts": {
51
51
  "test": "mocha --recursive tests/"
@@ -13,15 +13,37 @@ import informativeSelector from './informative-selector.mjs';
13
13
  export default function () {
14
14
  let res = {
15
15
  properties: extractTableDfns(document, 'propdef', { unique: true }),
16
- descriptors: extractTableDfns(document, 'descdef', { unique: false }),
16
+ atrules: {},
17
17
  valuespaces: extractValueSpaces(document)
18
18
  };
19
+ let descriptors = extractTableDfns(document, 'descdef', { unique: false });
19
20
 
20
21
  // Try old recipes if we couldn't extract anything
21
22
  if ((Object.keys(res.properties).length === 0) &&
22
- (Object.keys(res.descriptors).length === 0)) {
23
+ (Object.keys(descriptors).length === 0)) {
23
24
  res.properties = extractDlDfns(document, 'propdef', { unique: true });
24
- res.descriptors = extractDlDfns(document, 'descdef', { unique: false });
25
+ descriptors = extractDlDfns(document, 'descdef', { unique: false });
26
+ }
27
+
28
+ // Move at-rules definitions from valuespaces to at-rules structure
29
+ for (const [name, dfn] of Object.entries(res.valuespaces)) {
30
+ if (name.startsWith('@')) {
31
+ if (!res.atrules[name]) {
32
+ res.atrules[name] = Object.assign(dfn, { descriptors: [] });
33
+ }
34
+ delete res.valuespaces[name];
35
+ }
36
+ }
37
+
38
+ // Move descriptors to at-rules structure
39
+ for (const [name, desclist] of Object.entries(descriptors)) {
40
+ for (const desc of desclist) {
41
+ const rule = desc.for;
42
+ if (!res.atrules[rule]) {
43
+ res.atrules[rule] = { descriptors: [] };
44
+ }
45
+ res.atrules[rule].descriptors.push(desc);
46
+ }
25
47
  }
26
48
 
27
49
  return res;
@@ -198,6 +220,9 @@ const extractDlDfns = (doc, className, options) =>
198
220
  * Definitions with `data-dfn-type` attribute set to `value` are not extracted
199
221
  * on purpose as they are typically namespaced to another construct (through a
200
222
  * `data-dfn-for` attribute.
223
+ *
224
+ * The function also extracts syntax of at-rules (name starts with '@') defined
225
+ * in "pre.prod" blocks.
201
226
  */
202
227
  const extractValueSpaces = doc => {
203
228
  let res = {};
@@ -213,16 +238,27 @@ const extractValueSpaces = doc => {
213
238
  .replace(/\/\*[^]*?\*\//gm, '') // Drop comments
214
239
  .split(/\s?=\s/)
215
240
  .map(s => s.trim().replace(/\s+/g, ' '));
216
- if (nameAndValue[0].match(/^<.*>$|^.*\(\)$/)) {
217
- const name = nameAndValue[0].replace(/^(.*\(\))$/, '<$1>');
241
+
242
+ function addValuespace(name, value) {
218
243
  if (!(name in res)) {
219
244
  res[name] = {};
220
245
  }
221
246
  if (!res[name].value || (pureSyntax && !res[name].pureSyntax)) {
222
- res[name].value = normalize(nameAndValue[1]);
247
+ res[name].value = normalize(value);
223
248
  res[name].pureSyntax = pureSyntax;
224
249
  }
225
250
  }
251
+
252
+ if (nameAndValue[0].match(/^<.*>$|^.*\(\)$/)) {
253
+ // Regular valuespace
254
+ addValuespace(
255
+ nameAndValue[0].replace(/^(.*\(\))$/, '<$1>'),
256
+ nameAndValue[1]);
257
+ }
258
+ else if (nameAndValue[0].match(/^@[a-z\-]+$/)) {
259
+ // At-rule syntax
260
+ addValuespace(nameAndValue[0], nameAndValue[1]);
261
+ }
226
262
  };
227
263
 
228
264
  // Regular expression to use to split production rules:
@@ -351,8 +387,16 @@ const extractValueSpaces = doc => {
351
387
  .map(val => val.replace(/\/\*[^]*?\*\//gm, '')) // Drop comments
352
388
  .map(val => val.split(reSplitRules)) // Separate definitions
353
389
  .flat()
354
- .filter(text => text.match(/\s?=\s/))
355
- .map(text => parseProductionRule(text, { pureSyntax: true }));
390
+ .map(text => text.trim())
391
+ .map(text => {
392
+ if (text.match(/\s?=\s/)) {
393
+ return parseProductionRule(text, { pureSyntax: true });
394
+ }
395
+ else if (text.startsWith('@')) {
396
+ const name = text.split(' ')[0];
397
+ return parseProductionRule(`${name} = ${text}`, { pureSyntax: true });
398
+ }
399
+ });
356
400
 
357
401
  // Don't keep the info on whether value comes from a pure syntax section
358
402
  Object.values(res).map(value => delete value.pureSyntax);