@@ -4,15 +4,20 @@ import { is_tag_valid_with_parent } from '../../../../html-tree-validation.js';
44import { regex_bidirectional_control_characters , regex_not_whitespace } from '../../patterns.js' ;
55import * as e from '../../../errors.js' ;
66import * as w from '../../../warnings.js' ;
7+ import { extract_svelte_ignore } from '../../../utils/extract_svelte_ignore.js' ;
78
89/**
910 * @param {AST.Text } node
1011 * @param {Context } context
1112 */
1213export function Text ( node , context ) {
13- const in_template = context . path . at ( - 1 ) ?. type === 'Fragment' ;
14+ const parent = /** @type { AST.SvelteNode } */ ( context . path . at ( - 1 ) ) ;
1415
15- if ( in_template && context . state . parent_element && regex_not_whitespace . test ( node . data ) ) {
16+ if (
17+ parent . type === 'Fragment' &&
18+ context . state . parent_element &&
19+ regex_not_whitespace . test ( node . data )
20+ ) {
1621 const message = is_tag_valid_with_parent ( '#text' , context . state . parent_element ) ;
1722 if ( message ) {
1823 e . node_invalid_placement ( node , message ) ;
@@ -21,7 +26,27 @@ export function Text(node, context) {
2126
2227 regex_bidirectional_control_characters . lastIndex = 0 ;
2328 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 } ) ;
29+ let is_ignored = false ;
30+
31+ // if we have a svelte-ignore comment earlier in the text, bail
32+ // (otherwise we can only use svelte-ignore on parent elements/blocks)
33+ if ( parent . type === 'Fragment' ) {
34+ for ( const child of parent . nodes ) {
35+ if ( child === node ) break ;
36+
37+ if ( child . type === 'Comment' ) {
38+ is_ignored ||= extract_svelte_ignore (
39+ child . start + 4 ,
40+ child . data ,
41+ context . state . analysis . runes
42+ ) . includes ( 'bidirectional_control_characters' ) ;
43+ }
44+ }
45+ }
46+
47+ if ( ! is_ignored ) {
48+ let start = match . index + node . start ;
49+ w . bidirectional_control_characters ( { start, end : start + match [ 0 ] . length } ) ;
50+ }
2651 }
2752}
0 commit comments