Skip to content

Commit 318240e

Browse files
committed
fix: allow member access on directives
1 parent f5101c0 commit 318240e

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

packages/svelte/src/compiler/phases/1-parse/state/element.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,16 @@ function read_attribute(parser, unique_names) {
467467
}
468468

469469
if (type) {
470-
const [directive_name, ...modifiers] = name.slice(colon_index + 1).split('|');
470+
const [base_directive_name, ...modifiers] = name.slice(colon_index + 1).split('|');
471+
472+
// this allow for accessing members of an object
473+
const splitted_directive = base_directive_name.split('.');
474+
475+
let directive_name = splitted_directive.shift() ?? '';
476+
477+
for (let new_piece of splitted_directive) {
478+
directive_name += `['${new_piece}']`;
479+
}
471480

472481
if (directive_name === '') {
473482
error(start + colon_index + 1, 'empty-directive-name', type);
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<input use:nested.action>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"html": {
3+
"type": "Fragment",
4+
"start": 0,
5+
"end": 25,
6+
"children": [
7+
{
8+
"type": "Element",
9+
"start": 0,
10+
"end": 25,
11+
"name": "input",
12+
"attributes": [
13+
{
14+
"start": 7,
15+
"end": 24,
16+
"type": "Action",
17+
"name": "nested['action']",
18+
"modifiers": [],
19+
"expression": null
20+
}
21+
],
22+
"children": []
23+
}
24+
]
25+
}
26+
}

0 commit comments

Comments
 (0)