-
Notifications
You must be signed in to change notification settings - Fork 789
Created lexers for gjs and gts (used by Ember projects) #2165
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
Conversation
|
To the reviewers: I fixed the lint errors found in CI (new line missing at EOF). Will move the PR to draft so that @dknutsen from #2163 can look into adding specs to this branch. |
…t, and typescript
* fix: update regex to correctly delegate handlebars in gjs and gts lexers * chore: update demo to include javascript after the closing template tag * chore: update demo to include typescript after the closing template tag * test: add guessing test for gjs and gts lexer
This reverts commit a9953db.
…avascript, and typescript" This reverts commit 25eddf1.
This reverts commit 7822430.
…an existing bug in the handlebars lexer causes tests to fail
8ce53b5 to
36883f3
Compare
|
@tancnle Could you help with reviewing this pull request? |
|
@tancnle is there anything we can do to help move this forward? |
|
+1 |
|
Apology for the delay. Thank you for your work on this MR, @ijlee2. LGTM 🚀 |
|
@tancnle Thank you again for your help! Q. When could we expect a new release in |
Background
This pull request (PR) provides a simpler, more maintainable implementation than #2163.
In Ember.js, we use the extension
*.gjsand*.gtsto write JavaScript/TypeScript and template code in the same file. Templates are marked by a<template>tag. The main use case of*.{gjs,gts}: Developers can write single-file components, an idea that we can find in other web frameworks.To my understanding, GitLab and dev.to rely on
rougefor syntax highlighting. This PR would especially help developers who use GitLab, because they currently can't see diffs in*.{gjs,gts}highlighted in their PRs.Related issues on GitLab:
Solution
*.gjsand*.gtsare just JavaScript and TypeScript with some Handlebars-like code (technically, it's Glimmer). As a result, I believe the best solution is to delegate syntax highlighting to existingjavascript,typescript, andhandlebarslexers, since they've been tested out for years (not just in the context of Ember, but also of others).The new
gjsandgtslexers are only responsible for locating the starting<template>and the ending</template>tags. As an aside, I've used this separation of concerns successfully to implement syntax highlighting for Sublime Text.Note
There's a possibility that, in the future,
*.{gjs,gts}allows the<style>tag in addition to the<template>tag. The Ember community hasn't come to a consensus on where this tag should appear and how it should be invoked. So, to limit the scope, I allowed thegjsandgtslexers to not handle the<style>tag for now.Demos (Testing)
In the screenshots below, we should see the JavaScript part of a
*.gjsfile highlighted in the same manner as in a*.jsfile. Similarly, the TypeScript part of a*.gtsfile, as in a*.tsfile. In both*.gjsand*.gts, the template code inside a<template>tag should be highlighted as if it were in an*.hbsfile.Example 1: Component
gjs, theme is default
gjs, theme is github
gjs, theme is github-dark
gts, theme is default
gts, theme is github
gts, theme is github-dark
Example 2: Test for the component
gjs, theme is default
gjs, theme is github
gjs, theme is github-dark
gts, theme is default
gts, theme is github
gts, theme is github-dark