Skip to content

Commit 65608c7

Browse files
committed
move check into Text visitor so it happens in expected order
1 parent 926b9ee commit 65608c7

File tree

3 files changed

+25
-21
lines changed
  • packages/svelte

3 files changed

+25
-21
lines changed

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

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22
// @ts-expect-error acorn type definitions are borked in the release we use
33
import { isIdentifierStart, isIdentifierChar } from 'acorn';
44
import fragment from './state/fragment.js';
5-
import { regex_bidirectional_control_characters, regex_whitespace } from '../patterns.js';
5+
import { regex_whitespace } from '../patterns.js';
66
import * as e from '../../errors.js';
7-
import * as w from '../../warnings.js';
87
import { create_fragment } from './utils/create.js';
98
import read_options from './read/options.js';
109
import { is_reserved } from '../../../utils.js';
@@ -65,12 +64,6 @@ export class Parser {
6564
throw new TypeError('Template must be a string');
6665
}
6766

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 });
72-
}
73-
7467
this.loose = loose;
7568
this.template_untrimmed = template;
7669
this.template = template.trimEnd();

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
/** @import { AST } from '#compiler' */
22
/** @import { Context } from '../types' */
33
import { is_tag_valid_with_parent } from '../../../../html-tree-validation.js';
4-
import { regex_not_whitespace } from '../../patterns.js';
4+
import { regex_bidirectional_control_characters, regex_not_whitespace } from '../../patterns.js';
55
import * as e from '../../../errors.js';
6+
import * as w from '../../../warnings.js';
67

78
/**
89
* @param {AST.Text} node
@@ -17,4 +18,14 @@ export function Text(node, context) {
1718
e.node_invalid_placement(node, message);
1819
}
1920
}
21+
22+
regex_bidirectional_control_characters.lastIndex = 0;
23+
for (const match of node.data.matchAll(regex_bidirectional_control_characters)) {
24+
let start = match.index + node.start;
25+
w.bidirectional_control_characters({ start, end: start + match[0].length });
26+
}
27+
28+
// if (regex_bidirectional_control_characters.test(node.data)) {
29+
// w.bidirectional_control_characters(node);
30+
// }
2031
}

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,48 +3,48 @@
33
"code": "bidirectional_control_characters",
44
"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",
55
"start": {
6-
"line": 4,
7-
"column": 0
6+
"line": 2,
7+
"column": 15
88
},
99
"end": {
10-
"line": 4,
11-
"column": 2
10+
"line": 2,
11+
"column": 58
1212
}
1313
},
1414
{
1515
"code": "bidirectional_control_characters",
1616
"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",
1717
"start": {
1818
"line": 4,
19-
"column": 5
19+
"column": 0
2020
},
2121
"end": {
2222
"line": 4,
23-
"column": 7
23+
"column": 2
2424
}
2525
},
2626
{
2727
"code": "bidirectional_control_characters",
2828
"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",
2929
"start": {
3030
"line": 4,
31-
"column": 10
31+
"column": 5
3232
},
3333
"end": {
3434
"line": 4,
35-
"column": 12
35+
"column": 7
3636
}
3737
},
3838
{
3939
"code": "bidirectional_control_characters",
4040
"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",
4141
"start": {
42-
"line": 2,
43-
"column": 15
42+
"line": 4,
43+
"column": 10
4444
},
4545
"end": {
46-
"line": 2,
47-
"column": 58
46+
"line": 4,
47+
"column": 12
4848
}
4949
}
5050
]

0 commit comments

Comments
 (0)