(node)
| 73444 | return isTypeAssignableToKind(checkComputedPropertyName(name), 296 /* TypeFlags.NumberLike */); |
| 73445 | } |
| 73446 | function checkComputedPropertyName(node) { |
| 73447 | var links = getNodeLinks(node.expression); |
| 73448 | if (!links.resolvedType) { |
| 73449 | if ((ts.isTypeLiteralNode(node.parent.parent) || ts.isClassLike(node.parent.parent) || ts.isInterfaceDeclaration(node.parent.parent)) |
| 73450 | && ts.isBinaryExpression(node.expression) && node.expression.operatorToken.kind === 101 /* SyntaxKind.InKeyword */ |
| 73451 | && node.parent.kind !== 172 /* SyntaxKind.GetAccessor */ && node.parent.kind !== 173 /* SyntaxKind.SetAccessor */) { |
| 73452 | return links.resolvedType = errorType; |
| 73453 | } |
| 73454 | links.resolvedType = checkExpression(node.expression); |
| 73455 | // The computed property name of a non-static class field within a loop must be stored in a block-scoped binding. |
| 73456 | // (It needs to be bound at class evaluation time.) |
| 73457 | if (ts.isPropertyDeclaration(node.parent) && !ts.hasStaticModifier(node.parent) && ts.isClassExpression(node.parent.parent)) { |
| 73458 | var container = ts.getEnclosingBlockScopeContainer(node.parent.parent); |
| 73459 | var enclosingIterationStatement = getEnclosingIterationStatement(container); |
| 73460 | if (enclosingIterationStatement) { |
| 73461 | // The computed field name will use a block scoped binding which can be unique for each iteration of the loop. |
| 73462 | getNodeLinks(enclosingIterationStatement).flags |= 65536 /* NodeCheckFlags.LoopWithCapturedBlockScopedBinding */; |
| 73463 | // The generated variable which stores the computed field name must be block-scoped. |
| 73464 | getNodeLinks(node).flags |= 524288 /* NodeCheckFlags.BlockScopedBindingInLoop */; |
| 73465 | // The generated variable which stores the class must be block-scoped. |
| 73466 | getNodeLinks(node.parent.parent).flags |= 524288 /* NodeCheckFlags.BlockScopedBindingInLoop */; |
| 73467 | } |
| 73468 | } |
| 73469 | // This will allow types number, string, symbol or any. It will also allow enums, the unknown |
| 73470 | // type, and any union of these types (like string | number). |
| 73471 | if (links.resolvedType.flags & 98304 /* TypeFlags.Nullable */ || |
| 73472 | !isTypeAssignableToKind(links.resolvedType, 402653316 /* TypeFlags.StringLike */ | 296 /* TypeFlags.NumberLike */ | 12288 /* TypeFlags.ESSymbolLike */) && |
| 73473 | !isTypeAssignableTo(links.resolvedType, stringNumberSymbolType)) { |
| 73474 | error(node, ts.Diagnostics.A_computed_property_name_must_be_of_type_string_number_symbol_or_any); |
| 73475 | } |
| 73476 | } |
| 73477 | return links.resolvedType; |
| 73478 | } |
| 73479 | function isSymbolWithNumericName(symbol) { |
| 73480 | var _a; |
| 73481 | var firstDecl = (_a = symbol.declarations) === null || _a === void 0 ? void 0 : _a[0]; |
no test coverage detected
searching dependent graphs…