* Add comments showing parser arguments Since this is how they are invoked, the comments make it easier to maintain. * Use babylon.parseExpression for JSON See https://github.com/prettier/prettier/issues/2378#issuecomment-314600778 Note that this doesn't yet print comments: echo '{/*comment*/"K":"V"}' | ./bin/prettier.js --parser json * Remove parser-json.js This reduces duplicate code in the built package. See https://github.com/prettier/prettier/pull/2476#pullrequestreview-50181398 * Add test with block comment in JSON * Fix test with block comment in JSON * Add test with line comment in JSON * Don't build now-redundant parser-json.js
30 lines
855 B
JavaScript
30 lines
855 B
JavaScript
"use strict";
|
|
|
|
const createError = require("./parser-create-error");
|
|
const includeShebang = require("./parser-include-shebang");
|
|
|
|
function parse(text /*, parsers, opts*/) {
|
|
// Fixes Node 4 issue (#1986)
|
|
"use strict"; // eslint-disable-line
|
|
// Inline the require to avoid loading all the JS if we don't use it
|
|
const flowParser = require("flow-parser");
|
|
|
|
const ast = flowParser.parse(text, {
|
|
esproposal_class_instance_fields: true,
|
|
esproposal_class_static_fields: true,
|
|
esproposal_export_star_as: true
|
|
});
|
|
|
|
if (ast.errors.length > 0) {
|
|
const loc = ast.errors[0].loc;
|
|
throw createError(ast.errors[0].message, {
|
|
start: { line: loc.start.line, column: loc.start.column + 1 },
|
|
end: { line: loc.end.line, column: loc.end.column + 1 }
|
|
});
|
|
}
|
|
|
|
includeShebang(text, ast);
|
|
return ast;
|
|
}
|
|
module.exports = parse;
|