From 40d75f4968ddf1ebc140f26b1dfd86e8d9ee5495 Mon Sep 17 00:00:00 2001 From: Tan Li Hau Date: Thu, 24 Sep 2020 19:08:41 +0800 Subject: [PATCH 1/2] remove undefined warning for action object --- src/compiler/compile/nodes/Action.ts | 5 +++-- .../samples/action-object/input.svelte | 11 +++++++++++ .../samples/action-object/warnings.json | 17 +++++++++++++++++ 3 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 test/validator/samples/action-object/input.svelte create mode 100644 test/validator/samples/action-object/warnings.json diff --git a/src/compiler/compile/nodes/Action.ts b/src/compiler/compile/nodes/Action.ts index 86aefa0cedac..dc6f080b718c 100644 --- a/src/compiler/compile/nodes/Action.ts +++ b/src/compiler/compile/nodes/Action.ts @@ -11,10 +11,11 @@ export default class Action extends Node { constructor(component: Component, parent, scope, info) { super(component, parent, scope, info); - component.warn_if_undefined(info.name, info, scope); + const object = info.name.split('.')[0]; + component.warn_if_undefined(object, info, scope); this.name = info.name; - component.add_reference(info.name.split('.')[0]); + component.add_reference(object); this.expression = info.expression ? new Expression(component, this, scope, info.expression) diff --git a/test/validator/samples/action-object/input.svelte b/test/validator/samples/action-object/input.svelte new file mode 100644 index 000000000000..e0962fa594ac --- /dev/null +++ b/test/validator/samples/action-object/input.svelte @@ -0,0 +1,11 @@ + + + + \ No newline at end of file diff --git a/test/validator/samples/action-object/warnings.json b/test/validator/samples/action-object/warnings.json new file mode 100644 index 000000000000..e1ccbb55a28a --- /dev/null +++ b/test/validator/samples/action-object/warnings.json @@ -0,0 +1,17 @@ +[ + { + "code": "missing-declaration", + "end": { + "character": 217, + "column": 39, + "line": 11 + }, + "message": "'foo' is not defined", + "pos": 186, + "start": { + "character": 186, + "column": 8, + "line": 11 + } + } +] From ab1ddf252f627f5dae6dae9c206803f446dd0723 Mon Sep 17 00:00:00 2001 From: Conduitry Date: Thu, 24 Sep 2020 09:30:46 -0400 Subject: [PATCH 2/2] update changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3347052e7560..69edc48b0e3a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Svelte changelog +## Unreleased + +* Fix erroneous `missing-declaration` warning with `use:obj.method` ([#5451](https://github.com/sveltejs/svelte/issues/5451)) + ## 3.26.0 * Support `use:obj.method` as actions ([#3935](https://github.com/sveltejs/svelte/issues/3935))