Repository: w3c/webidl2.js
Pull request #90 (2017-10-23 02:45:02)

feat: give extended attributes a type

marcoscaceres: thanks @TimothyGu! 

Patch:
diff --git a/README.md b/README.md
index 180a7f0..ccfef66 100644
--- a/README.md
+++ b/README.md
@@ -530,6 +530,7 @@ Extended attributes are arrays of items that look like this:
   "extAttrs": [{
     "name": "TreatNullAs",
     "arguments": null,
+    "type": "extended-attribute",
     "rhs": {
       "type": "identifier",
       "value": "EmptyString"
@@ -547,6 +548,7 @@ The fields are as follows:
   whereas the lack thereof will yield a `null`. If there is an `rhs` field then
   they are the right-hand side's arguments, otherwise they apply to the extended
   attribute directly.
+* `type`: Always `"extended-attribute"`.
 * `rhs`: If there is a right-hand side, this will capture its `type` (which can be
   "identifier" or "identifier-list") and its `value`.
 * `typePair`: If the extended attribute is a `MapClass` this will capture the
diff --git a/lib/webidl2.js b/lib/webidl2.js
index da39f67..703a9bf 100644
--- a/lib/webidl2.js
+++ b/lib/webidl2.js
@@ -334,7 +334,8 @@
       if (!name) return;
       const ret = {
         name: name.value,
-        "arguments": null
+        "arguments": null,
+        type: "extended-attribute",
       };
       all_ws();
       const eq = consume(OTHER, "=");


Test patch:
diff --git a/test/syntax/json/allowany.json b/test/syntax/json/allowany.json
index f3a424e..ade5ba8 100644
--- a/test/syntax/json/allowany.json
+++ b/test/syntax/json/allowany.json
@@ -79,7 +79,8 @@
                         "extAttrs": [
                             {
                                 "name": "AllowAny",
-                                "arguments": null
+                                "arguments": null,
+                                "type": "extended-attribute"
                             }
                         ],
                         "idlType": {
diff --git a/test/syntax/json/constructor.json b/test/syntax/json/constructor.json
index ad6e1d8..8246372 100644
--- a/test/syntax/json/constructor.json
+++ b/test/syntax/json/constructor.json
@@ -73,7 +73,8 @@
         "extAttrs": [
             {
                 "name": "Constructor",
-                "arguments": null
+                "arguments": null,
+                "type": "extended-attribute"
             },
             {
                 "name": "Constructor",
@@ -91,7 +92,8 @@
                         },
                         "name": "radius"
                     }
-                ]
+                ],
+                "type": "extended-attribute"
             }
         ]
     }
