fix: simplify.resolve detects reference loop and throws error#2405
Conversation
josdejong
left a comment
There was a problem hiding this comment.
Really nice Job @gwhitney , thanks. I like that you took the time to improve on the automatically generated docs too.
I made a few minor inline remarks, and have one thought: shall we can flatten the function names simplify.simplifyCore and simplify.resolve into simplifyCore and simplifyResolve? So far the library doesn't have nested functions, and that is just of simple and straightforward :).
| scope = createMap(scope) | ||
| } | ||
| if (isSymbolNode(node)) { | ||
| if (within.indexOf(node.name) !== -1) { |
There was a problem hiding this comment.
Generally I prefer not to mutate function input arguments, but here with within (and only internally) it makes sense.
Would it make sense for performance to change make within a Set instead of an Array?
There was a problem hiding this comment.
Ah I was not thinking of a case with 100s of variables, but I suppose someone may want to use mathjs for such a case. Will change.
| @@ -17,3 +17,39 @@ export const simplifyDocs = { | |||
| 'derivative', 'parse', 'evaluate' | |||
There was a problem hiding this comment.
Can you add refrences to simplify.resolve and simplify.simplifyCore in simplify?
There was a problem hiding this comment.
Will do, to their new top-level names.
| '\n\n\n' | ||
| } | ||
|
|
||
| if (doc.mayThrow) { |
There was a problem hiding this comment.
Nice improvements documenting the exceptions that a function may throw!
I think naming should be entirely at your judgment and I can see in this comment and elsewhere that you favor a single layer of public names in mathJS. So I will revert the portions of this that track documentation down to a second layer, and move these two functions to the top layer. As for their names there, I'd suggest simplifyCore and resolve; the latter has a clear meaning and purpose on its own, independent of simplify, and the name does not conflict. |
For example, prior to this commit, docgenerator.js would miss simplify.resolve because it is not a direct key of the math object. Also incorporates any "throws" attributes in the comments into the generated documentation, and uses this to document the new error-case behavior of simplify.resolve to be added in the next commit.
Also extends resolve to work inside all node types. Adds tests for both changes.
To support finding the embedded doc from the `math.simplify.resolve` function itself, required extending the search for objects with documentation one level deeper in the `help()` function. Added test for this search. Also added support for documenting throws in embedded docs.
Also reverts changes searching for docs and embedded docs one level down in the naming hierarchy. Also splits tests for resolve and simplifyCore into their own files, reflecting their new top-level status.
269b141 to
ad93609
Compare
Also removed a stray blank line inadvertently introduced in docgenerator.js
ad93609 to
1ac7d49
Compare
|
OK, I think that should take care of all of the feedback. Thanks. |
|
Thanks
That sounds good 👍 . I do not see a conflict with some other function that we would want to call |
|
Oh, I just realized that now that resolve and simplifyCore are at the top level, simplify should just register them as dependencies. Give me a minute and I will fix. |
... rather than explicitly loading them, which is unnecessary now that they are at top level.
Also register simplifyCore as a dependency to rationalize
|
Oh and I have to do the same for rationalize, and then add the dependencies to factoriesNumber so the build won't fail. Now it should be OK to merge. |
|
This is published now in |
Also adds reference documentation and embedded documentation for
simplify.resolve(with docs forsimplify.simplifyCorecoming along for the ride). Making these additions involved extending both doc facilities to handle functions "one level down" from the top level, and to support descriptions of what errors a function might throw (which were already present in the reference docs for several other functions, and so will now be displayed).Also extends
simplify.resolveto perform variable substitution within all node types (formerly it would be blocked by, e.g., an ArrayNode and not perform variable resolution within).Adds tests for all new behaviors, including
simplify.resolvethrowing ReferenceErrors.Resolves #2383.