Skip to content

Commit ef6bc43

Browse files
authored
Call super()" before this in constructors (#2077)
* Call super()" before this in constructors * Fix issue with MapIterator re-setting the next method
1 parent dc647b1 commit ef6bc43

File tree

6 files changed

+20
-3
lines changed

6 files changed

+20
-3
lines changed

eslint.config.mjs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,11 @@ export default tseslint.config(
2727
{
2828
rules: {
2929
eqeqeq: 'error',
30-
'constructor-super': 'off',
3130
'no-constructor-return': 'error',
3231
'no-else-return': 'error',
3332
'no-lonely-if': 'error',
3433
'no-object-constructor': 'error',
3534
'no-prototype-builtins': 'off',
36-
'no-this-before-super': 'off',
3735
'no-useless-concat': 'error',
3836
'no-var': 'error',
3937
'operator-assignment': 'error',

src/Iterator.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ export const ITERATOR_SYMBOL = REAL_ITERATOR_SYMBOL || FAUX_ITERATOR_SYMBOL;
99

1010
export class Iterator {
1111
constructor(next) {
12-
this.next = next;
12+
if (next) {
13+
// Map extends Iterator and has a `next` method, do not erase it in that case. We could have checked `if (next && !this.next)` too.
14+
this.next = next;
15+
}
1316
}
1417

1518
toString() {

src/Map.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -553,6 +553,8 @@ ValueNode.prototype.iterate = function (fn, reverse) {
553553

554554
class MapIterator extends Iterator {
555555
constructor(map, type, reverse) {
556+
super();
557+
556558
this._type = type;
557559
this._reverse = reverse;
558560
this._stack = map._root && mapIteratorFrame(map._root);

src/Operations.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ import { OrderedMap } from './OrderedMap';
4444

4545
export class ToKeyedSequence extends KeyedSeqImpl {
4646
constructor(indexed, useKeys) {
47+
super();
48+
4749
this._iter = indexed;
4850
this._useKeys = useKeys;
4951
this.size = indexed.size;
@@ -89,6 +91,8 @@ ToKeyedSequence.prototype[IS_ORDERED_SYMBOL] = true;
8991

9092
export class ToIndexedSequence extends IndexedSeqImpl {
9193
constructor(iter) {
94+
super();
95+
9296
this._iter = iter;
9397
this.size = iter.size;
9498
}
@@ -128,6 +132,8 @@ export class ToIndexedSequence extends IndexedSeqImpl {
128132

129133
export class ToSetSequence extends SetSeqImpl {
130134
constructor(iter) {
135+
super();
136+
131137
this._iter = iter;
132138
this.size = iter.size;
133139
}
@@ -153,6 +159,8 @@ export class ToSetSequence extends SetSeqImpl {
153159

154160
export class FromEntriesSequence extends KeyedSeqImpl {
155161
constructor(entries) {
162+
super();
163+
156164
this._iter = entries;
157165
this.size = entries.size;
158166
}
@@ -597,6 +605,8 @@ export function skipWhileFactory(collection, predicate, context, useKeys) {
597605

598606
class ConcatSeq extends SeqImpl {
599607
constructor(iterables) {
608+
super();
609+
600610
this._wrappedIterables = iterables.flatMap((iterable) => {
601611
if (iterable._wrappedIterables) {
602612
return iterable._wrappedIterables;

src/Range.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ export const Range = (start, end, step = 1) => {
3333
};
3434
export class RangeImpl extends IndexedSeqImpl {
3535
constructor(start, end, step, size) {
36+
super();
37+
3638
this._start = start;
3739
this._end = end;
3840
this._step = step;

src/Repeat.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ export const Repeat = (value, times) => {
2222

2323
export class RepeatImpl extends IndexedSeqImpl {
2424
constructor(value, size) {
25+
super();
26+
2527
this._value = value;
2628
this.size = size;
2729
}

0 commit comments

Comments
 (0)