Repository: w3c/webidl2.js (js)

Issue:
Support full whitespace conservation
Currently, e.g.

```
TypeA /* Hi, I'm a comment */ includes          TypeB
```

automatically becomes `TypeA includes TypeB` even with `ws: true`, as both parser and writer do not support full whitespace conservation. 

Pull request:
BREAKING CHANGE: support full whitespace conservation
Yeah... so this fixes #125, but probably this is too big to review.

Breaking changes here:

1. Modifiers are now objects rather than Booleans, with `trivia` field.
2. `extAttrs` field now gives a nullable object with `items` and `trivia` field rather than an array.
3. Some fields on operation objects are now moved into `body`, because `stringify;` is a bodyless operation.
4. `name` field on operations now gives a nullable object with `trivia` field, as operations can be anonymous.

This should finally enable ReSpec to upgrade to the latest webidl2.js.

Patch:
diff --git a/lib/webidl2.js b/lib/webidl2.js
index 16771e8..2f67c02 100644
--- a/lib/webidl2.js
+++ b/lib/webidl2.js
@@ -140,6 +140,13 @@
       }
       lastIndex = result;
     }
+
+    // remaining trivia as eof
+    tokens.push({
+      type: "eof",
+      trivia
+    });
+
     return tokens;
 
     function attemptTokenMatch(type, { noFlushTrivia } = {}) {
@@ -211,7 +218,7 @@
         .slice(consume_position, consume_position + maxTokens)
         .map(t => t.trivia + t.value).join("");
       // Count newlines preceding the actual erroneous token
-      if (tokens[consume_position]) {
+      if (tokens[consume_position] && !probe("eof")) {
         line += count(tokens[consume_position].trivia, "\n");
       }
 
@@ -1168,6 +1175,7 @@
         def.extAttrs = ea;
         defs.push(def);
       }
+      defs.push(consume("eof"));
       return defs;
     }
     const res = definitions();
@@ -1183,9 +1191,13 @@
   };
 
   if (typeof module !== 'undefined' && typeof module.exports !== 'undefined') {
+    Object.assign(obj, require("./writer.js"));
     module.exports = obj;
   } else if (typeof define === 'function' && define.amd) {
-    define([], () => obj);
+    define(["writer"], writer => {
+      Object.assign(obj, writer);
+      return obj;
+    });
   } else {
     (self || window).WebIDL2 = obj;
   }
diff --git a/lib/writer.js b/lib/writer.js
index c66c54e..624082c 100644
--- a/lib/writer.js
+++ b/lib/writer.js
@@ -172,6 +172,9 @@
     function callbackInterface(it) {
       return `${it.trivia.callback}callback${interface_(it)}`;
     }
+    function eof(it) {
+      return it.trivia;
+    }
 
     const table = {
       interface: interface_,
@@ -191,7 +194,8 @@
       legacyiterable: iterable_like,
       maplike: iterable_like,
       setlike: iterable_like,
-      "callback interface": callbackInterface
+      "callback interface": callbackInterface,
+      eof
     };
     function dispatch(it) {
       const dispatcher = table[it.type];


Test patch:
diff --git a/test/syntax/json/allowany.json b/test/syntax/json/allowany.json
index 081f63b..8a1aff2 100644
--- a/test/syntax/json/allowany.json
+++ b/test/syntax/json/allowany.json
@@ -204,5 +204,9 @@
         },
         "inheritance": null,
         "extAttrs": null
+    },
+    {
+        "type": "eof",
+        "trivia": ""
     }
 ]
diff --git a/test/syntax/json/attributes.json b/test/syntax/json/attributes.json
index 74cd3b8..a3729f0 100644
--- a/test/syntax/json/attributes.json
+++ b/test/syntax/json/attributes.json
@@ -77,5 +77,9 @@
         },
         "inheritance": null,
         "extAttrs": null
+    },
+    {
+        "type": "eof",
+        "trivia": "\n"
     }
 ]
diff --git a/test/syntax/json/callback.json b/test/syntax/json/callback.json
index 0986de7..ba85fc0 100644
--- a/test/syntax/json/callback.json
+++ b/test/syntax/json/callback.json
@@ -226,5 +226,9 @@
             "termination": ""
         },
         "extAttrs": null
+    },
+    {
+        "type": "eof",
+        "trivia": "\n"
     }
 ]
diff --git a/test/syntax/json/constants.json b/test/syntax/json/constants.json
index 7eb19c9..7dd99cc 100644
--- a/test/syntax/json/constants.json
+++ b/test/syntax/json/constants.json
@@ -270,5 +270,9 @@
         },
         "inheritance": null,
         "extAttrs": null
+    },
+    {
+        "type": "eof",
+        "trivia": ""
     }
 ]
diff --git a/test/syntax/json/constructor.json b/test/syntax/json/constructor.json
index 4aebcf9..e6f141f 100644
--- a/test/syntax/json/constructor.json
+++ b/test/syntax/json/constructor.json
@@ -200,5 +200,9 @@
                 }
             ]
         }
+    },
+    {
+        "type": "eof",
+        "trivia": ""
     }
 ]
diff --git a/test/syntax/json/dictionary-inherits.json b/test/syntax/json/dictionary-inherits.json
index bb086cb..62d46f5 100644
--- a/test/syntax/json/dictionary-inherits.json
+++ b/test/syntax/json/dictionary-inherits.json
@@ -161,5 +161,9 @@
             }
         },
         "extAttrs": null
+    },
+    {
+        "type": "eof",
+        "trivia": ""
     }
 ]
diff --git a/test/syntax/json/dictionary.json b/test/syntax/json/dictionary.json
index f323d0d..f245fa6 100644
--- a/test/syntax/json/dictionary.json
+++ b/test/syntax/json/dictionary.json
@@ -269,5 +269,9 @@
             "termination": ""
         },
         "extAttrs": null
+    },
+    {
+        "type": "eof",
+        "trivia": ""
     }
 ]
diff --git a/test/syntax/json/documentation-dos.json b/test/syntax/json/documentation-dos.json
index 27efd44..975f0a5 100644
--- a/test/syntax/json/documentation-dos.json
+++ b/test/syntax/json/documentation-dos.json
@@ -13,5 +13,9 @@
         },
         "inheritance": null,
         "extAttrs": null
+    },
+    {
+        "type": "eof",
+        "trivia": ""
     }
 ]
diff --git a/test/syntax/json/documentation.json b/test/syntax/json/documentation.json
index 18a4f91..8b0e24f 100644
--- a/test/syntax/json/documentation.json
+++ b/test/syntax/json/documentation.json
@@ -13,5 +13,9 @@
         },
         "inheritance": null,
         "extAttrs": null
+    },
+    {
+        "type": "eof",
+        "trivia": ""
     }
 ]
diff --git a/test/syntax/json/enum.json b/test/syntax/json/enum.json
index f5fa094..84485a7 100644
--- a/test/syntax/json/enum.json
+++ b/test/syntax/json/enum.json
@@ -249,5 +249,9 @@
             "termination": ""
         },
         "extAttrs": null
+    },
+    {
+        "type": "eof",
+        "trivia": ""
     }
 ]
diff --git a/test/syntax/json/equivalent-decl.json b/test/syntax/json/equivalent-decl.json
index b8805e1..237a072 100644
--- a/test/syntax/json/equivalent-decl.json
+++ b/test/syntax/json/equivalent-decl.json
@@ -592,5 +592,9 @@
         },
         "inheritance": null,
         "extAttrs": null
+    },
+    {
+        "type": "eof",
+        "trivia": ""
     }
 ]
diff --git a/test/syntax/json/extended-attributes.json b/test/syntax/json/extended-attributes.json
index f6a5437..fa57cd8 100644
--- a/test/syntax/json/extended-attributes.json
+++ b/test/syntax/json/extended-attributes.json
@@ -481,5 +481,9 @@
                 }
             ]
         }
+    },
+    {
+        "type": "eof",
+        "trivia": "\n"
     }
 ]
diff --git a/test/syntax/json/generic.json b/test/syntax/json/generic.json
index 7687ba7..96d98ab 100644
--- a/test/syntax/json/generic.json
+++ b/test/syntax/json/generic.json
@@ -398,5 +398,9 @@
             }
         },
         "extAttrs": null
+    },
+    {
+        "type": "eof",
+        "trivia": "\n"
     }
 ]
diff --git a/test/syntax/json/getter-setter.json b/test/syntax/json/getter-setter.json
index 3ded434..5dd0e0f 100644
--- a/test/syntax/json/getter-setter.json
+++ b/test/syntax/json/getter-setter.json
@@ -209,5 +209,9 @@
         },
         "inheritance": null,
         "extAttrs": null
