MCPcopy Create free account
hub / github.com/prettier/prettier / parse

Function parse

src/language-handlebars/parser-glimmer.js:71–111  ·  view source on GitHub ↗
(text)

Source from the content-addressed store, hash-verified

69};
70
71function parse(text) {
72 const { frontMatter, content: textToParse } = parseFrontMatter(text);
73
74 let ast;
75 try {
76 ast = parseGlimmer(textToParse, glimmerParseOptions);
77 } catch (error) {
78 const location = getErrorLocation(error);
79
80 if (location) {
81 const message = getErrorMessage(error);
82
83 throw createError(message, { loc: location, cause: error });
84 }
85
86 /* c8 ignore next */
87 throw error;
88 }
89
90 if (frontMatter) {
91 /** @type {GlimmerFrontMatter} */
92 const glimmerFrontMatter = {
93 ...frontMatter,
94 type: "FrontMatter",
95 loc: {
96 start: {
97 ...frontMatter.start,
98 offset: frontMatter.start.index,
99 },
100 end: {
101 ...frontMatter.end,
102 offset: frontMatter.end.index,
103 },
104 },
105 };
106 // @ts-expect-error -- not a real "Node"
107 ast.body.unshift(glimmerFrontMatter);
108 }
109
110 return ast;
111}
112
113function getErrorMessage(error) {
114 const { message } = error;

Callers

nothing calls this directly

Calls 3

getErrorLocationFunction · 0.85
getErrorMessageFunction · 0.85
createErrorFunction · 0.85

Tested by

no test coverage detected