Skip to content

Commit e802d3b

Browse files
navoriteOcean-OS
andauthored
chore: replace inline regex with variable (#16340)
* chore: replace inline regex with variable * Update packages/svelte/src/compiler/phases/patterns.js Co-authored-by: ComputerGuy <[email protected]> * Update a11y.js * Update a11y.js --------- Co-authored-by: ComputerGuy <[email protected]>
1 parent ca1eb55 commit e802d3b

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

.changeset/tiny-news-whisper.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'svelte': patch
3+
---
4+
5+
chore: replace inline regex with variable

packages/svelte/src/compiler/phases/2-analyze/visitors/shared/a11y.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ import { roles as roles_map, aria, elementRoles } from 'aria-query';
66
import { AXObjects, AXObjectRoles, elementAXObjects } from 'axobject-query';
77
import {
88
regex_heading_tags,
9+
regex_js_prefix,
910
regex_not_whitespace,
11+
regex_redundant_img_alt,
1012
regex_starts_with_vowel,
1113
regex_whitespaces
1214
} from '../../../patterns.js';
@@ -1011,7 +1013,7 @@ export function check_element(node, context) {
10111013
if (href) {
10121014
const href_value = get_static_text_value(href);
10131015
if (href_value !== null) {
1014-
if (href_value === '' || href_value === '#' || /^\W*javascript:/i.test(href_value)) {
1016+
if (href_value === '' || href_value === '#' || regex_js_prefix.test(href_value)) {
10151017
w.a11y_invalid_attribute(href, href_value, href.name);
10161018
}
10171019
}
@@ -1061,7 +1063,7 @@ export function check_element(node, context) {
10611063
const alt_attribute = get_static_text_value(attribute_map.get('alt'));
10621064
const aria_hidden = get_static_value(attribute_map.get('aria-hidden'));
10631065
if (alt_attribute && !aria_hidden && !has_spread) {
1064-
if (/\b(image|picture|photo)\b/i.test(alt_attribute)) {
1066+
if (regex_redundant_img_alt.test(alt_attribute)) {
10651067
w.a11y_img_redundant_alt(node);
10661068
}
10671069
}

packages/svelte/src/compiler/phases/patterns.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,5 @@ export const regex_heading_tags = /^h[1-6]$/;
2323
export const regex_illegal_attribute_character = /(^[0-9-.])|[\^$@%&#?!|()[\]{}^*+~;]/;
2424
export const regex_bidirectional_control_characters =
2525
/[\u202a\u202b\u202c\u202d\u202e\u2066\u2067\u2068\u2069]+/g;
26+
export const regex_js_prefix = /^\W*javascript:/i;
27+
export const regex_redundant_img_alt = /\b(image|picture|photo)\b/i;

0 commit comments

Comments
 (0)