Skip to content

Commit 1cbb0bd

Browse files
jeanp413orta
andauthored
Do not classify Infinity and NaN (#44778)
* Do not classify Infinity and NaN. Fixes #42022 * Internally expose so that the classifier can use it * Increase the test complexity, and revert the type-checker * Drop the -Infinity Co-authored-by: Orta <[email protected]>
1 parent 4646640 commit 1cbb0bd

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

src/services/classifier2020.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ namespace ts.classifier.v2020 {
7979
inJSXElement = false;
8080
}
8181

82-
if (isIdentifier(node) && !inJSXElement && !inImportClause(node)) {
82+
if (isIdentifier(node) && !inJSXElement && !inImportClause(node) && !isInfinityOrNaNString(node.escapedText)) {
8383
let symbol = typeChecker.getSymbolAtLocation(node);
8484
if (symbol) {
8585
if (symbol.flags & SymbolFlags.Alias) {
@@ -225,6 +225,10 @@ namespace ts.classifier.v2020 {
225225
return (isQualifiedName(node.parent) && node.parent.right === node) || (isPropertyAccessExpression(node.parent) && node.parent.name === node);
226226
}
227227

228+
function isInfinityOrNaNString(name: __String): boolean {
229+
return name === "Infinity" || name === "NaN";
230+
}
231+
228232
const tokenFromDeclarationMapping = new Map<SyntaxKind, TokenType>([
229233
[SyntaxKind.VariableDeclaration, TokenType.variable],
230234
[SyntaxKind.Parameter, TokenType.parameter],
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/// <reference path="fourslash.ts"/>
2+
3+
//// Infinity;
4+
//// NaN;
5+
////
6+
////// Regular properties
7+
////
8+
////const obj1 = {
9+
//// Infinity: 100,
10+
//// NaN: 200,
11+
//// "-Infinity": 300
12+
////};
13+
////
14+
////obj1.Infinity;
15+
////obj1.NaN;
16+
////obj1["-Infinity"];
17+
////
18+
////// Shorthand properties
19+
////
20+
////const obj2 = {
21+
//// Infinity,
22+
//// NaN,
23+
////}
24+
////
25+
////obj2.Infinity;
26+
////obj2.NaN;
27+
28+
// Basically only the obj1 and obj2 should be showing up in this list
29+
30+
const c2 = classification("2020");
31+
verify.semanticClassificationsAre("2020",
32+
c2.semanticToken("variable.declaration.readonly", "obj1"),
33+
c2.semanticToken("variable.readonly", "obj1"),
34+
c2.semanticToken("variable.readonly", "obj1"),
35+
c2.semanticToken("variable.readonly", "obj1"),
36+
c2.semanticToken("variable.declaration.readonly", "obj2"),
37+
c2.semanticToken("variable.readonly", "obj2"),
38+
c2.semanticToken("variable.readonly", "obj2"),
39+
);

0 commit comments

Comments
 (0)