Open widcardw opened 8 months ago
zmx0142857 says that in this part, the program should judge if the body
of flat
has only one child and the type of the child is still flat
, then just remove it.
That's to say add
if (body.length === 1 && body[0].type === NodeTypes.Flat)
return body[0]
before the return
. This needs to be tested.
However, in the type declaration, the n
cannot be a FlatNode
, but n
can be a list that contains a FlatNode
. Maybe the problem is here.
After I have refactored the tests, there are some redundant
flat
wrappers in the generated syntax tree. Sometimes I even don't know why theflat
wrapper exists.https://github.com/widcardw/asciimath-parser/blob/f5a0bb1bbe163f7ac3c44e78634660ff9e99b213/packages/core/test/parser.test.ts#L44
https://github.com/widcardw/asciimath-parser/blob/f5a0bb1bbe163f7ac3c44e78634660ff9e99b213/packages/core/test/parser.test.ts#L103
https://github.com/widcardw/asciimath-parser/blob/f5a0bb1bbe163f7ac3c44e78634660ff9e99b213/packages/core/test/parser.test.ts#L166-L172
https://github.com/widcardw/asciimath-parser/blob/f5a0bb1bbe163f7ac3c44e78634660ff9e99b213/packages/core/test/parser.test.ts#L211
Although the redundant
flat
s may not change the output oftoTex
function, it still needs to be improved.