Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
"fast-xml-parser": "^4.5.2",
"glob": "^10.4.5",
"globals": "^15.15.0",
"hereby": "^1.10.0",
"hereby": "^1.11.0",
"jsonc-parser": "^3.3.1",
"knip": "^5.44.4",
"minimist": "^1.2.8",
Expand Down
23 changes: 12 additions & 11 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53174,17 +53174,18 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
addErrorOrSuggestion(/*isError*/ false, createDiagnosticForNode(node, Diagnostics.Numeric_literals_with_absolute_values_equal_to_2_53_or_greater_are_too_large_to_be_represented_accurately_as_integers));
}

function checkGrammarBigIntLiteral(node: BigIntLiteral): boolean {
const literalType = isLiteralTypeNode(node.parent) ||
isPrefixUnaryExpression(node.parent) && isLiteralTypeNode(node.parent.parent);
if (!literalType) {
if (languageVersion < ScriptTarget.ES2020) {
if (grammarErrorOnNode(node, Diagnostics.BigInt_literals_are_not_available_when_targeting_lower_than_ES2020)) {
return true;
}
}
}
return false;
function checkGrammarBigIntLiteral(node: BigIntLiteral): boolean {
const literalType = isLiteralTypeNode(node.parent) ||
isPrefixUnaryExpression(node.parent) && isLiteralTypeNode(node.parent.parent);
if (!literalType) {
// 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)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't use triple negation, just inline the flag check here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed by removing the intermediate variable and inlining the flag check. Commit 0e5f192.

return true;
}
}
}
return false;
}

function grammarErrorAfterFirstToken(node: Node, message: DiagnosticMessage, ...args: DiagnosticArguments): boolean {
Expand Down
17 changes: 17 additions & 0 deletions tests/baselines/reference/bigintAmbientMinimal.errors.txt
Original file line number Diff line number Diff line change
@@ -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 changes: 18 additions & 0 deletions tests/baselines/reference/bigintAmbientMinimal.js
Original file line number Diff line number Diff line change
@@ -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 changes: 22 additions & 0 deletions tests/baselines/reference/bigintAmbientMinimal.symbols
Original file line number Diff line number Diff line change
@@ -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 changes: 35 additions & 0 deletions tests/baselines/reference/bigintAmbientMinimal.types
Original file line number Diff line number Diff line change
@@ -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 changes: 14 additions & 0 deletions tests/cases/compiler/bigintAmbientMinimal.ts
Original file line number Diff line number Diff line change
@@ -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;