# Conflicts: # .github/workflows/dev-test.yml # jest.config.mjs # package.json # scripts/vendors/vendor-meta.json # scripts/vendors/vendors.mjs # src/cli/format.js # src/cli/options/create-minimist-options.js # src/cli/options/parse-cli-arguments.js # src/cli/usage.js # src/cli/utils.js # src/common/create-ignorer.js # src/common/load-plugins.js # src/config/resolve-config.js # src/index.js # src/language-css/utils/css-units.evaluate.js # src/language-html/ast.js # src/language-html/print-preprocess.js # src/language-html/utils/index.js # src/main/multiparser.js # tests/format/markdown/auto-link/jsfmt.spec.js # tests/integration/__tests__/__snapshots__/config-resolution.js.snap # tests/integration/__tests__/__snapshots__/with-config-precedence.js.snap # tests/integration/__tests__/file-info.js # yarn.lock
48 lines
956 B
JavaScript
48 lines
956 B
JavaScript
import { createRequire } from "node:module";
|
|
import createError from "../common/parser-create-error.js";
|
|
import { hasPragma } from "./pragma.js";
|
|
import { locStart, locEnd } from "./loc.js";
|
|
|
|
const require = createRequire(import.meta.url);
|
|
|
|
function parse(text) {
|
|
const { parse: parseYaml } = require("yaml-unist-parser");
|
|
|
|
try {
|
|
const root = parseYaml(text);
|
|
|
|
/**
|
|
* suppress `comment not printed` error
|
|
*
|
|
* comments are handled in printer-yaml.js without using `printComment`
|
|
* so that it'll always throw errors even if we printed it correctly
|
|
*/
|
|
delete root.comments;
|
|
|
|
return root;
|
|
} catch (error) {
|
|
if (error?.position) {
|
|
throw createError(error.message, error.position);
|
|
}
|
|
|
|
/* istanbul ignore next */
|
|
throw error;
|
|
}
|
|
}
|
|
|
|
const parser = {
|
|
astFormat: "yaml",
|
|
parse,
|
|
hasPragma,
|
|
locStart,
|
|
locEnd,
|
|
};
|
|
|
|
const yaml = {
|
|
parsers: {
|
|
yaml: parser,
|
|
},
|
|
};
|
|
|
|
export default yaml;
|