Skip to content

Commit 6e0cd9b

Browse files
authored
fix missing-declaration warning for use:obj.method (#5454)
1 parent 4c135b0 commit 6e0cd9b

File tree

4 files changed

+35
-2
lines changed

4 files changed

+35
-2
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Svelte changelog
22

3+
## Unreleased
4+
5+
* Fix erroneous `missing-declaration` warning with `use:obj.method` ([#5451](https://github.com/sveltejs/svelte/issues/5451))
6+
37
## 3.26.0
48

59
* Support `use:obj.method` as actions ([#3935](https://github.com/sveltejs/svelte/issues/3935))

src/compiler/compile/nodes/Action.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@ export default class Action extends Node {
1111
constructor(component: Component, parent, scope, info) {
1212
super(component, parent, scope, info);
1313

14-
component.warn_if_undefined(info.name, info, scope);
14+
const object = info.name.split('.')[0];
15+
component.warn_if_undefined(object, info, scope);
1516

1617
this.name = info.name;
17-
component.add_reference(info.name.split('.')[0]);
18+
component.add_reference(object);
1819

1920
this.expression = info.expression
2021
? new Expression(component, this, scope, info.expression)
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<script>
2+
const obj = {
3+
foo : "bar",
4+
action(element, { leet }) {
5+
element.foo = this.foo + leet;
6+
},
7+
}
8+
</script>
9+
10+
<button use:obj.action={{ leet: 1337 }}>action</button>
11+
<button use:foo.action={{ leet: 1337 }}>action</button>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
[
2+
{
3+
"code": "missing-declaration",
4+
"end": {
5+
"character": 217,
6+
"column": 39,
7+
"line": 11
8+
},
9+
"message": "'foo' is not defined",
10+
"pos": 186,
11+
"start": {
12+
"character": 186,
13+
"column": 8,
14+
"line": 11
15+
}
16+
}
17+
]

0 commit comments

Comments
 (0)