Skip to content
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

Pulled in previous JavaScript grammar improvements into TypeScript grammar. #3973

Merged
merged 4 commits into from
Feb 20, 2024

Conversation

aleppard
Copy link
Contributor

@aleppard aleppard commented Feb 20, 2024

TypeScript is a (typed) superset of the JavaScript language and there have been many improvements to the JavaScript grammar that haven't made it into the TypeScript grammar. This PR pulls them in, and adds a couple of minor TypeScript only improvements.

Improvements to the TypeScript grammar from the existing JavaScript grammar include:

  • Improved import and export support.
  • Addition of power (**, **=) and coalescing (??, ??=) operators.
  • Improved support for async.
  • Support for using underscore to break up long numbers.
  • Support for big numbers.
  • Better support for unicode characters.
  • Support for class expressions.
  • Member chain expressions.
  • ... and more

The TypeScript specific improvements are:

  • Fixed arbitrary nested generic types, e.g. Promise<Map<string, Set<string>>> now works.
  • Added the 'null' type.
  • The 'get' and 'set' identifiers are not reserved and can be used to create functions - just like in JavaScript grammar.
  • catch clauses can now be typed, e.g. catch (error: MyError) {

I've copied a couple of the JavaScript examples to the TypeScript example directory to help test the improvements. It would be nice if the TypeScript tests made sure we could parse all of the JavaScript examples. However without copying all the files, I wasn't sure how to do that (and whether the intention was to deliberately decouple each language).

To review it might make sense to look at the diff TypeScriptParser.g4 with JavaScriptParser.g4 (ditto for lexers) as most of the changes are just existing grammar.

There is still more work to be done to bring Typescript up to date.

@KvanTTT KvanTTT added example New example of file(s) parsed by grammar-generated parser typescript labels Feb 20, 2024
@KvanTTT KvanTTT merged commit c888914 into antlr:master Feb 20, 2024
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
example New example of file(s) parsed by grammar-generated parser typescript
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants