Skip to content

Commit 70a6a4b

Browse files
authored
Merge pull request #1161 from mathjax/refactor/aliased_this
Removes occurrences of aliased `this`
2 parents 42b1240 + c91b797 commit 70a6a4b

3 files changed

Lines changed: 14 additions & 13 deletions

File tree

ts/core/MmlTree/MmlNode.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -658,12 +658,13 @@ export abstract class AbstractMmlNode
658658
* @override
659659
*/
660660
public childPosition() {
661-
let child: MmlNode = this;
662-
let parent = child.parent;
661+
let child: MmlNode = null;
662+
let parent = this.parent;
663663
while (parent && parent.notParent) {
664664
child = parent;
665665
parent = parent.parent;
666666
}
667+
child = child || this;
667668
if (parent) {
668669
let i = 0;
669670
for (const node of parent.childNodes) {
@@ -1170,23 +1171,21 @@ export abstract class AbstractMmlBaseNode extends AbstractMmlNode {
11701171
this.getPrevClass(prev);
11711172
this.texClass = TEXCLASS.ORD;
11721173
const base = this.childNodes[0];
1174+
let result = null;
11731175
if (base) {
11741176
if (this.isEmbellished || base.isKind('mi')) {
1175-
prev = base.setTeXclass(prev);
1177+
result = base.setTeXclass(prev);
11761178
this.updateTeXclass(this.core());
11771179
} else {
11781180
base.setTeXclass(null);
1179-
prev = this;
11801181
}
1181-
} else {
1182-
prev = this;
11831182
}
11841183
for (const child of this.childNodes.slice(1)) {
11851184
if (child) {
11861185
child.setTeXclass(null);
11871186
}
11881187
}
1189-
return prev;
1188+
return result || this;
11901189
}
11911190
}
11921191

ts/core/MmlTree/MmlNodes/mo.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ export class MmlMo extends AbstractMmlTokenNode {
234234
* with this node as its core
235235
*/
236236
public coreParent(): MmlNode {
237-
let embellished = this;
237+
let embellished = null;
238238
let parent = this as MmlNode;
239239
const math = this.factory.getNodeClass('math');
240240
while (
@@ -246,7 +246,7 @@ export class MmlMo extends AbstractMmlTokenNode {
246246
embellished = parent;
247247
parent = (parent as MmlNode).parent;
248248
}
249-
return embellished;
249+
return embellished || this;
250250
}
251251

252252
/**
@@ -385,7 +385,7 @@ export class MmlMo extends AbstractMmlTokenNode {
385385
// Check if node is the last one in its container since the rule
386386
// above only takes effect if there is a node that follows.
387387
//
388-
let child: MmlNode = this;
388+
let child: MmlNode = null;
389389
let parent = this.parent;
390390
while (
391391
parent &&
@@ -397,6 +397,7 @@ export class MmlMo extends AbstractMmlTokenNode {
397397
child = parent;
398398
parent = parent.parent;
399399
}
400+
child = child || this;
400401
if (parent.childNodes[parent.childNodes.length - 1] === child) {
401402
this.texClass = TEXCLASS.ORD;
402403
}
@@ -472,14 +473,15 @@ export class MmlMo extends AbstractMmlTokenNode {
472473
* position of the element in its parent.
473474
*/
474475
public getForms(): [string, string, string] {
475-
let core: MmlNode = this;
476+
let core: MmlNode = null;
476477
let parent = this.parent;
477478
let Parent = this.Parent;
478479
while (Parent && Parent.isEmbellished) {
479480
core = parent;
480481
parent = Parent.parent;
481482
Parent = Parent.Parent;
482483
}
484+
core = core || this;
483485
if (
484486
parent &&
485487
parent.isKind('mrow') &&

ts/core/Tree/Factory.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,12 +167,12 @@ export abstract class AbstractFactory<
167167
*/
168168
public setNodeClass(kind: string, nodeClass: C) {
169169
this.nodeMap.set(kind, nodeClass);
170-
const THIS = this;
171170
const KIND = this.nodeMap.get(kind);
172171
this.node[kind] = (...args: any[]) => {
173-
return new KIND(THIS, ...args);
172+
return new KIND(this, ...args);
174173
};
175174
}
175+
176176
/**
177177
* @override
178178
*/

0 commit comments

Comments
 (0)