Update citeproc.js to include Juris-M/citeproc-js#256

This commit is contained in:
Dan Stillman 2025-08-07 00:59:20 -04:00
parent d1d62cb91d
commit cf91d62e59

View file

@ -1794,31 +1794,53 @@ CSL.XmlJSON.prototype.nodeCopy = function (myjson,clone) {
return clone;
}
CSL.XmlJSON.prototype.getNodesByName = function (myjson,name,nameattrval,ret) {
CSL.XmlJSON._nodesByNameCaches = new WeakMap();
CSL.XmlJSON.prototype.getNodesByName = function (myjson,name,nameattrval) {
//print("getNodesByName()");
var nodes, node, pos, len;
if (!ret) {
var ret = [];
}
if (!myjson || !myjson.children) {
return ret;
return [];
}
if (name === myjson.name) {
if (nameattrval) {
if (nameattrval === myjson.attrs.name) {
ret.push(myjson);
let getCache = (myjson) => {
if (CSL.XmlJSON._nodesByNameCaches.has(myjson)) {
return CSL.XmlJSON._nodesByNameCaches.get(myjson);
}
let cache = new Map();
CSL.XmlJSON._nodesByNameCaches.set(myjson, cache);
let name = myjson.name;
if (!cache.has(name)) {
cache.set(name, []);
}
cache.get(name).push(myjson);
for (let child of myjson.children) {
if (typeof child !== "object") continue;
let childCache = getCache(child);
// Copy cache entries upwards
for (let [cacheKey, nodes] of childCache) {
if (!cache.has(cacheKey)) {
cache.set(cacheKey, []);
}
cache.get(cacheKey).push(...nodes);
}
} else {
ret.push(myjson);
}
return cache;
};
let cache = getCache(myjson);
let nodes = cache.get(name);
if (!nodes) {
return [];
}
for (var i=0,ilen=myjson.children.length;i<ilen;i+=1){
if ("object" !== typeof myjson.children[i]) {
continue;
}
this.getNodesByName(myjson.children[i],name,nameattrval,ret);
if (nameattrval) {
return nodes.filter(node => node.attrs.name === nameattrval);
} else {
return Array.from(nodes);
}
return ret;
}
CSL.XmlJSON.prototype.nodeNameIs = function (myjson,name) {