Skip to content

Add Intl.DurationFormat / Intl.DateTimeFormat / Intl.RelativeTimeFormat option keys to domprops.js #1679

@thomasbachem

Description

@thomasbachem

#1652 added the Temporal, Duration, and DurationFormat class names to tools/domprops.js, which is great — but the field/option names that these (and Intl.DateTimeFormat) read off their argument objects aren't in the list, so mangle.properties silently breaks them.

Repro

// terser --mangle-props -- input.js
const units = { hours: 1, minutes: 30 };
new Intl.DurationFormat('en').format(units);

becomes

const e = { a: 1, b: 30 };
new Intl.DurationFormat("en").format(e);
// → TypeError: Did not provide any valid Duration fields.

Intl.DateTimeFormat and Intl.RelativeTimeFormat fail the same way, just more quietly:

new Intl.DateTimeFormat('en', { timeZoneName: 'short' }).formatToParts(new Date());
// after mangling: option is dropped, no timeZoneName part is emitted

new Intl.RelativeTimeFormat('en', { numeric: 'auto' }).format(-1, 'day');
// after mangling: numeric:'auto' is dropped, falls back to 'always'

Missing names

Intl.DurationFormat (Duration Record fields, per the spec):

years, months, weeks, days, hours, minutes, seconds,
milliseconds, microseconds, nanoseconds

Intl.DateTimeFormat options (per ecma-402):

weekday, era, year, month, day, dayPeriod,
hour, minute, second, fractionalSecondDigits,
hour12, hourCycle, dateStyle, timeStyle,
timeZone, timeZoneName, calendar, numberingSystem

(Several singulars — year, month, day, hour, etc. — also cover Temporal record fields used in object-literal arguments to Temporal.PlainDate.from(...) and friends.)

Intl.RelativeTimeFormat options:

numeric

Workaround

Currently every consumer has to spell these out themselves:

mangle: { properties: { reserved: ['years', 'months', /* ... */ 'timeZoneName'] } }

It would be much friendlier to have these in domprops.js alongside the class names that #1652 already added.

Happy to send a PR.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions