Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is the continuation of #52 which I had closed by mistake. The bugs which I've highlighted then seems already fixed, so this PR is only about types now.
Added JSDoc type annotations for output values
I've added type annotation for class properties and some function arguments so return types of exported functions (like
parseARule()
) can now be inferred.This may be very useful, for example, in this code:
a editor with enabled TypeScript features (such as VSCode) will suggest that
comp
has atype
property with one of predefined values ("BLOCK", "IDENT", "FUNCTION", ...) and insideif
condition thecomp
type will be narrowed down toFunc
with stringname
and arrayvalue
.For simplicity, arguments of exported functions and some of the internal code is not type annotated.
while(1) loops are now while(true) because "1" is not an "endless" condition for TS
This function return type will be
number | undefined
, but withwhile(true)
the type will benumber
as expected:I've used this jsconfig.json (not included to PR)
Question about consume()
There are some loops with condition
while(consume())
which looks as ifconsume()
will eventually stop the loop by returningfalse
. But it won't: it always returnstrue
. Is it intended? Willconsume()
someday start returningfalse
?If it won't, maybe remove
return true
fromconsume()
and rewrite loops conditions toto make it clear (for user and type checker) that
consume()
is not a condition?