Skip to content

Commit 7998f4c

Browse files
authored
fix: allow more characters in the unicode range as component identifiers (#13198)
fixes #13194 We narrowed the allowed characters in #13057, but didn't take into account all possible (and for JavaScript identifiers allowed) unicode characters. This widens that, which also removes the accidental breaking change (because in Svelte 4 you were allowed to use these unicode characters).
1 parent ccbb0b1 commit 7998f4c

File tree

4 files changed

+15
-2
lines changed

4 files changed

+15
-2
lines changed

.changeset/ten-singers-repair.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+
fix: allow more characters in the unicode range as component identifiers

packages/svelte/src/compiler/phases/1-parse/state/element.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ const regex_attribute_value = /^(?:"([^"]*)"|'([^'])*'|([^>\s]+))/;
2424
const regex_valid_element_name =
2525
/^(?:![a-zA-Z]+|[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?|[a-zA-Z][a-zA-Z0-9]*:[a-zA-Z][a-zA-Z0-9-]*[a-zA-Z0-9])$/;
2626
const regex_valid_component_name =
27-
/^(?:[A-Z][A-Za-z0-9_$.]*|[a-z][A-Za-z0-9_$]*(?:\.[A-Za-z0-9_$]+)+)$/;
27+
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Lexical_grammar#identifiers adjusted for our needs
28+
// (must start with uppercase letter if no dots, can contain dots)
29+
/^(?:\p{Lu}[$\u200c\u200d\p{ID_Continue}.]*|\p{ID_Start}[$\u200c\u200d\p{ID_Continue}]*(?:\.[$\u200c\u200d\p{ID_Continue}]+)+)$/u;
2830

2931
/** @type {Map<string, ElementLike['type']>} */
3032
const root_only_meta_tags = new Map([

packages/svelte/tests/compiler-errors/samples/component-invalid-name/_config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ export default test({
55
code: 'tag_invalid_name',
66
message:
77
'Expected a valid element or component name. Components must have a valid variable name or dot notation expression',
8-
position: [1, 14]
8+
position: [71, 84]
99
}
1010
});
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,7 @@
1+
<!-- ok -->
2+
<Component />
3+
<Wunderschön />
4+
<Cæжαकン中 />
5+
6+
<!-- error -->
17
<Components[1] />

0 commit comments

Comments
 (0)