Skip to content

Commit 137052c

Browse files
authored
Merge pull request #805 from mathjax/fix-symbol-maps
Allow return value of false to be used in SymbolMap parsers to continue the lookup process.
2 parents a06909b + 0fc3af0 commit 137052c

1 file changed

Lines changed: 11 additions & 9 deletions

File tree

ts/input/tex/SymbolMap.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,13 @@ export interface SymbolMap {
7070

7171
}
7272

73+
/**
74+
* @param {ParseResult} result The result to check
75+
* @return {ParseResult} True if result was void, result otherwise
76+
*/
77+
export function parseResult(result: ParseResult): ParseResult {
78+
return result === void 0 ? true : result;
79+
}
7380

7481
/**
7582
* Abstract implementation of symbol maps.
@@ -116,8 +123,7 @@ export abstract class AbstractSymbolMap<T> implements SymbolMap {
116123
public parse([env, symbol]: ParseInput) {
117124
let parser = this.parserFor(symbol);
118125
let mapped = this.lookup(symbol);
119-
return (parser && mapped) ?
120-
parser(env, mapped as any) || true as ParseResult : null;
126+
return (parser && mapped) ? parseResult(parser(env, mapped as any)) : null;
121127
}
122128

123129

@@ -311,7 +317,7 @@ export class MacroMap extends AbstractParseMap<Macro> {
311317
if (!macro || !parser) {
312318
return null;
313319
}
314-
return parser(env, macro.symbol, ...macro.args) || true as ParseResult;
320+
return parseResult(parser(env, macro.symbol, ...macro.args));
315321
}
316322

317323
}
@@ -334,14 +340,11 @@ export class CommandMap extends MacroMap {
334340
if (!macro || !parser) {
335341
return null;
336342
}
337-
if (!parser) {
338-
return null;
339-
}
340343
let saveCommand = env.currentCS;
341344
env.currentCS = '\\' + symbol;
342345
let result = parser(env, '\\' + macro.symbol, ...macro.args);
343346
env.currentCS = saveCommand;
344-
return result || true as ParseResult;
347+
return parseResult(result);
345348
}
346349

347350
}
@@ -383,8 +386,7 @@ export class EnvironmentMap extends MacroMap {
383386
if (!macro || !envParser) {
384387
return null;
385388
}
386-
this.parser(env, macro.symbol, envParser, macro.args);
387-
return true;
389+
return parseResult(this.parser(env, macro.symbol, envParser, macro.args));
388390
}
389391

390392
}

0 commit comments

Comments
 (0)