+    },
+    {
+        "type": "eof",
+        "trivia": ""
     }
 ]
diff --git a/test/syntax/json/identifier-qualified-names.json b/test/syntax/json/identifier-qualified-names.json
index 0fa2857..0a5ab36 100644
--- a/test/syntax/json/identifier-qualified-names.json
+++ b/test/syntax/json/identifier-qualified-names.json
@@ -334,5 +334,9 @@
         },
         "inheritance": null,
         "extAttrs": null
+    },
+    {
+        "type": "eof",
+        "trivia": "\n"
     }
 ]
diff --git a/test/syntax/json/implements.json b/test/syntax/json/implements.json
index 8485130..62fd9fc 100644
--- a/test/syntax/json/implements.json
+++ b/test/syntax/json/implements.json
@@ -204,5 +204,9 @@
             "termination": ""
         },
         "extAttrs": null
+    },
+    {
+        "type": "eof",
+        "trivia": "\n"
     }
 ]
diff --git a/test/syntax/json/indexed-properties.json b/test/syntax/json/indexed-properties.json
index 207afb6..a3badfd 100644
--- a/test/syntax/json/indexed-properties.json
+++ b/test/syntax/json/indexed-properties.json
@@ -532,5 +532,9 @@
         },
         "inheritance": null,
         "extAttrs": null
+    },
+    {
+        "type": "eof",
+        "trivia": "\n"
     }
 ]
diff --git a/test/syntax/json/inherits-getter.json b/test/syntax/json/inherits-getter.json
index 5da97aa..0745ce2 100644
--- a/test/syntax/json/inherits-getter.json
+++ b/test/syntax/json/inherits-getter.json
@@ -191,5 +191,9 @@
             }
         },
         "extAttrs": null
+    },
+    {
+        "type": "eof",
+        "trivia": "\n"
     }
 ]
diff --git a/test/syntax/json/interface-inherits.json b/test/syntax/json/interface-inherits.json
index dbead34..1a403a5 100644
--- a/test/syntax/json/interface-inherits.json
+++ b/test/syntax/json/interface-inherits.json
@@ -148,5 +148,9 @@
             }
         },
         "extAttrs": null
+    },
+    {
+        "type": "eof",
+        "trivia": ""
     }
 ]
diff --git a/test/syntax/json/iterable.json b/test/syntax/json/iterable.json
index 5f35b79..35375a1 100644
--- a/test/syntax/json/iterable.json
+++ b/test/syntax/json/iterable.json
@@ -164,5 +164,9 @@
         },
         "inheritance": null,
         "extAttrs": null
+    },
+    {
+        "type": "eof",
+        "trivia": ""
     }
 ]
diff --git a/test/syntax/json/legacyiterable.json b/test/syntax/json/legacyiterable.json
index 5c15851..57f5f62 100644
--- a/test/syntax/json/legacyiterable.json
+++ b/test/syntax/json/legacyiterable.json
@@ -41,5 +41,9 @@
         },
         "inheritance": null,
         "extAttrs": null
+    },
+    {
+        "type": "eof",
+        "trivia": "\n"
     }
 ]
diff --git a/test/syntax/json/maplike.json b/test/syntax/json/maplike.json
index fec5d21..4746ad9 100644
--- a/test/syntax/json/maplike.json
+++ b/test/syntax/json/maplike.json
@@ -220,5 +220,9 @@
         },
         "inheritance": null,
         "extAttrs": null
+    },
+    {
+        "type": "eof",
+        "trivia": "\n"
     }
 ]
diff --git a/test/syntax/json/mixin.json b/test/syntax/json/mixin.json
index d1e9725..de0e5aa 100644
--- a/test/syntax/json/mixin.json
+++ b/test/syntax/json/mixin.json
@@ -120,5 +120,9 @@
             "termination": ""
         },
         "extAttrs": null
+    },
+    {
+        "type": "eof",
+        "trivia": "\n"
     }
 ]
diff --git a/test/syntax/json/namedconstructor.json b/test/syntax/json/namedconstructor.json
index 20eaea6..377edd5 100644
--- a/test/syntax/json/namedconstructor.json
+++ b/test/syntax/json/namedconstructor.json
@@ -97,5 +97,9 @@
                 }
             ]
         }
+    },
+    {
+        "type": "eof",
+        "trivia": ""
     }
 ]
diff --git a/test/syntax/json/namespace.json b/test/syntax/json/namespace.json
index 0cefe8d..79bd21a 100644
--- a/test/syntax/json/namespace.json
+++ b/test/syntax/json/namespace.json
@@ -255,5 +255,9 @@
             "termination": ""
         },
         "extAttrs": null
+    },
+    {
+        "type": "eof",
+        "trivia": ""
     }
 ]
diff --git a/test/syntax/json/nointerfaceobject.json b/test/syntax/json/nointerfaceobject.json
index 44b8591..1765100 100644
--- a/test/syntax/json/nointerfaceobject.json
+++ b/test/syntax/json/nointerfaceobject.json
@@ -101,5 +101,9 @@
                 }
             ]
         }
+    },
+    {
+        "type": "eof",
+        "trivia": ""
     }
 ]
diff --git a/test/syntax/json/nullable.json b/test/syntax/json/nullable.json
index eafa299..fb1bb4d 100644
--- a/test/syntax/json/nullable.json
+++ b/test/syntax/json/nullable.json
@@ -97,5 +97,9 @@
         },
         "inheritance": null,
         "extAttrs": null
+    },
+    {
+        "type": "eof",
+        "trivia": ""
     }
 ]
diff --git a/test/syntax/json/nullableobjects.json b/test/syntax/json/nullableobjects.json
index 67c54e9..6c8e718 100644
--- a/test/syntax/json/nullableobjects.json
+++ b/test/syntax/json/nullableobjects.json
@@ -182,5 +182,9 @@
         },
         "inheritance": null,
         "extAttrs": null
+    },
+    {
+        "type": "eof",
+        "trivia": ""
     }
 ]
diff --git a/test/syntax/json/operation-optional-arg.json b/test/syntax/json/operation-optional-arg.json
index 90aa680..abf8dc0 100644
--- a/test/syntax/json/operation-optional-arg.json
+++ b/test/syntax/json/operation-optional-arg.json
@@ -180,5 +180,9 @@
         },
         "inheritance": null,
         "extAttrs": null
+    },
+    {
+        "type": "eof",
+        "trivia": ""
     }
 ]
diff --git a/test/syntax/json/overloading.json b/test/syntax/json/overloading.json
index 4b1d951..0ee805b 100644
--- a/test/syntax/json/overloading.json
+++ b/test/syntax/json/overloading.json
@@ -607,5 +607,9 @@
         },
         "inheritance": null,
         "extAttrs": null
+    },
+    {
+        "type": "eof",
+        "trivia": "\n"
     }
 ]
diff --git a/test/syntax/json/overridebuiltins.json b/test/syntax/json/overridebuiltins.json
index c0265b8..9171d34 100644
--- a/test/syntax/json/overridebuiltins.json
+++ b/test/syntax/json/overridebuiltins.json
@@ -135,5 +135,9 @@
                 }
             ]
         }
+    },
+    {
+        "type": "eof",
+        "trivia": ""
     }
 ]
diff --git a/test/syntax/json/partial-interface.json b/test/syntax/json/partial-interface.json
index 41bd2dd..2d9c2d7 100644
--- a/test/syntax/json/partial-interface.json
+++ b/test/syntax/json/partial-interface.json
@@ -91,5 +91,9 @@
             "termination": ""
         },
         "extAttrs": null
+    },
+    {
+        "type": "eof",
+        "trivia": ""
     }
 ]
diff --git a/test/syntax/json/primitives.json b/test/syntax/json/primitives.json
index 55f1913..6e7c093 100644
--- a/test/syntax/json/primitives.json
+++ b/test/syntax/json/primitives.json
@@ -545,5 +545,9 @@
         },
         "inheritance": null,
         "extAttrs": null
+    },
+    {
+        "type": "eof",
+        "trivia": "\n"
     }
 ]
diff --git a/test/syntax/json/promise-void.json b/test/syntax/json/promise-void.json
index 3815c8e..c5f670f 100644
--- a/test/syntax/json/promise-void.json
+++ b/test/syntax/json/promise-void.json
@@ -66,5 +66,9 @@
         },
         "inheritance": null,
         "extAttrs": null
