diff --git a/website/playground/Playground.js b/website/playground/Playground.js
index 042cb1407..58f21a201 100644
--- a/website/playground/Playground.js
+++ b/website/playground/Playground.js
@@ -241,7 +241,10 @@ class Playground extends React.Component {
onSelectionChange={this.setSelection}
/>
{editorState.showAst ? (
-
+
) : null}
{editorState.showDoc ? (
diff --git a/website/playground/panels.js b/website/playground/panels.js
index f37c80d90..4326a10e8 100644
--- a/website/playground/panels.js
+++ b/website/playground/panels.js
@@ -66,6 +66,16 @@ class CodeMirrorPanel extends React.Component {
updateValue(value) {
this._cached = value;
this._codeMirror.setValue(value);
+
+ if (this.props.autoFold instanceof RegExp) {
+ const lines = value.split("\n");
+ // going backwards to prevent unfolding folds created earlier
+ for (let i = lines.length - 1; i >= 0; i--) {
+ if (this.props.autoFold.test(lines[i])) {
+ this._codeMirror.foldCode(i);
+ }
+ }
+ }
}
updateOverlay() {
@@ -188,12 +198,13 @@ export function OutputPanel(props) {
);
}
-export function DebugPanel({ value }) {
+export function DebugPanel({ value, autoFold }) {
return (
diff --git a/website/playground/util.js b/website/playground/util.js
index c78ce6e9a..e82751b37 100644
--- a/website/playground/util.js
+++ b/website/playground/util.js
@@ -51,3 +51,32 @@ export function getCodemirrorMode(parser) {
return "jsx";
}
}
+
+const astAutoFold = {
+ estree: /^\s*"(loc|start|end)":/,
+ postcss: /^\s*"(source|input|raws|file)":/,
+ html: /^\s*"(sourceSpan|valueSpan|nameSpan|startSourceSpan|endSourceSpan|tagDefinition)":/,
+};
+
+export function getAstAutoFold(parser) {
+ switch (parser) {
+ case "flow":
+ case "babel":
+ case "babel-flow":
+ case "babel-ts":
+ case "typescript":
+ case "json":
+ case "json5":
+ case "json-stringify":
+ return astAutoFold.estree;
+ case "css":
+ case "less":
+ case "scss":
+ return astAutoFold.postcss;
+ case "html":
+ case "angular":
+ case "vue":
+ case "lws":
+ return astAutoFold.html;
+ }
+}