Currently, the following (valid) code doesn’t parse:
declare const f: (x: any) => asserts x;
declare const g: (x: any) => asserts x is number;
It does not parse because the grammar only supports the asserts keyword when it follows a colon (as in function f(x: any): asserts x {}). This pull request adds support for asserts in type declarations as above.
I removed the colon from the $.asserts rule and added a new rule $.asserts_annotation which adds the colon back (so that we can use $.asserts in places that do not have a colon). This mirrors the way the existing $.type_annotation and $.type_predicate_annotation work, but unfortunately it modifies the parse tree of existing code. But I think this change still makes sense.
Checklist:
[X] All tests pass in CI.
[X] There are sufficient tests for the new fix/feature.
[x] Grammar rules have not been renamed unless absolutely necessary.
[X] The conflicts section hasn't grown too much.
[X] The parser size hasn't grown too much (check the value of STATE_COUNT in src/parser.c).
(STATE_COUNT increased from 4437 to 4451)
Currently, the following (valid) code doesn’t parse:
It does not parse because the grammar only supports the
asserts
keyword when it follows a colon (as infunction f(x: any): asserts x {}
). This pull request adds support forasserts
in type declarations as above.I removed the colon from the
$.asserts
rule and added a new rule$.asserts_annotation
which adds the colon back (so that we can use$.asserts
in places that do not have a colon). This mirrors the way the existing$.type_annotation
and$.type_predicate_annotation
work, but unfortunately it modifies the parse tree of existing code. But I think this change still makes sense.Checklist: