codemirror-lang-glimmer 0.0.0-beta.3 → 0.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. package/.eslintrc.cjs +2 -2
  2. package/.turbo/turbo-build.log +5 -21
  3. package/.turbo/turbo-lint$colon$js$colon$fix.log +7 -0
  4. package/.turbo/turbo-lint$colon$js.log +7 -0
  5. package/.turbo/turbo-lint$colon$prettier$colon$fix.log +15 -0
  6. package/.turbo/turbo-lint$colon$prettier.log +9 -0
  7. package/.turbo/turbo-lint$colon$types.log +5 -0
  8. package/CHANGELOG.md +15 -0
  9. package/LICENSE +21 -0
  10. package/dev/.eslintcache +1 -0
  11. package/dev/.eslintrc.cjs +2 -2
  12. package/dev/CHANGELOG.md +3 -0
  13. package/dev/index.html +1 -1
  14. package/dev/index.ts +43 -3
  15. package/dev/node_modules/.bin/eslint +4 -4
  16. package/dev/node_modules/.bin/prettier +4 -4
  17. package/dev/node_modules/.bin/tsc +4 -4
  18. package/dev/node_modules/.bin/tsserver +4 -4
  19. package/dev/node_modules/.bin/vite +4 -4
  20. package/dev/package.json +28 -16
  21. package/dev/watch.cjs +3 -3
  22. package/dist/index.cjs +222 -321
  23. package/dist/index.d.cts +22 -4
  24. package/dist/index.d.ts +22 -4
  25. package/dist/index.js +224 -325
  26. package/package.json +42 -26
  27. package/src/auto-close.ts +91 -0
  28. package/src/glimmer.ts +79 -0
  29. package/src/index.ts +3 -154
  30. package/src/language.ts +176 -0
  31. package/src/snippets.ts +48 -0
  32. package/tsconfig.json +2 -1
  33. package/.eslintignore +0 -2
  34. package/.prettierignore +0 -2
  35. package/.prettierrc.cjs +0 -20
  36. package/dist/index.d.cts.map +0 -1
  37. package/dist/index.d.ts.map +0 -1
  38. package/src/highlight.ts +0 -57
  39. package/src/syntax.grammar +0 -139
  40. package/src/syntax.grammar.d.ts +0 -3
  41. package/src/syntax.grammar.terms.d.ts +0 -14
  42. package/src/tokens.ts +0 -277
  43. package/tests/.eslintrc.cjs +0 -5
  44. package/tests/comments.txt +0 -116
  45. package/tests/complex.txt +0 -24
  46. package/tests/expression.txt +0 -95
  47. package/tests/literals.txt +0 -78
  48. package/tests/node_modules/.bin/eslint +0 -17
  49. package/tests/node_modules/.bin/prettier +0 -17
  50. package/tests/node_modules/.bin/tsc +0 -17
  51. package/tests/node_modules/.bin/tsserver +0 -17
  52. package/tests/numbers.txt +0 -88
  53. package/tests/package.json +0 -25
  54. package/tests/property-paths.txt +0 -79
  55. package/tests/strings.txt +0 -64
package/dist/index.cjs CHANGED
@@ -1,315 +1,53 @@
1
1
  'use strict';
2
2
 
3
+ var autocomplete = require('@codemirror/autocomplete');
4
+ var langCss = require('@codemirror/lang-css');
3
5
  var langHtml = require('@codemirror/lang-html');
6
+ var langJavascript = require('@codemirror/lang-javascript');
4
7
  var language = require('@codemirror/language');
5
- var common = require('@lezer/common');
6
- var html = require('@lezer/html');
7
- var lr = require('@lezer/lr');
8
- var highlight = require('@lezer/highlight');
8
+ var state = require('@codemirror/state');
9
+ var lezerGlimmerExpression = require('@glimdown/lezer-glimmer-expression');
10
+ var view = require('@codemirror/view');
11
+ var lezerGlimmer = require('lezer-glimmer');
9
12
 
