Repository: w3c/webidl2.js (js)

Issue:
Extended Attributes `rhs` should always be there
It's somewhat annoying to have to check for missing properties, as is the case for `rhs` on extended attributes. 

We should make sure we don't conditionally add/remove members - and where they are null, they should just be `null`. 

Pull request description:
Always add rhs property
Fixes #96.

Patch:
diff --git a/lib/webidl2.js b/lib/webidl2.js
index 29da7ba..2f116c4 100644
--- a/lib/webidl2.js
+++ b/lib/webidl2.js
@@ -343,32 +343,28 @@
         name: name.value,
         "arguments": null,
         type: "extended-attribute",
+        rhs: null
       };
       all_ws();
       const eq = consume(OTHER, "=");
       if (eq) {
-        let rhs;
         all_ws();
-        if (rhs = consume(ID)) {
-          ret.rhs = rhs;
-        } else if (rhs = consume(FLOAT)) {
-          ret.rhs = rhs;
-        } else if (rhs = consume(INT)) {
-          ret.rhs = rhs;
-        } else if (rhs = consume(STR)) {
-          ret.rhs = rhs;
-        } else if (consume(OTHER, "(")) {
+        ret.rhs = consume(ID) ||
+          consume(FLOAT) ||
+          consume(INT) ||
+          consume(STR);
+        if (!ret.rhs && consume(OTHER, "(")) {
           // [Exposed=(Window,Worker)]
-          rhs = [];
+          const rhs_list = [];
           const id = consume(ID);
           if (id) {
-            rhs = [id.value];
+            rhs_list.push(id.value);
           }
-          identifiers(rhs);
+          identifiers(rhs_list);
           consume(OTHER, ")") || error("Unexpected token in extended attribute argument list or type pair");
           ret.rhs = {
             type: "identifier-list",
-            value: rhs
+            value: rhs_list
           };
         }
         if (!ret.rhs) return error("No right hand side to extended attribute assignment");


Test patch:
diff --git a/test/syntax/json/allowany.json b/test/syntax/json/allowany.json
index d99fd52..ee898d6 100644
--- a/test/syntax/json/allowany.json
+++ b/test/syntax/json/allowany.json
@@ -77,7 +77,8 @@
                             {
                                 "name": "AllowAny",
                                 "arguments": null,
-                                "type": "extended-attribute"
+                                "type": "extended-attribute",
+                                "rhs": null
                             }
                         ],
                         "idlType": {
diff --git a/test/syntax/json/constructor.json b/test/syntax/json/constructor.json
index 8246372..ee55ef0 100644
--- a/test/syntax/json/constructor.json
+++ b/test/syntax/json/constructor.json
@@ -74,7 +74,8 @@
             {
                 "name": "Constructor",
                 "arguments": null,
-                "type": "extended-attribute"
+                "type": "extended-attribute",
+                "rhs": null
             },
             {
                 "name": "Constructor",
@@ -93,8 +94,9 @@
                         "name": "radius"
                     }
                 ],
-                "type": "extended-attribute"
+                "type": "extended-attribute",
+                "rhs": null
             }
         ]
     }
-]
\ No newline at end of file
+]
diff --git a/test/syntax/json/extended-attributes.json b/test/syntax/json/extended-attributes.json
index ace9316..6526e2a 100644
--- a/test/syntax/json/extended-attributes.json
+++ b/test/syntax/json/extended-attributes.json
@@ -140,7 +140,8 @@
         {
           "name": "Constructor",
           "arguments": null,
-          "type": "extended-attribute"
+          "type": "extended-attribute",
+          "rhs": null
         },
         {
           "name": "Constructor",
@@ -159,8 +160,9 @@
               "name": "radius"
             }
           ],
-          "type": "extended-attribute"
+          "type": "extended-attribute",
+          "rhs": null
         }
       ]
     }
-]
\ No newline at end of file
+]
diff --git a/test/syntax/json/iterable.json b/test/syntax/json/iterable.json
index e9eac84..1e92307 100644
--- a/test/syntax/json/iterable.json
+++ b/test/syntax/json/iterable.json
@@ -65,7 +65,8 @@
                         {
                             "name": "XAttr",
                             "arguments": null,
-                            "type": "extended-attribute"
+                            "type": "extended-attribute",
+                            "rhs": null
                         }
                     ]
                 },
diff --git a/test/syntax/json/maplike.json b/test/syntax/json/maplike.json
index 87ecf79..97e76d5 100644
--- a/test/syntax/json/maplike.json
+++ b/test/syntax/json/maplike.json
@@ -77,7 +77,8 @@
                             {
                                 "name": "XAttr2",
                                 "arguments": null,
-                                "type": "extended-attribute"
+                                "type": "extended-attribute",
+                                "rhs": null
                             }
                         ]
                     },
@@ -91,7 +92,8 @@
                             {
                                 "name": "XAttr3",
                                 "arguments": null,
-                                "type": "extended-attribute"
+                                "type": "extended-attribute",
+                                "rhs": null
                             }
                         ]
                     }
diff --git a/test/syntax/json/nointerfaceobject.json b/test/syntax/json/nointerfaceobject.json
index d75a53c..85987e8 100644
--- a/test/syntax/json/nointerfaceobject.json
+++ b/test/syntax/json/nointerfaceobject.json
@@ -42,7 +42,8 @@
             {
                 "name": "NoInterfaceObject",
                 "arguments": null,
-                "type": "extended-attribute"
+                "type": "extended-attribute",
+                "rhs": null
             }
         ]
     }
