benjamn / ast-types

Esprima-compatible implementation of the Mozilla JS Parser API

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Why is there a ".." operator?

glmdgrielson opened this issue · comments

Writing a d.ts file for this project, I'm noticing that BinaryOperator includes a .. operator. Since no search engine seems to care about punctuation, I'm left to wonder: What the beep does that do? Throw off copiers?

Great question! I got it originally from the Mozilla Parser API, which was the genesis of every modern JS parser (Esprima, Acorn, Babylon, etc.).

If you scroll down to the definition of BinaryOperator, you'll see a curious note:

🗒 Note: The .. operator is E4X-specific.

E4X was an effort to add XML literals to JavaScript, which has long since been abandoned: https://developer.mozilla.org/en-US/docs/Archive/Web/E4X

Here's the only resource I could find that explains what .. used to do:
https://developer.mozilla.org/en-US/docs/Archive/Web/E4X/Processing_XML_with_E4X

While the . operator accesses direct children of the given node, the .. operator accesses all children no matter how deeply nested:

alert(person..*.length());

In short, no one uses this operator any more. Would it help your efforts if it were removed from this library? I'd be happy to do that!

Nah, keep it. With that logic, we may as well get rid of the with statement, too. It would probably be best to shove it with the other Mozilla stuff, though.

P.S. you have some blazing fast response time!

I’ve taken the liberty of sending a PR removing the .. operator since #303 removed the old Mozilla and E4X definitions.