this.placeholderToData = {};
this.dataToPlaceholder = {};
this.count = 0;
+ this.restoreMatcher = new RegExp(this.placeholderRoot + '(\\d+)');
};
EscapeStore.prototype._nextPlaceholder = function (metadata) {
- return placeholderBrace + this.placeholderRoot + (this.count++) + metadata + placeholderBrace;
+ return {
+ index: this.count,
+ value: placeholderBrace + this.placeholderRoot + this.count++ + metadata + placeholderBrace
+ };
};
EscapeStore.prototype.store = function (data, metadata) {
var placeholder = this.dataToPlaceholder[data];
if (!placeholder) {
- placeholder = this._nextPlaceholder(encodedMetadata);
- this.placeholderToData[placeholder] = data;
- this.dataToPlaceholder[data] = placeholder;
+ var nextPlaceholder = this._nextPlaceholder(encodedMetadata);
+ placeholder = nextPlaceholder.value;
+ this.placeholderToData[nextPlaceholder.index] = data;
+ this.dataToPlaceholder[data] = nextPlaceholder.value;
}
if (metadata)
};
EscapeStore.prototype.restore = function (placeholder) {
- return this.placeholderToData[placeholder];
+ var index = this.restoreMatcher.exec(placeholder)[1];
+ return this.placeholderToData[index];
};
module.exports = EscapeStore;
assert.equal(placeholder, '__ESCAPED_TEST_CLEAN_CSS0(1,2,3)__');
}
+ },
+ 'with different metadata but same index': {
+ topic: function () {
+ var escapeStore = new EscapeStore('TEST');
+ escapeStore.store('data', ['brown', 'fox']);
+ escapeStore.store('data', ['jumped', 'over']);
+ return escapeStore;
+ },
+ restore: function (escapeStore) {
+ var data = escapeStore.restore('__ESCAPED_TEST_CLEAN_CSS0(a,lazy,dog)__');
+ assert.equal(data, 'data');
+ }
}
})
.export(module);