Skip to content

Commit 2b5fb39

Browse files
authored
Fix the order of this property (#190)
1 parent e5e9b79 commit 2b5fb39

13 files changed

+9843
-178
lines changed

src/parser/converts/element.ts

+9-1
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,15 @@ function convertSpecialElement(
369369
ctx.scriptLet.addExpression(thisExpression, thisAttr, null, (es) => {
370370
thisAttr.expression = es;
371371
});
372-
element.startTag.attributes.push(thisAttr);
372+
373+
const targetIndex = element.startTag.attributes.findIndex(
374+
(attr) => thisAttr.range[1] <= attr.range[0]
375+
);
376+
if (targetIndex === -1) {
377+
element.startTag.attributes.push(thisAttr);
378+
} else {
379+
element.startTag.attributes.splice(targetIndex, 0, thisAttr);
380+
}
373381
}
374382

375383
extractElementTags(element, ctx, {

tests/fixtures/parser/ast/docs/template-syntax/15_1-svelte-component/02-output.json

+74-74
Original file line numberDiff line numberDiff line change
@@ -25,80 +25,6 @@
2525
"startTag": {
2626
"type": "SvelteStartTag",
2727
"attributes": [
28-
{
29-
"type": "SvelteAttribute",
30-
"key": {
31-
"type": "SvelteName",
32-
"name": "foo",
33-
"range": [
34-
52,
35-
55
36-
],
37-
"loc": {
38-
"start": {
39-
"line": 1,
40-
"column": 52
41-
},
42-
"end": {
43-
"line": 1,
44-
"column": 55
45-
}
46-
}
47-
},
48-
"boolean": false,
49-
"value": [
50-
{
51-
"type": "SvelteMustacheTag",
52-
"kind": "text",
53-
"expression": {
54-
"type": "Identifier",
55-
"name": "bar",
56-
"range": [
57-
57,
58-
60
59-
],
60-
"loc": {
61-
"start": {
62-
"line": 1,
63-
"column": 57
64-
},
65-
"end": {
66-
"line": 1,
67-
"column": 60
68-
}
69-
}
70-
},
71-
"range": [
72-
56,
73-
61
74-
],
75-
"loc": {
76-
"start": {
77-
"line": 1,
78-
"column": 56
79-
},
80-
"end": {
81-
"line": 1,
82-
"column": 61
83-
}
84-
}
85-
}
86-
],
87-
"range": [
88-
52,
89-
61
90-
],
91-
"loc": {
92-
"start": {
93-
"line": 1,
94-
"column": 52
95-
},
96-
"end": {
97-
"line": 1,
98-
"column": 61
99-
}
100-
}
101-
},
10228
{
10329
"type": "SvelteSpecialDirective",
10430
"kind": "this",
@@ -188,6 +114,80 @@
188114
"column": 51
189115
}
190116
}
117+
},
118+
{
119+
"type": "SvelteAttribute",
120+
"key": {
121+
"type": "SvelteName",
122+
"name": "foo",
123+
"range": [
124+
52,
125+
55
126+
],
127+
"loc": {
128+
"start": {
129+
"line": 1,
130+
"column": 52
131+
},
132+
"end": {
133+
"line": 1,
134+
"column": 55
135+
}
136+
}
137+
},
138+
"boolean": false,
139+
"value": [
140+
{
141+
"type": "SvelteMustacheTag",
142+
"kind": "text",
143+
"expression": {
144+
"type": "Identifier",
145+
"name": "bar",
146+
"range": [
147+
57,
148+
60
149+
],
150+
"loc": {
151+
"start": {
152+
"line": 1,
153+
"column": 57
154+
},
155+
"end": {
156+
"line": 1,
157+
"column": 60
158+
}
159+
}
160+
},
161+
"range": [
162+
56,
163+
61
164+
],
165+
"loc": {
166+
"start": {
167+
"line": 1,
168+
"column": 56
169+
},
170+
"end": {
171+
"line": 1,
172+
"column": 61
173+
}
174+
}
175+
}
176+
],
177+
"range": [
178+
52,
179+
61
180+
],
181+
"loc": {
182+
"start": {
183+
"line": 1,
184+
"column": 52
185+
},
186+
"end": {
187+
"line": 1,
188+
"column": 61
189+
}
190+
}
191191
}
192192
],
193193
"selfClosing": true,

tests/fixtures/parser/ast/docs/template-syntax/15_2-svelte-element/02-output.json

+51-51
Original file line numberDiff line numberDiff line change
@@ -266,127 +266,127 @@
266266
"type": "SvelteStartTag",
267267
"attributes": [
268268
{
269-
"type": "SvelteDirective",
270-
"kind": "EventHandler",
269+
"type": "SvelteSpecialDirective",
270+
"kind": "this",
271271
"key": {
272-
"type": "SvelteDirectiveKey",
273-
"name": {
274-
"type": "SvelteName",
275-
"name": "click",
276-
"range": [
277-
89,
278-
94
279-
],
280-
"loc": {
281-
"start": {
282-
"line": 6,
283-
"column": 30
284-
},
285-
"end": {
286-
"line": 6,
287-
"column": 35
288-
}
289-
}
290-
},
291-
"modifiers": [],
272+
"type": "SvelteSpecialDirectiveKey",
292273
"range": [
293-
86,
294-
94
274+
75,
275+
79
295276
],
296277
"loc": {
297278
"start": {
298279
"line": 6,
299-
"column": 27
280+
"column": 16
300281
},
301282
"end": {
302283
"line": 6,
303-
"column": 35
284+
"column": 20
304285
}
305286
}
306287
},
307288
"expression": {
308289
"type": "Identifier",
309-
"name": "handler",
290+
"name": "tag",
310291
"range": [
311-
96,
312-
103
292+
81,
293+
84
313294
],
314295
"loc": {
315296
"start": {
316297
"line": 6,
317-
"column": 37
298+
"column": 22
318299
},
319300
"end": {
320301
"line": 6,
321-
"column": 44
302+
"column": 25
322303
}
323304
}
324305
},
325306
"range": [
326-
86,
327-
104
307+
75,
308+
85
328309
],
329310
"loc": {
330311
"start": {
331312
"line": 6,
332-
"column": 27
313+
"column": 16
333314
},
334315
"end": {
335316
"line": 6,
336-
"column": 45
317+
"column": 26
337318
}
338319
}
339320
},
340321
{
341-
"type": "SvelteSpecialDirective",
342-
"kind": "this",
322+
"type": "SvelteDirective",
323+
"kind": "EventHandler",
343324
"key": {
344-
"type": "SvelteSpecialDirectiveKey",
325+
"type": "SvelteDirectiveKey",
326+
"name": {
327+
"type": "SvelteName",
328+
"name": "click",
329+
"range": [
330+
89,
331+
94
332+
],
333+
"loc": {
334+
"start": {
335+
"line": 6,
336+
"column": 30
337+
},
338+
"end": {
339+
"line": 6,
340+
"column": 35
341+
}
342+
}
343+
},
344+
"modifiers": [],
345345
"range": [
346-
75,
347-
79
346+
86,
347+
94
348348
],
349349
"loc": {
350350
"start": {
351351
"line": 6,
352-
"column": 16
352+
"column": 27
353353
},
354354
"end": {
355355
"line": 6,
356-
"column": 20
356+
"column": 35
357357
}
358358
}
359359
},
360360
"expression": {
361361
"type": "Identifier",
362-
"name": "tag",
362+
"name": "handler",
363363
"range": [
364-
81,
365-
84
364+
96,
365+
103
366366
],
367367
"loc": {
368368
"start": {
369369
"line": 6,
370-
"column": 22
370+
"column": 37
371371
},
372372
"end": {
373373
"line": 6,
374-
"column": 25
374+
"column": 44
375375
}
376376
}
377377
},
378378
"range": [
379-
75,
380-
85
379+
86,
380+
104
381381
],
382382
"loc": {
383383
"start": {
384384
"line": 6,
385-
"column": 16
385+
"column": 27
386386
},
387387
"end": {
388388
"line": 6,
389-
"column": 26
389+
"column": 45
390390
}
391391
}
392392
}

0 commit comments

Comments
 (0)