Files
klz-cables.com/.pnpm-store/v10/files/51/fb548ed68a835118741e51451c9d90d75cf83895c184114df6f28a7a8187d026f005f3422983cb73b333ba10c2ffc15b8621ac627aa3f4c71044368fcc1864
Marc Mintel 5397309103
Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 20s
Build & Deploy / 🧪 QA (push) Failing after 34s
Build & Deploy / 🏗️ Build (push) Has started running
Build & Deploy / 🚀 Deploy (push) Has been cancelled
Build & Deploy / 🧪 Smoke Test (push) Has been cancelled
Build & Deploy / ⚡ Lighthouse (push) Has been cancelled
Build & Deploy / 🔔 Notify (push) Has been cancelled
fix(products): fix breadcrumbs and product filtering (backport from main)
2026-02-24 16:04:21 +01:00

45 lines
1.4 KiB
Plaintext

import { ErrorKind } from "./error.js";
import { Parser } from "./parser.js";
import { isDateElement, isDateTimeSkeleton, isNumberElement, isNumberSkeleton, isPluralElement, isSelectElement, isTagElement, isTimeElement } from "./types.js";
function pruneLocation(els) {
els.forEach((el) => {
delete el.location;
if (isSelectElement(el) || isPluralElement(el)) {
for (const k in el.options) {
delete el.options[k].location;
pruneLocation(el.options[k].value);
}
} else if (isNumberElement(el) && isNumberSkeleton(el.style)) {
delete el.style.location;
} else if ((isDateElement(el) || isTimeElement(el)) && isDateTimeSkeleton(el.style)) {
delete el.style.location;
} else if (isTagElement(el)) {
pruneLocation(el.children);
}
});
}
export function parse(message, opts = {}) {
opts = {
shouldParseSkeletons: true,
requiresOtherClause: true,
...opts
};
const result = new Parser(message, opts).parse();
if (result.err) {
const error = SyntaxError(ErrorKind[result.err.kind]);
// @ts-expect-error Assign to error object
error.location = result.err.location;
// @ts-expect-error Assign to error object
error.originalMessage = result.err.message;
throw error;
}
if (!opts?.captureLocation) {
pruneLocation(result.val);
}
return result.val;
}
export * from "./types.js";
// only for testing
export const _Parser = Parser;
export { isStructurallySame } from "./manipulator.js";