Skip to content

Commit 64cba29

Browse files
committed
Fixes Top and Last.
1 parent 4a0774b commit 64cba29

File tree

2 files changed

+16
-24
lines changed

2 files changed

+16
-24
lines changed

mathjax3-ts/input/tex/StackItem.ts

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export interface NodeStack {
4949

5050
/**
5151
* Get or set the last element on the node stack without removing it.
52-
* @return {MmlNode} The topmost node on the stack.
52+
* @return {MmlNode} The last node on the stack.
5353
*/
5454
Last: MmlNode;
5555

@@ -114,7 +114,7 @@ export abstract class MmlStack implements NodeStack {
114114
* @override
115115
*/
116116
public Push(...nodes: MmlNode[]) {
117-
this._nodes.push.apply(this._nodes, nodes);
117+
this._nodes.push(...nodes);
118118
}
119119

120120

@@ -130,31 +130,31 @@ export abstract class MmlStack implements NodeStack {
130130
* @override
131131
*/
132132
public get Top(): MmlNode {
133-
return this._nodes[0];
133+
return this._nodes[this.Size() - 1];
134134
}
135135

136136

137137
/**
138138
* @override
139139
*/
140140
public set Top(node: MmlNode) {
141-
this._nodes[0] = node;
141+
this._nodes[this.Size() - 1] = node;
142142
}
143143

144144

145145
/**
146146
* @override
147147
*/
148148
public get Last(): MmlNode {
149-
return this._nodes[this._nodes.length - 1];
149+
return this._nodes[0];
150150
}
151151

152152

153153
/**
154154
* @override
155155
*/
156156
public set Last(node: MmlNode) {
157-
this._nodes[this._nodes.length - 1] = node;
157+
this._nodes[0] = node;
158158
}
159159

160160

@@ -165,7 +165,7 @@ export abstract class MmlStack implements NodeStack {
165165
if (n == null) {
166166
n = 1;
167167
}
168-
return this._nodes.slice(0, n);
168+
return this._nodes.slice(this.Size() - n);
169169
}
170170

171171

@@ -190,10 +190,7 @@ export abstract class MmlStack implements NodeStack {
190190
/**
191191
* @override
192192
*/
193-
public toMml(inferred?: boolean, forceRow?: boolean) {
194-
if (inferred == null) {
195-
inferred = true;
196-
}
193+
public toMml(inferred: boolean = true, forceRow?: boolean) {
197194
if (this._nodes.length === 1 && !forceRow) {
198195
return this.Top;
199196
}
@@ -437,8 +434,8 @@ export abstract class BaseItem extends MmlStack implements StackItem {
437434
if (item.isClose && this.errors[item.kind]) {
438435
// @test ExtraOpenMissingClose, ExtraCloseMissingOpen,
439436
// MissingLeftExtraRight, MissingBeginExtraEnd
440-
const error = this.errors[item.kind].concat([item.getName()]);
441-
throw new TexError(error[0], error[1], ...error.splice(2));
437+
const [id, message] = this.errors[item.kind];
438+
throw new TexError(id, message, item.getName());
442439
}
443440
if (!item.isFinal) {
444441
return true;
@@ -452,10 +449,8 @@ export abstract class BaseItem extends MmlStack implements StackItem {
452449
* Clears the item's environment.
453450
*/
454451
public clearEnv() {
455-
for (let id in this.env) {
456-
if (this.env.hasOwnProperty(id)) {
457-
delete this.env[id];
458-
}
452+
for (const id of Object.keys(this.env)) {
453+
delete this.env[id];
459454
}
460455
}
461456

@@ -466,11 +461,7 @@ export abstract class BaseItem extends MmlStack implements StackItem {
466461
* @return {StackItem} Returns the stack item object for pipelining.
467462
*/
468463
public setProperties(def: PropList) {
469-
for (let id in def) {
470-
if (def.hasOwnProperty(id)) {
471-
this.setProperty(id, def[id]);
472-
}
473-
}
464+
Object.assign(this._properties, def);
474465
return this;
475466
}
476467

mathjax3-ts/input/tex/StackItemFactory.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,9 @@ export default class StackItemFactory {
9797
* @return {}
9898
*/
9999
public create(kind: string, ...parameters: any[]) {
100-
return (this.item[kind] || this.item[this.defaultKind]).
101-
apply(null, [this].concat(...parameters));
100+
// return (this.item[kind] || this.item[this.defaultKind])(this, ...parameters);
101+
return (this.item[kind] || this.item[this.defaultKind])
102+
.apply(null, [this].concat(...parameters));
102103
}
103104

104105
}

0 commit comments

Comments
 (0)