diff --git a/packages/svelte/src/compiler/phases/1-parse/state/element.js b/packages/svelte/src/compiler/phases/1-parse/state/element.js index d193aeaeb6..e0cbf39ad2 100644 --- a/packages/svelte/src/compiler/phases/1-parse/state/element.js +++ b/packages/svelte/src/compiler/phases/1-parse/state/element.js @@ -467,7 +467,16 @@ function read_attribute(parser, unique_names) { } if (type) { - const [directive_name, ...modifiers] = name.slice(colon_index + 1).split('|'); + const [base_directive_name, ...modifiers] = name.slice(colon_index + 1).split('|'); + + // this allow for accessing members of an object + const splitted_directive = base_directive_name.split('.'); + + let directive_name = splitted_directive.shift() ?? ''; + + for (let new_piece of splitted_directive) { + directive_name += `['${new_piece}']`; + } if (directive_name === '') { error(start + colon_index + 1, 'empty-directive-name', type); diff --git a/packages/svelte/tests/parser-legacy/samples/action-with-memberaccess/input.svelte b/packages/svelte/tests/parser-legacy/samples/action-with-memberaccess/input.svelte new file mode 100644 index 0000000000..22249d8091 --- /dev/null +++ b/packages/svelte/tests/parser-legacy/samples/action-with-memberaccess/input.svelte @@ -0,0 +1 @@ + diff --git a/packages/svelte/tests/parser-legacy/samples/action-with-memberaccess/output.json b/packages/svelte/tests/parser-legacy/samples/action-with-memberaccess/output.json new file mode 100644 index 0000000000..54db4a21e4 --- /dev/null +++ b/packages/svelte/tests/parser-legacy/samples/action-with-memberaccess/output.json @@ -0,0 +1,26 @@ +{ + "html": { + "type": "Fragment", + "start": 0, + "end": 25, + "children": [ + { + "type": "Element", + "start": 0, + "end": 25, + "name": "input", + "attributes": [ + { + "start": 7, + "end": 24, + "type": "Action", + "name": "nested['action']", + "modifiers": [], + "expression": null + } + ], + "children": [] + } + ] + } +}