make 'names' accept only an array of strings, add warning comments about where new functions should be added

This commit is contained in:
Kevin Barabash
2017-08-26 19:15:40 -04:00
committed by Kevin Barabash
parent 6db61cb219
commit 12399da73d
7 changed files with 28 additions and 19 deletions

View File

@@ -1,5 +1,6 @@
/* eslint no-console:0 */
/**
* WARNING: New methods on groupTypes should be added to src/functions.
*
* This file does the main work of building a domTree structure from a parse
* tree. The entry point is the `buildHTML` function, which takes a parse tree.
* Then, the buildExpression, buildGroup, and various groupTypes functions are

View File

@@ -1,4 +1,6 @@
/**
* WARNING: New methods on groupTypes should be added to src/functions.
*
* This file converts a parse tree into a cooresponding MathML tree. The main
* entry point is the `buildMathML` function, which takes a parse tree from the
* parser.

View File

@@ -12,7 +12,7 @@ type FunctionSpec<T> = {
// The first argument to defineFunction is a single name or a list of names.
// All functions named in such a list will share a single implementation.
names: string | Array<string>,
names: Array<string>,
// Properties that control how the functions are parsed.
props: {
@@ -107,12 +107,6 @@ export default function defineFunction({
htmlBuilder,
mathmlBuilder,
}: FunctionSpec<*>) {
if (typeof names === "string") {
names = [names];
}
if (typeof props === "number") {
props = { numArgs: props };
}
// Set default values of functions
const data = {
numArgs: props.numArgs,

View File

@@ -3,9 +3,17 @@ import ParseError from "./ParseError";
import ParseNode from "./ParseNode";
import {default as _defineFunction, ordargument} from "./defineFunction";
// WARNING: New functions should be added to src/functions.
// Define a convenience function that mimcs the old semantics of defineFunction
// to support existing code so that we can migrate it a little bit at a time.
const defineFunction = function(names, props, handler) {
if (typeof names === "string") {
names = [names];
}
if (typeof props === "number") {
props = { numArgs: props };
}
_defineFunction({names, props, handler});
};

View File

@@ -231,7 +231,7 @@ defineFunction({
defineFunction({
type: "middle",
names: "\\middle",
names: ["\\middle"],
props: {
numArgs: 1,
},

View File

@@ -8,7 +8,7 @@ import * as mml from "../buildMathML";
defineFunction({
type: "phantom",
names: "\\phantom",
names: ["\\phantom"],
props: {
numArgs: 1,
},
@@ -38,7 +38,7 @@ defineFunction({
defineFunction({
type: "hphantom",
names: "\\hphantom",
names: ["\\hphantom"],
props: {
numArgs: 1,
},
@@ -79,7 +79,7 @@ defineFunction({
defineFunction({
type: "vphantom",
names: "\\vphantom",
names: ["\\vphantom"],
props: {
numArgs: 1,
},