mirror of
https://github.com/marko-js/marko.git
synced 2025-12-08 19:26:05 +00:00
16 lines
517 B
JavaScript
16 lines
517 B
JavaScript
var REPEATED_ID_KEY = '$rep';
|
|
|
|
module.exports = function nextRepeatedId(out, parentId, id) {
|
|
var nextIdLookup = out.global[REPEATED_ID_KEY] || (out.global[REPEATED_ID_KEY] = {});
|
|
|
|
var indexLookupKey = parentId + '-' + id;
|
|
var currentIndex = nextIdLookup[indexLookupKey];
|
|
if (currentIndex == null) {
|
|
currentIndex = nextIdLookup[indexLookupKey] = 0;
|
|
} else {
|
|
currentIndex = ++nextIdLookup[indexLookupKey];
|
|
}
|
|
|
|
return indexLookupKey.slice(0, -2) + '[' + currentIndex + ']';
|
|
};
|