-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Proposal: TypeScript should be built on the solid foundation of JS #2568
Comments
Or at the very least a 90% |
From my research just now about the actual differences between JS and TS grammars (after consolidating as much as we can)
|
And some weird things like TS decreasing the relevance of 'function' an saying that TS is more commonly |
@egor-rogov @allejo So the question is can TS simply consume JS or do we need to maintain both on a common foundation or some sort? The simplest thing would be to just merge them into a single language and then The "downside" would be that I suppose TS keywords MIGHT get highlighted in JS when used in other contexts: var number = 32 ; // number is a type in TS But there are different solutions for that... improving context, etc... I'm kind of curious to try the "simplest solution" first [TS consumes JS] - unless you all strongly object - and then if that fails to work in the long-run to fall back to a more nuanced solution. |
I haven't looked at the JS and TS grammars, but I'd be opposed to making JS an alias for TS. Like you mentioned, TS keywords could be highlighted in a JS context. I think the best way forward would be to make the TS grammar extend the JS grammar and add any extra TS keywords and syntaxes (e.g. generics) on top of that. |
I think it might be simpler to build JS on TS and remove keywords - even if that sounds counter intuitive. Our ability to make subtle changes to another language right now isn’t superb. |
...that sounds horribly counter-intuitive but if that's the best way to do things right now, sure! One way or another, I'd opt for having one language be the base of the other; whether it's additions or removals. |
I might do this in two pieces then, first pull TS up to the JS spec - which needs to be done anyways to make sure they are both pretty much 'doing the same thing', then work on one requiring the other. |
I agree with @allejo that merging the two languages doesn't look right. I'd rather have two grammars: either one based on another, or both based on a common foundation. |
End user expects from syntax highlighting to not have such petty problems as method/property name being highlighted as keyword or incomplete modifier list. Definitely merging here isn't an option, features from TS doesn't work in JS, but making TS extend JS dictionary seems to be the only wise solution. |
What I meant by merging is that TS is.a strict super-set of JS... so that means TS should 99.9% of the time correctly highlight all valid JS code. The only exception being keywords that don’t exist in JS. If someone had a ridiculously tight budget for download size using TS to highlight JS code would be a very workable decision with very few downsides for most code. But I will build TS on top of JS and find a way to make that work. |
Yes, sadly the quick solution is often far from the correct or optimal solution. Sometimes because of inadequate tests (and many potential contributors don’t even run the tests) - so it’s not clear what was just broken. Or sometimes because of common pattern we use (or avoid) or connections across languages that aren’t explicit (like JS and TS intertwining). Sadly, sometimes the answer is “there is no great way to do that yet at all” - and fixes that only half work or 80% work can often cause more trouble than they are worth... look at all the issues filed for edge cases just as an example. I’m open to suggestions on how to improve these things at a big picture level, but it’s a complicated problem since parsers and grammars are by their very nature a complicated thing. And some things are made much harder by the technical deficiencies of either JS (no look-behind support) or our parsing engine itself. For example the BEST way to not highlight keywords that are methods would be to use a look-behind in the
I think adding method dispatch highlighting might actually solve this particular problem (keywords as method names). See the related thread on improving the fidelity of our highlighting. |
Since TypeScript is purely a superset of Javascript (and all valid JS is also valid TS) and that we should merge our JS and TS grammars into a single grammar for ease of maintenance - this probably should have been done from the beginning, but water under the bridge. Right now many things require double the effort and there are strange differences between the grammars (like JS supports JSX but TS does not support TSX).
It also makes things harder for contributors... they need to do more work (perhaps double) be more aware of the bigger picture, etc...
Most recent example: #2562
We could literally make
js
andjavascript
as an alias of TypeScript or JS could be more of a "dummy" grammar that really just re-uses the TypeScript grammar under the hood. I'm not sure what the value there is though other than thatlang.name
would be "Javascript".@egor-rogov Any objections?
The text was updated successfully, but these errors were encountered: