gandm / language-babel

ES2017, flow, React JSX and GraphQL grammar and transpilation for ATOM
https://atom.io/packages/language-babel
MIT License
476 stars 83 forks source link

Parse interior javascript of grammar-extended tagged template literals #429

Closed skylize closed 7 years ago

skylize commented 7 years ago

Very nice feature of being able to parse html or other grammars from template literals, but still a bit annoying that the javascript expressions inside them get parsed as plain strings.

There seem to be quite a lot of mechanics already in place for extracting js from a file parsed by language-html. Would it not be realistic to extend this functionality to template strings parsed by language-html or similar grammar packages?

gandm commented 7 years ago

No I'm afraid it's impossible. Once I hand off to another grammar I can't control what it does. I do add a rule to handle interpolations but most grammars remove this as part of their descent into nested rules. It's a bit like monkey patching a function before calling it but then the actual function calls another and I loose control.

It's one of the reasons I use my own grammar for CSS/Styled-components/ and GraphQL, so I can maintain this control.