|
From: | Jackson Ray Hamilton |
Subject: | Re: Comprehensive JSX support in Emacs |
Date: | Sun, 17 Feb 2019 23:17:10 -0800 |
User-agent: | Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.4.0 |
Hi Jostein, Thank you for bringing this use case to my attention. I haven’t worked with TypeScript before, but I took a look at the docs, and read through the whole JSX page. It looks like the syntax for JSX is exactly the same in TS as in JS, so my work may have a chance of integrating with typescript-mode. However, skimming through the rest of the docs, there could be challenges dealing with code that uses angle brackets that look like “tags,” e.g.:
I understand that “type assertions” will be written with an
The parser I’ve written to disambiguate JSX from JS in js-mode makes the assumption that matching angle brackets around identifiers indicate the presence of JSX with certainty. In order to adapt that code for TS, one solution could be to parse more, looking at the surrounding context of the angle brackets to determine whether the thing is a TS type or if it’s JSX. If you’re up for that challenge, hooks could be added to the parser to perform additional context checks defined by your mode. Disclaimer: Maybe “parsing more” won’t work, in which case a
different strategy might be necessary. Maybe it’s impossible to
know the difference between a TS type and JSX without an AST… I
dunno. In any case, as long as you can figure out what is JSX in
TS, and the JSX is marked with the same text properties that
js-mode will use, then integration with the rest of the JSX code
(which indents and font-locks) should be possible. Since typescript-mode doesn’t derive from js-mode, I expect
you’ll manually pull in the JSX functions and variables from
js-mode, and call the functions and use the variables in similar
ways, mirroring js-mode’s ways. I expect you will do these
things:
I will try to keep the code modular to make it easy for you to
pull in the parts you need. Jackson |
[Prev in Thread] | Current Thread | [Next in Thread] |