Skip to content

Commit 0dd27ef

Browse files
committed
fixed a very bad issue with auto-keyed holes
1 parent f27b3bc commit 0dd27ef

7 files changed

Lines changed: 72 additions & 67 deletions

File tree

cjs/rabbit.js

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -107,29 +107,30 @@ const unroll = (info, hole, counter) => {
107107
};
108108

109109
const unrollArray = (info, values, counter) => {
110-
for (let i = 0, {length} = values; i < length; i++) {
110+
let {a, aLength} = counter;
111+
for (let i = 0, {length} = values, {sub} = info; i < length; i++) {
111112
const hole = values[i];
112-
if (typeof hole === 'object' && hole) {
113-
// The only values to process are Hole and arrays.
114-
// Accordingly, there is no `else` case to test.
115-
/* istanbul ignore else */
116-
if (hole instanceof Hole)
117-
values[i] = unroll(info, hole, counter);
118-
else if (isArray(hole)) {
119-
for (let i = 0, {length} = hole; i < length; i++) {
120-
const inner = hole[i];
121-
if (typeof inner === 'object' && inner && inner instanceof Hole) {
122-
const {sub} = info;
123-
const {a, aLength} = counter;
124-
if (a === aLength)
125-
counter.aLength = sub.push(cacheInfo());
126-
counter.a++;
127-
hole[i] = retrieve(sub[a], inner);
128-
}
129-
}
113+
// The only values to process are Hole and arrays.
114+
// Accordingly, there is no `else` case to test.
115+
/* istanbul ignore else */
116+
if (hole instanceof Hole)
117+
values[i] = unroll(info, hole, counter);
118+
else if (isArray(hole)) {
119+
const {length} = hole;
120+
const next = a + length;
121+
while (aLength < next)
122+
aLength = sub.push(null);
123+
for (let i = 0; i < length; i++) {
124+
const inner = hole[i];
125+
if (inner instanceof Hole)
126+
hole[i] = retrieve(sub[a] || (sub[a] = cacheInfo()), inner);
127+
a++;
130128
}
131129
}
130+
a++;
132131
}
132+
counter.a = a;
133+
counter.aLength = aLength;
133134
};
134135

135136
/**

esm/rabbit.js

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -105,29 +105,30 @@ const unroll = (info, hole, counter) => {
105105
};
106106

107107
const unrollArray = (info, values, counter) => {
108-
for (let i = 0, {length} = values; i < length; i++) {
108+
let {a, aLength} = counter;
109+
for (let i = 0, {length} = values, {sub} = info; i < length; i++) {
109110
const hole = values[i];
110-
if (typeof hole === 'object' && hole) {
111-
// The only values to process are Hole and arrays.
112-
// Accordingly, there is no `else` case to test.
113-
/* istanbul ignore else */
114-
if (hole instanceof Hole)
115-
values[i] = unroll(info, hole, counter);
116-
else if (isArray(hole)) {
117-
for (let i = 0, {length} = hole; i < length; i++) {
118-
const inner = hole[i];
119-
if (typeof inner === 'object' && inner && inner instanceof Hole) {
120-
const {sub} = info;
121-
const {a, aLength} = counter;
122-
if (a === aLength)
123-
counter.aLength = sub.push(cacheInfo());
124-
counter.a++;
125-
hole[i] = retrieve(sub[a], inner);
126-
}
127-
}
111+
// The only values to process are Hole and arrays.
112+
// Accordingly, there is no `else` case to test.
113+
/* istanbul ignore else */
114+
if (hole instanceof Hole)
115+
values[i] = unroll(info, hole, counter);
116+
else if (isArray(hole)) {
117+
const {length} = hole;
118+
const next = a + length;
119+
while (aLength < next)
120+
aLength = sub.push(null);
121+
for (let i = 0; i < length; i++) {
122+
const inner = hole[i];
123+
if (inner instanceof Hole)
124+
hole[i] = retrieve(sub[a] || (sub[a] = cacheInfo()), inner);
125+
a++;
128126
}
129127
}
128+
a++;
130129
}
130+
counter.a = a;
131+
counter.aLength = aLength;
131132
};
132133

133134
/**

index.js

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ var uhtml = (function (exports) {
1515
return info;
1616
};
1717

18-
19-
2018
var attr = /([^\s\\>"'=]+)\s*=\s*(['"]?)$/;
2119
var empty = /^(?:area|base|br|col|embed|hr|img|input|keygen|link|menuitem|meta|param|source|track|wbr)$/i;
2220
var node = /<[a-z][^>]+$/i;
@@ -104,6 +102,8 @@ var uhtml = (function (exports) {
104102
};
105103
};
106104

105+
106+
107107
/**
108108
* ISC License
109109
*
@@ -619,30 +619,34 @@ var uhtml = (function (exports) {
619619
};
620620

621621
var unrollArray = function unrollArray(info, values, counter) {
622-
for (var i = 0, length = values.length; i < length; i++) {
623-
var hole = values[i];
622+
var a = counter.a,
623+
aLength = counter.aLength;
624624

625-
if (typeof(hole) === 'object' && hole) {
626-
// The only values to process are Hole and arrays.
627-
// Accordingly, there is no `else` case to test.
625+
for (var i = 0, length = values.length, sub = info.sub; i < length; i++) {
626+
var hole = values[i]; // The only values to process are Hole and arrays.
627+
// Accordingly, there is no `else` case to test.
628628

629-
/* istanbul ignore else */
630-
if (hole instanceof Hole) values[i] = unroll(info, hole, counter);else if (isArray(hole)) {
631-
for (var _i2 = 0, _length = hole.length; _i2 < _length; _i2++) {
632-
var inner = hole[_i2];
633-
634-
if (typeof(inner) === 'object' && inner && inner instanceof Hole) {
635-
var sub = info.sub;
636-
var a = counter.a,
637-
aLength = counter.aLength;
638-
if (a === aLength) counter.aLength = sub.push(cacheInfo());
639-
counter.a++;
640-
hole[_i2] = retrieve(sub[a], inner);
641-
}
642-
}
629+
/* istanbul ignore else */
630+
631+
if (hole instanceof Hole) values[i] = unroll(info, hole, counter);else if (isArray(hole)) {
632+
var _length = hole.length;
633+
var next = a + _length;
634+
635+
while (aLength < next) {
636+
aLength = sub.push(null);
637+
}
638+
639+
for (var _i2 = 0; _i2 < _length; _i2++) {
640+
var inner = hole[_i2];
641+
if (inner instanceof Hole) hole[_i2] = retrieve(sub[a] || (sub[a] = cacheInfo()), inner);
642+
a++;
643643
}
644644
}
645+
a++;
645646
}
647+
648+
counter.a = a;
649+
counter.aLength = aLength;
646650
};
647651
/**
648652
* Holds all necessary details needed to render the content further on.

min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)