Files
klz-cables.com/.pnpm-store/v10/files/86/e5d9f4b629abaad5e7e56a7ae8f05bdfdfe4ec9deee51413a487c2da9e2cc08e055c60e7236f3ad8a06f8cd970d5252b563889c9317ff3c8315c653854b12a
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

69 lines
1.6 KiB
Plaintext

/*
MIT License http://www.opensource.org/licenses/mit-license.php
Author Tobias Koppers @sokra
*/
"use strict";
const LocalModule = require("./LocalModule");
/** @typedef {import("../javascript/JavascriptParser").JavascriptParserState} JavascriptParserState */
/**
* @param {string} parent parent module
* @param {string} mod module to resolve
* @returns {string} resolved module
*/
const lookup = (parent, mod) => {
if (mod.charAt(0) !== ".") return mod;
const path = parent.split("/");
const segments = mod.split("/");
path.pop();
for (let i = 0; i < segments.length; i++) {
const seg = segments[i];
if (seg === "..") {
path.pop();
} else if (seg !== ".") {
path.push(seg);
}
}
return path.join("/");
};
/**
* @param {JavascriptParserState} state parser state
* @param {string} name name
* @returns {LocalModule} local module
*/
module.exports.addLocalModule = (state, name) => {
if (!state.localModules) {
state.localModules = [];
}
const m = new LocalModule(name, state.localModules.length);
state.localModules.push(m);
return m;
};
/**
* @param {JavascriptParserState} state parser state
* @param {string} name name
* @param {string=} namedModule named module
* @returns {LocalModule | null} local module or null
*/
module.exports.getLocalModule = (state, name, namedModule) => {
if (!state.localModules) return null;
if (namedModule) {
// resolve dependency name relative to the defining named module
name = lookup(namedModule, name);
}
for (let i = 0; i < state.localModules.length; i++) {
if (state.localModules[i].name === name) {
return state.localModules[i];
}
}
return null;
};