Print playground AST with Prettier to make it easier to read

This commit is contained in:
Simon Lydell committed 2017-09-12 22:17:06 +02:00
1 parent 482a1d8311
commit 951aed47f6
1 file changed
+15 -8
+15 -8
View File
@@ -33,14 +33,21 @@ self.onmessage = function(message) {
var ast;
if (message.data.ast) {
var actualAst;
var errored = false;
try {
ast = JSON.stringify(
prettier.__debug.parse(message.data.text, options),
null,
2
);
actualAst = prettier.__debug.parse(message.data.text, options);
ast = JSON.stringify(actualAst);
} catch (e) {
ast = e.toString();
errored = true;
ast = String(e);
}
if (!errored) {
try {
ast = formatCode(ast, { parser: "json" });
} catch (e) {
ast = JSON.stringify(actualAst, null, 2);
}
}
}
@@ -52,7 +59,7 @@ self.onmessage = function(message) {
{ parser: "babylon" }
);
} catch (e) {
doc = e.toString();
doc = String(e);
}
}
@@ -70,7 +77,7 @@ function formatCode(text, options) {
lazyLoadParser(e.parser);
return formatCode(text, options);
}
return e.toString();
return String(e);
}
}