fix exception with empty alt attribute (#4778)

pull/4781/head
Conduitry 4 years ago committed by GitHub
parent bb5e2d2f26
commit bdabd89f09
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1,5 +1,9 @@
# Svelte changelog
## Unreleased
* Fix compiler exception with `a11y-img-redundant-alt` and value-less `alt` attribute ([#4777](https://github.com/sveltejs/svelte/issues/4777))
## 3.22.1
* Fix compiler exception with `a11y-img-redundant-alt` and dynamic `alt` attribute ([#4770](https://github.com/sveltejs/svelte/issues/4770))

@ -488,7 +488,7 @@ export default class Element extends Node {
if (alt_attribute && !aria_hidden_exist) {
const alt_value = alt_attribute.get_static_value();
if (alt_value && alt_value.match(/\b(image|picture|photo)\b/i)) {
if (/\b(image|picture|photo)\b/i.test(alt_value)) {
component.warn(this, {
code: `a11y-img-redundant-alt`,
message: `A11y: Screenreaders already announce <img> elements as an image.`

@ -6,3 +6,4 @@
<img src="bar" alt="Plant doing photosynthesis in the afternoon" />
<img src="foo" alt="Picturesque food" />
<img src="baz" alt={'baz'} />
<img src="baz" alt />

Loading…
Cancel
Save