Skip to content

Commit 74351f7

Browse files
committed
update according to review
1 parent 3feedf0 commit 74351f7

22 files changed

+9734
-12347
lines changed

docs/AST.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ interface SvelteStartTag extends Node {
169169
| SvelteAttribute
170170
| SvelteShorthandAttribute
171171
| SvelteSpreadAttribute
172+
| SvelteAttachTag
172173
| SvelteDirective
173174
| SvelteStyleDirective
174175
| SvelteSpecialDirective
@@ -451,6 +452,18 @@ interface SvelteRenderTag extends Node {
451452
}
452453
```
453454

455+
### SvelteAttachTag
456+
457+
This is `{@attach}` tag node.
458+
459+
```ts
460+
export interface SvelteAttachTag extends BaseNode {
461+
type: "SvelteAttachTag";
462+
expression: ESTree.Expression;
463+
parent: SvelteStartTag;
464+
}
465+
```
466+
454467
### SvelteIfBlock
455468

456469
This is the `{#if}` tag node. `{:else if}` is also included in this node.

src/parser/converts/attr.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ function convertSpreadAttribute(
352352
}
353353

354354
function convertAttachTag(
355-
node: SvAST.AttachTag | Compiler.AttachTag,
355+
node: Compiler.AttachTag,
356356
parent: SvelteAttachTag["parent"],
357357
ctx: Context,
358358
): SvelteAttachTag {
@@ -367,6 +367,12 @@ function convertAttachTag(
367367
attachTag.expression = es;
368368
});
369369

370+
const atAttachStart = ctx.code.indexOf("@attach", attachTag.range[0]);
371+
ctx.addToken("MustacheKeyword", {
372+
start: atAttachStart,
373+
end: atAttachStart + 7,
374+
});
375+
370376
return attachTag;
371377
}
372378

src/parser/svelte-ast-types.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -203,12 +203,6 @@ export interface AttributeShorthand extends BaseNode {
203203
type: "AttributeShorthand";
204204
expression: ESTree.Identifier;
205205
}
206-
207-
export interface AttachTag extends BaseNode {
208-
type: "AttachTag";
209-
expression: ESTree.Expression;
210-
}
211-
212206
export type AttributeOrDirective =
213207
| Attribute
214208
| Spread

tests/fixtures/parser/ast/svelte5/attach-ts-01-output.json

Lines changed: 3 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -1939,124 +1939,16 @@
19391939
}
19401940
},
19411941
{
1942-
"type": "Punctuator",
1943-
"value": "@",
1942+
"type": "MustacheKeyword",
1943+
"value": "@attach",
19441944
"range": [
19451945
242,
1946-
243
1947-
],
1948-
"loc": {
1949-
"start": {
1950-
"line": 14,
1951-
"column": 6
1952-
},
1953-
"end": {
1954-
"line": 14,
1955-
"column": 7
1956-
}
1957-
}
1958-
},
1959-
{
1960-
"type": "Identifier",
1961-
"value": "a",
1962-
"range": [
1963-
243,
1964-
244
1965-
],
1966-
"loc": {
1967-
"start": {
1968-
"line": 14,
1969-
"column": 7
1970-
},
1971-
"end": {
1972-
"line": 14,
1973-
"column": 8
1974-
}
1975-
}
1976-
},
1977-
{
1978-
"type": "Identifier",
1979-
"value": "t",
1980-
"range": [
1981-
244,
1982-
245
1983-
],
1984-
"loc": {
1985-
"start": {
1986-
"line": 14,
1987-
"column": 8
1988-
},
1989-
"end": {
1990-
"line": 14,
1991-
"column": 9
1992-
}
1993-
}
1994-
},
1995-
{
1996-
"type": "Identifier",
1997-
"value": "t",
1998-
"range": [
1999-
245,
2000-
246
2001-
],
2002-
"loc": {
2003-
"start": {
2004-
"line": 14,
2005-
"column": 9
2006-
},
2007-
"end": {
2008-
"line": 14,
2009-
"column": 10
2010-
}
2011-
}
2012-
},
2013-
{
2014-
"type": "Identifier",
2015-
"value": "a",
2016-
"range": [
2017-
246,
2018-
247
2019-
],
2020-
"loc": {
2021-
"start": {
2022-
"line": 14,
2023-
"column": 10
2024-
},
2025-
"end": {
2026-
"line": 14,
2027-
"column": 11
2028-
}
2029-
}
2030-
},
2031-
{
2032-
"type": "Identifier",
2033-
"value": "c",
2034-
"range": [
2035-
247,
2036-
248
2037-
],
2038-
"loc": {
2039-
"start": {
2040-
"line": 14,
2041-
"column": 11
2042-
},
2043-
"end": {
2044-
"line": 14,
2045-
"column": 12
2046-
}
2047-
}
2048-
},
2049-
{
2050-
"type": "Identifier",
2051-
"value": "h",
2052-
"range": [
2053-
248,
20541946
249
20551947
],
20561948
"loc": {
20571949
"start": {
20581950
"line": 14,
2059-
"column": 12
1951+
"column": 6
20601952
},
20611953
"end": {
20621954
"line": 14,

tests/fixtures/parser/ast/svelte5/attach-ts-02-output.json

Lines changed: 3 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -2777,124 +2777,16 @@
27772777
}
27782778
},
27792779
{
2780-
"type": "Punctuator",
2781-
"value": "@",
2780+
"type": "MustacheKeyword",
2781+
"value": "@attach",
27822782
"range": [
27832783
348,
2784-
349
2785-
],
2786-
"loc": {
2787-
"start": {
2788-
"line": 17,
2789-
"column": 9
2790-
},
2791-
"end": {
2792-
"line": 17,
2793-
"column": 10
2794-
}
2795-
}
2796-
},
2797-
{
2798-
"type": "Identifier",
2799-
"value": "a",
2800-
"range": [
2801-
349,
2802-
350
2803-
],
2804-
"loc": {
2805-
"start": {
2806-
"line": 17,
2807-
"column": 10
2808-
},
2809-
"end": {
2810-
"line": 17,
2811-
"column": 11
2812-
}
2813-
}
2814-
},
2815-
{
2816-
"type": "Identifier",
2817-
"value": "t",
2818-
"range": [
2819-
350,
2820-
351
2821-
],
2822-
"loc": {
2823-
"start": {
2824-
"line": 17,
2825-
"column": 11
2826-
},
2827-
"end": {
2828-
"line": 17,
2829-
"column": 12
2830-
}
2831-
}
2832-
},
2833-
{
2834-
"type": "Identifier",
2835-
"value": "t",
2836-
"range": [
2837-
351,
2838-
352
2839-
],
2840-
"loc": {
2841-
"start": {
2842-
"line": 17,
2843-
"column": 12
2844-
},
2845-
"end": {
2846-
"line": 17,
2847-
"column": 13
2848-
}
2849-
}
2850-
},
2851-
{
2852-
"type": "Identifier",
2853-
"value": "a",
2854-
"range": [
2855-
352,
2856-
353
2857-
],
2858-
"loc": {
2859-
"start": {
2860-
"line": 17,
2861-
"column": 13
2862-
},
2863-
"end": {
2864-
"line": 17,
2865-
"column": 14
2866-
}
2867-
}
2868-
},
2869-
{
2870-
"type": "Identifier",
2871-
"value": "c",
2872-
"range": [
2873-
353,
2874-
354
2875-
],
2876-
"loc": {
2877-
"start": {
2878-
"line": 17,
2879-
"column": 14
2880-
},
2881-
"end": {
2882-
"line": 17,
2883-
"column": 15
2884-
}
2885-
}
2886-
},
2887-
{
2888-
"type": "Identifier",
2889-
"value": "h",
2890-
"range": [
2891-
354,
28922784
355
28932785
],
28942786
"loc": {
28952787
"start": {
28962788
"line": 17,
2897-
"column": 15
2789+
"column": 9
28982790
},
28992791
"end": {
29002792
"line": 17,

0 commit comments

Comments
 (0)