How is VariableDeclaration an Expression?

21 views
Skip to first unread message

Sébastien Ros

unread,
Sep 9, 2016, 8:29:57 PM9/9/16
to esprima
Using this code:

for (let n of fibonacci) {
    
};

The "let n" portion is parsed as a VariableDeclaration, which is a Statement (and a Declaration), and assigned to the 'left' property of ForOfStatement, as per https://github.com/jquery/esprima/blob/master/src/nodes.ts

How do you explain that the ForOfStatement constructor only accepts an Expression for its 'left' property and there is no mismatch as per https://github.com/jquery/esprima/blob/master/src/nodes.ts#L315
Is that some TypeScript magic?

Thanks

Ariya Hidayat

unread,
Sep 12, 2016, 11:59:05 PM9/12/16
to esp...@googlegroups.com

I think it's mostly because the code for parsing the for/for-of/for-in statement does not use type annotations that much.

Speaking of which, the entire for/for-of/for-in statement parsing is a mess anyway. It contains a few defects which are hard to fix with the current state of the code. Cleaning it up is something I am planning to prioritize pretty soon.

Thank you!

--
You received this message because you are subscribed to the Google Groups "esprima" group.
To unsubscribe from this group and stop receiving emails from it, send an email to esprima+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Ariya Hidayat, https://ariya.io

Jonny Johnson

unread,
Nov 8, 2017, 3:50:05 AM11/8/17
to esprima
Hi. I noticed this post and wonder if the forStatement have been cleaned up and the bugs been fixed? Or is the variable declaration still an expression? I also noticed you should prioritize this very soon, so nice to get an update on the progress.
Reply all
Reply to author
Forward
0 new messages