Example #1
0
            private void ProcessModuleValueRegistration(string serviceName, IExpressionOrSpread expression)
            {
                // The type of the second argument - function, value, etc.
                var serviceType   = expression.GetJsType(context, new JsCyclicFlowAccumulator());
                var serviceOffset = context.GetDocumentStartOffset(expression);

                AssociateToServiceGlobalType(serviceName, serviceType, serviceOffset);
            }
Example #2
0
            private void ProcessServiceInjection(IExpressionOrSpread owner, IFunctionExpression factoryFunction)
            {
                var injectedServiceNames = GetInjectedServiceNames(owner, factoryFunction);

                for (var i = 0; i < factoryFunction.Parameters.Count; i++)
                {
                    var parameter   = factoryFunction.Parameters[i];
                    var serviceName = injectedServiceNames[i];

                    AssociateToParameter(serviceName, parameter);
                }
            }
Example #3
0
            private static IFunctionExpression GetFactoryFunction(IExpressionOrSpread argument)
            {
                var factoryFunction = argument as IFunctionExpression;

                if (factoryFunction == null)
                {
                    var arrayLiteral = argument as IArrayLiteral;
                    if (arrayLiteral != null)
                    {
                        factoryFunction = arrayLiteral.ArrayElements.LastOrDefault() as IFunctionExpression;
                    }
                }

                return(factoryFunction);
            }
Example #4
0
            private string[] GetInjectedServiceNames(IExpressionOrSpread owner, IFunctionExpression factoryFunction)
            {
                // TODO: Get the names from the $inject string literal array
                var injectedServiceNames = factoryFunction.Parameters.Select(p => p.GetDeclaredName()).ToArray();

                var arrayLiteral = owner as IArrayLiteral;

                if (arrayLiteral != null)
                {
                    for (int i = 0; i < injectedServiceNames.Length && i < arrayLiteral.ArrayElements.Count; i++)
                    {
                        var serviceName = arrayLiteral.ArrayElements[i].GetStringLiteralValue();
                        if (!string.IsNullOrEmpty(serviceName))
                        {
                            injectedServiceNames[i] = serviceName;
                        }
                    }
                }

                return(injectedServiceNames);
            }
Example #5
0
            private void AssociateToServiceGlobalType(string serviceName, string providerFunctionName, IExpressionOrSpread providerExpression)
            {
                var constructedFactoryType = providerExpression.GetJsType(context, new JsCyclicFlowAccumulator()).
                                             GetConstructedType(JsUnresolvedTypeArray.NoList);

                // The type of the service is the return type of the $get property, if it's a function.
                // If it's an array literal injectable, we need to add the association later, so create
                // a composite type that allows us to add it later
                var providerGetReturnType = constructedFactoryType.GetPropertyReferenceType("$get").GetReturnType();
                var providerGetGlobalType = GetProviderGetGlobalType(providerFunctionName);
                var serviceType           = JavaScriptType.CreateCompositeType(JsCombinedTypeKind.JsDynamic,
                                                                               providerGetReturnType, providerGetGlobalType);

                var offset = context.GetDocumentStartOffset(providerExpression);

                AssociateToServiceGlobalType(serviceName, serviceType, offset);
            }
            private void ProcessServiceInjection(IExpressionOrSpread owner, IFunctionExpression factoryFunction)
            {
                var injectedServiceNames = GetInjectedServiceNames(owner, factoryFunction);

                for (var i = 0; i < factoryFunction.Parameters.Count; i++)
                {
                    var parameter = factoryFunction.Parameters[i];
                    var serviceName = injectedServiceNames[i];

                    AssociateToParameter(serviceName, parameter);
                }
            }
 private void ProcessModuleValueRegistration(string serviceName, IExpressionOrSpread expression)
 {
     // The type of the second argument - function, value, etc.
     var serviceType = expression.GetJsType(context);
     var serviceOffset = context.GetDocumentStartOffset(expression);
     AssociateToServiceGlobalType(serviceName, serviceType, serviceOffset);
 }
            private string[] GetInjectedServiceNames(IExpressionOrSpread owner, IFunctionExpression factoryFunction)
            {
                // TODO: Get the names from the $inject string literal array
                var injectedServiceNames = factoryFunction.Parameters.Select(p => p.GetDeclaredName()).ToArray();

                var arrayLiteral = owner as IArrayLiteral;
                if (arrayLiteral != null)
                {
                    for (int i = 0; i < injectedServiceNames.Length && i < arrayLiteral.ArrayElements.Count; i++)
                    {
                        var serviceName = arrayLiteral.ArrayElements[i].GetStringLiteralValue();
                        if (!string.IsNullOrEmpty(serviceName))
                            injectedServiceNames[i] = serviceName;
                    }
                }

                return injectedServiceNames;
            }
            private void AssociateToServiceGlobalType(string serviceName, string providerFunctionName, IExpressionOrSpread providerExpression)
            {
                var constructedFactoryType = providerExpression.GetJsType(context).
                    GetConstructedType(JsUnresolvedTypeArray.EmptyList);

                // The type of the service is the return type of the $get property, if it's a function.
                // If it's an array literal injectable, we need to add the association later, so create
                // a composite type that allows us to add it later
                var providerGetReturnType = constructedFactoryType.GetPropertyReferenceType("$get").GetReturnType();
                var providerGetGlobalType = GetProviderGetGlobalType(providerFunctionName);
                var serviceType = JavaScriptType.CreateCompositeType(JsCombinedTypeKind.JsDynamic,
                    providerGetReturnType, providerGetGlobalType);

                var offset = context.GetDocumentStartOffset(providerExpression);
                AssociateToServiceGlobalType(serviceName, serviceType, offset);
            }
            private static IFunctionExpression GetFactoryFunction(IExpressionOrSpread argument)
            {
                var factoryFunction = argument as IFunctionExpression;
                if (factoryFunction == null)
                {
                    var arrayLiteral = argument as IArrayLiteral;
                    if (arrayLiteral != null)
                        factoryFunction = arrayLiteral.ArrayElements.LastOrDefault() as IFunctionExpression;
                }

                return factoryFunction;
            }