, 7 tweets, 2 min read Read on Twitter
I have learned the most wonderful thing about parsing JS.
The other day I was chatting with @loganfsmyth about JS parsers. What if, I said, we made a fast JS parser that could compile to wasm? Could any existing JS-ecosystem projects use that? What about Babel? It must have a parser of some kind. And he's like “ok, SO...”
It turns out Babel has to support not only the syntax of JS—which is already pretty special—but all the syntax of TypeScript, Flow, and JSX. Flow in particular is… a little odd!
var foo = doThing<Foo>(x);

is valid JS code and valid Flow code. But with two different meanings! In Flow, it's a call to a generic function. Bahaha. Only if it appears after a `// @flow` comment, though 😂
there's a COMMENT
that SWITCHES THE GRAMMAR
It gets even better when you cross the streams, use two extensions at once :D

<@loganfsmyth> e.g. `var foo = <T>(a = 1 + 2 + 3, b = a)`, you can't know if that's the first piece of a Flow generic arrow function, or a JSX element with some text until you find a `</T>` or a `=>`
unbounded lookahead IN THE TOKENIZER lolololol 🤣 💃💃💃

Because I work inside a browser engine, I miss all this exciting nonsense going on so close by, right in the same ecosystem! It's amazing.
Missing some Tweet in this thread?
You can try to force a refresh.

Like this thread? Get email updates or save it to PDF!

Subscribe to every_jorendorff
Profile picture

Get real-time email alerts when new unrolls are available from this author!

This content may be removed anytime!

Twitter may remove this content at anytime, convert it as a PDF, save and print for later use!

Try unrolling a thread yourself!

how to unroll video

1) Follow Thread Reader App on Twitter so you can easily mention us!

2) Go to a Twitter thread (series of Tweets by the same owner) and mention us with a keyword "unroll" @threadreaderapp unroll

You can practice here first or read more on our help page!

Follow Us on Twitter!

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just three indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3.00/month or $30.00/year) and get exclusive features!

Become Premium

Too expensive? Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal Become our Patreon

Thank you for your support!