From 47c1d29b2adf6a46faaae7a45fdfdc9090135321 Mon Sep 17 00:00:00 2001 From: Kagami Sascha Rosylight Date: Sun, 17 Jun 2018 19:52:06 +0900 Subject: [PATCH 1/4] document trivia for iterable-likes --- README.md | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index b33a4d89..c843e1d7 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,7 @@ 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. * `extAttrs`: A list of [extended attributes](#extended-attributes). From 62423dbe2fea8fe65167dee846f400e897f4e54d Mon Sep 17 00:00:00 2001 From: Kagami Sascha Rosylight Date: Sun, 17 Jun 2018 19:52:19 +0900 Subject: [PATCH 2/4] use base for consistency with others --- lib/webidl2.js | 2 +- test/syntax/json/iterable.json | 6 +++--- test/syntax/json/legacyiterable.json | 2 +- test/syntax/json/maplike.json | 6 +++--- test/syntax/json/setlike.json | 6 +++--- 5 files changed, 11 insertions(+), 11 deletions(-) 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/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": "" From 1594df422c2618369c05ba40cb43959eef14f588 Mon Sep 17 00:00:00 2001 From: Kagami Sascha Rosylight Date: Sun, 17 Jun 2018 19:54:44 +0900 Subject: [PATCH 3/4] add missing field --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index c843e1d7..8fded8b4 100644 --- a/README.md +++ b/README.md @@ -657,6 +657,7 @@ 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`: 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). From 69688efbc9807c2fecf0d5846547f3ec9c2fc14b Mon Sep 17 00:00:00 2001 From: Kagami Sascha Rosylight Date: Sun, 17 Jun 2018 20:51:56 +0900 Subject: [PATCH 4/4] rename in writer --- lib/writer.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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)}`;