Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Write end offsets to
_debug
even if validation fails
Fixes a regression introduced in 7154301 that was well noticeable in the devel Web IDE with the kaitai-io/kaitai_struct_webide#156 feature: a field with a failed validation (specified by the `contents` or `valid` key) no longer had its byte range highlighted in the hex dump. This is because the aforementioned commit changed the order of operations in the generated JavaScript code (in debug mode, or more precisely with `--read-pos`) so that the assignment of the end offset to the `_debug` map for a field with `contents` or `valid` was done *after* the `if` statement performing the validation, which meant that the end offset was not assigned if the validation failed. A nice side effect of this commit is that it eliminates duplicate `this._debug.{ATTR_NAME}.arr[i]` assignments in the case of a field with type switching and `repeat`, such as when you compile https://github.com/kaitai-io/kaitai_struct_tests/blob/9f782819b70db6069674995b969d2b801c86a515/formats/switch_repeat_expr.ksy in `--read-pos` mode (in JavaScript, it removes the `this._debug.body.arr[i] = ...` assignments from every branch of the `switch` statement, which are indeed unnecessary, because the exact same assignments already exist around the `switch` statement as well). Note: this commit unfortunately doesn't have any impact on the current set of test formats in [`formats/`](https://github.com/kaitai-io/kaitai_struct_tests/tree/9f782819b70db6069674995b969d2b801c86a515/formats) when compiled with the usual settings in [`build-formats`](https://github.com/kaitai-io/kaitai_struct_tests/blob/9f782819b70db6069674995b969d2b801c86a515/build-formats). This is because we only test the debug mode on 4 formats that have the `meta/ks-debug: true` key, and none of them has a field with `contents` or `valid`. But if you add `--debug` to the KSC incantation in `build-formats`, you will see the changes.
- Loading branch information