Repository: w3c/webidl2.js
Pull request #213 (2018-06-17 10:55:43)

Document trivia for iterable-likes
Also including renaming from `trivia.type` to `trivia.base` for consistency with other types.


Patch:
diff --git a/README.md b/README.md
index b33a4d8..8fded8b 100644
--- a/README.md
+++ b/README.md
@@ -641,7 +641,13 @@ These appear as members of interfaces that look like this:
 {
   "type": "maplike", // or "legacyiterable" / "iterable" / "setlike"
   "idlType": /* One or two types */ ,
-  "readonly": false, // only for maplike and setlike
+  "readonly": null, // only for maplike and setlike
+  "trivia": {
+    "base": " ",
+    "open": "",
+    "close": "",
+    "termination": ""
+  },
   "extAttrs": []
 }
 ```
@@ -650,7 +656,8 @@ The fields are as follows:
 
 * `type`: Always one of "iterable", "legacyiterable", "maplike" or "setlike".
 * `idlType`: An array with one or more [IDL Types](#idl-type) representing the declared type arguments.
-* `readonly`: Whether the maplike or setlike is declared as read only.
+* `readonly`: An object with a string type field `trivia` if the maplike or setlike is declared as read only.
+* `trivia`: A trivia object.
 * `extAttrs`: A list of [extended attributes](#extended-attributes).
 
 
diff --git a/lib/webidl2.js b/lib/webidl2.js
index 2f67c02..685c185 100644
--- a/lib/webidl2.js
+++ b/lib/webidl2.js
@@ -840,7 +840,7 @@
         unconsume(start_position);
         return;
       }
-      ret.trivia.type = ittype.trivia;
+      ret.trivia.base = ittype.trivia;
 
       const secondTypeRequired = ittype.value === "maplike";
       const secondTypeAllowed = secondTypeRequired || ittype.value === "iterable";
diff --git a/lib/writer.js b/lib/writer.js
index 624082c..7f95fab 100644
--- a/lib/writer.js
+++ b/lib/writer.js
@@ -167,7 +167,7 @@
     function iterable_like(it) {
       const readonly = it.readonly ? `${it.readonly.trivia}readonly` : "";
       const bracket = `${it.trivia.open}<${it.idlType.map(type).join("")}${it.trivia.close}>`;
-      return `${readonly}${it.trivia.type}${it.type}${bracket}${it.trivia.termination};`;
+      return `${readonly}${it.trivia.base}${it.type}${bracket}${it.trivia.termination};`;
     }
     function callbackInterface(it) {
       return `${it.trivia.callback}callback${interface_(it)}`;


Test patch:
diff --git a/test/syntax/json/iterable.json b/test/syntax/json/iterable.json
index 35375a1..c8f4929 100644
--- a/test/syntax/json/iterable.json
+++ b/test/syntax/json/iterable.json
@@ -24,7 +24,7 @@
                     }
                 ],
                 "trivia": {
-                    "type": "\n  ",
+                    "base": "\n  ",
                     "open": "",
                     "close": "",
                     "termination": ""
@@ -87,7 +87,7 @@
                     }
                 ],
                 "trivia": {
-                    "type": "\n  ",
+                    "base": "\n  ",
                     "open": "",
                     "close": "",
                     "termination": ""
@@ -147,7 +147,7 @@
                     }
                 ],
                 "trivia": {
-                    "type": "\n  ",
+                    "base": "\n  ",
                     "open": "",
                     "close": "",
                     "termination": ""
diff --git a/test/syntax/json/legacyiterable.json b/test/syntax/json/legacyiterable.json
index 57f5f62..e4a7534 100644
--- a/test/syntax/json/legacyiterable.json
+++ b/test/syntax/json/legacyiterable.json
@@ -24,7 +24,7 @@
                     }
                 ],
                 "trivia": {
-                    "type": "\n  ",
+                    "base": "\n  ",
                     "open": "",
                     "close": "",
                     "termination": ""
diff --git a/test/syntax/json/maplike.json b/test/syntax/json/maplike.json
index 4746ad9..15fa234 100644
--- a/test/syntax/json/maplike.json
+++ b/test/syntax/json/maplike.json
@@ -43,7 +43,7 @@
                 ],
                 "readonly": null,
                 "trivia": {
-                    "type": "\n  ",
+                    "base": "\n  ",
                     "open": "",
                     "close": "",
                     "termination": ""
@@ -107,7 +107,7 @@
                     "trivia": "\n  "
                 },
                 "trivia": {
-                    "type": " ",
+                    "base": " ",
                     "open": "",
                     "close": "",
                     "termination": ""
@@ -203,7 +203,7 @@
                 ],
                 "readonly": null,
                 "trivia": {
-                    "type": "\n    ",
+                    "base": "\n    ",
                     "open": "",
                     "close": "",
                     "termination": ""
diff --git a/test/syntax/json/setlike.json b/test/syntax/json/setlike.json
index 4c797cf..05d12e9 100644
--- a/test/syntax/json/setlike.json
+++ b/test/syntax/json/setlike.json
@@ -25,7 +25,7 @@
                 ],
                 "readonly": null,
                 "trivia": {
-                    "type": "\n  ",
+                    "base": "\n  ",
                     "open": "",
                     "close": "",
                     "termination": ""
@@ -71,7 +71,7 @@
                     "trivia": "\n  "
                 },
                 "trivia": {
-                    "type": " ",
+                    "base": " ",
                     "open": "",
                     "close": "",
                     "termination": ""
@@ -132,7 +132,7 @@
                 ],
                 "readonly": null,
                 "trivia": {
-                    "type": "\n  ",
+                    "base": "\n  ",
                     "open": "",
                     "close": "",
                     "termination": ""