Skip to content

Commit 612981e

Browse files
authored
Add support for Glimmer JS/TS (#1052)
* feat: add glimmer lang support * tests: add glimmer lang test files * fix: use js comment matches * tests: add style block example * fix: use template tag * feat: add template multiline comments to gjs/gts * fix(tests): comment line include heads * tests: add template comment examples * fix(test): rename test file as it doesn't like dashes * fix: no hbs comments
1 parent 2645a11 commit 612981e

File tree

4 files changed

+64
-1
lines changed

4 files changed

+64
-1
lines changed

languages.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -598,6 +598,22 @@
598598
"quotes": [["\\\"", "\\\""]],
599599
"extensions": ["gleam"]
600600
},
601+
"GlimmerJs": {
602+
"name": "Glimmer JS",
603+
"line_comment": ["//"],
604+
"multi_line_comments": [["/*", "*/"], ["<!--", "-->"]],
605+
"quotes": [["\\\"", "\\\""], ["'", "'"], ["`", "`"]],
606+
"important_syntax": ["<template", "<style"],
607+
"extensions": ["gjs"]
608+
},
609+
"GlimmerTs": {
610+
"name": "Glimmer TS",
611+
"line_comment": ["//"],
612+
"multi_line_comments": [["/*", "*/"], ["<!--", "-->"]],
613+
"quotes": [["\\\"", "\\\""], ["'", "'"], ["`", "`"]],
614+
"important_syntax": ["<template", "<style"],
615+
"extensions": ["gts"]
616+
},
601617
"Glsl": {
602618
"name": "GLSL",
603619
"line_comment": ["//"],

src/language/embedding.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,9 @@ impl<'a> RegexCache<'a> {
171171
LanguageType::Html
172172
| LanguageType::RubyHtml
173173
| LanguageType::Svelte
174-
| LanguageType::Vue => {
174+
| LanguageType::Vue
175+
| LanguageType::GlimmerJs
176+
| LanguageType::GlimmerTs => {
175177
let html = HtmlLike {
176178
start_script: save_captures(&START_SCRIPT, lines, start, end),
177179
start_style: save_captures(&START_STYLE, lines, start, end),

tests/data/glimmer_js.gjs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// 27 lines, 18 code, 6 comments, 3 blanks
2+
import { helper } from '@ember/component/helper';
3+
import { modifier } from 'ember-modifier';
4+
5+
// A single-line comment
6+
const plusOne = helper(([num]) => num + 1);
7+
8+
/**
9+
* A multi-line comment
10+
*/
11+
const setScrollPosition = modifier((element, [position]) => {
12+
element.scrollTop = position
13+
});
14+
15+
<template>
16+
<!-- A HTML-like comment -->
17+
<div class="scroll-container" {{setScrollPosition @scrollPos}}>
18+
{{#each @items as |item index|}}
19+
Item #{{plusOne index}}: {{item}}
20+
{{/each}}
21+
</div>
22+
<style>
23+
div {
24+
background-color: #E04E39;
25+
}
26+
</style>
27+
</template>

tests/data/glimmer_ts.gts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// 18 lines, 10 code, 6 comments, 2 blanks
2+
import type { TemplateOnlyComponent } from '@glimmer/component';
3+
4+
// A single-line comment
5+
const localVariable = 'foo';
6+
7+
/**
8+
* A multi-line comment
9+
*/
10+
const Greet: TemplateOnlyComponent<{ name: string }> = <template>
11+
<!-- A HTML-like comment -->
12+
<p>Hello, {{@name}}! {{localVariable}}</p>
13+
<style>
14+
p {
15+
background-color: #E04E39;
16+
}
17+
</style>
18+
</template>

0 commit comments

Comments
 (0)