Fix empty file error in json and graphql (#4553)

* Fix empty file error in json and graphql

* fix AST_COMPARE=1 issue

* use tests/empty

* revert

* fix lint
master
Aakansha Doshi 2018-06-06 19:11:12 +05:30 committed by Lucas Duailibe
parent 70604f1fd1
commit 8ec5432768
3 changed files with 7 additions and 4 deletions

View File

@ -49,6 +49,9 @@ function genericPrint(path, options, print) {
return JSON.stringify(node.value);
case "Identifier":
return JSON.stringify(node.name);
default:
/* istanbul ignore next */
throw new Error("unknown type: " + JSON.stringify(node.type));
}
}

View File

@ -63,6 +63,10 @@ function attachComments(text, ast, opts) {
}
function coreFormat(text, opts, addAlignmentSize) {
if (!text || !text.trim().length) {
return { formatted: "", cursorOffset: 0 };
}
addAlignmentSize = addAlignmentSize || 0;
const parsed = parser.parse(text, opts);

View File

@ -8,8 +8,4 @@ run_spec(
parsers.choices
.filter(choice => !choice.deprecated)
.map(choice => choice.value)
.filter(
parser =>
["json", "json5", "json-stringify", "graphql"].indexOf(parser) === -1
)
);