MCPcopy
hub / github.com/webpack/webpack / parseValueAtRuleParams

Function parseValueAtRuleParams

lib/css/CssParser.js:617–682  ·  view source on GitHub ↗
(str)

Source from the content-addressed store, hash-verified

615 * @returns {ValueAtRuleImport | ValueAtRuleValue} parsed result
616 */
617const parseValueAtRuleParams = (str) => {
618 if (VALUE_IMPORT_FORM.test(str)) {
619 str = str.replace(CSS_COMMENT, " ").trim().replace(/;$/, "");
620 const fromIdx = str.lastIndexOf("from");
621 const path = str
622 .slice(fromIdx + 5)
623 .trim()
624 .replace(/['"]/g, "");
625 let content = str.slice(0, fromIdx).trim();
626
627 if (content.startsWith("(") && content.endsWith(")")) {
628 content = content.slice(1, -1);
629 }
630
631 return {
632 from: path,
633 items: content.split(",").map((item) => {
634 item = item.trim();
635
636 if (item.includes(":")) {
637 const [local, remote] = item.split(":");
638
639 return { localName: local.trim(), importName: remote.trim() };
640 }
641
642 const asParts = item.split(VALUE_AS_ALIAS);
643
644 if (asParts.length === 2) {
645 return {
646 localName: asParts[1].trim(),
647 importName: asParts[0].trim()
648 };
649 }
650
651 return { localName: item, importName: item };
652 })
653 };
654 }
655
656 /** @type {string} */
657 let localName;
658 /** @type {string} */
659 let value;
660
661 const idx = str.indexOf(":");
662
663 if (idx !== -1) {
664 localName = str.slice(0, idx).replace(CSS_COMMENT, "").trim();
665 value = str.slice(idx + 1);
666 } else {
667 const mask = str.replace(CSS_COMMENT, (m) => " ".repeat(m.length));
668 const idx = mask.search(VALUE_NAME_BOUNDARY) + 1;
669
670 localName = str.slice(0, idx).replace(CSS_COMMENT, "").trim();
671 value = str.slice(idx + (str[idx] === " " ? 1 : 0));
672 }
673
674 if (

Callers 1

handleValueAtRuleMethod · 0.85

Calls 4

sliceMethod · 0.80
splitMethod · 0.80
testMethod · 0.45
replaceMethod · 0.45

Tested by

no test coverage detected