diff --git a/test/syntax/json/overloading.json b/test/syntax/json/overloading.json
index f9cef91..8d7e8e2 100644
--- a/test/syntax/json/overloading.json
+++ b/test/syntax/json/overloading.json
@@ -148,7 +148,8 @@
                             {
                                 "name": "AllowAny",
                                 "arguments": null,
-                                "type": "extended-attribute"
+                                "type": "extended-attribute",
+                                "rhs": null
                             }
                         ],
                         "idlType": {
diff --git a/test/syntax/json/overridebuiltins.json b/test/syntax/json/overridebuiltins.json
index 8b47114..4ded17c 100644
--- a/test/syntax/json/overridebuiltins.json
+++ b/test/syntax/json/overridebuiltins.json
@@ -58,7 +58,8 @@
             {
                 "name": "OverrideBuiltins",
                 "arguments": null,
-                "type": "extended-attribute"
+                "type": "extended-attribute",
+                "rhs": null
             }
         ]
     }
diff --git a/test/syntax/json/prototyperoot.json b/test/syntax/json/prototyperoot.json
index c7a4ead..c75f00e 100644
--- a/test/syntax/json/prototyperoot.json
+++ b/test/syntax/json/prototyperoot.json
@@ -26,8 +26,9 @@
             {
                 "name": "PrototypeRoot",
                 "arguments": null,
-                "type": "extended-attribute"
+                "type": "extended-attribute",
+                "rhs": null
             }
         ]
     }
-]
\ No newline at end of file
+]
diff --git a/test/syntax/json/record.json b/test/syntax/json/record.json
index f049e9a..339ae08 100644
--- a/test/syntax/json/record.json
+++ b/test/syntax/json/record.json
@@ -158,7 +158,8 @@
                         "name": "init"
                     }
                 ],
-                "type": "extended-attribute"
+                "type": "extended-attribute",
+                "rhs": null
             }
         ]
     },
@@ -197,7 +198,8 @@
                                 {
                                     "name": "XAttr",
                                     "arguments": null,
-                                    "type": "extended-attribute"
+                                    "type": "extended-attribute",
+                                    "rhs": null
                                 }
                             ]
                         }
diff --git a/test/syntax/json/replaceable.json b/test/syntax/json/replaceable.json
index fb1935f..f53009b 100644
--- a/test/syntax/json/replaceable.json
+++ b/test/syntax/json/replaceable.json
@@ -22,7 +22,8 @@
                     {
                         "name": "Replaceable",
                         "arguments": null,
-                        "type": "extended-attribute"
+                        "type": "extended-attribute",
+                        "rhs": null
                     }
                 ]
             },
diff --git a/test/syntax/json/sequence.json b/test/syntax/json/sequence.json
index 1166391..7982118 100644
--- a/test/syntax/json/sequence.json
+++ b/test/syntax/json/sequence.json
@@ -139,7 +139,8 @@
                                     {
                                         "name": "XAttr",
                                         "arguments": null,
-                                        "type": "extended-attribute"
+                                        "type": "extended-attribute",
+                                        "rhs": null
                                     }
                                 ]
                             }
diff --git a/test/syntax/json/setlike.json b/test/syntax/json/setlike.json
index 9a99f9c..3c1591b 100644
--- a/test/syntax/json/setlike.json
+++ b/test/syntax/json/setlike.json
@@ -58,7 +58,8 @@
                         {
                             "name": "XAttr",
                             "arguments": null,
-                            "type": "extended-attribute"
+                            "type": "extended-attribute",
+                            "rhs": null
                         }
                     ]
                 },
diff --git a/test/syntax/json/stringifier-attribute.json b/test/syntax/json/stringifier-attribute.json
index e85c7aa..acb26c2 100644
--- a/test/syntax/json/stringifier-attribute.json
+++ b/test/syntax/json/stringifier-attribute.json
@@ -42,8 +42,9 @@
             {
                 "name": "Constructor",
                 "arguments": null,
-                "type": "extended-attribute"
+                "type": "extended-attribute",
+                "rhs": null
             }
         ]
     }
-]
\ No newline at end of file
+]
diff --git a/test/syntax/json/stringifier-custom.json b/test/syntax/json/stringifier-custom.json
index a06d1b5..3c84305 100644
--- a/test/syntax/json/stringifier-custom.json
+++ b/test/syntax/json/stringifier-custom.json
@@ -76,7 +76,8 @@
             {
                 "name": "Constructor",
                 "arguments": null,
-                "type": "extended-attribute"
+                "type": "extended-attribute",
+                "rhs": null
             }
         ]
     }
diff --git a/test/syntax/json/typedef.json b/test/syntax/json/typedef.json
index 9846686..612cfe7 100644
--- a/test/syntax/json/typedef.json
+++ b/test/syntax/json/typedef.json
@@ -200,7 +200,8 @@
                 {
                     "name": "Clamp",
                     "arguments": null,
-                    "type": "extended-attribute"
+                    "type": "extended-attribute",
+                    "rhs": null
                 }
             ]
         },
diff --git a/test/syntax/json/uniontype.json b/test/syntax/json/uniontype.json
index 0eab219..c4725d4 100644
--- a/test/syntax/json/uniontype.json
+++ b/test/syntax/json/uniontype.json
@@ -84,7 +84,8 @@
                         {
                            "name": "EnforceRange",
                            "arguments": null,
-                           "type": "extended-attribute"
+                           "type": "extended-attribute",
+                           "rhs": null
                         }
                      ],
                      "nullable": false,