@markuplint/svelte-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,267 +0,0 @@
1
- const { parseCtrlBlock } = require('../lib/parse-ctrl-block');
2
- const svelteParse = require('../lib/svelte-parser').default;
3
-
4
- describe('parser', () => {
5
- test('if', () => {
6
- const raw = '{#if cond}text{/if}';
7
- const ast = svelteParse(raw);
8
- expect(parseCtrlBlock('if', ast[0], raw, raw, 0, null, null, null)).toEqual([
9
- expect.objectContaining({
10
- type: 'psblock',
11
- startOffset: 0,
12
- endOffset: 10,
13
- startLine: 1,
14
- endLine: 1,
15
- startCol: 1,
16
- endCol: 11,
17
- raw: '{#if cond}',
18
- nodeName: 'IfBlock',
19
- parentNode: null,
20
- prevNode: null,
21
- nextNode: null,
22
- childNodes: [
23
- expect.objectContaining({
24
- type: 'text',
25
- startOffset: 10,
26
- endOffset: 14,
27
- startLine: 1,
28
- endLine: 1,
29
- startCol: 11,
30
- endCol: 15,
31
- raw: 'text',
32
- nodeName: '#text',
33
- // parentNode: [Circular],
34
- prevNode: null,
35
- nextNode: null,
36
- isFragment: false,
37
- isGhost: false,
38
- }),
39
- ],
40
- isFragment: false,
41
- isGhost: false,
42
- }),
43
- expect.objectContaining({
44
- type: 'psblock',
45
- startOffset: 14,
46
- endOffset: 19,
47
- startLine: 1,
48
- endLine: 1,
49
- startCol: 15,
50
- endCol: 20,
51
- raw: '{/if}',
52
- nodeName: 'IfBlock',
53
- parentNode: null,
54
- prevNode: null,
55
- nextNode: null,
56
- isFragment: false,
57
- isGhost: false,
58
- }),
59
- ]);
60
- });
61
-
62
- test('if else', () => {
63
- const raw = '{#if cond}text1{:else}text2{/if}';
64
- const ast = svelteParse(raw);
65
- expect(parseCtrlBlock('if', ast[0], raw, raw, 0, null, null, null)).toEqual([
66
- expect.objectContaining({
67
- type: 'psblock',
68
- startOffset: 0,
69
- endOffset: 10,
70
- startLine: 1,
71
- endLine: 1,
72
- startCol: 1,
73
- endCol: 11,
74
- raw: '{#if cond}',
75
- nodeName: 'IfBlock',
76
- parentNode: null,
77
- prevNode: null,
78
- nextNode: null,
79
- childNodes: [
80
- expect.objectContaining({
81
- type: 'text',
82
- startOffset: 10,
83
- endOffset: 15,
84
- startLine: 1,
85
- endLine: 1,
86
- startCol: 11,
87
- endCol: 16,
88
- raw: 'text1',
89
- nodeName: '#text',
90
- // parentNode: [Circular],
91
- prevNode: null,
92
- nextNode: null,
93
- isFragment: false,
94
- isGhost: false,
95
- }),
96
- ],
97
- isFragment: false,
98
- isGhost: false,
99
- }),
100
- expect.objectContaining({
101
- type: 'psblock',
102
- startOffset: 15,
103
- endOffset: 22,
104
- startLine: 1,
105
- endLine: 1,
106
- startCol: 16,
107
- endCol: 23,
108
- raw: '{:else}',
109
- nodeName: 'ElseBlock',
110
- parentNode: null,
111
- prevNode: null,
112
- nextNode: null,
113
- childNodes: [
114
- expect.objectContaining({
115
- type: 'text',
116
- startOffset: 22,
117
- endOffset: 27,
118
- startLine: 1,
119
- endLine: 1,
120
- startCol: 23,
121
- endCol: 28,
122
- raw: 'text2',
123
- nodeName: '#text',
124
- // parentNode: [Circular],
125
- prevNode: null,
126
- nextNode: null,
127
- isFragment: false,
128
- isGhost: false,
129
- }),
130
- ],
131
- isFragment: false,
132
- isGhost: false,
133
- }),
134
- expect.objectContaining({
135
- type: 'psblock',
136
- startOffset: 27,
137
- endOffset: 32,
138
- startLine: 1,
139
- endLine: 1,
140
- startCol: 28,
141
- endCol: 33,
142
- raw: '{/if}',
143
- nodeName: 'IfBlock',
144
- parentNode: null,
145
- prevNode: null,
146
- nextNode: null,
147
- isFragment: false,
148
- isGhost: false,
149
- }),
150
- ]);
151
- });
152
-
153
- test('if else if', () => {
154
- const raw = '{#if cond}text1{:else if cond}text2{/if}';
155
- const ast = svelteParse(raw);
156
- const ast2 = parseCtrlBlock('if', ast[0], raw, raw, 0, null, null, null);
157
- expect(ast2).toEqual([
158
- expect.objectContaining({
159
- type: 'psblock',
160
- startOffset: 0,
161
- endOffset: 10,
162
- startLine: 1,
163
- endLine: 1,
164
- startCol: 1,
165
- endCol: 11,
166
- raw: '{#if cond}',
167
- nodeName: 'IfBlock',
168
- parentNode: null,
169
- prevNode: null,
170
- nextNode: null,
171
- childNodes: [
172
- expect.objectContaining({
173
- type: 'text',
174
- startOffset: 10,
175
- endOffset: 15,
176
- startLine: 1,
177
- endLine: 1,
178
- startCol: 11,
179
- endCol: 16,
180
- raw: 'text1',
181
- nodeName: '#text',
182
- // parentNode: [Circular],
183
- prevNode: null,
184
- nextNode: null,
185
- isFragment: false,
186
- isGhost: false,
187
- }),
188
- ],
189
- isFragment: false,
190
- isGhost: false,
191
- }),
192
- expect.objectContaining({
193
- type: 'psblock',
194
- startOffset: 15,
195
- endOffset: 30,
196
- startLine: 1,
197
- endLine: 1,
198
- startCol: 16,
199
- endCol: 31,
200
- raw: '{:else if cond}',
201
- nodeName: 'ElseIfBlock',
202
- parentNode: null,
203
- prevNode: null,
204
- nextNode: null,
205
- childNodes: [
206
- expect.objectContaining({
207
- type: 'text',
208
- startOffset: 30,
209
- endOffset: 35,
210
- startLine: 1,
211
- endLine: 1,
212
- startCol: 31,
213
- endCol: 36,
214
- raw: 'text2',
215
- nodeName: '#text',
216
- // parentNode: [Circular],
217
- prevNode: null,
218
- nextNode: null,
219
- isFragment: false,
220
- isGhost: false,
221
- }),
222
- ],
223
- isFragment: false,
224
- isGhost: false,
225
- }),
226
- expect.objectContaining({
227
- type: 'psblock',
228
- startOffset: 35,
229
- endOffset: 40,
230
- startLine: 1,
231
- endLine: 1,
232
- startCol: 36,
233
- endCol: 41,
234
- raw: '{/if}',
235
- nodeName: 'IfBlock',
236
- parentNode: null,
237
- prevNode: null,
238
- nextNode: null,
239
- isFragment: false,
240
- isGhost: false,
241
- }),
242
- ]);
243
- });
244
-
245
- test('if else if else if else if...', () => {
246
- const raw =
247
- '{#if cond}text1{:else if cond}text2{:else if cond}text3{:else if cond}text4{:else if cond}text5{/if}';
248
- const ast = svelteParse(raw);
249
- const ast2 = parseCtrlBlock('if', ast[0], raw, raw, 0, null, null, null);
250
- expect(ast2.length).toBe(6);
251
- });
252
-
253
- test('white spaces and line breaks', () => {
254
- const raw = ` {#if cond}
255
- text1
256
- {:else if cond}
257
- text2
258
- {:else if cond}
259
- text3
260
- {/if}
261
-
262
- `;
263
- const ast = svelteParse(raw);
264
- const ast2 = parseCtrlBlock('if', ast[0], raw, raw, 0, null, null, null);
265
- expect(ast2.length).toBe(4);
266
- });
267
- });
@@ -1,141 +0,0 @@
1
- const svelteParse = require('../../lib/svelte-parser').default;
2
-
3
- describe('parser', () => {
4
- test('if', () => {
5
- expect(svelteParse('{#if cond}text{/if}')).toEqual([
6
- {
7
- type: 'IfBlock',
8
- start: 0,
9
- end: 19,
10
- expression: {
11
- end: 9,
12
- loc: { end: { column: 9, line: 1 }, start: { column: 5, line: 1 } },
13
- name: 'cond',
14
- start: 5,
15
- type: 'Identifier',
16
- },
17
- children: [{ data: 'text', end: 14, raw: 'text', start: 10, type: 'Text' }],
18
- },
19
- ]);
20
- });
21
-
22
- test('if else', () => {
23
- expect(svelteParse('{#if cond}text1{:else}text2{/if}')).toEqual([
24
- {
25
- type: 'IfBlock',
26
- start: 0,
27
- end: 32,
28
- expression: {
29
- end: 9,
30
- loc: { end: { column: 9, line: 1 }, start: { column: 5, line: 1 } },
31
- name: 'cond',
32
- start: 5,
33
- type: 'Identifier',
34
- },
35
- children: [{ data: 'text1', end: 15, raw: 'text1', start: 10, type: 'Text' }],
36
- else: {
37
- children: [{ data: 'text2', end: 27, raw: 'text2', start: 22, type: 'Text' }],
38
- end: 27,
39
- start: 22,
40
- type: 'ElseBlock',
41
- },
42
- },
43
- ]);
44
- });
45
-
46
- test('if else if', () => {
47
- expect(svelteParse('{#if cond}text1{:else if cond}text2{/if}')).toEqual([
48
- {
49
- type: 'IfBlock',
50
- start: 0,
51
- end: 40,
52
- expression: {
53
- end: 9,
54
- loc: { end: { column: 9, line: 1 }, start: { column: 5, line: 1 } },
55
- name: 'cond',
56
- start: 5,
57
- type: 'Identifier',
58
- },
59
- children: [{ data: 'text1', end: 15, raw: 'text1', start: 10, type: 'Text' }],
60
- else: {
61
- type: 'ElseBlock',
62
- start: 30,
63
- end: 35,
64
- children: [
65
- {
66
- type: 'IfBlock',
67
- start: 30,
68
- end: 40,
69
- elseif: true,
70
- children: [{ data: 'text2', end: 35, raw: 'text2', start: 30, type: 'Text' }],
71
- expression: {
72
- end: 29,
73
- loc: { end: { column: 29, line: 1 }, start: { column: 25, line: 1 } },
74
- name: 'cond',
75
- start: 25,
76
- type: 'Identifier',
77
- },
78
- },
79
- ],
80
- },
81
- },
82
- ]);
83
- });
84
-
85
- test('white spaces with if', () => {
86
- expect(svelteParse('text1 {#if cond} text2 {/if} ')).toEqual([
87
- {
88
- data: 'text1 ',
89
- end: 7,
90
- raw: 'text1 ',
91
- start: 0,
92
- type: 'Text',
93
- },
94
- {
95
- type: 'IfBlock',
96
- start: 7,
97
- end: 31,
98
- expression: {
99
- end: 16,
100
- loc: { end: { column: 16, line: 1 }, start: { column: 12, line: 1 } },
101
- name: 'cond',
102
- start: 12,
103
- type: 'Identifier',
104
- },
105
- children: [{ data: 'text2', end: 26, raw: ' text2 ', start: 17, type: 'Text' }],
106
- },
107
- ]);
108
- });
109
- });
110
-
111
- describe('Issues', () => {
112
- test('#991', () => {
113
- expect(svelteParse("<CustomElement><div>Evaluation doesn't work</div></CustomElement>")).toEqual([
114
- {
115
- type: 'InlineComponent',
116
- name: 'CustomElement',
117
- start: 0,
118
- end: 65,
119
- attributes: [],
120
- children: [
121
- {
122
- type: 'Element',
123
- name: 'div',
124
- start: 15,
125
- end: 49,
126
- attributes: [],
127
- children: [
128
- {
129
- type: 'Text',
130
- start: 20,
131
- end: 43,
132
- data: "Evaluation doesn't work",
133
- raw: "Evaluation doesn't work",
134
- },
135
- ],
136
- },
137
- ],
138
- },
139
- ]);
140
- });
141
- });