diff --git a/test/syntax/json/extended-attributes.json b/test/syntax/json/extended-attributes.json
index de8a816..ace9316 100644
--- a/test/syntax/json/extended-attributes.json
+++ b/test/syntax/json/extended-attributes.json
@@ -9,6 +9,7 @@
             {
                 "name": "Global",
                 "arguments": null,
+                "type": "extended-attribute",
                 "rhs": {
                     "type": "identifier-list",
                     "value": [
@@ -20,6 +21,7 @@
             {
                 "name": "Exposed",
                 "arguments": null,
+                "type": "extended-attribute",
                 "rhs": {
                     "type": "identifier",
                     "value": "ServiceWorker"
@@ -37,6 +39,7 @@
         {
           "name": "IntAttr",
           "arguments": null,
+          "type": "extended-attribute",
           "rhs": {
             "type": "integer",
             "value": "0"
@@ -45,6 +48,7 @@
         {
           "name": "FloatAttr",
           "arguments": null,
+          "type": "extended-attribute",
           "rhs": {
             "type": "float",
             "value": "3.14"
@@ -53,6 +57,7 @@
         {
           "name": "StringAttr",
           "arguments": null,
+          "type": "extended-attribute",
           "rhs": {
             "type": "string",
             "value": "\"abc\""
@@ -134,7 +139,8 @@
       "extAttrs": [
         {
           "name": "Constructor",
-          "arguments": null
+          "arguments": null,
+          "type": "extended-attribute"
         },
         {
           "name": "Constructor",
@@ -152,7 +158,8 @@
               },
               "name": "radius"
             }
-          ]
+          ],
+          "type": "extended-attribute"
         }
       ]
     }
diff --git a/test/syntax/json/iterable.json b/test/syntax/json/iterable.json
index ecec327..e9eac84 100644
--- a/test/syntax/json/iterable.json
+++ b/test/syntax/json/iterable.json
@@ -64,7 +64,8 @@
                     "extAttrs": [
                         {
                             "name": "XAttr",
-                            "arguments": null
+                            "arguments": null,
+                            "type": "extended-attribute"
                         }
                     ]
                 },
diff --git a/test/syntax/json/maplike.json b/test/syntax/json/maplike.json
index 106f170..87ecf79 100644
--- a/test/syntax/json/maplike.json
+++ b/test/syntax/json/maplike.json
@@ -76,7 +76,8 @@
                         "extAttrs": [
                             {
                                 "name": "XAttr2",
-                                "arguments": null
+                                "arguments": null,
+                                "type": "extended-attribute"
                             }
                         ]
                     },
@@ -89,7 +90,8 @@
                         "extAttrs": [
                             {
                                 "name": "XAttr3",
-                                "arguments": null
+                                "arguments": null,
+                                "type": "extended-attribute"
                             }
                         ]
                     }
diff --git a/test/syntax/json/namedconstructor.json b/test/syntax/json/namedconstructor.json
index cdbbc62..cee1630 100644
--- a/test/syntax/json/namedconstructor.json
+++ b/test/syntax/json/namedconstructor.json
@@ -9,6 +9,7 @@
             {
                 "name": "NamedConstructor",
                 "arguments": null,
+                "type": "extended-attribute",
                 "rhs": {
                     "type": "identifier",
                     "value": "Audio"
@@ -31,6 +32,7 @@
                         "name": "src"
                     }
                 ],
+                "type": "extended-attribute",
                 "rhs": {
                     "type": "identifier",
                     "value": "Audio"
diff --git a/test/syntax/json/nointerfaceobject.json b/test/syntax/json/nointerfaceobject.json
index 37d4931..9efbdc7 100644
--- a/test/syntax/json/nointerfaceobject.json
+++ b/test/syntax/json/nointerfaceobject.json
@@ -42,7 +42,8 @@
         "extAttrs": [
             {
                 "name": "NoInterfaceObject",
-                "arguments": null
+                "arguments": null,
+                "type": "extended-attribute"
             }
         ]
     }
diff --git a/test/syntax/json/overloading.json b/test/syntax/json/overloading.json
index 81f28e3..8893a89 100644
--- a/test/syntax/json/overloading.json
+++ b/test/syntax/json/overloading.json
@@ -151,7 +151,8 @@
                         "extAttrs": [
                             {
                                 "name": "AllowAny",
-                                "arguments": null
+                                "arguments": null,
+                                "type": "extended-attribute"
                             }
                         ],
                         "idlType": {
diff --git a/test/syntax/json/overridebuiltins.json b/test/syntax/json/overridebuiltins.json
index 31c1516..8b8684b 100644
--- a/test/syntax/json/overridebuiltins.json
+++ b/test/syntax/json/overridebuiltins.json
@@ -58,7 +58,8 @@
         "extAttrs": [
             {
                 "name": "OverrideBuiltins",
-                "arguments": null
+                "arguments": null,
+                "type": "extended-attribute"
             }
         ]
     }
diff --git a/test/syntax/json/prototyperoot.json b/test/syntax/json/prototyperoot.json
index f521431..c7a4ead 100644
--- a/test/syntax/json/prototyperoot.json
+++ b/test/syntax/json/prototyperoot.json
@@ -25,7 +25,8 @@
         "extAttrs": [
             {
                 "name": "PrototypeRoot",
-                "arguments": null
+                "arguments": null,
+                "type": "extended-attribute"
             }
         ]
     }
diff --git a/test/syntax/json/putforwards.json b/test/syntax/json/putforwards.json
index 692aae1..1b0a7b6 100644
--- a/test/syntax/json/putforwards.json
+++ b/test/syntax/json/putforwards.json
@@ -22,6 +22,7 @@
                     {
                         "name": "PutForwards",
                         "arguments": null,
+                        "type": "extended-attribute",
                         "rhs": {
                             "type": "identifier",
                             "value": "full"
diff --git a/test/syntax/json/record.json b/test/syntax/json/record.json
index deb9ed3..9ba41ab 100644
--- a/test/syntax/json/record.json
+++ b/test/syntax/json/record.json
@@ -160,7 +160,8 @@
                         },
                         "name": "init"
                     }
-                ]
+                ],
+                "type": "extended-attribute"
             }
         ]
     },