+    },
+    {
+        "type": "eof",
+        "trivia": "\n"
     }
 ]
diff --git a/test/syntax/json/prototyperoot.json b/test/syntax/json/prototyperoot.json
index bd62b47..5b526e7 100644
--- a/test/syntax/json/prototyperoot.json
+++ b/test/syntax/json/prototyperoot.json
@@ -66,5 +66,9 @@
                 }
             ]
         }
+    },
+    {
+        "type": "eof",
+        "trivia": ""
     }
 ]
diff --git a/test/syntax/json/putforwards.json b/test/syntax/json/putforwards.json
index 376c8e6..e9e79a8 100644
--- a/test/syntax/json/putforwards.json
+++ b/test/syntax/json/putforwards.json
@@ -103,5 +103,9 @@
         },
         "inheritance": null,
         "extAttrs": null
+    },
+    {
+        "type": "eof",
+        "trivia": ""
     }
 ]
diff --git a/test/syntax/json/record.json b/test/syntax/json/record.json
index 30bb762..d05908f 100644
--- a/test/syntax/json/record.json
+++ b/test/syntax/json/record.json
@@ -462,5 +462,9 @@
         },
         "inheritance": null,
         "extAttrs": null
+    },
+    {
+        "type": "eof",
+        "trivia": "\n"
     }
 ]
diff --git a/test/syntax/json/reg-operations.json b/test/syntax/json/reg-operations.json
index e1a6dc4..d356e6e 100644
--- a/test/syntax/json/reg-operations.json
+++ b/test/syntax/json/reg-operations.json
@@ -305,5 +305,9 @@
         },
         "inheritance": null,
         "extAttrs": null
+    },
+    {
+        "type": "eof",
+        "trivia": ""
     }
 ]
diff --git a/test/syntax/json/replaceable.json b/test/syntax/json/replaceable.json
index 2861710..0bcac8e 100644
--- a/test/syntax/json/replaceable.json
+++ b/test/syntax/json/replaceable.json
@@ -105,5 +105,9 @@
         },
         "inheritance": null,
         "extAttrs": null
+    },
+    {
+        "type": "eof",
+        "trivia": ""
     }
 ]
diff --git a/test/syntax/json/sequence.json b/test/syntax/json/sequence.json
index dbcc6c8..1bac1a1 100644
--- a/test/syntax/json/sequence.json
+++ b/test/syntax/json/sequence.json
@@ -286,5 +286,9 @@
         },
         "inheritance": null,
         "extAttrs": null
+    },
+    {
+        "type": "eof",
+        "trivia": "\n"
     }
 ]
diff --git a/test/syntax/json/setlike.json b/test/syntax/json/setlike.json
index f862549..4c797cf 100644
--- a/test/syntax/json/setlike.json
+++ b/test/syntax/json/setlike.json
@@ -149,5 +149,9 @@
         },
         "inheritance": null,
         "extAttrs": null
+    },
+    {
+        "type": "eof",
+        "trivia": "\n"
     }
 ]
diff --git a/test/syntax/json/static.json b/test/syntax/json/static.json
index 88ed34c..c3a7bba 100644
--- a/test/syntax/json/static.json
+++ b/test/syntax/json/static.json
@@ -282,5 +282,9 @@
         },
         "inheritance": null,
         "extAttrs": null
+    },
+    {
+        "type": "eof",
+        "trivia": ""
     }
 ]
diff --git a/test/syntax/json/stringifier-attribute.json b/test/syntax/json/stringifier-attribute.json
index 56d9c17..fd6f129 100644
--- a/test/syntax/json/stringifier-attribute.json
+++ b/test/syntax/json/stringifier-attribute.json
@@ -96,5 +96,9 @@
                 }
             ]
         }
+    },
+    {
+        "type": "eof",
+        "trivia": ""
     }
 ]
diff --git a/test/syntax/json/stringifier-custom.json b/test/syntax/json/stringifier-custom.json
index 26b3c18..3edf1f0 100644
--- a/test/syntax/json/stringifier-custom.json
+++ b/test/syntax/json/stringifier-custom.json
@@ -163,5 +163,9 @@
                 }
             ]
         }
+    },
+    {
+        "type": "eof",
+        "trivia": ""
     }
 ]
