Skip to content

Commit 88296b9

Browse files
committed
fix(compiler): skip timeZone check when first arg is a spread in strong render policy
When the first argument to toLocaleString/DateTimeFormat is a SpreadElement, args[1] is undefined, causing missingTimeZone to return true and report a false positive. A spread can supply both locale and options, so the compiler cannot prove the timeZone is absent -- fail open per the existing convention.
1 parent 757aa6e commit 88296b9

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

‎packages/octane/src/compiler/strong-render-policy.js‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,9 @@ export function createStrongRenderPolicy({
139139
name,
140140
implicit:
141141
missingValue(args[0], scope) ||
142-
(name === 'DateTimeFormat' && missingTimeZone(args[1], scope)),
142+
(name === 'DateTimeFormat' &&
143+
args[0]?.type !== 'SpreadElement' &&
144+
missingTimeZone(args[1], scope)),
143145
};
144146
}
145147

@@ -253,7 +255,11 @@ export function createStrongRenderPolicy({
253255
const locale = DATE_LOCALE_METHODS.has(name);
254256
if ((!locale && !DATE_ZONE_METHODS.has(name)) || !isDate(member.object, scope)) return;
255257
const args = node.arguments ?? [];
256-
if (locale && (missingValue(args[0], scope) || missingTimeZone(args[1], scope))) {
258+
if (
259+
locale &&
260+
(missingValue(args[0], scope) ||
261+
(args[0]?.type !== 'SpreadElement' && missingTimeZone(args[1], scope)))
262+
) {
257263
report(
258264
STRONG_RENDER_LOCALE_FORMAT,
259265
member,

‎packages/octane/tests/compiler/strong-render-determinism.test.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,8 @@ export function App({ t, n, date, locale, timeZone, options }) {
307307
{new Date(t).toISOString()}{new Date(t).toUTCString()}{new Date(t).getTime()}
308308
{new Date(2024, 0, 1).toDateString()}
309309
{new Intl.DateTimeFormat(locale, { timeZone, month: 'long' }).format(t)}
310+
{new Intl.DateTimeFormat(...options).format(t)}
311+
{new Date(t).toLocaleString(...options)}
310312
{utc.format(t)}{count.format(n)}{date.toLocaleString()}{n.toLocaleString()}
311313
{label}{clicked}
312314
</button>

0 commit comments

Comments
 (0)