Print playground AST with Prettier to make it easier to read
This commit is contained in:
1 parent
482a1d8311
commit
951aed47f6
1 file changed
+15
-8
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user