diff --git a/internal/checker/grammarchecks.go b/internal/checker/grammarchecks.go index 9ad9476d0a..06153c7055 100644 --- a/internal/checker/grammarchecks.go +++ b/internal/checker/grammarchecks.go @@ -2140,7 +2140,8 @@ func (c *Checker) checkGrammarNumericLiteral(node *ast.NumericLiteral) { func (c *Checker) checkGrammarBigIntLiteral(node *ast.BigIntLiteral) bool { literalType := ast.IsLiteralTypeNode(node.Parent) || ast.IsPrefixUnaryExpression(node.Parent) && ast.IsLiteralTypeNode(node.Parent.Parent) if !literalType { - if c.languageVersion < core.ScriptTargetES2020 { + // Don't error on BigInt literals in ambient contexts + if node.Flags&ast.NodeFlagsAmbient == 0 && c.languageVersion < core.ScriptTargetES2020 { if c.grammarErrorOnNode(node.AsNode(), diagnostics.BigInt_literals_are_not_available_when_targeting_lower_than_ES2020) { return true } diff --git a/testdata/baselines/reference/submodule/compiler/bigintAmbientMinimal.errors.txt b/testdata/baselines/reference/submodule/compiler/bigintAmbientMinimal.errors.txt index d7dc0ab5eb..e95b511da0 100644 --- a/testdata/baselines/reference/submodule/compiler/bigintAmbientMinimal.errors.txt +++ b/testdata/baselines/reference/submodule/compiler/bigintAmbientMinimal.errors.txt @@ -1,24 +1,15 @@ -/ambient.d.ts(1,25): error TS2737: BigInt literals are not available when targeting lower than ES2020. -/ambient.d.ts(3,19): error TS2737: BigInt literals are not available when targeting lower than ES2020. -/main.ts(2,19): error TS2737: BigInt literals are not available when targeting lower than ES2020. /main.ts(5,17): error TS2737: BigInt literals are not available when targeting lower than ES2020. -==== /ambient.d.ts (2 errors) ==== +==== /ambient.d.ts (0 errors) ==== declare const fromDts = 789n; - ~~~~ -!!! error TS2737: BigInt literals are not available when targeting lower than ES2020. declare namespace Lib { const value = 999n; - ~~~~ -!!! error TS2737: BigInt literals are not available when targeting lower than ES2020. } -==== /main.ts (2 errors) ==== +==== /main.ts (1 errors) ==== // Minimal repro from issue declare const n = 123n; - ~~~~ -!!! error TS2737: BigInt literals are not available when targeting lower than ES2020. // Non-ambient for comparison const regular = 456n; diff --git a/testdata/baselines/reference/submodule/compiler/bigintAmbientMinimal.errors.txt.diff b/testdata/baselines/reference/submodule/compiler/bigintAmbientMinimal.errors.txt.diff deleted file mode 100644 index 4e42f9dea2..0000000000 --- a/testdata/baselines/reference/submodule/compiler/bigintAmbientMinimal.errors.txt.diff +++ /dev/null @@ -1,29 +0,0 @@ ---- old.bigintAmbientMinimal.errors.txt -+++ new.bigintAmbientMinimal.errors.txt -@@= skipped -0, +0 lines =@@ -+/ambient.d.ts(1,25): error TS2737: BigInt literals are not available when targeting lower than ES2020. -+/ambient.d.ts(3,19): error TS2737: BigInt literals are not available when targeting lower than ES2020. -+/main.ts(2,19): error TS2737: BigInt literals are not available when targeting lower than ES2020. - /main.ts(5,17): error TS2737: BigInt literals are not available when targeting lower than ES2020. - - --==== /ambient.d.ts (0 errors) ==== -+==== /ambient.d.ts (2 errors) ==== - declare const fromDts = 789n; -+ ~~~~ -+!!! error TS2737: BigInt literals are not available when targeting lower than ES2020. - declare namespace Lib { - const value = 999n; -+ ~~~~ -+!!! error TS2737: BigInt literals are not available when targeting lower than ES2020. - } - --==== /main.ts (1 errors) ==== -+==== /main.ts (2 errors) ==== - // Minimal repro from issue - declare const n = 123n; -+ ~~~~ -+!!! error TS2737: BigInt literals are not available when targeting lower than ES2020. - - // Non-ambient for comparison - const regular = 456n; \ No newline at end of file