Closed tamasfe closed 2 years ago
I've realized that the right side of .
should be a lot stricter and should allow identifiers only. How to restrict this properly is not immediately trivial to me as the .
is just an operator in an expression tree where both sides can be any expression.
I'll leave this as-is for the time being as it's not a huge issue.
Yes, the RHS of .
should always be an identifier.
In the parser, .
and [
are split off from operators. They are actually handled as part of the parsing of a primary term, which loosely can be defined as:
(unary operator)* identifier ( '.' identifier | '[' expression ']' )*
In the parser this is called an "indexing chain", although dotting is also covered.
Thus, [
and .
are not parsed as operators, allowing you to catch invalid syntax early.
For the sake of simplicity, constructs like
let a = 0
are also expressions that evaluate to()
.As a consequence currently the following is also accepted:
It is roughly equivalent to
(this) . (const a = 2)
, It's not clear whether to leave it as is, or specify stricter rules.