(expr *ast.Node, location *ast.Node)
| 23930 | } |
| 23931 | |
| 23932 | func (c *Checker) evaluateEntity(expr *ast.Node, location *ast.Node) evaluator.Result { |
| 23933 | switch expr.Kind { |
| 23934 | case ast.KindIdentifier, ast.KindPropertyAccessExpression: |
| 23935 | symbol := c.resolveEntityName(expr, ast.SymbolFlagsValue, true /*ignoreErrors*/, false, nil) |
| 23936 | if symbol == nil { |
| 23937 | return evaluator.NewResult(nil, false, false, false) |
| 23938 | } |
| 23939 | if expr.Kind == ast.KindIdentifier { |
| 23940 | if ast.IsInfinityOrNaNString(expr.Text()) && (symbol == c.getGlobalSymbol(expr.Text(), ast.SymbolFlagsValue, nil /*diagnostic*/)) { |
| 23941 | // Technically we resolved a global lib file here, but the decision to treat this as numeric |
| 23942 | // is more predicated on the fact that the single-file resolution *didn't* resolve to a |
| 23943 | // different meaning of `Infinity` or `NaN`. Transpilers handle this no problem. |
| 23944 | return evaluator.NewResult(jsnum.FromString(expr.Text()), false, false, false) |
| 23945 | } |
| 23946 | } |
| 23947 | if symbol.Flags&ast.SymbolFlagsEnumMember != 0 { |
| 23948 | if location != nil { |
| 23949 | return c.evaluateEnumMember(expr, symbol, location) |
| 23950 | } |
| 23951 | return c.getEnumMemberValue(symbol.ValueDeclaration) |
| 23952 | } |
| 23953 | if c.isConstantVariable(symbol) { |
| 23954 | declaration := symbol.ValueDeclaration |
| 23955 | if declaration != nil && ast.IsVariableDeclaration(declaration) && declaration.Type() == nil && declaration.Initializer() != nil && |
| 23956 | (location == nil || declaration != location && c.isBlockScopedNameDeclaredBeforeUse(declaration, location)) { |
| 23957 | result := c.evaluate(declaration.Initializer(), declaration) |
| 23958 | if location != nil && ast.GetSourceFileOfNode(location) != ast.GetSourceFileOfNode(declaration) { |
| 23959 | return evaluator.NewResult(result.Value, false, true, true) |
| 23960 | } |
| 23961 | return evaluator.NewResult(result.Value, result.IsSyntacticallyString, result.ResolvedOtherFiles, true /*hasExternalReferences*/) |
| 23962 | } |
| 23963 | } |
| 23964 | return evaluator.NewResult(nil, false, false, false) |
| 23965 | case ast.KindElementAccessExpression: |
| 23966 | root := expr.Expression() |
| 23967 | if ast.IsEntityNameExpression(root) && ast.IsStringLiteralLike(expr.AsElementAccessExpression().ArgumentExpression) { |
| 23968 | rootSymbol := c.resolveEntityName(root, ast.SymbolFlagsValue, true /*ignoreErrors*/, false, nil) |
| 23969 | if rootSymbol != nil && rootSymbol.Flags&ast.SymbolFlagsEnum != 0 { |
| 23970 | name := expr.AsElementAccessExpression().ArgumentExpression.Text() |
| 23971 | member := rootSymbol.Exports[name] |
| 23972 | if member != nil { |
| 23973 | if location != nil { |
| 23974 | return c.evaluateEnumMember(expr, member, location) |
| 23975 | } |
| 23976 | return c.getEnumMemberValue(member.ValueDeclaration) |
| 23977 | } |
| 23978 | } |
| 23979 | } |
| 23980 | return evaluator.NewResult(nil, false, false, false) |
| 23981 | } |
| 23982 | panic("Unhandled case in evaluateEntity") |
| 23983 | } |
| 23984 | |
| 23985 | func (c *Checker) evaluateEnumMember(expr *ast.Node, symbol *ast.Symbol, location *ast.Node) evaluator.Result { |
| 23986 | declaration := symbol.ValueDeclaration |
nothing calls this directly
no test coverage detected