Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add support for Glimmer JS/TS #1052

Merged
merged 11 commits into from
Aug 22, 2024
16 changes: 16 additions & 0 deletions languages.json
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,22 @@
"quotes": [["\\\"", "\\\""]],
"extensions": ["gleam"]
},
"GlimmerJs": {
"name": "Glimmer JS",
"line_comment": ["//"],
"multi_line_comments": [["/*", "*/"], ["<!--", "-->"]],
"quotes": [["\\\"", "\\\""], ["'", "'"], ["`", "`"]],
"important_syntax": ["<template", "<style"],
"extensions": ["gjs"]
},
"GlimmerTs": {
"name": "Glimmer TS",
"line_comment": ["//"],
"multi_line_comments": [["/*", "*/"], ["<!--", "-->"]],
"quotes": [["\\\"", "\\\""], ["'", "'"], ["`", "`"]],
"important_syntax": ["<template", "<style"],
"extensions": ["gts"]
},
"Glsl": {
"name": "GLSL",
"line_comment": ["//"],
Expand Down
4 changes: 3 additions & 1 deletion src/language/embedding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,9 @@ impl<'a> RegexCache<'a> {
LanguageType::Html
| LanguageType::RubyHtml
| LanguageType::Svelte
| LanguageType::Vue => {
| LanguageType::Vue
| LanguageType::GlimmerJs
| LanguageType::GlimmerTs => {
let html = HtmlLike {
start_script: save_captures(&START_SCRIPT, lines, start, end),
start_style: save_captures(&START_STYLE, lines, start, end),
Expand Down
27 changes: 27 additions & 0 deletions tests/data/glimmer_js.gjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// 27 lines, 18 code, 6 comments, 3 blanks
import { helper } from '@ember/component/helper';
import { modifier } from 'ember-modifier';

// A single-line comment
const plusOne = helper(([num]) => num + 1);

/**
* A multi-line comment
*/
const setScrollPosition = modifier((element, [position]) => {
element.scrollTop = position
});

<template>
<!-- A HTML-like comment -->
<div class="scroll-container" {{setScrollPosition @scrollPos}}>
{{#each @items as |item index|}}
Item #{{plusOne index}}: {{item}}
{{/each}}
</div>
<style>
div {
background-color: #E04E39;
}
</style>
</template>
18 changes: 18 additions & 0 deletions tests/data/glimmer_ts.gts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// 18 lines, 10 code, 6 comments, 2 blanks
import type { TemplateOnlyComponent } from '@glimmer/component';

// A single-line comment
const localVariable = 'foo';

/**
* A multi-line comment
*/
const Greet: TemplateOnlyComponent<{ name: string }> = <template>
<!-- A HTML-like comment -->
<p>Hello, {{@name}}! {{localVariable}}</p>
<style>
p {
background-color: #E04E39;
}
</style>
</template>
Loading