Skip to content

Commit 6b181df

Browse files
authored
Port "Fix BigInt literal error in ambient contexts when targeting < ES2020" (#1819)
1 parent cc68740 commit 6b181df

File tree

3 files changed

+4
-41
lines changed

3 files changed

+4
-41
lines changed

internal/checker/grammarchecks.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2145,7 +2145,8 @@ func (c *Checker) checkGrammarNumericLiteral(node *ast.NumericLiteral) {
21452145
func (c *Checker) checkGrammarBigIntLiteral(node *ast.BigIntLiteral) bool {
21462146
literalType := ast.IsLiteralTypeNode(node.Parent) || ast.IsPrefixUnaryExpression(node.Parent) && ast.IsLiteralTypeNode(node.Parent.Parent)
21472147
if !literalType {
2148-
if c.languageVersion < core.ScriptTargetES2020 {
2148+
// Don't error on BigInt literals in ambient contexts
2149+
if node.Flags&ast.NodeFlagsAmbient == 0 && c.languageVersion < core.ScriptTargetES2020 {
21492150
if c.grammarErrorOnNode(node.AsNode(), diagnostics.BigInt_literals_are_not_available_when_targeting_lower_than_ES2020) {
21502151
return true
21512152
}

testdata/baselines/reference/submodule/compiler/bigintAmbientMinimal.errors.txt

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,15 @@
1-
/ambient.d.ts(1,25): error TS2737: BigInt literals are not available when targeting lower than ES2020.
2-
/ambient.d.ts(3,19): error TS2737: BigInt literals are not available when targeting lower than ES2020.
3-
/main.ts(2,19): error TS2737: BigInt literals are not available when targeting lower than ES2020.
41
/main.ts(5,17): error TS2737: BigInt literals are not available when targeting lower than ES2020.
52

63

7-
==== /ambient.d.ts (2 errors) ====
4+
==== /ambient.d.ts (0 errors) ====
85
declare const fromDts = 789n;
9-
~~~~
10-
!!! error TS2737: BigInt literals are not available when targeting lower than ES2020.
116
declare namespace Lib {
127
const value = 999n;
13-
~~~~
14-
!!! error TS2737: BigInt literals are not available when targeting lower than ES2020.
158
}
169

17-
==== /main.ts (2 errors) ====
10+
==== /main.ts (1 errors) ====
1811
// Minimal repro from issue
1912
declare const n = 123n;
20-
~~~~
21-
!!! error TS2737: BigInt literals are not available when targeting lower than ES2020.
2213

2314
// Non-ambient for comparison
2415
const regular = 456n;

testdata/baselines/reference/submodule/compiler/bigintAmbientMinimal.errors.txt.diff

Lines changed: 0 additions & 29 deletions
This file was deleted.

0 commit comments

Comments
 (0)