Пример #1
0
        /// <nodoc />
        public static IReadOnlyList <ISymbol> GetPropertySymbolsFromContextualType(INode node, ITypeChecker checker)
        {
            if (IsNameOfPropertyAssignment(node))
            {
                var objectLiteral  = node.Parent?.Parent.As <IObjectLiteralExpression>();
                var contextualType = objectLiteral != null?checker.GetContextualType(objectLiteral) : null;

                var name = node.GetText(); // TODO: saqadri - verify correctness (const name = (<Identifier>node).text;

                if (contextualType != null)
                {
                    if ((contextualType.Flags & TypeFlags.Union) != TypeFlags.None)
                    {
                        // TODO: saqadri - port
                        // This is a union type, first see if the property we are looking for is a union property (i.e. exists in all types)
                        // if not, search the constituent types for the property
                        var unionProperty = checker.GetPropertyOfType(contextualType, name);
                        if (unionProperty != null)
                        {
                            return(new List <ISymbol> {
                                unionProperty
                            });
                        }

                        var result = new List <ISymbol>();
                        foreach (var t in contextualType.Cast <IUnionType>().Types ?? Enumerable.Empty <IType>())
                        {
                            var symbol = checker.GetPropertyOfType(t, name);
                            if (symbol != null)
                            {
                                result.Add(symbol);
                            }
                        }

                        return(result);
                    }

                    var contextualSymbol = checker.GetPropertyOfType(contextualType, name);
                    if (contextualSymbol != null)
                    {
                        return(new List <ISymbol> {
                            contextualSymbol
                        });
                    }
                }
            }

            return(BuildXL.Utilities.Collections.CollectionUtilities.EmptyArray <ISymbol>());
        }