Skip to content

Commit 0571a19

Browse files
committed
Simplied setProperties to setProperty wherever possible.
1 parent 9cae258 commit 0571a19

File tree

6 files changed

+28
-26
lines changed

6 files changed

+28
-26
lines changed

mathjax3-ts/input/tex/StackItem.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,8 +269,9 @@ export interface StackItem extends NodeStack {
269269
* Set a property.
270270
* @param {string} key Property name.
271271
* @param {Prop} value Property value.
272+
* @return {StackItem} The item for pipelining.
272273
*/
273-
setProperty(key: string, value: Prop): void;
274+
setProperty(key: string, value: Prop): StackItem;
274275

275276
/**
276277
* Convenience method for returning the string property "name".
@@ -379,6 +380,7 @@ export abstract class BaseItem extends MmlStack implements StackItem {
379380
*/
380381
public setProperty(key: string, value: Prop) {
381382
this._properties[key] = value;
383+
return this;
382384
}
383385

384386

mathjax3-ts/input/tex/ams/AmsMethods.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -228,18 +228,18 @@ AmsMethods.xArrow = function(parser: TexParser, name: string,
228228
'mo', {stretchy: true, texClass: TEXCLASS.REL}, String.fromCharCode(chr));
229229
let mml = parser.create('node', 'munderover', [arrow]) as MmlMunderover;
230230
let mpadded = parser.create('node', 'mpadded', [first], def);
231-
NodeUtil.setProperties(mpadded, {voffset: '.15em'});
231+
NodeUtil.setAttribute(mpadded, 'voffset', '.15em');
232232
NodeUtil.setChild(mml, mml.over, mpadded);
233233
if (bot) {
234234
// @test Above Below Left Arrow, Above Below Right Arrow
235235
let bottom = new TexParser(bot, parser.stack.env, parser.configuration).mml();
236236
mpadded = parser.create('node', 'mpadded', [bottom], def);
237-
NodeUtil.setProperties(mpadded, {voffset: '-.24em'});
237+
NodeUtil.setAttribute(mpadded, 'voffset', '-.24em');
238238
NodeUtil.setChild(mml, mml.under, mpadded);
239239
}
240240
// @test Above Left Arrow, Above Right Arrow, Above Left Arrow in Context,
241241
// Above Right Arrow in Context
242-
NodeUtil.setProperties(mml, {subsupOK: true});
242+
NodeUtil.setProperty(mml, 'subsupOK', true);
243243
parser.Push(mml);
244244
};
245245

