Make ParseNode value payload and defineFunction handler functions type-safe (#1276)

* Make ParseNode `value` payload type-safe.

* Make defineFunction handlers aware of ParseNode data types.

* Add `type` to all function definitions to help determine handler return type.

* Added unit test for case caught only in screenshot test and fixed issue.

* Rename some symbol `Group`s to avoid conflicts with `ParseNode` groups.

Symbol `Group`s are also used as `ParseNode` types. However, `ParseNode`s of
these types always contain a raw text token as opposed to any structured
content. These `ParseNode`s are passed as arguments into function handlers to
create more semantical `ParseNode`s with more structure.

Before this change, "accent" and "op" were both symbol `Group`s and `ParseNode`
types. With this change, these two types (the raw accent token `ParseNode`, and
the structured semantical `ParseNode` are separated for better type-safety on
the `ParseNode` payload).

* stretchy: Remove FlowFixMe for a forced typecast that's no longer needed.
This commit is contained in:
Ashish Myles
2018-05-09 20:13:31 -04:00
committed by Kevin Barabash
parent 3613885da1
commit 5a4aedd882
18 changed files with 370 additions and 87 deletions

View File

@@ -69,7 +69,7 @@ const renderToString = function(
const generateParseTree = function(
expression: string,
options: SettingsOptions,
): ParseNode[] {
): ParseNode<*>[] {
const settings = new Settings(options);
return parseTree(expression, settings);
};