strict mode failure
adamklein opened this issue · 4 comments
adding
'use strict';
to pgn-parser.js leads to test failures of the sort
TypeError: Cannot create property 'turn' on string '1/2-1/2'
because the post-processing of the parse tree then tries to set the turn on the "move" which is actually just a result string (and the last element of the parse array).
This comes up when a module manager (like rollup) includes the library with strict mode on by default. It would be better if the case were just handled correctly.
I think it just needs something simple like
if (typeof _move !== 'string') {
_move.turn = _currentTurn
}
at
Line 37 in f978433
Thank you for bringing that to my attention. This is pretty ugly (not your solution, but the original code):
- When parsing PGN, the last "move" may be the result of the game.
- Depending on if tags are used in the pgn, and depending on which parse start rule was used, the resulting structure may or may not contain the result explicitly.
- So users of the parser have to check the last "move", if that is the result or not.
I will merge your pull request, but I will think about a better solution. Parsing the result is done by the parser, so the resulting structure should contain the result not as move, but as a separate property.
I created and published a new version 1.3.6 so that others may use your fix in the public. See #99 for a correct fix of the problem then (sometimes in the future).
Thanks! And I forgot to say, thank you so much for the great library!