diff --git a/test/syntax/json/stringifier.json b/test/syntax/json/stringifier.json
index 6983f06..e149983 100644
--- a/test/syntax/json/stringifier.json
+++ b/test/syntax/json/stringifier.json
@@ -82,5 +82,9 @@
         },
         "inheritance": null,
         "extAttrs": null
+    },
+    {
+        "type": "eof",
+        "trivia": ""
     }
 ]
diff --git a/test/syntax/json/treatasnull.json b/test/syntax/json/treatasnull.json
index e61d69a..69bce25 100644
--- a/test/syntax/json/treatasnull.json
+++ b/test/syntax/json/treatasnull.json
@@ -165,5 +165,9 @@
         },
         "inheritance": null,
         "extAttrs": null
+    },
+    {
+        "type": "eof",
+        "trivia": ""
     }
 ]
diff --git a/test/syntax/json/treatasundefined.json b/test/syntax/json/treatasundefined.json
index 2b7c585..3f4cb83 100644
--- a/test/syntax/json/treatasundefined.json
+++ b/test/syntax/json/treatasundefined.json
@@ -165,5 +165,9 @@
         },
         "inheritance": null,
         "extAttrs": null
+    },
+    {
+        "type": "eof",
+        "trivia": ""
     }
 ]
diff --git a/test/syntax/json/typedef-union.json b/test/syntax/json/typedef-union.json
index 0e9a4f3..da3ba7e 100644
--- a/test/syntax/json/typedef-union.json
+++ b/test/syntax/json/typedef-union.json
@@ -94,5 +94,9 @@
             "termination": ""
         },
         "extAttrs": null
+    },
+    {
+        "type": "eof",
+        "trivia": "\n"
     }
 ]
diff --git a/test/syntax/json/typedef.json b/test/syntax/json/typedef.json
index e420235..6537966 100644
--- a/test/syntax/json/typedef.json
+++ b/test/syntax/json/typedef.json
@@ -421,5 +421,9 @@
             "termination": ""
         },
         "extAttrs": null
+    },
+    {
+        "type": "eof",
+        "trivia": ""
     }
 ]
diff --git a/test/syntax/json/typesuffixes.json b/test/syntax/json/typesuffixes.json
index 50010ef..b04ecec 100644
--- a/test/syntax/json/typesuffixes.json
+++ b/test/syntax/json/typesuffixes.json
@@ -107,5 +107,9 @@
         },
         "inheritance": null,
         "extAttrs": null
+    },
+    {
+        "type": "eof",
+        "trivia": "\n"
     }
 ]
diff --git a/test/syntax/json/uniontype.json b/test/syntax/json/uniontype.json
index 89e0064..cecc82c 100644
--- a/test/syntax/json/uniontype.json
+++ b/test/syntax/json/uniontype.json
@@ -251,5 +251,9 @@
         },
         "inheritance": null,
         "extAttrs": null
+    },
+    {
+        "type": "eof",
+        "trivia": ""
     }
 ]
diff --git a/test/syntax/json/variadic-operations.json b/test/syntax/json/variadic-operations.json
index 75dbd0b..91c8533 100644
--- a/test/syntax/json/variadic-operations.json
+++ b/test/syntax/json/variadic-operations.json
@@ -187,5 +187,9 @@
         },
         "inheritance": null,
         "extAttrs": null
+    },
+    {
+        "type": "eof",
+        "trivia": ""
     }
 ]
diff --git a/test/writer.js b/test/writer.js
index 33e1782..764a74e 100644
--- a/test/writer.js
+++ b/test/writer.js
@@ -2,21 +2,13 @@
 
 const { collect } = require("./util/collect");
 const wp = require("../lib/webidl2");
-const writer = require("../lib/writer");
 const expect = require("expect");
-const path = require("path");
 
 describe("Rewrite and parses all of the IDLs to produce the same ASTs", () => {
-  const whitelist = [
-    "documentation",
-    "documentation-dos"
-  ];
   for (const test of collect("syntax")) {
     it(`should produce the same AST for ${test.path}`, () => {
-      const rewritten = writer.write(test.ast);
-      if (whitelist.includes(path.basename(test.path).slice(0, -5))) {
-        expect(rewritten).toEqual(test.text.trim());
-      }
+      const rewritten = wp.write(test.ast);
+      expect(rewritten).toEqual(test.text);
       const diff = test.diff(wp.parse(rewritten, test.opt));
       expect(diff).toBe(undefined);
     });