Skip to content

Commit

Permalink
feat(@formatjs/intl-locale): update impl to match stage-3
Browse files Browse the repository at this point in the history
also fix #4375

BREAKING CHANGE: a lot of getters have been removed from the spec so
we've also removed them from this polyfill
  • Loading branch information
longlho committed May 19, 2024
1 parent 763c6b6 commit 753bfea
Show file tree
Hide file tree
Showing 6 changed files with 160 additions and 169 deletions.
15 changes: 8 additions & 7 deletions packages/ecma402-abstract/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,23 +31,24 @@ export {default as _formatToParts} from './NumberFormat/format_to_parts'
export * from './PartitionPattern'
export * from './SupportedLocales'
export {
createDataProperty,
defineProperty,
getInternalSlot,
getMagnitude,
getMultiInternalSlots,
isLiteralPart,
setInternalSlot,
setMultiInternalSlots,
getMagnitude,
defineProperty,
} from './utils'
export type {LiteralPart} from './utils'

export * from './262'
export {isMissingLocaleDataError} from './data'
export * from './types/relative-time'
export type {LocaleData} from './types/core'
export * from './types/date-time'
export * from './types/displaynames'
export * from './types/list'
export * from './types/plural-rules'
export * from './types/number'
export * from './types/displaynames'
export * from './types/plural-rules'
export * from './types/relative-time'
export {invariant} from './utils'
export type {LocaleData} from './types/core'
export * from './262'
19 changes: 19 additions & 0 deletions packages/ecma402-abstract/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,25 @@ export function defineProperty<T extends object>(
})
}

/**
* 7.3.5 CreateDataProperty
* @param target
* @param name
* @param value
*/
export function createDataProperty<T extends object>(
target: T,
name: string | symbol,
value: any
) {
Object.defineProperty(target, name, {
configurable: true,
enumerable: true,
writable: true,
value,
})
}

export const UNICODE_EXTENSION_SEQUENCE_REGEX = /-u(?:-[0-9a-z]{2,8})+/gi

export function invariant(
Expand Down
17 changes: 15 additions & 2 deletions packages/intl-locale/get_internal_slots.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,23 @@ import Locale, {IntlLocaleInternal} from '.'

const internalSlotMap = new WeakMap<Locale, IntlLocaleInternal>()

export default function getInternalSlots(x: Locale): IntlLocaleInternal {
export default function getInternalSlots(
x: Locale,
internalSlotsList: string[] = []
): IntlLocaleInternal {
let internalSlots = internalSlotMap.get(x)
if (!internalSlots) {
internalSlots = Object.create(null) as IntlLocaleInternal
internalSlots = Object.create(
null,
internalSlotsList.reduce<PropertyDescriptorMap>((all, prop) => {
all[prop] = {
enumerable: false,
writable: true,
configurable: true,
}
return all
}, {})
) as IntlLocaleInternal
internalSlotMap.set(x, internalSlots)
}
return internalSlots
Expand Down
Loading

0 comments on commit 753bfea

Please sign in to comment.