@markuplint/astro-parser 3.12.0 → 4.0.0-alpha.10

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.
@@ -1,456 +0,0 @@
1
- const { astroParse } = require('../lib/astro-parser');
2
-
3
- it('Basic', () => {
4
- const ast = astroParse(`---
5
- const name = "World";
6
- ---
7
- <!-- Comment -->
8
- <style>
9
- div {
10
- color: red;
11
- }
12
- </style>
13
- <div data-attr="v">Hello {name}!</div>
14
- `);
15
- expect(ast).toStrictEqual(
16
- expect.objectContaining({
17
- children: [
18
- {
19
- position: {
20
- end: {
21
- column: 4,
22
- line: 3,
23
- offset: 29,
24
- },
25
- start: {
26
- column: 1,
27
- line: 1,
28
- offset: 0,
29
- },
30
- },
31
- type: 'frontmatter',
32
- value: '\nconst name = "World";\n',
33
- },
34
- {
35
- position: {
36
- end: {
37
- column: 17,
38
- line: 4,
39
- offset: 46,
40
- },
41
- start: {
42
- column: 5,
43
- line: 4,
44
- offset: 30,
45
- },
46
- },
47
- type: 'comment',
48
- value: ' Comment ',
49
- },
50
- {
51
- attributes: [],
52
- children: [
53
- {
54
- position: {
55
- end: {
56
- column: 1,
57
- line: 9,
58
- offset: 79,
59
- },
60
- start: {
61
- column: 8,
62
- line: 5,
63
- offset: 54,
64
- },
65
- },
66
- type: 'text',
67
- value: '\ndiv {\n color: red;\n}\n',
68
- },
69
- ],
70
- name: 'style',
71
- position: {
72
- end: {
73
- column: 9,
74
- line: 9,
75
- offset: 87,
76
- },
77
- start: {
78
- column: 1,
79
- line: 5,
80
- offset: 47,
81
- },
82
- },
83
- type: 'element',
84
- },
85
- {
86
- position: {
87
- end: {
88
- column: 1,
89
- line: 10,
90
- offset: 88,
91
- },
92
- start: {
93
- column: 9,
94
- line: 9,
95
- offset: 87,
96
- },
97
- },
98
- type: 'text',
99
- value: '\n',
100
- },
101
- {
102
- attributes: [
103
- {
104
- kind: 'quoted',
105
- name: 'data-attr',
106
- position: {
107
- start: {
108
- column: 6,
109
- line: 10,
110
- offset: 93,
111
- },
112
- },
113
- raw: '"v"',
114
- type: 'attribute',
115
- value: 'v',
116
- },
117
- ],
118
- children: [
119
- {
120
- position: {
121
- end: {
122
- column: 26,
123
- line: 10,
124
- offset: 113,
125
- },
126
- start: {
127
- column: 20,
128
- line: 10,
129
- offset: 107,
130
- },
131
- },
132
- type: 'text',
133
- value: 'Hello ',
134
- },
135
- {
136
- children: [
137
- {
138
- position: {
139
- end: {
140
- column: 31,
141
- line: 10,
142
- offset: 118,
143
- },
144
- start: {
145
- column: 27,
146
- line: 10,
147
- offset: 114,
148
- },
149
- },
150
- type: 'text',
151
- value: 'name',
152
- },
153
- ],
154
- position: {
155
- end: {
156
- column: 9,
157
- line: 11,
158
- offset: 119,
159
- },
160
- start: {
161
- column: 25,
162
- line: 10,
163
- offset: 113,
164
- },
165
- },
166
- type: 'expression',
167
- },
168
- {
169
- position: {
170
- end: {
171
- column: 33,
172
- line: 10,
173
- offset: 120,
174
- },
175
- start: {
176
- column: 32,
177
- line: 10,
178
- offset: 119,
179
- },
180
- },
181
- type: 'text',
182
- value: '!',
183
- },
184
- ],
185
- name: 'div',
186
- position: {
187
- end: {
188
- column: 39,
189
- line: 10,
190
- offset: 126,
191
- },
192
- start: {
193
- column: 1,
194
- line: 10,
195
- offset: 88,
196
- },
197
- },
198
- type: 'element',
199
- },
200
- {
201
- position: {
202
- end: {
203
- column: 1,
204
- line: 11,
205
- offset: 127,
206
- },
207
- start: {
208
- column: 39,
209
- line: 10,
210
- offset: 126,
211
- },
212
- },
213
- type: 'text',
214
- value: '\n',
215
- },
216
- ],
217
- type: 'root',
218
- }),
219
- );
220
- });
221
-
222
- it('Attr and Template Directive', () => {
223
- const ast = astroParse('<div a b=c d="e" f=`g` x:y prop={ prop }></div>');
224
- expect(ast.children?.[0].attributes).toStrictEqual(
225
- expect.objectContaining([
226
- {
227
- type: 'attribute',
228
- kind: 'empty',
229
- name: 'a',
230
- value: '',
231
- raw: '',
232
- position: { start: { column: 6, line: 1, offset: 5 } },
233
- },
234
- {
235
- type: 'attribute',
236
- kind: 'quoted',
237
- name: 'b',
238
- value: 'c',
239
- raw: 'c',
240
- position: { start: { column: 8, line: 1, offset: 7 } },
241
- },
242
- {
243
- type: 'attribute',
244
- kind: 'quoted',
245
- name: 'd',
246
- value: 'e',
247
- raw: '"e"',
248
- position: { start: { column: 12, line: 1, offset: 11 } },
249
- },
250
- {
251
- type: 'attribute',
252
- kind: 'template-literal',
253
- name: 'f',
254
- value: 'g',
255
- raw: '',
256
- position: { start: { column: 18, line: 1, offset: 17 } },
257
- },
258
- {
259
- type: 'attribute',
260
- kind: 'empty',
261
- name: 'x:y',
262
- value: '',
263
- raw: '',
264
- position: { start: { column: 24, line: 1, offset: 23 } },
265
- },
266
- {
267
- type: 'attribute',
268
- kind: 'expression',
269
- name: 'prop',
270
- value: ' prop ',
271
- raw: '',
272
- position: { start: { column: 28, line: 1, offset: 27 } },
273
- },
274
- ]),
275
- );
276
- });
277
-
278
- test('Greater-than sign in attribute value', () => {
279
- const ast = astroParse('<div attr="a>b"></div>');
280
- expect(ast.children?.[0].attributes).toStrictEqual(
281
- expect.objectContaining([
282
- {
283
- kind: 'quoted',
284
- name: 'attr',
285
- position: { start: { column: 6, line: 1, offset: 5 } },
286
- type: 'attribute',
287
- value: 'a>b',
288
- raw: '"a>b"',
289
- },
290
- ]),
291
- );
292
- });
293
-
294
- describe('Issues', () => {
295
- test('#803', () => {
296
- const code = `<html lang="en">
297
- <head>
298
- <meta charset="utf-8" />
299
- <title>Title</title>
300
- <meta name="viewport" content="width=device-width" />
301
- </head>
302
- </html>
303
- `;
304
- const ast = astroParse(code);
305
- expect(ast).toStrictEqual(
306
- expect.objectContaining({
307
- type: 'root',
308
- children: [
309
- {
310
- type: 'element',
311
- name: 'html',
312
- position: { start: { line: 1, column: 2, offset: 0 } },
313
- attributes: [
314
- {
315
- type: 'attribute',
316
- kind: 'quoted',
317
- name: 'lang',
318
- value: 'en',
319
- raw: '"en"',
320
- position: { start: { line: 1, column: 7, offset: 6 } },
321
- },
322
- ],
323
- children: [
324
- {
325
- type: 'text',
326
- value: '\n\t',
327
- position: {
328
- start: { line: 1, column: 17, offset: 16 },
329
- end: { line: 2, column: 2, offset: 18 },
330
- },
331
- },
332
- {
333
- type: 'element',
334
- name: 'head',
335
- attributes: [],
336
- position: {
337
- start: { line: 2, column: 2, offset: 18 },
338
- end: { line: 6, column: 9, offset: 139 },
339
- },
340
- children: [
341
- {
342
- type: 'text',
343
- value: '\n\t\t',
344
- position: {
345
- start: { line: 2, column: 8, offset: 24 },
346
- end: { line: 3, column: 3, offset: 27 },
347
- },
348
- },
349
- {
350
- type: 'element',
351
- name: 'meta',
352
- position: { start: { line: 3, column: 4, offset: 27 } },
353
- attributes: [
354
- {
355
- type: 'attribute',
356
- kind: 'quoted',
357
- name: 'charset',
358
- value: 'utf-8',
359
- raw: '"utf-8"',
360
- position: { start: { line: 3, column: 9, offset: 33 } },
361
- },
362
- ],
363
- children: [],
364
- },
365
- {
366
- type: 'text',
367
- value: '\n\t\t',
368
- position: {
369
- start: { line: 3, column: 27, offset: 51 },
370
- end: { line: 4, column: 3, offset: 54 },
371
- },
372
- },
373
- {
374
- type: 'element',
375
- name: 'title',
376
- position: {
377
- start: { line: 4, column: 3, offset: 54 },
378
- end: { line: 4, column: 23, offset: 74 },
379
- },
380
- attributes: [],
381
- children: [
382
- {
383
- type: 'text',
384
- value: 'Title',
385
- position: {
386
- start: { line: 4, column: 10, offset: 61 },
387
- end: { line: 4, column: 15, offset: 66 },
388
- },
389
- },
390
- ],
391
- },
392
- {
393
- type: 'text',
394
- value: '\n\t\t',
395
- position: {
396
- start: { line: 4, column: 23, offset: 74 },
397
- end: { line: 5, column: 3, offset: 77 },
398
- },
399
- },
400
- {
401
- type: 'element',
402
- name: 'meta',
403
- attributes: [
404
- {
405
- type: 'attribute',
406
- kind: 'quoted',
407
- name: 'name',
408
- value: 'viewport',
409
- raw: '"viewport"',
410
- position: { start: { line: 5, column: 9, offset: 83 } },
411
- },
412
- {
413
- type: 'attribute',
414
- kind: 'quoted',
415
- name: 'content',
416
- value: 'width=device-width',
417
- raw: '"width=device-width"',
418
- position: { start: { line: 5, column: 25, offset: 99 } },
419
- },
420
- ],
421
- position: { start: { line: 5, column: 4, offset: 77 } },
422
- children: [],
423
- },
424
- {
425
- type: 'text',
426
- value: '\n\t',
427
- position: {
428
- start: { line: 5, column: 56, offset: 130 },
429
- end: { line: 6, column: 2, offset: 132 },
430
- },
431
- },
432
- ],
433
- },
434
- {
435
- type: 'text',
436
- value: '\n',
437
- position: {
438
- start: { line: 6, column: 9, offset: 139 },
439
- end: { line: 7, column: 1, offset: 140 },
440
- },
441
- },
442
- {
443
- type: 'text',
444
- value: '',
445
- position: {
446
- start: { line: 7, column: 8, offset: 140 },
447
- end: { line: 8, column: 1, offset: 140 },
448
- },
449
- },
450
- ],
451
- },
452
- ],
453
- }),
454
- );
455
- });
456
- });