Skip to content

Commit 05a2f1b

Browse files
saschanazDanielRosenwasser
authored andcommitted
Support bigints in ES2020 (#33874)
1 parent bed7c89 commit 05a2f1b

19 files changed

+124
-119
lines changed

src/compiler/checker.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36313,8 +36313,8 @@ namespace ts {
3631336313
const literalType = isLiteralTypeNode(node.parent) ||
3631436314
isPrefixUnaryExpression(node.parent) && isLiteralTypeNode(node.parent.parent);
3631536315
if (!literalType) {
36316-
if (languageVersion < ScriptTarget.ESNext) {
36317-
if (grammarErrorOnNode(node, Diagnostics.BigInt_literals_are_not_available_when_targeting_lower_than_ESNext)) {
36316+
if (languageVersion < ScriptTarget.ES2020) {
36317+
if (grammarErrorOnNode(node, Diagnostics.BigInt_literals_are_not_available_when_targeting_lower_than_ES2020)) {
3631836318
return true;
3631936319
}
3632036320
}

src/compiler/commandLineParser.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,14 @@ namespace ts {
4949
["es2019.object", "lib.es2019.object.d.ts"],
5050
["es2019.string", "lib.es2019.string.d.ts"],
5151
["es2019.symbol", "lib.es2019.symbol.d.ts"],
52+
["es2020.bigint", "lib.es2020.bigint.d.ts"],
5253
["es2020.string", "lib.es2020.string.d.ts"],
5354
["es2020.symbol.wellknown", "lib.es2020.symbol.wellknown.d.ts"],
5455
["esnext.array", "lib.es2019.array.d.ts"],
5556
["esnext.symbol", "lib.es2019.symbol.d.ts"],
5657
["esnext.asynciterable", "lib.es2018.asynciterable.d.ts"],
5758
["esnext.intl", "lib.esnext.intl.d.ts"],
58-
["esnext.bigint", "lib.esnext.bigint.d.ts"]
59+
["esnext.bigint", "lib.es2020.bigint.d.ts"]
5960
];
6061

6162
/**

src/compiler/diagnosticMessages.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2615,7 +2615,7 @@
26152615
"category": "Error",
26162616
"code": 2736
26172617
},
2618-
"BigInt literals are not available when targeting lower than ESNext.": {
2618+
"BigInt literals are not available when targeting lower than ES2020.": {
26192619
"category": "Error",
26202620
"code": 2737
26212621
},
File renamed without changes.

src/lib/es2020.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
/// <reference lib="es2019" />
2+
/// <reference lib="es2020.bigint" />
23
/// <reference lib="es2020.string" />
34
/// <reference lib="es2020.symbol.wellknown" />

src/lib/esnext.d.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
/// <reference lib="es2020" />
2-
/// <reference lib="esnext.bigint" />
32
/// <reference lib="esnext.intl" />

src/lib/libs.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@
4040
"es2019.object",
4141
"es2019.string",
4242
"es2019.symbol",
43+
"es2020.bigint",
4344
"es2020.string",
4445
"es2020.symbol.wellknown",
45-
"esnext.bigint",
4646
"esnext.intl",
4747
// Default libraries
4848
"es5.full",

src/testRunner/unittests/config/commandLineParsing.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ namespace ts {
8585
assertParseResult(["--lib", "es5,invalidOption", "0.ts"],
8686
{
8787
errors: [{
88-
messageText: "Argument for '--lib' option must be: 'es5', 'es6', 'es2015', 'es7', 'es2016', 'es2017', 'es2018', 'es2019', 'es2020', 'esnext', 'dom', 'dom.iterable', 'webworker', 'webworker.importscripts', 'scripthost', 'es2015.core', 'es2015.collection', 'es2015.generator', 'es2015.iterable', 'es2015.promise', 'es2015.proxy', 'es2015.reflect', 'es2015.symbol', 'es2015.symbol.wellknown', 'es2016.array.include', 'es2017.object', 'es2017.sharedmemory', 'es2017.string', 'es2017.intl', 'es2017.typedarrays', 'es2018.asyncgenerator', 'es2018.asynciterable', 'es2018.intl', 'es2018.promise', 'es2018.regexp', 'es2019.array', 'es2019.object', 'es2019.string', 'es2019.symbol', 'es2020.string', 'es2020.symbol.wellknown', 'esnext.array', 'esnext.symbol', 'esnext.asynciterable', 'esnext.intl', 'esnext.bigint'.",
88+
messageText: "Argument for '--lib' option must be: 'es5', 'es6', 'es2015', 'es7', 'es2016', 'es2017', 'es2018', 'es2019', 'es2020', 'esnext', 'dom', 'dom.iterable', 'webworker', 'webworker.importscripts', 'scripthost', 'es2015.core', 'es2015.collection', 'es2015.generator', 'es2015.iterable', 'es2015.promise', 'es2015.proxy', 'es2015.reflect', 'es2015.symbol', 'es2015.symbol.wellknown', 'es2016.array.include', 'es2017.object', 'es2017.sharedmemory', 'es2017.string', 'es2017.intl', 'es2017.typedarrays', 'es2018.asyncgenerator', 'es2018.asynciterable', 'es2018.intl', 'es2018.promise', 'es2018.regexp', 'es2019.array', 'es2019.object', 'es2019.string', 'es2019.symbol', 'es2020.bigint', 'es2020.string', 'es2020.symbol.wellknown', 'esnext.array', 'esnext.symbol', 'esnext.asynciterable', 'esnext.intl', 'esnext.bigint'.",
8989
category: Diagnostics.Argument_for_0_option_must_be_Colon_1.category,
9090
code: Diagnostics.Argument_for_0_option_must_be_Colon_1.code,
9191
file: undefined,
@@ -287,7 +287,7 @@ namespace ts {
287287
assertParseResult(["--lib", "es5,", "es7", "0.ts"],
288288
{
289289
errors: [{
290-
messageText: "Argument for '--lib' option must be: 'es5', 'es6', 'es2015', 'es7', 'es2016', 'es2017', 'es2018', 'es2019', 'es2020', 'esnext', 'dom', 'dom.iterable', 'webworker', 'webworker.importscripts', 'scripthost', 'es2015.core', 'es2015.collection', 'es2015.generator', 'es2015.iterable', 'es2015.promise', 'es2015.proxy', 'es2015.reflect', 'es2015.symbol', 'es2015.symbol.wellknown', 'es2016.array.include', 'es2017.object', 'es2017.sharedmemory', 'es2017.string', 'es2017.intl', 'es2017.typedarrays', 'es2018.asyncgenerator', 'es2018.asynciterable', 'es2018.intl', 'es2018.promise', 'es2018.regexp', 'es2019.array', 'es2019.object', 'es2019.string', 'es2019.symbol', 'es2020.string', 'es2020.symbol.wellknown', 'esnext.array', 'esnext.symbol', 'esnext.asynciterable', 'esnext.intl', 'esnext.bigint'.",
290+
messageText: "Argument for '--lib' option must be: 'es5', 'es6', 'es2015', 'es7', 'es2016', 'es2017', 'es2018', 'es2019', 'es2020', 'esnext', 'dom', 'dom.iterable', 'webworker', 'webworker.importscripts', 'scripthost', 'es2015.core', 'es2015.collection', 'es2015.generator', 'es2015.iterable', 'es2015.promise', 'es2015.proxy', 'es2015.reflect', 'es2015.symbol', 'es2015.symbol.wellknown', 'es2016.array.include', 'es2017.object', 'es2017.sharedmemory', 'es2017.string', 'es2017.intl', 'es2017.typedarrays', 'es2018.asyncgenerator', 'es2018.asynciterable', 'es2018.intl', 'es2018.promise', 'es2018.regexp', 'es2019.array', 'es2019.object', 'es2019.string', 'es2019.symbol', 'es2020.bigint', 'es2020.string', 'es2020.symbol.wellknown', 'esnext.array', 'esnext.symbol', 'esnext.asynciterable', 'esnext.intl', 'esnext.bigint'.",
291291
category: Diagnostics.Argument_for_0_option_must_be_Colon_1.category,
292292
code: Diagnostics.Argument_for_0_option_must_be_Colon_1.code,
293293
file: undefined,
@@ -306,7 +306,7 @@ namespace ts {
306306
assertParseResult(["--lib", "es5, ", "es7", "0.ts"],
307307
{
308308
errors: [{
309-
messageText: "Argument for '--lib' option must be: 'es5', 'es6', 'es2015', 'es7', 'es2016', 'es2017', 'es2018', 'es2019', 'es2020', 'esnext', 'dom', 'dom.iterable', 'webworker', 'webworker.importscripts', 'scripthost', 'es2015.core', 'es2015.collection', 'es2015.generator', 'es2015.iterable', 'es2015.promise', 'es2015.proxy', 'es2015.reflect', 'es2015.symbol', 'es2015.symbol.wellknown', 'es2016.array.include', 'es2017.object', 'es2017.sharedmemory', 'es2017.string', 'es2017.intl', 'es2017.typedarrays', 'es2018.asyncgenerator', 'es2018.asynciterable', 'es2018.intl', 'es2018.promise', 'es2018.regexp', 'es2019.array', 'es2019.object', 'es2019.string', 'es2019.symbol', 'es2020.string', 'es2020.symbol.wellknown', 'esnext.array', 'esnext.symbol', 'esnext.asynciterable', 'esnext.intl', 'esnext.bigint'.",
309+
messageText: "Argument for '--lib' option must be: 'es5', 'es6', 'es2015', 'es7', 'es2016', 'es2017', 'es2018', 'es2019', 'es2020', 'esnext', 'dom', 'dom.iterable', 'webworker', 'webworker.importscripts', 'scripthost', 'es2015.core', 'es2015.collection', 'es2015.generator', 'es2015.iterable', 'es2015.promise', 'es2015.proxy', 'es2015.reflect', 'es2015.symbol', 'es2015.symbol.wellknown', 'es2016.array.include', 'es2017.object', 'es2017.sharedmemory', 'es2017.string', 'es2017.intl', 'es2017.typedarrays', 'es2018.asyncgenerator', 'es2018.asynciterable', 'es2018.intl', 'es2018.promise', 'es2018.regexp', 'es2019.array', 'es2019.object', 'es2019.string', 'es2019.symbol', 'es2020.bigint', 'es2020.string', 'es2020.symbol.wellknown', 'esnext.array', 'esnext.symbol', 'esnext.asynciterable', 'esnext.intl', 'esnext.bigint'.",
310310
category: Diagnostics.Argument_for_0_option_must_be_Colon_1.category,
311311
code: Diagnostics.Argument_for_0_option_must_be_Colon_1.code,
312312
file: undefined,
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
tests/cases/compiler/bigIntWithTargetES3.ts(5,22): error TS2737: BigInt literals are not available when targeting lower than ESNext.
2-
tests/cases/compiler/bigIntWithTargetES3.ts(5,29): error TS2737: BigInt literals are not available when targeting lower than ESNext.
3-
tests/cases/compiler/bigIntWithTargetES3.ts(5,39): error TS2737: BigInt literals are not available when targeting lower than ESNext.
4-
tests/cases/compiler/bigIntWithTargetES3.ts(5,48): error TS2737: BigInt literals are not available when targeting lower than ESNext.
1+
tests/cases/compiler/bigIntWithTargetES3.ts(5,22): error TS2737: BigInt literals are not available when targeting lower than ES2020.
2+
tests/cases/compiler/bigIntWithTargetES3.ts(5,29): error TS2737: BigInt literals are not available when targeting lower than ES2020.
3+
tests/cases/compiler/bigIntWithTargetES3.ts(5,39): error TS2737: BigInt literals are not available when targeting lower than ES2020.
4+
tests/cases/compiler/bigIntWithTargetES3.ts(5,48): error TS2737: BigInt literals are not available when targeting lower than ES2020.
55

66

77
==== tests/cases/compiler/bigIntWithTargetES3.ts (4 errors) ====
@@ -11,11 +11,11 @@ tests/cases/compiler/bigIntWithTargetES3.ts(5,48): error TS2737: BigInt literals
1111
let bigintNegativeLiteralType: -123n; // should not error when used as type
1212
const bigintNumber = 123n * 0b1111n + 0o444n * 0x7fn; // each literal should error
1313
~~~~
14-
!!! error TS2737: BigInt literals are not available when targeting lower than ESNext.
14+
!!! error TS2737: BigInt literals are not available when targeting lower than ES2020.
1515
~~~~~~~
16-
!!! error TS2737: BigInt literals are not available when targeting lower than ESNext.
16+
!!! error TS2737: BigInt literals are not available when targeting lower than ES2020.
1717
~~~~~~
18-
!!! error TS2737: BigInt literals are not available when targeting lower than ESNext.
18+
!!! error TS2737: BigInt literals are not available when targeting lower than ES2020.
1919
~~~~~
20-
!!! error TS2737: BigInt literals are not available when targeting lower than ESNext.
20+
!!! error TS2737: BigInt literals are not available when targeting lower than ES2020.
2121

tests/baselines/reference/bigint64ArraySubarray.symbols

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,21 @@ function bigInt64ArraySubarray() {
44

55
var arr = new BigInt64Array(10);
66
>arr : Symbol(arr, Decl(bigint64ArraySubarray.ts, 1, 7))
7-
>BigInt64Array : Symbol(BigInt64Array, Decl(lib.esnext.bigint.d.ts, --, --), Decl(lib.esnext.bigint.d.ts, --, --))
7+
>BigInt64Array : Symbol(BigInt64Array, Decl(lib.es2020.bigint.d.ts, --, --), Decl(lib.es2020.bigint.d.ts, --, --))
88

99
arr.subarray();
10-
>arr.subarray : Symbol(BigInt64Array.subarray, Decl(lib.esnext.bigint.d.ts, --, --))
10+
>arr.subarray : Symbol(BigInt64Array.subarray, Decl(lib.es2020.bigint.d.ts, --, --))
1111
>arr : Symbol(arr, Decl(bigint64ArraySubarray.ts, 1, 7))
12-
>subarray : Symbol(BigInt64Array.subarray, Decl(lib.esnext.bigint.d.ts, --, --))
12+
>subarray : Symbol(BigInt64Array.subarray, Decl(lib.es2020.bigint.d.ts, --, --))
1313

1414
arr.subarray(0);
15-
>arr.subarray : Symbol(BigInt64Array.subarray, Decl(lib.esnext.bigint.d.ts, --, --))
15+
>arr.subarray : Symbol(BigInt64Array.subarray, Decl(lib.es2020.bigint.d.ts, --, --))
1616
>arr : Symbol(arr, Decl(bigint64ArraySubarray.ts, 1, 7))
17-
>subarray : Symbol(BigInt64Array.subarray, Decl(lib.esnext.bigint.d.ts, --, --))
17+
>subarray : Symbol(BigInt64Array.subarray, Decl(lib.es2020.bigint.d.ts, --, --))
1818

1919
arr.subarray(0, 10);
20-
>arr.subarray : Symbol(BigInt64Array.subarray, Decl(lib.esnext.bigint.d.ts, --, --))
20+
>arr.subarray : Symbol(BigInt64Array.subarray, Decl(lib.es2020.bigint.d.ts, --, --))
2121
>arr : Symbol(arr, Decl(bigint64ArraySubarray.ts, 1, 7))
22-
>subarray : Symbol(BigInt64Array.subarray, Decl(lib.esnext.bigint.d.ts, --, --))
22+
>subarray : Symbol(BigInt64Array.subarray, Decl(lib.es2020.bigint.d.ts, --, --))
2323
}
2424

tests/baselines/reference/bigintIndex.errors.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,5 @@ tests/cases/compiler/b.ts(4,12): error TS2464: A computed property name must be
5656
!!! error TS2464: A computed property name must be of type 'string', 'number', 'symbol', or 'any'.
5757
const c = {[bigNum]: 789};
5858
~~~~~~~~
59-
!!! error TS2464: A computed property name must be of type 'string', 'number', 'symbol', or 'any'.
59+
!!! error TS2464: A computed property name must be of type 'string', 'number', 'symbol', or 'any'.
60+

tests/baselines/reference/bigintIndex.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ typedArray[2] = 0xCC;
2929
// BigInt cannot be used as an object literal property
3030
const a = {1n: 123};
3131
const b = {[1n]: 456};
32-
const c = {[bigNum]: 789};
32+
const c = {[bigNum]: 789};
33+
3334

3435
//// [a.js]
3536
const arr = [1, 2, 3];

tests/baselines/reference/bigintWithLib.errors.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,4 +112,5 @@ tests/cases/compiler/bigintWithLib.ts(43,26): error TS2345: Argument of type '12
112112
const w = 12n; // should emit as const w = 12n
113113
const x = -12n; // should emit as const x = -12n
114114
const y: 12n = 12n; // should emit type 12n
115-
let z = 12n; // should emit type bigint in declaration file
115+
let z = 12n; // should emit type bigint in declaration file
116+

tests/baselines/reference/bigintWithLib.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ bigintVal = dataView.getBigUint64(2, true);
5151
const w = 12n; // should emit as const w = 12n
5252
const x = -12n; // should emit as const x = -12n
5353
const y: 12n = 12n; // should emit type 12n
54-
let z = 12n; // should emit type bigint in declaration file
54+
let z = 12n; // should emit type bigint in declaration file
55+
5556

5657
//// [bigintWithLib.js]
5758
// Test BigInt functions

0 commit comments

Comments
 (0)