Skip to content

Commit 013b575

Browse files
💥 refactor!: Enable deterministic mangling for private properties.
BREAKING CHANGE: Some properties have been renamed.
1 parent 2989720 commit 013b575

File tree

5 files changed

+82
-65
lines changed

5 files changed

+82
-65
lines changed

mangle.json

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,23 @@
77
}
88
},
99
"props": {
10-
"props": {}
10+
"props": {
11+
"$_center": "x",
12+
"$_checkbounds": "b",
13+
"$_container": "c",
14+
"$_copy": "y",
15+
"$_currentsize": "s",
16+
"$_empty": "e",
17+
"$_grow": "g",
18+
"$_growth": "G",
19+
"$_maxlen": "M",
20+
"$_minsize": "m",
21+
"$_popindex": "p",
22+
"$_range": "r",
23+
"$_realloc": "a",
24+
"$_shrink": "s",
25+
"$_value": "v",
26+
"$_where": "w"
27+
}
1128
}
1229
}

src/implementation/ArbitrarySizeDeque.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,19 @@ export default function ArbitrarySizeDeque() {}
55
ArbitrarySizeDeque.prototype = new Deque();
66

77
ArbitrarySizeDeque.prototype.values = function* () {
8-
let i = this.center;
8+
let i = this._center;
99
const _m = i + this.length;
1010
const m = Math.min(this.capacity(), _m);
1111

1212
for (; i < m; ++i) {
13-
yield this.container[i];
13+
yield this._container[i];
1414
}
1515

1616
const n = _m % this.capacity();
1717

1818
if (n < _m) {
1919
for (i = 0; i < n; ++i) {
20-
yield this.container[i];
20+
yield this._container[i];
2121
}
2222
}
2323
};
@@ -31,8 +31,8 @@ ArbitrarySizeDeque.prototype.pop = function () {
3131
ArbitrarySizeDeque.prototype.popleft = function () {
3232
const [container, index] = this._where(0);
3333

34-
++this.center;
35-
this.center %= this.capacity();
34+
++this._center;
35+
this._center %= this.capacity();
3636

3737
return this._popindex(container, index);
3838
};

src/implementation/BoundedDeque.js

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import ArbitrarySizeDeque from './ArbitrarySizeDeque.js';
22

33
export default function BoundedDeque(iterable, maxlen) {
4-
this.maxlen = maxlen;
4+
this._maxlen = maxlen;
55

66
// eslint-disable-next-line unicorn/no-new-array
7-
this.container = new Array(maxlen);
7+
this._container = new Array(maxlen);
88

9-
this.center = 0;
9+
this._center = 0;
1010

1111
this.length = 0;
1212

@@ -22,55 +22,55 @@ BoundedDeque.prototype.len = function () {
2222
};
2323

2424
BoundedDeque.prototype.capacity = function () {
25-
return this.maxlen;
25+
return this._maxlen;
2626
};
2727

2828
BoundedDeque.prototype.append = function (x) {
29-
if (this.length === this.maxlen) {
30-
this.container[this.center] = x;
31-
++this.center;
32-
this.center %= this.maxlen;
29+
if (this.length === this._maxlen) {
30+
this._container[this._center] = x;
31+
++this._center;
32+
this._center %= this._maxlen;
3333
} else {
34-
const i = (this.center + this.length) % this.maxlen;
35-
this.container[i] = x;
34+
const i = (this._center + this.length) % this._maxlen;
35+
this._container[i] = x;
3636
++this.length;
3737
}
3838

3939
return this;
4040
};
4141

4242
BoundedDeque.prototype.appendleft = function (x) {
43-
--this.center;
44-
this.center += this.maxlen;
45-
this.center %= this.maxlen;
46-
this.container[this.center] = x;
43+
--this._center;
44+
this._center += this._maxlen;
45+
this._center %= this._maxlen;
46+
this._container[this._center] = x;
4747

48-
if (this.length < this.maxlen) {
48+
if (this.length < this._maxlen) {
4949
++this.length;
5050
}
5151

5252
return this;
5353
};
5454

5555
BoundedDeque.prototype.clear = function () {
56-
this.center = 0;
56+
this._center = 0;
5757

5858
this.length = 0;
5959

6060
// eslint-disable-next-line unicorn/no-new-array
61-
this.container = new Array(this.maxlen);
61+
this._container = new Array(this._maxlen);
6262

6363
return this;
6464
};
6565

6666
BoundedDeque.prototype.copy = function () {
67-
return new BoundedDeque(this, this.maxlen);
67+
return new BoundedDeque(this, this._maxlen);
6868
};
6969

7070
BoundedDeque.prototype._where = function (i) {
7171
this._checkbounds(i);
7272

73-
return [this.container, (this.center + i) % this.maxlen];
73+
return [this._container, (this._center + i) % this._maxlen];
7474
};
7575

7676
BoundedDeque.prototype._popindex = function (container, index) {

src/implementation/SingleElementDeque.js

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import {IndexError} from '@aureooms/js-error';
22
import Deque from './Deque.js';
33

44
export default function SingleElementDeque(iterable) {
5-
this.empty = true;
5+
this._empty = true;
66

7-
this.value = 0;
7+
this._value = 0;
88

99
if (iterable !== null) {
1010
this.extend(iterable);
@@ -14,33 +14,33 @@ export default function SingleElementDeque(iterable) {
1414
SingleElementDeque.prototype = new Deque();
1515

1616
SingleElementDeque.prototype.len = function () {
17-
return this.empty ? 0 : 1;
17+
return this._empty ? 0 : 1;
1818
};
1919

2020
SingleElementDeque.prototype.capacity = function () {
2121
return 1;
2222
};
2323

2424
SingleElementDeque.prototype.values = function* () {
25-
if (this.empty) {
25+
if (this._empty) {
2626
return;
2727
}
2828

29-
yield this.value;
29+
yield this._value;
3030
};
3131

3232
SingleElementDeque.prototype.append =
3333
// eslint-disable-next-line no-multi-assign
3434
SingleElementDeque.prototype.appendleft = function (x) {
35-
this.empty = false;
36-
this.value = x;
35+
this._empty = false;
36+
this._value = x;
3737

3838
return this;
3939
};
4040

4141
SingleElementDeque.prototype.clear = function () {
42-
this.empty = true;
43-
this.value = 0;
42+
this._empty = true;
43+
this._value = 0;
4444

4545
return this;
4646
};
@@ -52,32 +52,32 @@ SingleElementDeque.prototype.copy = function () {
5252
SingleElementDeque.prototype.pop =
5353
// eslint-disable-next-line no-multi-assign
5454
SingleElementDeque.prototype.popleft = function () {
55-
if (this.empty) {
55+
if (this._empty) {
5656
throw new IndexError('pop / popleft');
5757
}
5858

59-
const value = this.value;
59+
const value = this._value;
6060

61-
this.empty = true;
62-
this.value = 0;
61+
this._empty = true;
62+
this._value = 0;
6363

6464
return value;
6565
};
6666

6767
SingleElementDeque.prototype.get = function (i) {
68-
if (this.empty || i !== 0) {
68+
if (this._empty || i !== 0) {
6969
throw new IndexError(i);
7070
}
7171

72-
return this.value;
72+
return this._value;
7373
};
7474

7575
SingleElementDeque.prototype.set = function (i, value) {
76-
if (this.empty || i !== 0) {
76+
if (this._empty || i !== 0) {
7777
throw new IndexError(i);
7878
}
7979

80-
this.value = value;
80+
this._value = value;
8181

8282
return this;
8383
};

src/implementation/UnboundedDeque.js

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
import ArbitrarySizeDeque from './ArbitrarySizeDeque.js';
22

33
export default function UnboundedDeque(iterable) {
4-
this.growth = 2;
4+
this._growth = 2;
55

6-
this.minsize = 10;
6+
this._minsize = 10;
77

8-
this.currentsize = this.minsize;
8+
this._currentsize = this._minsize;
99

1010
// eslint-disable-next-line unicorn/no-new-array
11-
this.container = new Array(this.currentsize);
11+
this._container = new Array(this._currentsize);
1212

13-
this.center = 0;
13+
this._center = 0;
1414

1515
this.length = 0;
1616

@@ -35,44 +35,44 @@ UnboundedDeque.prototype._realloc = function (newsize) {
3535

3636
this._copy(container);
3737

38-
this.container = container;
38+
this._container = container;
3939

40-
this.center = 0;
40+
this._center = 0;
4141

42-
this.currentsize = newsize;
42+
this._currentsize = newsize;
4343
};
4444

4545
UnboundedDeque.prototype._shrink = function () {
46-
const newsize = Math.max(this.minsize, this.length * this.growth);
46+
const newsize = Math.max(this._minsize, this.length * this._growth);
4747

48-
if (newsize * this.growth >= this.currentsize) {
48+
if (newsize * this._growth >= this._currentsize) {
4949
return;
5050
}
5151

5252
this._realloc(newsize);
5353
};
5454

5555
UnboundedDeque.prototype._grow = function (newlen) {
56-
if (newlen <= this.currentsize) {
56+
if (newlen <= this._currentsize) {
5757
return;
5858
}
5959

60-
this._realloc(newlen * this.growth);
60+
this._realloc(newlen * this._growth);
6161
};
6262

6363
UnboundedDeque.prototype.len = function () {
6464
return this.length;
6565
};
6666

6767
UnboundedDeque.prototype.capacity = function () {
68-
return this.currentsize;
68+
return this._currentsize;
6969
};
7070

7171
UnboundedDeque.prototype.append = function (x) {
7272
this._grow(this.length + 1);
7373

74-
const i = (this.center + this.length) % this.currentsize;
75-
this.container[i] = x;
74+
const i = (this._center + this.length) % this._currentsize;
75+
this._container[i] = x;
7676
++this.length;
7777

7878
return this;
@@ -81,23 +81,23 @@ UnboundedDeque.prototype.append = function (x) {
8181
UnboundedDeque.prototype.appendleft = function (x) {
8282
this._grow(this.length + 1);
8383

84-
--this.center;
85-
this.center += this.currentsize;
86-
this.center %= this.currentsize;
87-
this.container[this.center] = x;
84+
--this._center;
85+
this._center += this._currentsize;
86+
this._center %= this._currentsize;
87+
this._container[this._center] = x;
8888

8989
++this.length;
9090

9191
return this;
9292
};
9393

9494
UnboundedDeque.prototype.clear = function () {
95-
this.currentsize = this.minsize;
95+
this._currentsize = this._minsize;
9696

9797
// eslint-disable-next-line unicorn/no-new-array
98-
this.container = new Array(this.currentsize);
98+
this._container = new Array(this._currentsize);
9999

100-
this.center = 0;
100+
this._center = 0;
101101

102102
this.length = 0;
103103

@@ -111,7 +111,7 @@ UnboundedDeque.prototype.copy = function () {
111111
UnboundedDeque.prototype._where = function (i) {
112112
this._checkbounds(i);
113113

114-
return [this.container, (this.center + i) % this.currentsize];
114+
return [this._container, (this._center + i) % this._currentsize];
115115
};
116116

117117
UnboundedDeque.prototype._popindex = function (container, index) {

0 commit comments

Comments
 (0)