diff --git a/README.md b/README.md index b33a4d89..8fded8b4 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 2f67c02f..685c185c 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 624082ca..7f95fabd 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)}`; diff --git a/test/syntax/json/iterable.json b/test/syntax/json/iterable.json index 35375a1c..c8f49297 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 57f5f628..e4a75346 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 4746ad91..15fa2340 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 4c797cfa..05d12e9b 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": ""