Skip to content

Commit 1c67ebe

Browse files
committed
include attributes of script tags in ast
1 parent 516cd22 commit 1c67ebe

File tree

7 files changed

+62
-4
lines changed

7 files changed

+62
-4
lines changed

packages/svelte/src/compiler/legacy.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,15 @@ export function convert(source, ast) {
8686
if (instance) {
8787
// @ts-ignore
8888
delete instance.parent;
89+
// @ts-ignore
90+
delete instance.attributes;
8991
}
9092

9193
if (module) {
9294
// @ts-ignore
9395
delete module.parent;
96+
// @ts-ignore
97+
delete module.attributes;
9498
}
9599

96100
return {

packages/svelte/src/compiler/phases/1-parse/read/script.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ export function read_script(parser, start, attributes) {
6363
end: parser.index,
6464
context: get_context(attributes),
6565
content: ast,
66-
parent: null
66+
parent: null,
67+
attributes: attributes
6768
};
6869
}

packages/svelte/src/compiler/types/template.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,7 @@ export interface Script extends BaseNode {
467467
type: 'Script';
468468
context: string;
469469
content: Program;
470+
attributes: Array<Attribute | SpreadAttribute | Directive>;
470471
}
471472

472473
declare module 'estree' {

packages/svelte/tests/parser-modern/samples/comment-before-script/output.json

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,23 @@
133133
"value": "should not error out"
134134
}
135135
]
136-
}
136+
},
137+
"attributes": [
138+
{
139+
"type": "Attribute",
140+
"start": 36,
141+
"end": 45,
142+
"name": "lang",
143+
"value": [
144+
{
145+
"start": 42,
146+
"end": 44,
147+
"type": "Text",
148+
"raw": "ts",
149+
"data": "ts"
150+
}
151+
]
152+
}
153+
]
137154
}
138155
}

packages/svelte/tests/parser-modern/samples/snippets/output.json

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,23 @@
206206
},
207207
"body": [],
208208
"sourceType": "module"
209-
}
209+
},
210+
"attributes": [
211+
{
212+
"type": "Attribute",
213+
"start": 8,
214+
"end": 17,
215+
"name": "lang",
216+
"value": [
217+
{
218+
"start": 14,
219+
"end": 16,
220+
"type": "Text",
221+
"raw": "ts",
222+
"data": "ts"
223+
}
224+
]
225+
}
226+
]
210227
}
211228
}

packages/svelte/tests/parser-modern/samples/typescript-in-event-handler/output.json

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,23 @@
477477
}
478478
],
479479
"sourceType": "module"
480-
}
480+
},
481+
"attributes": [
482+
{
483+
"type": "Attribute",
484+
"start": 8,
485+
"end": 17,
486+
"name": "lang",
487+
"value": [
488+
{
489+
"start": 14,
490+
"end": 16,
491+
"type": "Text",
492+
"raw": "ts",
493+
"data": "ts"
494+
}
495+
]
496+
}
497+
]
481498
}
482499
}

packages/svelte/types/index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1690,6 +1690,7 @@ declare module 'svelte/compiler' {
16901690
type: 'Script';
16911691
context: string;
16921692
content: Program;
1693+
attributes: Array<Attribute | SpreadAttribute | Directive>;
16931694
}
16941695
/**
16951696
* The result of a preprocessor run. If the preprocessor does not return a result, it is assumed that the code is unchanged.

0 commit comments

Comments
 (0)