mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-30 11:24:49 -05:00
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 <git@orta.io>
This commit is contained in:
@@ -79,7 +79,7 @@ namespace ts.classifier.v2020 {
|
||||
inJSXElement = false;
|
||||
}
|
||||
|
||||
if (isIdentifier(node) && !inJSXElement && !inImportClause(node)) {
|
||||
if (isIdentifier(node) && !inJSXElement && !inImportClause(node) && !isInfinityOrNaNString(node.escapedText)) {
|
||||
let symbol = typeChecker.getSymbolAtLocation(node);
|
||||
if (symbol) {
|
||||
if (symbol.flags & SymbolFlags.Alias) {
|
||||
@@ -225,6 +225,10 @@ namespace ts.classifier.v2020 {
|
||||
return (isQualifiedName(node.parent) && node.parent.right === node) || (isPropertyAccessExpression(node.parent) && node.parent.name === node);
|
||||
}
|
||||
|
||||
function isInfinityOrNaNString(name: __String): boolean {
|
||||
return name === "Infinity" || name === "NaN";
|
||||
}
|
||||
|
||||
const tokenFromDeclarationMapping = new Map<SyntaxKind, TokenType>([
|
||||
[SyntaxKind.VariableDeclaration, TokenType.variable],
|
||||
[SyntaxKind.Parameter, TokenType.parameter],
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
/// <reference path="fourslash.ts"/>
|
||||
|
||||
//// Infinity;
|
||||
//// NaN;
|
||||
////
|
||||
////// Regular properties
|
||||
////
|
||||
////const obj1 = {
|
||||
//// Infinity: 100,
|
||||
//// NaN: 200,
|
||||
//// "-Infinity": 300
|
||||
////};
|
||||
////
|
||||
////obj1.Infinity;
|
||||
////obj1.NaN;
|
||||
////obj1["-Infinity"];
|
||||
////
|
||||
////// Shorthand properties
|
||||
////
|
||||
////const obj2 = {
|
||||
//// Infinity,
|
||||
//// NaN,
|
||||
////}
|
||||
////
|
||||
////obj2.Infinity;
|
||||
////obj2.NaN;
|
||||
|
||||
// Basically only the obj1 and obj2 should be showing up in this list
|
||||
|
||||
const c2 = classification("2020");
|
||||
verify.semanticClassificationsAre("2020",
|
||||
c2.semanticToken("variable.declaration.readonly", "obj1"),
|
||||
c2.semanticToken("variable.readonly", "obj1"),
|
||||
c2.semanticToken("variable.readonly", "obj1"),
|
||||
c2.semanticToken("variable.readonly", "obj1"),
|
||||
c2.semanticToken("variable.declaration.readonly", "obj2"),
|
||||
c2.semanticToken("variable.readonly", "obj2"),
|
||||
c2.semanticToken("variable.readonly", "obj2"),
|
||||
);
|
||||
Reference in New Issue
Block a user