mirror of
https://github.com/marko-js/marko.git
synced 2026-02-01 16:07:13 +00:00
29 lines
806 B
JavaScript
29 lines
806 B
JavaScript
var REPEATED_ID_KEY = '$rep';
|
|
|
|
function RepeatedId() {
|
|
this.$__nextIdLookup = {};
|
|
}
|
|
|
|
RepeatedId.prototype = {
|
|
$__nextId: function(parentId, id) {
|
|
var indexLookupKey = parentId + '-' + id;
|
|
var currentIndex = this.$__nextIdLookup[indexLookupKey];
|
|
if (currentIndex == null) {
|
|
currentIndex = this.$__nextIdLookup[indexLookupKey] = 0;
|
|
} else {
|
|
currentIndex = ++this.$__nextIdLookup[indexLookupKey];
|
|
}
|
|
|
|
return indexLookupKey.slice(0, -2) + '[' + currentIndex + ']';
|
|
}
|
|
};
|
|
|
|
exports.$__nextId = function(out, parentId, id) {
|
|
var repeatedId = out.global[REPEATED_ID_KEY];
|
|
if (repeatedId == null) {
|
|
repeatedId = out.global[REPEATED_ID_KEY] = new RepeatedId();
|
|
}
|
|
|
|
return repeatedId.$__nextId(parentId, id);
|
|
};
|