Skip to content

Commit 89dd5d8

Browse files
committed
check evaluated values as well, fix minor issue
1 parent 98356b7 commit 89dd5d8

File tree

3 files changed

+23
-6
lines changed

3 files changed

+23
-6
lines changed

packages/svelte/src/compiler/phases/3-transform/client/visitors/shared/utils.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,12 @@
44
import { walk } from 'zimmerframe';
55
import { object } from '../../../../../utils/ast.js';
66
import * as b from '#compiler/builders';
7+
import * as w from '../../../../../warnings.js';
78
import { sanitize_template_string } from '../../../../../utils/sanitize_template_string.js';
8-
import { regex_is_valid_identifier } from '../../../../patterns.js';
9+
import {
10+
regex_is_valid_identifier,
11+
regex_bidirectional_control_characters
12+
} from '../../../../patterns.js';
913
import is_reference from 'is-reference';
1014
import { dev, is_ignored, locator } from '../../../../../state.js';
1115
import { create_derived } from '../../utils.js';
@@ -77,7 +81,10 @@ export function build_template_chunk(
7781
// If we have a single expression, then pass that in directly to possibly avoid doing
7882
// extra work in the template_effect (instead we do the work in set_text).
7983
if (evaluated.is_known) {
80-
value = b.literal(evaluated.value);
84+
if (regex_bidirectional_control_characters.test((evaluated.value ?? '') + '')) {
85+
w.bidirectional_control_characters_detected(node);
86+
}
87+
value = b.literal((evaluated.value ?? '') + '');
8188
}
8289

8390
return { value, has_state };
@@ -96,7 +103,10 @@ export function build_template_chunk(
96103
}
97104

98105
if (evaluated.is_known) {
99-
quasi.value.cooked += evaluated.value + '';
106+
if (regex_bidirectional_control_characters.test((evaluated.value ?? '') + '')) {
107+
w.bidirectional_control_characters_detected(node);
108+
}
109+
quasi.value.cooked += (evaluated.value ?? '') + '';
100110
} else {
101111
if (!evaluated.is_defined) {
102112
// add `?? ''` where necessary

packages/svelte/src/compiler/phases/3-transform/server/visitors/shared/utils.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,12 @@ import {
99
EMPTY_COMMENT
1010
} from '../../../../../../internal/server/hydration.js';
1111
import * as b from '#compiler/builders';
12+
import * as w from '../../../../../warnings.js';
1213
import { sanitize_template_string } from '../../../../../utils/sanitize_template_string.js';
13-
import { regex_whitespaces_strict } from '../../../../patterns.js';
14+
import {
15+
regex_bidirectional_control_characters,
16+
regex_whitespaces_strict
17+
} from '../../../../patterns.js';
1418

1519
/** Opens an if/each block, so that we can remove nodes in the case of a mismatch */
1620
export const block_open = b.literal(BLOCK_OPEN);
@@ -48,6 +52,9 @@ export function process_children(nodes, { visit, state }) {
4852
const evaluated = state.scope.evaluate(node.expression);
4953

5054
if (evaluated.is_known) {
55+
if (regex_bidirectional_control_characters.test((evaluated.value ?? '') + '')) {
56+
w.bidirectional_control_characters_detected(node);
57+
}
5158
quasi.value.cooked += escape_html((evaluated.value ?? '') + '');
5259
} else {
5360
expressions.push(b.call('$.escape', /** @type {Expression} */ (visit(node.expression))));

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ export const STRING = Symbol('string');
2323

2424
/** @type {Record<string, [type: NUMBER | STRING | UNKNOWN, fn?: Function]>} */
2525
const globals = {
26-
BigInt: [NUMBER, BigInt],
26+
BigInt: [NUMBER],
2727
'Math.min': [NUMBER, Math.min],
2828
'Math.max': [NUMBER, Math.max],
2929
'Math.random': [NUMBER],
3030
'Math.floor': [NUMBER, Math.floor],
31-
// @ts-expect-error
31+
// @ts-ignore
3232
'Math.f16round': [NUMBER, Math.f16round],
3333
'Math.round': [NUMBER, Math.round],
3434
'Math.abs': [NUMBER, Math.abs],

0 commit comments

Comments
 (0)