-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: warn on invalid event handlers (#12818)
* feat: warn on invalid event handlers * handle assignments etc * handle component events too where possible * lint
- Loading branch information
1 parent
c2fb1a6
commit c51dfcf
Showing
12 changed files
with
200 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'svelte': patch | ||
--- | ||
|
||
feat: warn on invalid event handlers |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
.../svelte/tests/runtime-runes/samples/event-handler-component-invalid-warning/Button.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<script> | ||
let { children, onclick } = $props(); | ||
</script> | ||
|
||
<button {onclick}> | ||
{@render children()} | ||
</button> |
17 changes: 17 additions & 0 deletions
17
...ges/svelte/tests/runtime-runes/samples/event-handler-component-invalid-warning/_config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { test } from '../../test'; | ||
|
||
export default test({ | ||
mode: ['client'], | ||
|
||
compileOptions: { | ||
dev: true | ||
}, | ||
|
||
test({ assert, target, warnings }) { | ||
target.querySelector('button')?.click(); | ||
|
||
assert.deepEqual(warnings, [ | ||
'`click` handler at Button.svelte:5:9 should be a function. Did you mean to add a leading `() =>`?' | ||
]); | ||
} | ||
}); |
9 changes: 9 additions & 0 deletions
9
...es/svelte/tests/runtime-runes/samples/event-handler-component-invalid-warning/main.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<script> | ||
import Button from './Button.svelte'; | ||
let count = $state(0); | ||
</script> | ||
|
||
<Button onclick={count++}> | ||
clicks: {count} | ||
</Button> |
17 changes: 17 additions & 0 deletions
17
packages/svelte/tests/runtime-runes/samples/event-handler-invalid-warning/_config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { test } from '../../test'; | ||
|
||
export default test({ | ||
mode: ['client'], | ||
|
||
compileOptions: { | ||
dev: true | ||
}, | ||
|
||
test({ assert, target, warnings }) { | ||
target.querySelector('button')?.click(); | ||
|
||
assert.deepEqual(warnings, [ | ||
'`click` handler at main.svelte:9:17 should be a function. Did you mean to remove the trailing `()`?' | ||
]); | ||
} | ||
}); |
11 changes: 11 additions & 0 deletions
11
packages/svelte/tests/runtime-runes/samples/event-handler-invalid-warning/main.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<script> | ||
let count = $state(0); | ||
function increment() { | ||
count += 1; | ||
} | ||
</script> | ||
|
||
<button onclick={increment()}> | ||
clicks: {count} | ||
</button> |