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
This commit is contained in:
Ignace Maes 2024-08-22 11:35:06 +02:00 committed by GitHub
parent 2645a116d1
commit 612981e4a8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 64 additions and 1 deletions

View File

@ -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": ["//"],

View File

@ -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),

27
tests/data/glimmer_js.gjs Normal file
View File

@ -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
tests/data/glimmer_ts.gts Normal file
View File

@ -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>