Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
move check into Text visitor so it happens in expected order
  • Loading branch information
Rich-Harris committed May 12, 2025
commit 65608c7174dee6fb9da44a190ca14b4782bf00e2
9 changes: 1 addition & 8 deletions packages/svelte/src/compiler/phases/1-parse/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
// @ts-expect-error acorn type definitions are borked in the release we use
import { isIdentifierStart, isIdentifierChar } from 'acorn';
import fragment from './state/fragment.js';
import { regex_bidirectional_control_characters, regex_whitespace } from '../patterns.js';
import { regex_whitespace } from '../patterns.js';
import * as e from '../../errors.js';
import * as w from '../../warnings.js';
import { create_fragment } from './utils/create.js';
import read_options from './read/options.js';
import { is_reserved } from '../../../utils.js';
Expand Down Expand Up @@ -65,12 +64,6 @@ export class Parser {
throw new TypeError('Template must be a string');
}

regex_bidirectional_control_characters.lastIndex = 0;
for (const match of template.matchAll(regex_bidirectional_control_characters)) {
let start = match.index;
w.bidirectional_control_characters({ start, end: start + match[0].length });
}

this.loose = loose;
this.template_untrimmed = template;
this.template = template.trimEnd();
Expand Down
13 changes: 12 additions & 1 deletion packages/svelte/src/compiler/phases/2-analyze/visitors/Text.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
/** @import { AST } from '#compiler' */
/** @import { Context } from '../types' */
import { is_tag_valid_with_parent } from '../../../../html-tree-validation.js';
import { regex_not_whitespace } from '../../patterns.js';
import { regex_bidirectional_control_characters, regex_not_whitespace } from '../../patterns.js';
import * as e from '../../../errors.js';
import * as w from '../../../warnings.js';

/**
* @param {AST.Text} node
Expand All @@ -17,4 +18,14 @@ export function Text(node, context) {
e.node_invalid_placement(node, message);
}
}

regex_bidirectional_control_characters.lastIndex = 0;
for (const match of node.data.matchAll(regex_bidirectional_control_characters)) {
let start = match.index + node.start;
w.bidirectional_control_characters({ start, end: start + match[0].length });
}

// if (regex_bidirectional_control_characters.test(node.data)) {
// w.bidirectional_control_characters(node);
// }
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,48 +3,48 @@
"code": "bidirectional_control_characters",
"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",
"start": {
"line": 4,
"column": 0
"line": 2,
"column": 15
},
"end": {
"line": 4,
"column": 2
"line": 2,
"column": 58
}
},
{
"code": "bidirectional_control_characters",
"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",
"start": {
"line": 4,
"column": 5
"column": 0
},
"end": {
"line": 4,
"column": 7
"column": 2
}
},
{
"code": "bidirectional_control_characters",
"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",
"start": {
"line": 4,
"column": 10
"column": 5
},
"end": {
"line": 4,
"column": 12
"column": 7
}
},
{
"code": "bidirectional_control_characters",
"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",
"start": {
"line": 2,
"column": 15
"line": 4,
"column": 10
},
"end": {
"line": 2,
"column": 58
"line": 4,
"column": 12
}
}
]