mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-15 03:23:08 -06:00
Fix BigInt literal error in ambient contexts when targeting < ES2020 (#61935)
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: RyanCavanaugh <6685088+RyanCavanaugh@users.noreply.github.com>
This commit is contained in:
parent
1ed8674bba
commit
6e519c59c1
@ -53188,7 +53188,8 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
|
||||
const literalType = isLiteralTypeNode(node.parent) ||
|
||||
isPrefixUnaryExpression(node.parent) && isLiteralTypeNode(node.parent.parent);
|
||||
if (!literalType) {
|
||||
if (languageVersion < ScriptTarget.ES2020) {
|
||||
// Don't error on BigInt literals in ambient contexts
|
||||
if (!(node.flags & NodeFlags.Ambient) && languageVersion < ScriptTarget.ES2020) {
|
||||
if (grammarErrorOnNode(node, Diagnostics.BigInt_literals_are_not_available_when_targeting_lower_than_ES2020)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
17
tests/baselines/reference/bigintAmbientMinimal.errors.txt
Normal file
17
tests/baselines/reference/bigintAmbientMinimal.errors.txt
Normal file
@ -0,0 +1,17 @@
|
||||
/main.ts(5,17): error TS2737: BigInt literals are not available when targeting lower than ES2020.
|
||||
|
||||
|
||||
==== /ambient.d.ts (0 errors) ====
|
||||
declare const fromDts = 789n;
|
||||
declare namespace Lib {
|
||||
const value = 999n;
|
||||
}
|
||||
|
||||
==== /main.ts (1 errors) ====
|
||||
// Minimal repro from issue
|
||||
declare const n = 123n;
|
||||
|
||||
// Non-ambient for comparison
|
||||
const regular = 456n;
|
||||
~~~~
|
||||
!!! error TS2737: BigInt literals are not available when targeting lower than ES2020.
|
||||
18
tests/baselines/reference/bigintAmbientMinimal.js
Normal file
18
tests/baselines/reference/bigintAmbientMinimal.js
Normal file
@ -0,0 +1,18 @@
|
||||
//// [tests/cases/compiler/bigintAmbientMinimal.ts] ////
|
||||
|
||||
//// [ambient.d.ts]
|
||||
declare const fromDts = 789n;
|
||||
declare namespace Lib {
|
||||
const value = 999n;
|
||||
}
|
||||
|
||||
//// [main.ts]
|
||||
// Minimal repro from issue
|
||||
declare const n = 123n;
|
||||
|
||||
// Non-ambient for comparison
|
||||
const regular = 456n;
|
||||
|
||||
//// [main.js]
|
||||
// Non-ambient for comparison
|
||||
var regular = 456n;
|
||||
22
tests/baselines/reference/bigintAmbientMinimal.symbols
Normal file
22
tests/baselines/reference/bigintAmbientMinimal.symbols
Normal file
@ -0,0 +1,22 @@
|
||||
//// [tests/cases/compiler/bigintAmbientMinimal.ts] ////
|
||||
|
||||
=== /ambient.d.ts ===
|
||||
declare const fromDts = 789n;
|
||||
>fromDts : Symbol(fromDts, Decl(ambient.d.ts, 0, 13))
|
||||
|
||||
declare namespace Lib {
|
||||
>Lib : Symbol(Lib, Decl(ambient.d.ts, 0, 29))
|
||||
|
||||
const value = 999n;
|
||||
>value : Symbol(value, Decl(ambient.d.ts, 2, 9))
|
||||
}
|
||||
|
||||
=== /main.ts ===
|
||||
// Minimal repro from issue
|
||||
declare const n = 123n;
|
||||
>n : Symbol(n, Decl(main.ts, 1, 13))
|
||||
|
||||
// Non-ambient for comparison
|
||||
const regular = 456n;
|
||||
>regular : Symbol(regular, Decl(main.ts, 4, 5))
|
||||
|
||||
35
tests/baselines/reference/bigintAmbientMinimal.types
Normal file
35
tests/baselines/reference/bigintAmbientMinimal.types
Normal file
@ -0,0 +1,35 @@
|
||||
//// [tests/cases/compiler/bigintAmbientMinimal.ts] ////
|
||||
|
||||
=== /ambient.d.ts ===
|
||||
declare const fromDts = 789n;
|
||||
>fromDts : 789n
|
||||
> : ^^^^
|
||||
>789n : 789n
|
||||
> : ^^^^
|
||||
|
||||
declare namespace Lib {
|
||||
>Lib : typeof Lib
|
||||
> : ^^^^^^^^^^
|
||||
|
||||
const value = 999n;
|
||||
>value : 999n
|
||||
> : ^^^^
|
||||
>999n : 999n
|
||||
> : ^^^^
|
||||
}
|
||||
|
||||
=== /main.ts ===
|
||||
// Minimal repro from issue
|
||||
declare const n = 123n;
|
||||
>n : 123n
|
||||
> : ^^^^
|
||||
>123n : 123n
|
||||
> : ^^^^
|
||||
|
||||
// Non-ambient for comparison
|
||||
const regular = 456n;
|
||||
>regular : 456n
|
||||
> : ^^^^
|
||||
>456n : 456n
|
||||
> : ^^^^
|
||||
|
||||
14
tests/cases/compiler/bigintAmbientMinimal.ts
Normal file
14
tests/cases/compiler/bigintAmbientMinimal.ts
Normal file
@ -0,0 +1,14 @@
|
||||
// @target: ES5
|
||||
|
||||
// @Filename: /ambient.d.ts
|
||||
declare const fromDts = 789n;
|
||||
declare namespace Lib {
|
||||
const value = 999n;
|
||||
}
|
||||
|
||||
// @Filename: /main.ts
|
||||
// Minimal repro from issue
|
||||
declare const n = 123n;
|
||||
|
||||
// Non-ambient for comparison
|
||||
const regular = 456n;
|
||||
Loading…
x
Reference in New Issue
Block a user