MCPcopy Index your code
hub / github.com/prettier/prettier / parseWithParser

Function parseWithParser

src/language-css/parser-postcss.js:382–422  ·  view source on GitHub ↗
(parse, text, options)

Source from the content-addressed store, hash-verified

380}
381
382function parseWithParser(parse, text, options) {
383 const { frontMatter, content: textToParse } = parseFrontMatter(text);
384
385 let result;
386
387 try {
388 result = parse(textToParse, {
389 // Prevent file access https://github.com/postcss/postcss/blob/4f4e2932fc97e2c117e1a4b15f0272ed551ed59d/lib/previous-map.js#L18
390 map: false,
391 });
392 } catch (/** @type {any} */ error) {
393 const { name, reason, line, column } = error;
394 /* c8 ignore 3 */
395 if (typeof line !== "number") {
396 throw error;
397 }
398
399 throw createError(`${name}: ${reason}`, {
400 loc: { start: { line, column } },
401 cause: error,
402 });
403 }
404
405 options.originalText = text;
406 result = parseNestedCSS(addTypePrefix(result, "css-"), options);
407
408 calculateLoc(result, text);
409
410 if (frontMatter) {
411 result.frontMatter = {
412 ...frontMatter,
413 type: "front-matter",
414 source: {
415 startOffset: frontMatter.start.index,
416 endOffset: frontMatter.end.index,
417 },
418 };
419 }
420
421 return result;
422}
423
424function parseCss(text, options = {}) {
425 return parseWithParser(postcssParse.default, text, options);

Callers 3

parseCssFunction · 0.85
parseLessFunction · 0.85
parseScssFunction · 0.85

Calls 5

addTypePrefixFunction · 0.90
calculateLocFunction · 0.90
createErrorFunction · 0.85
parseNestedCSSFunction · 0.85
parseFunction · 0.50

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…