fix(43799): Support bigint type for Intl.NumberFormat.formatToParts (#44015)

* Add bigint support for formatToParts

* Add tests for Intl.NumberFormat.formatToParts

* Cleanup test

* Fix EOL symbols

* Update baseline test
This commit is contained in:
Matas Rastenis
2021-05-19 03:05:18 +03:00
committed by GitHub
parent 3f9e724c9f
commit fde2c55652
5 changed files with 68 additions and 1 deletions

View File

@@ -7,6 +7,6 @@ declare namespace Intl {
}
interface NumberFormat {
formatToParts(number?: number): NumberFormatPart[];
formatToParts(number?: number | bigint): NumberFormatPart[];
}
}

View File

@@ -0,0 +1,13 @@
//// [formatToPartsBigInt.ts]
// Intl.NumberFormat.formatToParts should support bigInt
// Test Intl methods with new parameter type
new Intl.NumberFormat("fr").formatToParts(3000n);
new Intl.NumberFormat("fr").formatToParts(BigInt(123));
//// [formatToPartsBigInt.js]
// Intl.NumberFormat.formatToParts should support bigInt
// Test Intl methods with new parameter type
new Intl.NumberFormat("fr").formatToParts(3000n);
new Intl.NumberFormat("fr").formatToParts(BigInt(123));

View File

@@ -0,0 +1,19 @@
=== tests/cases/compiler/formatToPartsBigInt.ts ===
// Intl.NumberFormat.formatToParts should support bigInt
// Test Intl methods with new parameter type
new Intl.NumberFormat("fr").formatToParts(3000n);
>new Intl.NumberFormat("fr").formatToParts : Symbol(Intl.NumberFormat.formatToParts, Decl(lib.esnext.intl.d.ts, --, --))
>Intl.NumberFormat : Symbol(Intl.NumberFormat, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2020.bigint.d.ts, --, --), Decl(lib.esnext.intl.d.ts, --, --))
>Intl : Symbol(Intl, Decl(lib.es5.d.ts, --, --), Decl(lib.es2017.intl.d.ts, --, --), Decl(lib.es2018.intl.d.ts, --, --), Decl(lib.es2020.bigint.d.ts, --, --), Decl(lib.es2020.intl.d.ts, --, --) ... and 1 more)
>NumberFormat : Symbol(Intl.NumberFormat, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2020.bigint.d.ts, --, --), Decl(lib.esnext.intl.d.ts, --, --))
>formatToParts : Symbol(Intl.NumberFormat.formatToParts, Decl(lib.esnext.intl.d.ts, --, --))
new Intl.NumberFormat("fr").formatToParts(BigInt(123));
>new Intl.NumberFormat("fr").formatToParts : Symbol(Intl.NumberFormat.formatToParts, Decl(lib.esnext.intl.d.ts, --, --))
>Intl.NumberFormat : Symbol(Intl.NumberFormat, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2020.bigint.d.ts, --, --), Decl(lib.esnext.intl.d.ts, --, --))
>Intl : Symbol(Intl, Decl(lib.es5.d.ts, --, --), Decl(lib.es2017.intl.d.ts, --, --), Decl(lib.es2018.intl.d.ts, --, --), Decl(lib.es2020.bigint.d.ts, --, --), Decl(lib.es2020.intl.d.ts, --, --) ... and 1 more)
>NumberFormat : Symbol(Intl.NumberFormat, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2020.bigint.d.ts, --, --), Decl(lib.esnext.intl.d.ts, --, --))
>formatToParts : Symbol(Intl.NumberFormat.formatToParts, Decl(lib.esnext.intl.d.ts, --, --))
>BigInt : Symbol(BigInt, Decl(lib.es2020.bigint.d.ts, --, --), Decl(lib.es2020.bigint.d.ts, --, --))

View File

@@ -0,0 +1,28 @@
=== tests/cases/compiler/formatToPartsBigInt.ts ===
// Intl.NumberFormat.formatToParts should support bigInt
// Test Intl methods with new parameter type
new Intl.NumberFormat("fr").formatToParts(3000n);
>new Intl.NumberFormat("fr").formatToParts(3000n) : Intl.NumberFormatPart[]
>new Intl.NumberFormat("fr").formatToParts : (number?: number | bigint) => Intl.NumberFormatPart[]
>new Intl.NumberFormat("fr") : Intl.NumberFormat
>Intl.NumberFormat : { (locales?: string | string[], options?: Intl.NumberFormatOptions): Intl.NumberFormat; new (locales?: string | string[], options?: Intl.NumberFormatOptions): Intl.NumberFormat; supportedLocalesOf(locales: string | string[], options?: Intl.NumberFormatOptions): string[]; }
>Intl : typeof Intl
>NumberFormat : { (locales?: string | string[], options?: Intl.NumberFormatOptions): Intl.NumberFormat; new (locales?: string | string[], options?: Intl.NumberFormatOptions): Intl.NumberFormat; supportedLocalesOf(locales: string | string[], options?: Intl.NumberFormatOptions): string[]; }
>"fr" : "fr"
>formatToParts : (number?: number | bigint) => Intl.NumberFormatPart[]
>3000n : 3000n
new Intl.NumberFormat("fr").formatToParts(BigInt(123));
>new Intl.NumberFormat("fr").formatToParts(BigInt(123)) : Intl.NumberFormatPart[]
>new Intl.NumberFormat("fr").formatToParts : (number?: number | bigint) => Intl.NumberFormatPart[]
>new Intl.NumberFormat("fr") : Intl.NumberFormat
>Intl.NumberFormat : { (locales?: string | string[], options?: Intl.NumberFormatOptions): Intl.NumberFormat; new (locales?: string | string[], options?: Intl.NumberFormatOptions): Intl.NumberFormat; supportedLocalesOf(locales: string | string[], options?: Intl.NumberFormatOptions): string[]; }
>Intl : typeof Intl
>NumberFormat : { (locales?: string | string[], options?: Intl.NumberFormatOptions): Intl.NumberFormat; new (locales?: string | string[], options?: Intl.NumberFormatOptions): Intl.NumberFormat; supportedLocalesOf(locales: string | string[], options?: Intl.NumberFormatOptions): string[]; }
>"fr" : "fr"
>formatToParts : (number?: number | bigint) => Intl.NumberFormatPart[]
>BigInt(123) : bigint
>BigInt : BigIntConstructor
>123 : 123

View File

@@ -0,0 +1,7 @@
// @target: esnext
// Intl.NumberFormat.formatToParts should support bigInt
// Test Intl methods with new parameter type
new Intl.NumberFormat("fr").formatToParts(3000n);
new Intl.NumberFormat("fr").formatToParts(BigInt(123));