MCPcopy
hub / github.com/prettier/prettier / parse

Function parse

src/language-html/parse/parse.js:182–238  ·  view source on GitHub ↗

@param {string} text @param {typeof parseHtml | typeof parseVue} parser @param {ParseOptions} parseOptions @param {Options} options

(text, parser, parseOptions, options = {})

Source from the content-addressed store, hash-verified

180@param {Options} options
181*/
182function parse(text, parser, parseOptions, options = {}) {
183 const { frontMatter, content: textToParse } =
184 parseOptions.shouldParseFrontMatter
185 ? parseFrontMatter(text)
186 : { content: text };
187
188 const file = new ParseSourceFile(text, options.filepath);
189 const start = new ParseLocation(file, 0, 0, 0);
190 const end = start.moveBy(text.length);
191
192 const { parseOptions: actualParseOptions, rootNodes } = parser(
193 textToParse,
194 parseOptions,
195 );
196
197 const rawAst = {
198 kind: "root",
199 sourceSpan: new ParseSourceSpan(start, end),
200 children: rootNodes,
201 };
202
203 /** @type {HtmlFrontMatter} */
204 let htmlFrontMatter;
205 if (frontMatter) {
206 const [start, end] = [frontMatter.start, frontMatter.end].map(
207 (location) =>
208 new ParseLocation(
209 file,
210 location.index,
211 location.line - 1,
212 location.column,
213 ),
214 );
215 htmlFrontMatter = {
216 ...frontMatter,
217 kind: "frontMatter",
218 sourceSpan: new ParseSourceSpan(start, end),
219 };
220 }
221
222 const ast = postprocess(
223 rawAst,
224 htmlFrontMatter,
225 actualParseOptions,
226 (subContent, startSpan) =>
227 parseSubHtml(
228 parser,
229 text,
230 subContent,
231 startSpan,
232 actualParseOptions,
233 options,
234 ),
235 );
236
237 return ast;
238}
239

Callers 3

createParserFunction · 0.90
parseSubHtmlFunction · 0.70

Calls 3

postprocessFunction · 0.90
parseSubHtmlFunction · 0.85
mapMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…