@@ -331,7 +331,7 @@ AmsMethods.Genfrac = function(parser: TexParser, name: string, left: string,
331331
}
332332
if (left || right) {
333333
// @test Normal Binomial, Text Binomial, Display Binomial
334-
NodeUtil.setProperties(frac, {withDelims: true});
334+
NodeUtil.setProperty(frac, 'withDelims', true);
335335
frac = ParseUtil.fixedFence(parser.configuration, left, frac, right);
336336
}
337337
if (style !== '') {

mathjax3-ts/input/tex/base/BaseItems.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -248,15 +248,15 @@ export class SubsupItem extends BaseItem {
248248
NodeUtil.setChild(top, 2, this.getProperty('primes') as MmlNode);
249249
} else {
250250
// @test Prime on Prime
251-
NodeUtil.setProperties(this.getProperty('primes') as MmlNode, {variantForm: true});
251+
NodeUtil.setProperty(this.getProperty('primes') as MmlNode, 'variantForm', true);
252252
const node = this.create('node', 'mrow', [this.getProperty('primes') as MmlNode, item.First]);
253253
item.First = node;
254254
}
255255
}
256256
NodeUtil.setChild(top, position, item.First);
257257
if (this.getProperty('movesupsub') != null) {
258258
// @test Limits Subsup (currently does not work! Check again!)
259-
NodeUtil.setProperties(top, {movesupsub: this.getProperty('movesupsub')} as PropertyList);
259+
NodeUtil.setProperty(top, 'movesupsub', this.getProperty('movesupsub') as Property);
260260
}
261261
const result = this.factory.create('mml', top);
262262
return result;
@@ -320,7 +320,7 @@ export class OverItem extends BaseItem {
320320
}
321321
if (this.getProperty('open') || this.getProperty('close')) {
322322
// @test Choose
323-
NodeUtil.setProperties(mml, {'withDelims': true});
323+
NodeUtil.setProperty(mml, 'withDelims', true);
324324
mml = ParseUtil.fixedFence(this.factory.configuration,
325325
this.getProperty('open') as string, mml,
326326
this.getProperty('close') as string);
@@ -842,7 +842,7 @@ export class ArrayItem extends BaseItem {
842842
if (this.arraydef['rowlines']) {
843843
// @test Enclosed dashed row, Enclosed solid row,
844844
this.arraydef['rowlines'] =
845-
(this.arraydef['rowlines'] as string).replace(/none( none) + $/, 'none');
845+
(this.arraydef['rowlines'] as string).replace(/none( none)+$/, 'none');
846846
}
847847
// @test Enclosed left right
848848
mml = this.create('node', 'menclose', [mml],

mathjax3-ts/input/tex/base/BaseMethods.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -302,8 +302,8 @@ BaseMethods.SetStyle = function(parser: TexParser, name: string,
302302
parser.stack.env['style'] = texStyle;
303303
parser.stack.env['level'] = level;
304304
parser.Push(
305-
parser.itemFactory.create('style').setProperties(
306-
{styles: {displaystyle: style, scriptlevel: level}}) );
305+
parser.itemFactory.create('style').setProperty(
306+
'styles', {displaystyle: style, scriptlevel: level}));
307307
};
308308

309309

@@ -316,7 +316,7 @@ BaseMethods.SetStyle = function(parser: TexParser, name: string,
316316
BaseMethods.SetSize = function(parser: TexParser, name: string, size: string) {
317317
parser.stack.env['size'] = size;
318318
parser.Push(
319-
parser.itemFactory.create('style').setProperties({styles: {mathsize: size + 'em'}}) );
319+
parser.itemFactory.create('style').setProperty('styles', {mathsize: size + 'em'}));
320320
};
321321

322322
// TODO: Will be replaced by the color extension!
@@ -364,7 +364,7 @@ BaseMethods.LeftRight = function(parser: TexParser, name: string) {
364364
const first = name.substr(1);
365365
parser.Push(
366366
parser.itemFactory.create(first)
367-
.setProperties({delim: parser.GetDelimiter(name)}) );
367+
.setProperty('delim', parser.GetDelimiter(name)));
368368
};
369369

370370
/**
@@ -455,7 +455,7 @@ BaseMethods.Limits = function(parser: TexParser, name: string, limits: string) {
455455
NodeUtil.copyChildren(op, node);
456456
op = top.Last = node;
457457
}
458-
NodeUtil.setProperties(op, {'movesupsub': limits ? true : false});
458+
NodeUtil.setProperty(op, 'movesupsub', limits ? true : false);
459459
NodeUtil.setProperties(NodeUtil.getCoreMO(op), {'movablelimits': false});
460460
if (NodeUtil.getAttribute(op, 'movablelimits') ||
461461
NodeUtil.getProperty(op, 'movablelimits')) {
@@ -473,7 +473,7 @@ BaseMethods.Limits = function(parser: TexParser, name: string, limits: string) {
473473
*/
474474
BaseMethods.Over = function(parser: TexParser, name: string, open: string, close: string) {
475475
// @test Over
476-
const mml = parser.itemFactory.create('over').setProperties({name: parser.currentCS}) ;
476+
const mml = parser.itemFactory.create('over').setProperty('name', parser.currentCS) ;
477477
if (open || close) {
478478
// @test Choose
479479
mml.setProperty('open', open);
@@ -672,7 +672,7 @@ BaseMethods.UnderOver = function(parser: TexParser, name: string, c: string, sta
672672
node = parser.create('node', 'TeXAtom', [mml],
673673
{texClass: TEXCLASS.OP, movesupsub: true});
674674
}
675-
NodeUtil.setProperties(node, {subsupOK: true});
675+
NodeUtil.setProperty(node, 'subsupOK', true);
676676
parser.Push(node);
677677
};
678678

@@ -1109,7 +1109,7 @@ BaseMethods.Matrix = function(parser: TexParser, name: string,
11091109
parser.i = 0;
11101110
}
11111111
// @test Matrix Braces, Matrix Columns, Matrix Rows.
1112-
const array = parser.itemFactory.create('array').setProperties({requireClose: true});
1112+
const array = parser.itemFactory.create('array').setProperty('requireClose', true);
11131113
array.arraydef = {
11141114
rowspacing: (vspacing || '4pt'),
11151115
columnspacing: (spacing || '1em')
@@ -1148,7 +1148,7 @@ BaseMethods.Matrix = function(parser: TexParser, name: string,
11481148
BaseMethods.Entry = function(parser: TexParser, name: string) {
11491149
// @test Label, Array, Cross Product Formula
11501150
parser.Push(
1151-
parser.itemFactory.create('cell').setProperties({isEntry: true, name: name}) );
1151+
parser.itemFactory.create('cell').setProperties({isEntry: true, name: name}));
11521152
if (parser.stack.Top().getProperty('isCases')) {
11531153
//
11541154
// Make second column be in \text{...} (unless it is already
@@ -1232,7 +1232,7 @@ BaseMethods.Entry = function(parser: TexParser, name: string) {
12321232
BaseMethods.Cr = function(parser: TexParser, name: string) {
12331233
// @test Cr Linebreak, Misplaced Cr
12341234
parser.Push(
1235-
parser.itemFactory.create('cell').setProperties({isCR: true, name: name}) );
1235+
parser.itemFactory.create('cell').setProperties({isCR: true, name: name}));
12361236
};
12371237

12381238

@@ -1356,7 +1356,7 @@ BaseMethods.BeginEnd = function(parser: TexParser, name: string) {
13561356
// environment. Otherwise we have a standard LaTeX environment that is
13571357
// handled with begin and end items.
13581358
if (!macro.args[0]) {
1359-
const mml = parser.itemFactory.create('end').setProperties({name: env});
1359+
const mml = parser.itemFactory.create('end').setProperty('name', env);
13601360
parser.Push(mml);
13611361
return;
13621362
}
@@ -1469,7 +1469,7 @@ BaseMethods.Equation = function (parser: TexParser, begin: StackItem, numbered:
14691469
parser.Push(begin);
14701470
ParseUtil.checkEqnEnv(parser);
14711471
return parser.itemFactory.create('equation', numbered).
1472-
setProperties({name: begin.getName()});
1472+
setProperty('name', begin.getName());
14731473
};
14741474

14751475

mathjax3-ts/input/tex/boldsymbol/BoldsymbolConfiguration.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,10 @@ export function rewriteBoldTokens(arg: {data: ParseOptions}) {
9494
if (NodeUtil.getProperty(node, 'fixBold')) {
9595
let variant = NodeUtil.getAttribute(node, 'mathvariant') as string;
9696
if (variant == null) {
97-
NodeUtil.setProperties(node, {mathvariant: TexConstant.Variant.BOLD});
97+
NodeUtil.setAttribute(node, 'mathvariant', TexConstant.Variant.BOLD);
9898
} else {
99-
NodeUtil.setProperties(node,
100-
{mathvariant: BOLDVARIANT[variant] || variant});
99+
NodeUtil.setAttribute(node,
100+
'mathvariant', BOLDVARIANT[variant] || variant);
101101
}
102102
NodeUtil.removeProperties(node, 'fixBold');
103103
}

mathjax3-ts/input/tex/newcommand/NewcommandMethods.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ NewcommandMethods.BeginEnv = function(parser: TexParser, begin: StackItem,
247247
parser.string = rest;
248248
parser.i = 0;
249249
// Close this environment.
250-
return parser.itemFactory.create('end').setProperties({name: begin.getName()});
250+
return parser.itemFactory.create('end').setProperty('name', begin.getName());
251251
}
252252
if (n) {
253253
// @test Newenvironment Optional, Newenvironment Arg Optional
@@ -267,7 +267,7 @@ NewcommandMethods.BeginEnv = function(parser: TexParser, begin: StackItem,
267267
parser.string = ParseUtil.addArgs(parser, bdef,
268268
parser.string.slice(parser.i));
269269
parser.i = 0;
270-
return parser.itemFactory.create('beginEnv').setProperties({name: begin.getName()});
270+
return parser.itemFactory.create('beginEnv').setProperty('name', begin.getName());
271271
};
272272

273273
NewcommandMethods.Macro = BaseMethods.Macro;

0 commit comments

Comments
 (0)