Skip to content

Commit 926b9ee

Browse files
committed
show ranges during parsing, and warn on all occurrences rather than just the first
1 parent 4294d5b commit 926b9ee

File tree

3 files changed

+30
-5
lines changed

3 files changed

+30
-5
lines changed

packages/svelte/src/compiler/phases/1-parse/index.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,10 @@ export class Parser {
6565
throw new TypeError('Template must be a string');
6666
}
6767

68-
const control_chars = regex_bidirectional_control_characters.exec(template);
69-
if (control_chars) {
70-
w.bidirectional_control_characters({ start: template.indexOf(control_chars[0][0]) });
68+
regex_bidirectional_control_characters.lastIndex = 0;
69+
for (const match of template.matchAll(regex_bidirectional_control_characters)) {
70+
let start = match.index;
71+
w.bidirectional_control_characters({ start, end: start + match[0].length });
7172
}
7273

7374
this.loose = loose;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@ export const regex_starts_with_vowel = /^[aeiou]/;
2222
export const regex_heading_tags = /^h[1-6]$/;
2323
export const regex_illegal_attribute_character = /(^[0-9-.])|[\^$@%&#?!|()[\]{}^*+~;]/;
2424
export const regex_bidirectional_control_characters =
25-
/[\u202a\u202b\u202c\u202d\u202e\u2066\u2067\u2068\u2069]/;
25+
/[\u202a\u202b\u202c\u202d\u202e\u2066\u2067\u2068\u2069]+/g;

packages/svelte/tests/validator/samples/bidirectional-control-characters/warnings.json

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,31 @@
88
},
99
"end": {
1010
"line": 4,
11-
"column": 0
11+
"column": 2
12+
}
13+
},
14+
{
15+
"code": "bidirectional_control_characters",
16+
"message": "A bidirectional control character was detected in your code. These characters can be used to alter the visual direction of your code and could have unintended consequences",
17+
"start": {
18+
"line": 4,
19+
"column": 5
20+
},
21+
"end": {
22+
"line": 4,
23+
"column": 7
24+
}
25+
},
26+
{
27+
"code": "bidirectional_control_characters",
28+
"message": "A bidirectional control character was detected in your code. These characters can be used to alter the visual direction of your code and could have unintended consequences",
29+
"start": {
30+
"line": 4,
31+
"column": 10
32+
},
33+
"end": {
34+
"line": 4,
35+
"column": 12
1236
}
1337
},
1438
{

0 commit comments

Comments
 (0)