@@ -199,7 +200,8 @@
                             "extAttrs": [
                                 {
                                     "name": "XAttr",
-                                    "arguments": null
+                                    "arguments": null,
+                                    "type": "extended-attribute"
                                 }
                             ]
                         }
diff --git a/test/syntax/json/replaceable.json b/test/syntax/json/replaceable.json
index 348b06f..c6ccba2 100644
--- a/test/syntax/json/replaceable.json
+++ b/test/syntax/json/replaceable.json
@@ -21,7 +21,8 @@
                 "extAttrs": [
                     {
                         "name": "Replaceable",
-                        "arguments": null
+                        "arguments": null,
+                        "type": "extended-attribute"
                     }
                 ]
             },
diff --git a/test/syntax/json/sequence.json b/test/syntax/json/sequence.json
index a98af34..8212f82 100644
--- a/test/syntax/json/sequence.json
+++ b/test/syntax/json/sequence.json
@@ -142,7 +142,8 @@
                                 "extAttrs": [
                                     {
                                         "name": "XAttr",
-                                        "arguments": null
+                                        "arguments": null,
+                                        "type": "extended-attribute"
                                     }
                                 ]
                             }
diff --git a/test/syntax/json/setlike.json b/test/syntax/json/setlike.json
index 62e2d39..9a99f9c 100644
--- a/test/syntax/json/setlike.json
+++ b/test/syntax/json/setlike.json
@@ -57,7 +57,8 @@
                     "extAttrs": [
                         {
                             "name": "XAttr",
-                            "arguments": null
+                            "arguments": null,
+                            "type": "extended-attribute"
                         }
                     ]
                 },
diff --git a/test/syntax/json/stringifier-attribute.json b/test/syntax/json/stringifier-attribute.json
index 9cf4892..e85c7aa 100644
--- a/test/syntax/json/stringifier-attribute.json
+++ b/test/syntax/json/stringifier-attribute.json
@@ -41,7 +41,8 @@
         "extAttrs": [
             {
                 "name": "Constructor",
-                "arguments": null
+                "arguments": null,
+                "type": "extended-attribute"
             }
         ]
     }
diff --git a/test/syntax/json/stringifier-custom.json b/test/syntax/json/stringifier-custom.json
index 05568b6..76b2fc0 100644
--- a/test/syntax/json/stringifier-custom.json
+++ b/test/syntax/json/stringifier-custom.json
@@ -76,7 +76,8 @@
         "extAttrs": [
             {
                 "name": "Constructor",
-                "arguments": null
+                "arguments": null,
+                "type": "extended-attribute"
             }
         ]
     }
diff --git a/test/syntax/json/treatasnull.json b/test/syntax/json/treatasnull.json
index f8ebe3f..21c7b8e 100644
--- a/test/syntax/json/treatasnull.json
+++ b/test/syntax/json/treatasnull.json
@@ -60,6 +60,7 @@
                             {
                                 "name": "TreatNullAs",
                                 "arguments": null,
+                                "type": "extended-attribute",
                                 "rhs": {
                                     "type": "identifier",
                                     "value": "EmptyString"
diff --git a/test/syntax/json/treatasundefined.json b/test/syntax/json/treatasundefined.json
index e72bd25..61a96b2 100644
--- a/test/syntax/json/treatasundefined.json
+++ b/test/syntax/json/treatasundefined.json
@@ -60,6 +60,7 @@
                             {
                                 "name": "TreatUndefinedAs",
                                 "arguments": null,
+                                "type": "extended-attribute",
                                 "rhs": {
                                     "type": "identifier",
                                     "value": "EmptyString"
diff --git a/test/syntax/json/typedef.json b/test/syntax/json/typedef.json
index 4154d19..bcb6a63 100644
--- a/test/syntax/json/typedef.json
+++ b/test/syntax/json/typedef.json
@@ -201,7 +201,8 @@
             "extAttrs": [
                 {
                     "name": "Clamp",
-                    "arguments": null
+                    "arguments": null,
+                    "type": "extended-attribute"
                 }
             ]
         },
diff --git a/test/syntax/json/uniontype.json b/test/syntax/json/uniontype.json
index 343a44b..0eab219 100644
--- a/test/syntax/json/uniontype.json
+++ b/test/syntax/json/uniontype.json
@@ -83,7 +83,8 @@
                      "extAttrs": [
                         {
                            "name": "EnforceRange",
-                           "arguments": null
+                           "arguments": null,
+                           "type": "extended-attribute"
                         }
                      ],
                      "nullable": false,