diff --git a/packages/svelte/src/compiler/phases/1-parse/read/options.js b/packages/svelte/src/compiler/phases/1-parse/read/options.js index 5d4f58868f..0204fc805a 100644 --- a/packages/svelte/src/compiler/phases/1-parse/read/options.js +++ b/packages/svelte/src/compiler/phases/1-parse/read/options.js @@ -11,7 +11,8 @@ export default function read_options(node) { /** @type {import('#compiler').SvelteOptions} */ const component_options = { start: node.start, - end: node.end + end: node.end, + attributes: node.attributes }; if (!node) { diff --git a/packages/svelte/src/compiler/types/template.d.ts b/packages/svelte/src/compiler/types/template.d.ts index cf9e9d9e82..2e4373116b 100644 --- a/packages/svelte/src/compiler/types/template.d.ts +++ b/packages/svelte/src/compiler/types/template.d.ts @@ -93,6 +93,7 @@ export interface SvelteOptions { */ extend?: ArrowFunctionExpression | Identifier; }; + attributes: Array; } /** Static text */ diff --git a/packages/svelte/tests/parser-modern/samples/options/input.svelte b/packages/svelte/tests/parser-modern/samples/options/input.svelte new file mode 100644 index 0000000000..062c119163 --- /dev/null +++ b/packages/svelte/tests/parser-modern/samples/options/input.svelte @@ -0,0 +1,7 @@ + + + + + diff --git a/packages/svelte/tests/parser-modern/samples/options/output.json b/packages/svelte/tests/parser-modern/samples/options/output.json new file mode 100644 index 0000000000..af68829455 --- /dev/null +++ b/packages/svelte/tests/parser-modern/samples/options/output.json @@ -0,0 +1,193 @@ +{ + "css": null, + "js": [], + "start": 0, + "end": 112, + "type": "Root", + "fragment": { + "type": "Fragment", + "nodes": [ + { + "type": "Text", + "start": 65, + "end": 67, + "raw": "\n\n", + "data": "\n\n" + }, + { + "type": "Text", + "start": 112, + "end": 114, + "raw": "\n\n", + "data": "\n\n" + } + ], + "transparent": false + }, + "options": { + "start": 0, + "end": 65, + "attributes": [ + { + "type": "Attribute", + "start": 16, + "end": 49, + "name": "customElement", + "value": [ + { + "start": 31, + "end": 48, + "type": "Text", + "raw": "my-custom-element", + "data": "my-custom-element", + "parent": null + } + ], + "parent": null, + "metadata": { + "dynamic": false, + "delegated": null + } + }, + { + "type": "Attribute", + "start": 50, + "end": 62, + "name": "runes", + "value": [ + { + "type": "ExpressionTag", + "start": 56, + "end": 62, + "expression": { + "type": "Literal", + "start": 57, + "end": 61, + "loc": { + "start": { + "line": 1, + "column": 57 + }, + "end": { + "line": 1, + "column": 61 + } + }, + "value": true, + "raw": "true" + }, + "parent": null, + "metadata": { + "contains_call_expression": false, + "dynamic": false + } + } + ], + "parent": null, + "metadata": { + "dynamic": false, + "delegated": null + } + } + ], + "customElement": { + "tag": "my-custom-element" + }, + "runes": true + }, + "module": { + "type": "Script", + "start": 67, + "end": 112, + "context": "module", + "content": { + "type": "Program", + "start": 102, + "end": 103, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 0 + } + }, + "body": [], + "sourceType": "module" + }, + "attributes": [ + { + "type": "Attribute", + "start": 75, + "end": 91, + "name": "context", + "value": [ + { + "start": 84, + "end": 90, + "type": "Text", + "raw": "module", + "data": "module" + } + ] + }, + { + "type": "Attribute", + "start": 92, + "end": 101, + "name": "lang", + "value": [ + { + "start": 98, + "end": 100, + "type": "Text", + "raw": "ts", + "data": "ts" + } + ] + } + ] + }, + "instance": { + "type": "Script", + "start": 114, + "end": 142, + "context": "default", + "content": { + "type": "Program", + "start": 132, + "end": 133, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 7, + "column": 0 + } + }, + "body": [], + "sourceType": "module" + }, + "attributes": [ + { + "type": "Attribute", + "start": 122, + "end": 131, + "name": "lang", + "value": [ + { + "start": 128, + "end": 130, + "type": "Text", + "raw": "ts", + "data": "ts" + } + ] + } + ] + } +} diff --git a/packages/svelte/types/index.d.ts b/packages/svelte/types/index.d.ts index cd2bdc4fa7..c9b9b942f5 100644 --- a/packages/svelte/types/index.d.ts +++ b/packages/svelte/types/index.d.ts @@ -1316,6 +1316,7 @@ declare module 'svelte/compiler' { */ extend?: ArrowFunctionExpression | Identifier; }; + attributes: Array; } /** Static text */