예제 #1
0
 public TreeUpdateAnalysis(ModuleTree tree, IEnumerable <string> dependencies = null, ProjectEntry projectEntry = null, ModuleTable modules = null)
 {
     _tree         = tree;
     _dependencies = dependencies;
     _projectEntry = projectEntry;
     _modules      = modules;
 }
예제 #2
0
        private static ModuleTree ResolveModule(ModuleTree parentTree, string relativeName, AnalysisUnit unit)
        {
            ModuleTree curTree    = parentTree;
            var        components = ModuleTable.GetPathComponents(relativeName);

            for (int i = 0; i < components.Length; i++)
            {
                var comp = components[i];

                if (curTree == null)
                {
                    return(null);
                }

                if (comp == "." || comp == "")
                {
                    continue;
                }
                else if (comp == "..")
                {
                    curTree = curTree.Parent;
                    continue;
                }

                ModuleTree nextTree;
                if (i == components.Length - 1)
                {
                    nextTree = curTree.GetChild(comp + ".js", unit);

                    if (nextTree.ProjectEntry != null)
                    {
                        return(nextTree);
                    }
                }

                nextTree = curTree.GetChild(comp, unit);

                if (nextTree.Children.Count > 0 || nextTree.ProjectEntry != null)
                {
                    curTree = nextTree;
                    continue;
                }

                return(null);
            }

            return(curTree);
        }
예제 #3
0
        public JsAnalyzer(AnalysisLimits limits = null)
        {
            _modules      = new ModuleTable();
            _itemCache    = new Dictionary <object, AnalysisValue>();
            _builtinEntry = new ProjectEntry(this, String.Empty, null);

            Limits = limits ?? new AnalysisLimits();

            _queue = new Deque <AnalysisUnit>();

            _nullInst  = new NullValue(this);
            _trueInst  = new BooleanValue(true, this);
            _falseInst = new BooleanValue(false, this);
            _undefined = new UndefinedValue(this);

            _emptyStringValue = GetConstant(String.Empty);
            _zeroIntValue     = GetConstant(0.0);

            var globals = GlobalBuilder.MakeGlobal(this);

            _globalObject      = globals.GlobalObject;
            _numberPrototype   = globals.NumberPrototype;
            _stringPrototype   = globals.StringPrototype;
            _booleanPrototype  = globals.BooleanPrototype;
            _functionPrototype = globals.FunctionPrototype;
            _arrayFunction     = globals.ArrayFunction;
            _objectPrototype   = globals.ObjectPrototype;
            _requireFunc       = globals.RequireFunction;
            _arrayPrototype    = globals.ArrayPrototype;
            _objectGetOwnPropertyDescriptor = globals.ObjectGetOwnPropertyDescriptor;
            _immutableObject = new ImmutableObjectValue(_builtinEntry);

            var allJson = Path.Combine(
                Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location),
                "all.json"
                );


            if (File.Exists(allJson))
            {
                NodejsModuleBuilder.Build(allJson, this);
            }
            else
            {
                Debug.Fail("Could not find all.json");
            }
        }
예제 #4
0
        internal IEnumerable <MemberResult> GetModules()
        {
            //TODO - Handle require('../a/b/c.js'

            List <MemberResult> res = new List <MemberResult>();

            //Add the builtIns
            foreach (var m in ProjectState.Modules.BuiltinModules)
            {
                res.Add(new MemberResult(
                            m.ModuleName,
                            m.Module.Documentation,
                            JsMemberType.Module));
            }

            ModuleTree moduleTree = ProjectState.Modules.GetModuleTree(ModuleName);

            if (moduleTree == null || moduleTree.Parent == null)
            {
                return(res);
            }

            ModuleTree parentMT = moduleTree.Parent;

            //Walk up the tree looking for node_modules
            do
            {
                ModuleTree nodeModules;
                if (parentMT.Children.TryGetValue(AnalysisConstants.NodeModulesFolder, out nodeModules))
                {
                    foreach (var child in GetChildrenExcludingNodeModules(nodeModules))
                    {
                        var module = ModuleTable.ResolveModule(child.Parent, child.Name);
                        if (module != null)
                        {
                            res.Add(MakeProjectMemberResult(module.Name));
                        }
                    }
                }
                parentMT = parentMT.Parent;
            } while (parentMT != null);

            foreach (var sibling in GetChildrenExcludingNodeModules(moduleTree.Parent))
            {
                if (sibling == moduleTree)
                {
                    //Don't let us require ourself
                    continue;
                }
                if (sibling.ProjectEntry != null)
                {
                    res.Add(MakeProjectMemberResult("./" + sibling.Name));
                }
                else
                {
                    //We're looking at a folder include the children
                    GetChildModules(res, sibling, "./" + sibling.Name + "/");
                }
            }
            return(res);
        }