Skip to content

Commit 61da84c

Browse files
committed
Port "Fix BigInt literal error in ambient contexts when targeting < ES2020"
1 parent e729a0a commit 61da84c

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
@@ -2140,7 +2140,8 @@ func (c *Checker) checkGrammarNumericLiteral(node *ast.NumericLiteral) {
21402140
func (c *Checker) checkGrammarBigIntLiteral(node *ast.BigIntLiteral) bool {
21412141
literalType := ast.IsLiteralTypeNode(node.Parent) || ast.IsPrefixUnaryExpression(node.Parent) && ast.IsLiteralTypeNode(node.Parent.Parent)
21422142
if !literalType {
2143-
if c.languageVersion < core.ScriptTargetES2020 {
2143+
// Don't error on BigInt literals in ambient contexts
2144+
if node.Flags&ast.NodeFlagsAmbient == 0 && c.languageVersion < core.ScriptTargetES2020 {
21442145
if c.grammarErrorOnNode(node.AsNode(), diagnostics.BigInt_literals_are_not_available_when_targeting_lower_than_ES2020) {
21452146
return true
21462147
}

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)