10
- // This file was generated by lezer-generator. You probably shouldn't edit it.
11
- const shortCommentContent$1 = 56,
12
- longCommentContent$1 = 57,
13
- htmlCommentContent$1 = 58,
14
- templateTagContent$1 = 59,
15
- MoustacheExpression = 9;
16
-
17
- // Ascii values
18
- const parenOpen = 40;
19
- const parenClose = 41;
20
- const squareOpen = 91;
21
- const squareClose = 93;
22
- const curlyOpen = 123;
23
- const curlyClose = 125;
24
- const colon = 58;
25
- const hash = 35;
26
- const at = 64;
27
- const slash = 47;
28
- const greaterThan = 62;
29
- const dash = 45;
30
- const quoteDouble = 34;
31
- const quoteSingle = 39;
32
- const backslash = 92;
33
- const newline = 10;
34
- const asterisk = 42;
35
- const tick = 96;
36
- const prefixes = [colon, hash, at, slash];
37
- const shortCommentEnd = [curlyClose, curlyClose];
38
- const longCommentEnd = [dash, dash, curlyClose, curlyClose];
39
- const htmlCommentEnd = [dash, dash, greaterThan];
40
- // Is there a way to make this a build time (rather than eval-time?) operation?
41
- const closingTemplateTag = '</template>'.split('').map((char) => char.charCodeAt(0));
42
- function matchForComment(commentEndPattern, commentToken, input) {
43
- for (let found = 0, i = 0;; i++) {
44
- if (input.next < 0) {
45
- if (i)
46
- input.acceptToken(commentToken);
47
- break;
48
- }
49
- let hasMatch = commentEndPattern[found] === input.next;
50
- if (!hasMatch) {
51
- found = 0;
52
- input.advance();
53
- break;
54
- }
55
- if (found === commentEndPattern.length - 1) {
56
- if (i > commentEndPattern.length - 1) {
57
- input.acceptToken(commentToken, 1 - commentEndPattern.length);
58
- break;
59
- }
60
- else {
61
- console.warn('Reached end of comment but there is still content left');
62
- }
63
- break;
64
- }
65
- found++;
66
- input.advance();
67
- }
68
- }
69
- const shortCommentContent = new lr.ExternalTokenizer((input) => {
70
- return matchForComment(shortCommentEnd, shortCommentContent$1, input);
71
- });
72
- const longCommentContent = new lr.ExternalTokenizer((input) => {
73
- return matchForComment(longCommentEnd, longCommentContent$1, input);
74
- });
75
- const htmlCommentContent = new lr.ExternalTokenizer((input) => {
76
- return matchForComment(htmlCommentEnd, htmlCommentContent$1, input);
77
- });
78
- const templateTagContent = new lr.ExternalTokenizer((input) => {
79
- return matchForComment(closingTemplateTag, templateTagContent$1, input);
80
- });
81
- // TODO: string handler does not handle interpolation
82
- function createStringHandler(input) {
83
- let inString = false;
84
- let inStringType = null;
85
- let inStringIgnoreNext = false;
86
- return () => {
87
- if (inString) {
88
- if (inStringIgnoreNext) {
89
- inStringIgnoreNext = false;
90
- return true;
91
- }
92
- if (input.next === backslash) {
93
- inStringIgnoreNext = true;
94
- return true;
95
- }
96
- if (inStringType === 'double' && input.next === quoteDouble) {
97
- inString = false;
98
- inStringType = null;
99
- return true;
100
- }
101
- if (inStringType === 'single' && input.next === quoteSingle) {
102
- inString = false;
103
- inStringType = null;
104
- return true;
105
- }
106
- if (inStringType === 'template' && input.next === tick) {
107
- inString = false;
108
- inStringType = null;
109
- return true;
110
- }
111
- return true;
112
- }
113
- if (input.next === quoteDouble) {
114
- inString = true;
115
- inStringType = 'double';
116
- return true;
117
- }
118
- if (input.next === quoteSingle) {
119
- inString = true;
120
- inStringType = 'single';
121
- return true;
122
- }
123
- if (input.next === tick) {
124
- inString = true;
125
- inStringType = 'template';
126
- return true;
127
- }
128
- return false;
129
- };
130
- }
131
- function createCommentHandler(input) {
132
- let inLineComment = false;
133
- let inBlockComment = false;
134
- return () => {
135
- if (inLineComment) {
136
- if (input.next === newline) {
137
- inLineComment = false;
138
- return true;
139
- }
140
- return true;
141
- }
142
- if (inBlockComment) {
143
- if (input.next === asterisk && input.peek(1) === slash) {
144
- inBlockComment = false;
145
- return true;
146
- }
147
- return true;
148
- }
149
- if (input.next === slash && input.peek(1) === slash) {
150
- inLineComment = true;
151
- return true;
152
- }
153
- if (input.next === slash && input.peek(1) === asterisk) {
154
- inBlockComment = true;
13
+ const defaultNesting = [
14
+ {
15
+ tag: 'script',
16
+ attrs: (attrs) => attrs['type'] === 'text/typescript' || attrs['lang'] === 'ts',
17
+ parser: langJavascript.typescriptLanguage.parser,
18
+ },
19
+ {
20
+ tag: 'script',
21
+ attrs(attrs) {
22
+ return (!attrs['type'] ||
23
+ /^(?:text|application)\/(?:x-)?(?:java|ecma)script$|^module$|^$/i.test(attrs['type']));
24
+ },
25
+ parser: langJavascript.javascriptLanguage.parser,
26
+ },
27
+ {
28
+ tag: 'style',
29
+ attrs( /* attrs */) {
155
30
  return true;
156
- }
157
- return false;
158
- };
159
- }
160
- // closes on a delimiter that probably isn't in the expression
161
- new lr.ExternalTokenizer((input) => {
162
- if (prefixes.includes(input.next)) {
163
- return;
164
- }
165
- const commentHandler = createCommentHandler(input);
166
- const stringHandler = createStringHandler(input);
167
- let stack = [];
168
- const popIfMatch = (match) => {
169
- const idx = stack.lastIndexOf(match);
170
- if (idx !== -1) {
171
- while (stack.length > idx) {
172
- stack.pop();
173
- }
174
- }
175
- };
176
- for (let pos = 0;; pos++) {
177
- // end of input
178
- if (input.next < 0) {
179
- if (pos > 0)
180
- input.acceptToken(MoustacheExpression);
181
- break;
182
- }
183
- if (commentHandler() || stringHandler()) {
184
- input.advance();
185
- continue;
186
- }
187
- if (stack.length === 0 &&
188
- (input.next === curlyClose || input.next === parenClose || input.next === squareClose)) {
189
- input.acceptToken(MoustacheExpression);
190
- break;
191
- }
192
- switch (input.next) {
193
- case parenOpen:
194
- stack.push('(');
195
- break;
196
- case parenClose:
197
- popIfMatch('(');
198
- break;
199
- case squareOpen:
200
- stack.push('[');
201
- break;
202
- case squareClose:
203
- popIfMatch('[');
204
- break;
205
- case curlyOpen:
206
- stack.push('{');
207
- break;
208
- case curlyClose:
209
- popIfMatch('{');
210
- break;
211
- }
212
- input.advance();
213
- }
214
- });
215
-
216
- const glimmerHighlighting = highlight.styleTags({
217
- 'Text RawText': highlight.tags.content,
218
- 'StartTag StartCloseTag SelfClosingEndTag EndTag': highlight.tags.angleBracket,
219
- TagName: highlight.tags.tagName,
220
- 'MismatchedCloseTag/TagName': [highlight.tags.tagName, highlight.tags.invalid],
221
- AttributeName: highlight.tags.attributeName,
222
- // Glimmer
223
- TemplateTag: highlight.tags.definition(highlight.tags.annotation),
224
- '{{ }}': highlight.tags.bracket,
225
- '( )': highlight.tags.paren,
226
- Function: highlight.tags.function(highlight.tags.name),
227
- Splattributes: highlight.tags.derefOperator,
228
- Comment: highlight.tags.blockComment,
229
- ShortComment: highlight.tags.blockComment,
230
- LongComment: highlight.tags.blockComment,
231
- HtmlComment: highlight.tags.blockComment,
232
- ArgName: highlight.tags.attributeName,
233
- Argument: highlight.tags.propertyName,
234
- NamedBlock: highlight.tags.tagName,
235
- Is: highlight.tags.definitionOperator,
236
- Pipe: highlight.tags.definitionOperator,
237
- as: highlight.tags.definitionOperator,
238
- let: highlight.tags.function(highlight.tags.definitionOperator),
239
- this: highlight.tags.self,
240
- yield: highlight.tags.operatorKeyword,
241
- outlet: highlight.tags.operatorKeyword,
242
- component: highlight.tags.function(highlight.tags.definitionKeyword),
243
- modifier: highlight.tags.function(highlight.tags.definitionKeyword),
244
- helper: highlight.tags.function(highlight.tags.definitionKeyword),
245
- hash: highlight.tags.function(highlight.tags.definitionKeyword),
246
- array: highlight.tags.function(highlight.tags.definitionKeyword),
247
- on: highlight.tags.function(highlight.tags.definitionKeyword),
248
- concat: highlight.tags.function(highlight.tags.operatorKeyword),
249
- 'if then catch unless else each each-in': highlight.tags.controlKeyword,
250
- // TODO:
251
- UnquotedAttributeValue: highlight.tags.attributeValue,
252
- 'DoubleQuote SingleQuote AttributeValueContent': highlight.tags.attributeValue,
253
- 'EntityReference CharacterReference': highlight.tags.character,
254
- '[ ]': highlight.tags.squareBracket,
255
- ComponentName: highlight.tags.className,
256
- StyleAttributeName: highlight.tags.propertyName,
257
- BlockType: highlight.tags.controlKeyword,
258
- BlockPrefix: highlight.tags.typeOperator,
259
- 'UnknownBlock/BlockType': highlight.tags.invalid,
260
- UnknownBlockContent: highlight.tags.invalid,
261
- Variable: highlight.tags.variableName,
262
- Modifier: highlight.tags.modifier,
263
- ModifierValue: highlight.tags.function(highlight.tags.modifier),
264
- });
265
-
266
- // This file was generated by lezer-generator. You probably shouldn't edit it.
267
- const spec_identifier = {__proto__:null,this:36, as:38, if:40, unless:42, else:44, let:46, and:48, or:50, not:52, eq:54, neq:56, "not-eq":58, gt:60, gte:62, lt:64, lte:66, array:68, concat:70, hash:72, each:74, "each-in":76, on:78, modifier:80, component:82, helper:84, "in-element":86, yield:88, outlet:90};
268
- const parser = lr.LRParser.deserialize({
269
- version: 14,
270
- states: "(dQVQ`OOOwQhO'#C^O!PQaO'#CbO!XQbO'#CcO!aQ`O'#CmO$oOpO'#CeO$vO`O'#CeO${QdO'#CdOOQO'#Ca'#CaOOQO'#D]'#D]O%^Q`O'#D^OOQO'#Dl'#DlOOQO'#D_'#D_QVQ`OOOOQW'#D`'#D`O%cQhO,58xOOQO,58x,58xOOQP'#Da'#DaO%kQaO,58|OOQO,58|,58|OOQQ'#Db'#DbO%sQbO,58}OOQO,58},58}OOQO,59X,59XO(RQ`O'#ChOOOO'#Cg'#CgOOOO'#Dd'#DdO(]OpO,59POOQS,59P,59POOOO'#Dt'#DtO(dOpO,59POOQS'#Dc'#DcO(iQdO,59OOOQO,59O,59OOOQO,59x,59xOOQO-E7]-E7]OOQW-E7^-E7^OOQO1G.d1G.dOOQP-E7_-E7_OOQO1G.h1G.hOOQQ-E7`-E7`OOQO1G.i1G.iOOOO,59S,59SO(zQ`O,59SO)VQ`O,59SOOOO-E7b-E7bOOQS1G.k1G.kOOQS-E7a-E7aOOQO1G.j1G.jO!fQ`O1G.nOOOO1G.n1G.nO)_Q`O1G.nO)dQ`O7+$YO!fQ`O7+$YOOOO<<Gt<<GtO)iQ`O<<GtOOOOAN=`AN=`",
271
- stateData: ")p~O!_OS~ORPOYTO!aQO!cRO!eVO!gSO!iTO!jUO!lXO!mYO~OS`O!]^O~O!YaO!bcO~O!ZdO!dfO~O!fgO~O]hO^iO`iObmOcmOdmOemOfmOgmOhmOimOjmOkmOlmOmmOnmOomOpmOqmOrmOsmOtmOumOvmOwmOxmOymOzmO{mO|mO}mO!fiO!gSO~O!OlO~P!fO!fnO~OYTO![oO!iTO!jUO!kqO~O!frO~OSuO!]^O~O!YaO!bwO~O!ZdO!dyO~O]hO^iO`iObmOcmOdmOemOfmOgmOhmOimOjmOkmOlmOmmOnmOomOpmOqmOrmOsmOtmOumOvmOwmOxmOymOzmO{mO|mO}mO!gSO~O_zO!f{O~P%{O!O!OO~P!fO!O!OO~OYTO![oO!iTO!jUO!k!QO~O^!RO_ZX!fZX~O_!SO!f!TO~O^!VO~O_!WO~O_!YO~O!_~",
272
- goto: "$e!iPP!jPP!j!n!n!n!rP!z#XPPPP#`PPPPPPPPPPPPPPPPPPPPPPPPPPPPP!j!j#k#q#w#}$T$ZPPPPPPP$aPPPPPPP#XTZO]TWO]SZO]ToVpSjTkQ|hQ!U!RR!X!VZiThk!R!VSZO]ZiThk!R!VQ]ORs]Q_PRt_QbQRvbQeRRxeQpVR!PpQkTR}kT[O]",
273
- nodeNames: "⚠ Template GlimmerTemplateTag TemplateTag TemplateTag Comment ShortComment LongComment HtmlComment MoustacheExpression {{ SExpression CallExpression ( Is ) Pipe Argument this as if unless else let and or not eq neq not-eq gt gte lt lte array concat hash each each-in on modifier component helper in-element yield outlet }} Splattributes NamedBlock",
274
- maxTerm: 75,
275
- nodeProps: [
276
- ["closedBy", 3,"templateTagEnd",10,"}}",13,"("],
277
- ["openedBy", 4,"templateTagStart",15,")",46,"{{"]
278
- ],
279
- propSources: [glimmerHighlighting],
280
- skippedNodes: [0],
281
- repeatNodeCount: 6,
282
- tokenData: "+W~RhX^!mpq!mxy#eyz#j|}!m}!O#o!O!P$`![!]&P!^!_&U!_!`)X!b!c)^!c!})c#T#o)c#o#p)q#p#q*t#q#r*y#y#z!m$f$g!m#BY#BZ!m$IS$I_!m$I|$JO!m$JT$JU!m$KV$KW!m&FU&FV!m~!rZ!_~X^!mpq!m|}!m#y#z!m$f$g!m#BY#BZ!m$IS$I_!m$I|$JO!m$JT$JU!m$KV$KW!m&FU&FV!m~#jO]~~#oO_~~#rP}!O#u~#xQ!`!a$O#q#r$T~$TO!k~~$WP#q#r$Z~$`O!d~~$cP!O!P$f~$iP!O!P$l~$oP#T#U$r~$uP#h#i$x~${P#h#i%O~%RP#f#g%U~%XP#]#^%[~%_P#U#V%b~%eP#i#j%h~%kP#h#i%n~%qP#X#Y%t~%wP#g#h%z~&PO!l~~&UO!m~~&XRqr&b!P!Q&s#h#i(Q~&eP}!O&h~&kP}!O&n~&sO!e~~&vP#h#i&y~&|P#X#Y'P~'SP#a#b'V~'YP#d#e']~'`P#`#a'c~'fP#T#U'i~'lP#h#i'o~'rP#X#Y'u~'xP!`!a'{~(QOS~~(TP#X#Y(W~(ZP#a#b(^~(aP#d#e(d~(gP#`#a(j~(mP#T#U(p~(sP#h#i(v~(yP#X#Y(|~)PP!`!a)S~)XOR~~)^O^~~)cO!g~~)hR!f~!Q![)c!c!})c#T#o)c~)tP#o#p)w~)|RY~qr*Vst*j!P!Q*o~*[P!a~}!O*_~*bP}!O*e~*jO!c~~*oO!i~~*tO!j~~*yO`~R*|P#q#r+PR+WO!OQ!bP",
283
- tokenizers: [shortCommentContent, longCommentContent, htmlCommentContent, templateTagContent, 0, 1],
284
- topRules: {"Template":[0,1]},
285
- specialized: [{term: 68, get: value => spec_identifier[value] || -1}],
286
- tokenPrec: 398
287
- });
288
-
289
- const glimmerParser = parser;
290
- const glimmerLanguage = language.LRLanguage.define({
291
- parser: parser.configure({
292
- wrap: common.parseMixed((node) => {
293
- let { name } = node.type;
294
- switch (name) {
295
- case 'Template':
296
- return null;
297
- case 'Comment':
298
- case 'MoustacheExpression':
299
- case 'NamedBlock':
300
- case 'Splattributes':
301
- case 'Argument':
302
- return { parser };
303
- }
304
- return { parser: html.parser };
305
- }),
31
+ // Always use CSS. We can add varying support later
32
+ // return (
33
+ // (!attrs['lang'] || attrs['lang'] === 'css' || attrs['lang'] === 'scss') &&
34
+ // (!attrs['type'] || /^(text\/)?(x-)?(stylesheet|css|scss)$/i.test(attrs['type']))
35
+ // );
36
+ },
37
+ parser: langCss.cssLanguage.parser,
38
+ },
39
+ ];
40
+ const glimmerPlain = language.LRLanguage.define({
41
+ parser: lezerGlimmer.glimmerParser.configure({
306
42
  props: [
307
43
  language.indentNodeProp.add({
308
44
  Element: (context) => {
309
45
  let after = /^(\s*)(<\/)?/.exec(context.textAfter);
310
- if (context.node.to <= context.pos + (after?.[0].length || 0))
46
+ if (!after)
47
+ return null;
48
+ if (context.node.to <= context.pos + after[0].length)
311
49
  return context.continue();
312
- return context.lineIndent(context.node.from) + (after?.[2] ? 0 : context.unit);
50
+ return context.lineIndent(context.node.from) + (after[2] ? 0 : context.unit);
313
51
  },
314
52
  Block: (context) => {
315
53
  const node = context.node;
@@ -317,13 +55,19 @@ const glimmerLanguage = language.LRLanguage.define({
317
55
  if (text.startsWith('{/')) {
318
56
  const name = node.name;
319
57
  if ((name === 'IfBlock' && text.startsWith('{/if')) ||
58
+ (name === 'UnlessBlock' && text.startsWith('{/unless')) ||
59
+ (name === 'InElementBlock' && text.startsWith('{/in-element')) ||
320
60
  (name === 'EachBlock' && text.startsWith('{/each')) ||
321
- (name === 'KeyBlock' && text.startsWith('{/key'))) {
61
+ (name === 'EachInBlock' && text.startsWith('{/each-in')) ||
62
+ (name === 'LetBlock' && text.startsWith('{/let'))) {
322
63
  return context.lineIndent(context.node.from);
323
64
  }
324
65
  return null;
325
66
  }
326
- if (node.name === 'IfBlock' || node.name === 'EachBlock') {
67
+ if (node.name === 'IfBlock' ||
68
+ node.name === 'EachBlock' ||
69
+ node.name === 'EachInBlock' ||
70
+ node.name === 'UnlessBlock') {
327
71
  if (text.startsWith('{{:else'))
328
72
  return context.lineIndent(node.from);
329
73
  if (text.startsWith('{{else'))
@@ -331,9 +75,11 @@ const glimmerLanguage = language.LRLanguage.define({
331
75
  }
332
76
  // not sure if this needed to be duplicated
333
77
  let after = /^(\s*)(<\/)?/.exec(context.textAfter);
334
- if (context.node.to <= context.pos + (after?.[0].length || 0))
78
+ if (!after)
79
+ return null;
80
+ if (context.node.to <= context.pos + after[0].length)
335
81
  return context.continue();
336
- return context.lineIndent(context.node.from) + (after?.[2] ? 0 : context.unit);
82
+ return context.lineIndent(context.node.from) + (after[2] ? 0 : context.unit);
337
83
  },
338
84
  'BlockOpen BlockClose BlockInline': (context) => {
339
85
  return context.column(context.node.from) + context.unit;
@@ -342,7 +88,8 @@ const glimmerLanguage = language.LRLanguage.define({
342
88
  return context.column(context.node.from) + context.unit;
343
89
  },
344
90
  Document: (context) => {
345
- if (context.pos + (/\s*/.exec(context.textAfter)?.[0].length || 0) < context.node.to) {
91
+ var _a, _b;
92
+ if (context.pos + (((_b = (_a = /\s*/.exec(context.textAfter)) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.length) || 0) < context.node.to) {
346
93
  return context.continue();
347
94
  }
348
95
  let endElt = null;
@@ -353,7 +100,7 @@ const glimmerLanguage = language.LRLanguage.define({
353
100
  break;
354
101
  endElt = cur = last;
355
102
  }
356
- if (endElt?.lastChild &&
103
+ if (endElt &&
357
104
  !((close = endElt.lastChild) &&
358
105
  (close.name === 'CloseTag' || close.name === 'SelfClosingTag'))) {
359
106
  return context.lineIndent(endElt.from) + context.unit;
@@ -369,20 +116,16 @@ const glimmerLanguage = language.LRLanguage.define({
369
116
  const last = node.lastChild;
370
117
  if (!first || first.name !== open)
371
118
  return null;
372
- return {
373
- from: first.to,
374
- to: last?.name === close ? last.from : node.to,
375
- };
119
+ return { from: first.to, to: (last === null || last === void 0 ? void 0 : last.name) === close ? last.from : node.to };
376
120
  },
377
121
  Element: (node) => {
378
122
  let first = node.firstChild;
379
123
  let last = node.lastChild;
124
+ if (!last)
125
+ return null;
380
126
  if (!first || first.name != 'OpenTag')
381
127
  return null;
382
- return {
383
- from: first.to,
384
- to: last?.name === 'CloseTag' ? last.from : node.to,
385
- };
128
+ return { from: first.to, to: last.name === 'CloseTag' ? last.from : node.to };
386
129
  },
387
130
  }),
388
131
  ],
@@ -390,18 +133,176 @@ const glimmerLanguage = language.LRLanguage.define({
390
133
  languageData: {
391
134
  commentTokens: {
392
135
  block: { open: '<!--', close: '-->' },
393
- devBlock: { open: '{{!--', close: '--}}' },
394
- devBlockShort: { open: '{{!', close: '}}' },
136
+ moustacheLong: { open: '{{!--', close: '--}}' },
395
137
  },
396
- indentOnInput: /^\s*((<\/\w+\W)|(\{:(else|then|catch))|(\{\/(if|unless|each|await|key)))$/,
138
+ indentOnInput: /^\s*((<\/\w+\W)|(\{\{:?(else|then|catch))|(\{\{\/(if|each|each-in|in-element|unless|let)))$/,
397
139
  wordChars: '-._',
398
- autocomplete: langHtml.htmlCompletionSource,
399
140
  },
400
141
  });
142
+ const glimmerLanguage = glimmerPlain.configure({
143
+ wrap: lezerGlimmer.configureNesting(defaultNesting),
144
+ });
145
+
146
+ // unfortunately the HTML language explicitly checks for the language type,
147
+ // so we have to duplicate the entire autoCloseTags extension
148
+ function elementName(doc, tree, max = doc.length) {
149
+ if (!tree)
150
+ return '';
151
+ let tag = tree.firstChild;
152
+ let name = tag &&
153
+ (tag.getChild('TagName') || tag.getChild('ComponentName') || tag.getChild('SvelteElementName'));
154
+ return name ? doc.sliceString(name.from, Math.min(name.to, max)) : '';
155
+ }
156
+ const autoCloseTags = view.EditorView.inputHandler.of((view, from, to, text) => {
157
+ if (view.composing ||
158
+ view.state.readOnly ||
159
+ from != to ||
160
+ (text != '>' && text != '/') ||
161
+ !glimmerLanguage.isActiveAt(view.state, from, -1))
162
+ return false;
163
+ let { state: state$1 } = view;
164
+ const noChanges = { range: undefined, changes: undefined, effects: undefined };
165
+ let changes = state$1.changeByRange((range) => {
166
+ var _a, _b, _c;
167
+ let { head } = range;
168
+ let around = language.syntaxTree(state$1).resolveInner(head, -1);
169
+ let name;
170
+ if (around.name === 'TagName' ||
171
+ around.name === 'ComponentName' ||
172
+ around.name === 'StartTag') {
173
+ if (!around.parent)
174
+ return Object.assign(Object.assign({}, noChanges), { range });
175
+ around = around.parent;
176
+ }
177
+ if (text === '>' && around.name === 'OpenTag') {
178
+ if (((_b = (_a = around.parent) === null || _a === void 0 ? void 0 : _a.lastChild) === null || _b === void 0 ? void 0 : _b.name) != 'CloseTag' &&
179
+ (name = elementName(state$1.doc, around.parent, head))) {
180
+ let hasRightBracket = view.state.doc.sliceString(head, head + 1) === '>';
181
+ let insert = `${hasRightBracket ? '' : '>'}</${name}>`;
182
+ return {
183
+ range: state.EditorSelection.cursor(head + 1),
184
+ changes: { from: head + (hasRightBracket ? 1 : 0), insert },
185
+ };
186
+ }
187
+ }
188
+ else if (text === '/' && around.name === 'OpenTag') {
189
+ let empty = around.parent, base = empty === null || empty === void 0 ? void 0 : empty.parent;
190
+ if (!empty)
191
+ return Object.assign(Object.assign({}, noChanges), { range });
192
+ if (!base)
193
+ return Object.assign(Object.assign({}, noChanges), { range });
194
+ if (empty.from == head - 1 &&
195
+ ((_c = base.lastChild) === null || _c === void 0 ? void 0 : _c.name) != 'CloseTag' &&
196
+ (name = elementName(state$1.doc, base, head))) {
197
+ let hasRightBracket = view.state.doc.sliceString(head, head + 1) === '>';
198
+ let insert = `/${name}${hasRightBracket ? '' : '>'}`;
199
+ let pos = head + insert.length + (hasRightBracket ? 1 : 0);
200
+ return { range: state.EditorSelection.cursor(pos), changes: { from: head, insert } };
201
+ }
202
+ }
203
+ return { range };
204
+ });
205
+ if (changes.changes.empty)
206
+ return false;
207
+ view.dispatch(changes, { userEvent: 'input.type', scrollIntoView: true });
208
+ return true;
209
+ });
210
+
211
+ /**
212
+ A collection of JavaScript-related
213
+ [snippets](https://codemirror.net/6/docs/ref/#autocomplete.snippet).
214
+ */
215
+ const snippets = [
216
+ autocomplete.snippetCompletion('#each ${list} as |${item}|}}\n\t${}\n{{/each', {
217
+ label: '#each',
218
+ detail: 'loop',
219
+ type: 'keyword',
220
+ }),
221
+ autocomplete.snippetCompletion('#each-in ${object} as |${key} ${value}|}}\n\t${}\n{{/each-in', {
222
+ label: '#each-in',
223
+ detail: 'loop',
224
+ type: 'keyword',
225
+ }),
226
+ autocomplete.snippetCompletion('#let ${subExpression} as |${result}|}}\n\t${}\n{{/let', {
227
+ label: '#let',
228
+ detail: 'block',
229
+ type: 'keyword',
230
+ }),
231
+ autocomplete.snippetCompletion('#if ${condition}}}\n\t${}\n{{/if', {
232
+ label: '#if',
233
+ detail: 'block',
234
+ type: 'keyword',
235
+ }),
236
+ autocomplete.snippetCompletion('#in-element ${element}}}\n\t${}\n{{/in-element', {
237
+ label: '#in-element',
238
+ detail: 'block',
239
+ type: 'keyword',
240
+ }),
241
+ autocomplete.snippetCompletion('#unless ${condition}}}\n\t${}\n{{/unless', {
242
+ label: '#unless',
243
+ detail: 'block',
244
+ type: 'keyword',
245
+ }),
246
+ autocomplete.snippetCompletion('#if ${condition}}}\n\t${}\n{{else}}\n\t${}\n{{/if', {
247
+ label: '#if',
248
+ detail: '/ else block',
249
+ type: 'keyword',
250
+ }),
251
+ autocomplete.snippetCompletion('#unless ${condition}}}\n\t${}\n{{else}}\n\t${}\n{{/unless', {
252
+ label: '#unless',
253
+ detail: '/ else block',
254
+ type: 'keyword',
255
+ }),
256
+ ];
257
+
401
258
  function glimmer() {
402
- return new language.LanguageSupport(glimmerLanguage, [langHtml.html().support]);
259
+ return new language.LanguageSupport(glimmerLanguage, [
260
+ langJavascript.javascript().support,
261
+ langCss.css().support,
262
+ new language.LanguageSupport(language.LRLanguage.define({
263
+ name: 'glimmer-expression',
264
+ parser: lezerGlimmerExpression.parser.configure({}),
265
+ }), []),
266
+ glimmerLanguage.data.of({ autocomplete: snippets }),
267
+ // We may want to swap this with Glimmer-specific tag completion
268
+ glimmerLanguage.data.of({ autocomplete: htmlTagCompletion }),
269
+ autoCloseTags,
270
+ ]);
271
+ }
272
+ function htmlTagCompletion(context) {
273
+ let { state, pos } = context, m = /<[:\-.\w\u00b7-\uffff]*$/.exec(state.sliceDoc(pos - 25, pos));
274
+ if (!m)
275
+ return null;
276
+ let tree = language.syntaxTree(state).resolveInner(pos, -1);
277
+ while (tree && !tree.type.isTop) {
278
+ if (tree.name == 'CodeBlock' ||
279
+ tree.name == 'FencedCode' ||
280
+ tree.name == 'ProcessingInstructionBlock' ||
281
+ tree.name == 'CommentBlock' ||
282
+ tree.name == 'Link' ||
283
+ tree.name == 'Image') {
284
+ return null;
285
+ }
286
+ tree = tree.parent;
287
+ }
288
+ return {
289
+ from: pos - m[0].length,
290
+ to: pos,
291
+ options: htmlTagCompletions(),
292
+ validFor: /^<[:\-.\w\u00b7-\uffff]*$/,
293
+ };
294
+ }
295
+ let _tagCompletions = null;
296
+ const htmlNoMatch = langHtml.html({ matchClosingTags: false });
297
+ function htmlTagCompletions() {
298
+ if (_tagCompletions)
299
+ return _tagCompletions;
300
+ let result = langHtml.htmlCompletionSource(new autocomplete.CompletionContext(state.EditorState.create({ extensions: htmlNoMatch }), 0, true));
301
+ return (_tagCompletions = result ? result.options : []);
403
302
  }
404
303
 
304
+ exports.defaultNesting = defaultNesting;
405
305
  exports.glimmer = glimmer;
406
306
  exports.glimmerLanguage = glimmerLanguage;
407
- exports.glimmerParser = glimmerParser;
307
+ exports.glimmerPlain = glimmerPlain;
308
+ exports.snippets = snippets;
package/dist/index.d.cts CHANGED
@@ -1,6 +1,24 @@
1
1
  import { LanguageSupport, LRLanguage } from '@codemirror/language';
2
- declare const glimmerParser: import("@lezer/lr").LRParser;
3
- declare const glimmerLanguage: LRLanguage;
2
+ import { Parser } from '@lezer/common';
3
+ import { Completion } from '@codemirror/autocomplete';
4
+
4
5
  declare function glimmer(): LanguageSupport;
5
- export { glimmerParser, glimmerLanguage, glimmer };
6
- //# sourceMappingURL=index.d.cts.map
6
+
7
+ type NestedLang = {
8
+ tag: 'script' | 'style' | 'textarea';
9
+ attrs?: (attrs: {
10
+ [attr: string]: string;
11
+ }) => boolean;
12
+ parser: Parser;
13
+ };
14
+ declare const defaultNesting: NestedLang[];
15
+ declare const glimmerPlain: LRLanguage;
16
+ declare const glimmerLanguage: LRLanguage;
17
+
18
+ /**
19
+ A collection of JavaScript-related
20
+ [snippets](https://codemirror.net/6/docs/ref/#autocomplete.snippet).
21
+ */
22
+ declare const snippets: readonly Completion[];
23
+
24
+ export { defaultNesting, glimmer, glimmerLanguage, glimmerPlain, snippets };
package/dist/index.d.ts CHANGED
@@ -1,6 +1,24 @@
1
1
  import { LanguageSupport, LRLanguage } from '@codemirror/language';
2
- declare const glimmerParser: import("@lezer/lr").LRParser;
3
- declare const glimmerLanguage: LRLanguage;
2
+ import { Parser } from '@lezer/common';
3
+ import { Completion } from '@codemirror/autocomplete';
4
+
4
5
  declare function glimmer(): LanguageSupport;
5
- export { glimmerParser, glimmerLanguage, glimmer };
6
- //# sourceMappingURL=index.d.ts.map
6
+
7
+ type NestedLang = {
8
+ tag: 'script' | 'style' | 'textarea';
9
+ attrs?: (attrs: {
10
+ [attr: string]: string;
11
+ }) => boolean;
12
+ parser: Parser;
13
+ };
14
+ declare const defaultNesting: NestedLang[];
15
+ declare const glimmerPlain: LRLanguage;
16
+ declare const glimmerLanguage: LRLanguage;
17
+
18
+ /**
19
+ A collection of JavaScript-related
20
+ [snippets](https://codemirror.net/6/docs/ref/#autocomplete.snippet).
21
+ */
22
+ declare const snippets: readonly Completion[];
23
+
24
+ export { defaultNesting, glimmer, glimmerLanguage, glimmerPlain, snippets };