Ejemplo n.º 1
0
 public StringValue(string value, JsAnalyzer javaScriptAnalyzer)
     : base(javaScriptAnalyzer._builtinEntry)
 {
     _value    = value;
     _analyzer = javaScriptAnalyzer;
     javaScriptAnalyzer.AnalysisValueCreated(typeof(StringValue));
 }
Ejemplo n.º 2
0
 private static void AssertIsNotVisible(JsAnalyzer analyzer, string from, string to)
 {
     Assert.IsFalse(
         IsVisible(analyzer, from, to),
         String.Format("{0} can see {1}", from, to)
         );
 }
Ejemplo n.º 3
0
 public NumberValue(double p, JsAnalyzer analyzer)
     : base(analyzer._builtinEntry)
 {
     _value    = p;
     _analyzer = analyzer;
     analyzer.AnalysisValueCreated(typeof(NumberValue));
 }
Ejemplo n.º 4
0
        public void BadRequire()
        {
            // foo.js
            //      require('./rec1')
            // rec1\
            //      package.json
            //          { "main": "../rec2" }
            // rec2\
            //      package.json
            //          { "main": "../rec1" }

            var analyzer = new JsAnalyzer();
            var mod      = @"var x = require('./rec1')";

            analyzer.AddPackageJson("rec1\\package.json", "../rec2");
            analyzer.AddPackageJson("rec2\\package.json", "../rec1");

            var sourceUnit = Analysis.GetSourceUnit(mod);
            var entry      = analyzer.AddModule("one.js", null);

            Analysis.Prepare(entry, sourceUnit);

            entry.Analyze(CancellationToken.None);

            Assert.AreEqual(
                0,
                entry.Analysis.GetTypeIdsByIndex("x", 0).Count()
                );
        }
 internal ProjectEntry(JsAnalyzer analyzer, string filePath, IAnalysisCookie cookie, bool isBuiltin = false) {
     _analyzer = analyzer;
     _filePath = filePath;
     _cookie = cookie;
     _moduleRecord = new ModuleEnvironmentRecord(this);
     _isBuiltin = isBuiltin;
 }
Ejemplo n.º 6
0
 public BooleanValue(bool value, JsAnalyzer javaScriptAnalyzer)
     : base(javaScriptAnalyzer._builtinEntry)
 {
     _value    = value;
     _analyzer = javaScriptAnalyzer;
     javaScriptAnalyzer.AnalysisValueCreated(typeof(BooleanValue));
 }
Ejemplo n.º 7
0
        public static JsAnalyzer Analyze(AnalysisLimits limits, Action parseCallback, params AnalysisFile[] files)
        {
            Dictionary <string, IJsProjectEntry> entries = new Dictionary <string, IJsProjectEntry>();
            var analyzer = new JsAnalyzer(limits);

            foreach (var file in files)
            {
                if (Path.GetFileName(file.Filename).Equals("package.json", StringComparison.OrdinalIgnoreCase))
                {
                    analyzer.AddPackageJson(file.Filename, file.Content);
                }
                else
                {
                    var projEntry = analyzer.AddModule(file.Filename);
                    entries[file.Filename] = projEntry;
                }
            }

            foreach (var file in files)
            {
                if (!Path.GetFileName(file.Filename).Equals("package.json", StringComparison.OrdinalIgnoreCase))
                {
                    var source = Analysis.GetSourceUnit(file.Content);
                    Analysis.Prepare(
                        entries[file.Filename],
                        source
                        );
                }
            }

            if (parseCallback != null)
            {
                parseCallback();
            }

            foreach (var file in files)
            {
                if (!Path.GetFileName(file.Filename).Equals("package.json", StringComparison.OrdinalIgnoreCase))
                {
                    ((IGroupableAnalysisProjectEntry)entries[file.Filename]).Analyze(CancellationToken.None, true);
                }
            }

            foreach (var file in files)
            {
                IJsProjectEntry projEntry;
                if (entries.TryGetValue(file.Filename, out projEntry))
                {
                    projEntry.AnalysisGroup.AnalyzeQueuedEntries(CancellationToken.None);
                    break;
                }
            }

            return(analyzer);
        }
Ejemplo n.º 8
0
        public bool AddTypes(ProjectEntry projectEntry, JsAnalyzer projectState, IAnalysisSet keyTypes, IAnalysisSet valueTypes, bool enqueue = true)
        {
            bool anyAdded = false;

            if (keyTypes.Count > 0)
            {
                var dependencies = GetDependentItems(projectEntry);

                if (dependencies.KeyValues.Count > projectState.Limits.DictKeyTypes)
                {
                    dependencies.MakeUnionStronger();
                }

                foreach (var key in keyTypes)
                {
                    IAnalysisSet values;
                    if (!dependencies.KeyValues.TryGetValue(key, out values))
                    {
                        values   = AnalysisSet.Create(valueTypes);
                        anyAdded = true;
                    }
                    else
                    {
                        bool added;
                        values    = values.Union(valueTypes, out added);
                        anyAdded |= added;
                    }
                    if (anyAdded && values.Count > projectState.Limits.DictValueTypes)
                    {
                        values = values.AsStrongerUnion();
                    }
                    dependencies.KeyValues[key] = values;
                }

#if FALSE   // Currently unused but could come back
                if (anyAdded)
                {
                    _allValues = null;
                }
#endif
                if (anyAdded && enqueue)
                {
                    EnqueueDependents();
                }
            }
            return(anyAdded);
        }
Ejemplo n.º 9
0
        public static string DumpAnalysis(JsAnalyzer analyzer)
        {
            var entries = analyzer.AllModules.ToArray();

            Array.Sort(entries, (x, y) => String.Compare(x.FilePath, y.FilePath));
            StringBuilder analysis = new StringBuilder();

            foreach (var entry in entries)
            {
                if (entry.Analysis != null)
                {
                    analysis.AppendLine(entry.Analysis.Dump());
                }
            }

            return(analysis.ToString());
        }
        public static JsAnalyzer Analyze(AnalysisLimits limits, Action parseCallback, params AnalysisFile[] files) {
            Dictionary<string, IJsProjectEntry> entries = new Dictionary<string, IJsProjectEntry>();
            var analyzer = new JsAnalyzer(limits);

            foreach (var file in files) {
                if (Path.GetFileName(file.Filename).Equals("package.json", StringComparison.OrdinalIgnoreCase)) {
                    analyzer.AddPackageJson(file.Filename, file.Content);
                } else {
                    var projEntry = analyzer.AddModule(file.Filename);
                    entries[file.Filename] = projEntry;
                }
            }

            foreach (var file in files) {
                if (!Path.GetFileName(file.Filename).Equals("package.json", StringComparison.OrdinalIgnoreCase)) {
                    var source = Analysis.GetSourceUnit(file.Content);
                    Analysis.Prepare(
                        entries[file.Filename],
                        source
                    );
                }
            }

            if (parseCallback != null) {
                parseCallback();
            }

            foreach (var file in files) {
                
                if (!Path.GetFileName(file.Filename).Equals("package.json", StringComparison.OrdinalIgnoreCase)) {
                    ((IGroupableAnalysisProjectEntry)entries[file.Filename]).Analyze(CancellationToken.None, true);
                }
            }

            foreach (var file in files) {
                IJsProjectEntry projEntry;
                if (entries.TryGetValue(file.Filename, out projEntry)) {
                    projEntry.AnalysisGroup.AnalyzeQueuedEntries(CancellationToken.None);
                    break;
                }
            }

            return analyzer;
        }
Ejemplo n.º 11
0
        public void RequireNodeModules()
        {
            var mod1 = @"exports.foo = 42;";
            var mod2 = @"x = require('one.js').foo";

            var sourceUnit1 = Analysis.GetSourceUnit(mod1);
            var sourceUnit2 = Analysis.GetSourceUnit(mod2);
            var state       = new JsAnalyzer();
            var entry1      = state.AddModule("node_modules\\one.js", null);
            var entry2      = state.AddModule("two.js", null);

            Analysis.Prepare(entry1, sourceUnit1);
            Analysis.Prepare(entry2, sourceUnit2);

            entry1.Analyze(CancellationToken.None);
            entry2.Analyze(CancellationToken.None);

            AssertUtil.ContainsExactly(
                entry2.Analysis.GetTypeIdsByIndex("x", mod2.Length),
                BuiltinTypeId.Number
                );
        }
Ejemplo n.º 12
0
        public void RequireNonRelativePackageJson()
        {
            var analyzer = new JsAnalyzer();
            var mod      = @"var x = require('./rec1')";
            var myindex  = @"exports.abc = 100;";

            analyzer.AddPackageJson("rec1\\package.json", "lib/myindex.js");

            var sourceUnit        = Analysis.GetSourceUnit(mod);
            var myindexSourceUnit = Analysis.GetSourceUnit(myindex);
            var entry             = analyzer.AddModule("one.js", null);
            var myindexEntry      = analyzer.AddModule("rec1\\lib\\myindex.js", null);

            Analysis.Prepare(entry, sourceUnit);
            Analysis.Prepare(myindexEntry, myindexSourceUnit);

            entry.Analyze(CancellationToken.None);
            myindexEntry.Analyze(CancellationToken.None);

            AssertUtil.ContainsExactly(
                entry.Analysis.GetTypeIdsByIndex("x.abc", 0),
                BuiltinTypeId.Number
                );
        }
 public NodejsModuleBuilder(string filename, JsAnalyzer analyzer) {
     _all = _serializer.DeserializeObject(File.ReadAllText(filename));
     _analyzer = analyzer;
     _readableStream = new LazyPropertyFunctionValue(_analyzer._builtinEntry, "readable", "stream");
     _writableStream = new LazyPropertyFunctionValue(_analyzer._builtinEntry, "writable", "stream");
 }
 private static ProjectEntry CreateProjectEntry() {
     var analyzer = new JsAnalyzer();
     return (ProjectEntry)analyzer.AddModule("test.js");            
 }
Ejemplo n.º 15
0
        public void Require()
        {
            var testCases = new[] {
                new { File = "server.js", Line = 4, Type = "mymod.", Expected = "mymod_export" },
                new { File = "server.js", Line = 8, Type = "mymod2.", Expected = "mymod_export" },
                new { File = "server.js", Line = 12, Type = "mymod3.", Expected = (string)null },
                new { File = "server.js", Line = 19, Type = "foo.", Expected = "foo_export" },
                new { File = "server.js", Line = 22, Type = "bar.", Expected = "bar_entry" },
                new { File = "server.js", Line = 25, Type = "bar2.", Expected = "bar2_entry" },
                new { File = "server.js", Line = 28, Type = "dup.", Expected = "node_modules_dup" },
                new { File = "server.js", Line = 31, Type = "dup1.", Expected = "top_level" },
                new { File = "server.js", Line = 34, Type = "dup2.", Expected = "top_level" },
                new { File = "server.js", Line = 37, Type = "baz_dup.", Expected = "baz_dup" },
                new { File = "server.js", Line = 40, Type = "baz_dup2.", Expected = "baz_dup" },
                new { File = "server.js", Line = 42, Type = "recursive.", Expected = "recursive1" },
                new { File = "server.js", Line = 42, Type = "recursive.", Expected = "recursive2" },
                new { File = "server.js", Line = 48, Type = "nested.", Expected = (string)null },
                new { File = "server.js", Line = 54, Type = "indexfolder.", Expected = "indexfolder" },
                new { File = "server.js", Line = 56, Type = "indexfolder2.", Expected = "indexfolder" },
                // TODO: Requires require('path').resolve('./indexfolder') to work
                //new { File="server.js", Line = 60, Type = "resolve_path.", Expected = "indexfolder" },

                new { File = "node_modules\\mymod.js", Line = 5, Type = "dup.", Expected = "node_modules_dup" },
                new { File = "node_modules\\mymod.js", Line = 8, Type = "dup0.", Expected = "node_modules_dup" },
                new { File = "node_modules\\mymod.js", Line = 11, Type = "dup1.", Expected = "node_modules_dup" },
                new { File = "node_modules\\mymod.js", Line = 14, Type = "dup2.", Expected = "node_modules_dup" },
                new { File = "node_modules\\mymod.js", Line = 17, Type = "dup3.", Expected = "dup" },

                new { File = "node_modules\\foo\\index.js", Line = 5, Type = "dup.", Expected = "foo_node_modules" },
                new { File = "node_modules\\foo\\index.js", Line = 8, Type = "dup1.", Expected = "dup" },
                new { File = "node_modules\\foo\\index.js", Line = 11, Type = "dup2.", Expected = "dup" },
                new { File = "node_modules\\foo\\index.js", Line = 14, Type = "other.", Expected = "other" },
                new { File = "node_modules\\foo\\index.js", Line = 17, Type = "other2.", Expected = "other" },
                new { File = "node_modules\\foo\\index.js", Line = 20, Type = "other3.", Expected = (string)null },
                new { File = "node_modules\\foo\\index.js", Line = 27, Type = "other4.", Expected = (string)null },

                new { File = "baz\\dup.js", Line = 3, Type = "parent_dup.", Expected = "top_level" },
                new { File = "baz\\dup.js", Line = 6, Type = "bar.", Expected = "bar_entry" },
                new { File = "baz\\dup.js", Line = 9, Type = "parent_dup2.", Expected = "top_level" },
            };

            var analyzer = new JsAnalyzer();

            Dictionary <string, IJsProjectEntry> entries = new Dictionary <string, IJsProjectEntry>();
            var basePath = TestData.GetPath("TestData\\RequireTestApp\\RequireTestApp");

            foreach (var file in Directory.GetFiles(
                         basePath,
                         "*.js",
                         SearchOption.AllDirectories
                         ))
            {
                var entry = analyzer.AddModule(file, null);

                entries[file.Substring(basePath.Length + 1)] = entry;

                Analysis.Prepare(entry, new StreamReader(file));
            }
            var serializer = new JavaScriptSerializer();

            foreach (var file in Directory.GetFiles(
                         basePath,
                         "package.json",
                         SearchOption.AllDirectories
                         ))
            {
                var    packageJson = serializer.Deserialize <Dictionary <string, string> >(File.ReadAllText(file));
                string mainFile;
                if (packageJson.TryGetValue("main", out mainFile))
                {
                    analyzer.AddPackageJson(file, mainFile);
                }
            }

            foreach (var entry in entries)
            {
                entry.Value.Analyze(CancellationToken.None);
            }
            foreach (var testCase in testCases)
            {
                Console.WriteLine(testCase);
                var analysis = entries[testCase.File].Analysis;
                var allText  = File.ReadAllText(entries[testCase.File].FilePath);
                int offset   = 0;
                for (int i = 1; i < testCase.Line; i++)
                {
                    offset = allText.IndexOf("\r\n", offset);
                    if (offset == -1)
                    {
                        System.Diagnostics.Debug.Fail("failed to find line");
                    }
                    offset += 2;
                }
                var members = analysis.GetMembersByIndex(
                    testCase.Type.Substring(0, testCase.Type.Length - 1),
                    offset
                    ).Select(x => x.Name).ToSet();

                if (testCase.Expected == null)
                {
                    Assert.AreEqual(0, members.Count);
                }
                else
                {
                    Assert.IsTrue(members.Contains(testCase.Expected));
                }
            }
        }
 public override IAnalysisSet GetReturnValue(JsAnalyzer analyzer) {
     return analyzer._emptyStringValue.SelfSet;
 }
Ejemplo n.º 17
0
 public NumberValue(double p, JsAnalyzer analyzer)
     : base(analyzer._builtinEntry) {
     _value = p;
     _analyzer = analyzer;
     analyzer.AnalysisValueCreated(typeof(NumberValue));
 }
Ejemplo n.º 18
0
 private GlobalBuilder(JsAnalyzer analyzer) {
     _analyzer = analyzer;
 }
Ejemplo n.º 19
0
 public UndefinedValue(JsAnalyzer analyzer)
     : base(analyzer._builtinEntry) {
 }
        public void RequireNonRelativePackageJson() {
            var analyzer = new JsAnalyzer();
            var mod = @"var x = require('./rec1')";
            var myindex = @"exports.abc = 100;";
            analyzer.AddPackageJson("rec1\\package.json", "lib/myindex.js");

            var sourceUnit = Analysis.GetSourceUnit(mod);
            var myindexSourceUnit = Analysis.GetSourceUnit(myindex);
            var entry = analyzer.AddModule("one.js", null);
            var myindexEntry = analyzer.AddModule("rec1\\lib\\myindex.js", null);
            Analysis.Prepare(entry, sourceUnit);
            Analysis.Prepare(myindexEntry, myindexSourceUnit);

            entry.Analyze(CancellationToken.None);
            myindexEntry.Analyze(CancellationToken.None);

            AssertUtil.ContainsExactly(
                entry.Analysis.GetTypeIdsByIndex("x.abc", 0),
                BuiltinTypeId.Number
            );
        }
        public void BadRequire() {
            // foo.js
            //      require('./rec1')
            // rec1\
            //      package.json
            //          { "main": "../rec2" }
            // rec2\
            //      package.json
            //          { "main": "../rec1" }

            var analyzer = new JsAnalyzer();
            var mod = @"var x = require('./rec1')";
            analyzer.AddPackageJson("rec1\\package.json", "../rec2");
            analyzer.AddPackageJson("rec2\\package.json", "../rec1");

            var sourceUnit = Analysis.GetSourceUnit(mod);
            var entry = analyzer.AddModule("one.js", null);
            Analysis.Prepare(entry, sourceUnit);

            entry.Analyze(CancellationToken.None);

            Assert.AreEqual(
                0,
                entry.Analysis.GetTypeIdsByIndex("x", 0).Count()
            );
        }
Ejemplo n.º 22
0
 private static bool IsVisible(JsAnalyzer analyzer, string from, string to)
 {
     return(((ProjectEntry)analyzer[from])._visibleEntries.Contains(
                analyzer[to]
                ));
 }
 public abstract IAnalysisSet GetReturnValue(JsAnalyzer analyzer);
Ejemplo n.º 24
0
 public NullValue(JsAnalyzer analyzer)
     : base(analyzer._builtinEntry) {
     _analyzer = analyzer;
 }
Ejemplo n.º 25
0
 private void CreateNewAnalyzer(AnalysisLimits limits) {
     _jsAnalyzer = new JsAnalyzer(limits);
     if (_analysisLevel != AnalysisLevel.None) {
         _analysisQueue = new AnalysisQueue(this);
     }
     _fullyLoaded = true;
 }
        public static string DumpAnalysis(JsAnalyzer analyzer) {
            var entries = analyzer.AllModules.ToArray();
            Array.Sort(entries, (x, y) => String.Compare(x.FilePath, y.FilePath));
            StringBuilder analysis = new StringBuilder();
            foreach (var entry in entries) {
                if (entry.Analysis != null) {
                    analysis.AppendLine(entry.Analysis.Dump());
                }
            }

            return analysis.ToString();
        }
 private static bool IsVisible(JsAnalyzer analyzer, string from, string to) {
     return ((ProjectEntry)analyzer[from])._visibleEntries.Contains(
         analyzer[to]
     );
 }
        public void RequireNodeModules() {
            var mod1 = @"exports.foo = 42;";
            var mod2 = @"x = require('one.js').foo";

            var sourceUnit1 = Analysis.GetSourceUnit(mod1);
            var sourceUnit2 = Analysis.GetSourceUnit(mod2);
            var state = new JsAnalyzer();
            var entry1 = state.AddModule("node_modules\\one.js", null);
            var entry2 = state.AddModule("two.js", null);
            Analysis.Prepare(entry1, sourceUnit1);
            Analysis.Prepare(entry2, sourceUnit2);

            entry1.Analyze(CancellationToken.None);
            entry2.Analyze(CancellationToken.None);

            AssertUtil.ContainsExactly(
                entry2.Analysis.GetTypeIdsByIndex("x", mod2.Length),
                BuiltinTypeId.Number
            );
        }
Ejemplo n.º 29
0
        public void BasicTest()
        {
            var analyzer = new JsAnalyzer();

            RoundTrip(analyzer);
        }
        public void Require() {
            var testCases = new[] {
                new { File="server.js", Line = 4, Type = "mymod.", Expected = "mymod_export" },
                new { File="server.js", Line = 8, Type = "mymod2.", Expected = "mymod_export" },
                new { File="server.js", Line = 12, Type = "mymod3.", Expected = (string)null },
                new { File="server.js", Line = 19, Type = "foo.", Expected = "foo_export" },
                new { File="server.js", Line = 22, Type = "bar.", Expected = "bar_entry" },
                new { File="server.js", Line = 25, Type = "bar2.", Expected = "bar2_entry" },
                new { File="server.js", Line = 28, Type = "dup.", Expected = "node_modules_dup" },
                new { File="server.js", Line = 31, Type = "dup1.", Expected = "top_level" },
                new { File="server.js", Line = 34, Type = "dup2.", Expected = "top_level" },
                new { File="server.js", Line = 37, Type = "baz_dup.", Expected = "baz_dup" },
                new { File="server.js", Line = 40, Type = "baz_dup2.", Expected = "baz_dup" },
                new { File="server.js", Line = 42, Type = "recursive.", Expected = "recursive1" },
                new { File="server.js", Line = 42, Type = "recursive.", Expected = "recursive2" },
                new { File="server.js", Line = 48, Type = "nested.", Expected = (string)null },
                new { File="server.js", Line = 54, Type = "indexfolder.", Expected = "indexfolder" },
                new { File="server.js", Line = 56, Type = "indexfolder2.", Expected = "indexfolder" },
                // TODO: Requires require('path').resolve('./indexfolder') to work
                //new { File="server.js", Line = 60, Type = "resolve_path.", Expected = "indexfolder" },

                new { File="node_modules\\mymod.js", Line = 5, Type = "dup.", Expected = "node_modules_dup" },
                new { File="node_modules\\mymod.js", Line = 8, Type = "dup0.", Expected = "node_modules_dup" },
                new { File="node_modules\\mymod.js", Line = 11, Type = "dup1.", Expected = "node_modules_dup" },
                new { File="node_modules\\mymod.js", Line = 14, Type = "dup2.", Expected = "node_modules_dup" },
                new { File="node_modules\\mymod.js", Line = 17, Type = "dup3.", Expected = "dup" },

                new { File="node_modules\\foo\\index.js", Line = 5, Type = "dup.", Expected = "foo_node_modules" },
                new { File="node_modules\\foo\\index.js", Line = 8, Type = "dup1.", Expected = "dup" },
                new { File="node_modules\\foo\\index.js", Line = 11, Type = "dup2.", Expected = "dup" },
                new { File="node_modules\\foo\\index.js", Line = 14, Type = "other.", Expected = "other" },
                new { File="node_modules\\foo\\index.js", Line = 17, Type = "other2.", Expected = "other" },
                new { File="node_modules\\foo\\index.js", Line = 20, Type = "other3.", Expected = (string)null },
                new { File="node_modules\\foo\\index.js", Line = 27, Type = "other4.", Expected = (string)null },

                new { File="baz\\dup.js", Line = 3, Type = "parent_dup.", Expected = "top_level" },
                new { File="baz\\dup.js", Line = 6, Type = "bar.", Expected = "bar_entry" },
                new { File="baz\\dup.js", Line = 9, Type = "parent_dup2.", Expected = "top_level" },
            };

            var analyzer = new JsAnalyzer();

            Dictionary<string, IJsProjectEntry> entries = new Dictionary<string, IJsProjectEntry>();
            var basePath = TestData.GetPath("TestData\\RequireTestApp\\RequireTestApp");
            foreach (var file in Directory.GetFiles(
                basePath,
                "*.js",
                SearchOption.AllDirectories
            )) {
                var entry = analyzer.AddModule(file, null);

                entries[file.Substring(basePath.Length + 1)] = entry;

                Analysis.Prepare(entry, new StreamReader(file));
            }
            var serializer = new JavaScriptSerializer();
            foreach (var file in Directory.GetFiles(
                basePath,
                "package.json",
                SearchOption.AllDirectories
            )) {
                var packageJson = serializer.Deserialize<Dictionary<string, string>>(File.ReadAllText(file));
                string mainFile;
                if (packageJson.TryGetValue("main", out mainFile)) {
                    analyzer.AddPackageJson(file, mainFile);
                }
            }

            foreach (var entry in entries) {
                entry.Value.Analyze(CancellationToken.None);
            }
            foreach (var testCase in testCases) {
                Console.WriteLine(testCase);
                var analysis = entries[testCase.File].Analysis;
                var allText = File.ReadAllText(entries[testCase.File].FilePath);
                int offset = 0;
                for (int i = 1; i < testCase.Line; i++) {
                    offset = allText.IndexOf("\r\n", offset);
                    if (offset == -1) {
                        System.Diagnostics.Debug.Fail("failed to find line");
                    }
                    offset += 2;
                }
                var members = analysis.GetMembersByIndex(
                    testCase.Type.Substring(0, testCase.Type.Length - 1),
                    offset
                ).Select(x => x.Name).ToSet();

                if (testCase.Expected == null) {
                    Assert.AreEqual(0, members.Count);
                } else {
                    Assert.IsTrue(members.Contains(testCase.Expected));
                }
            }
        }
Ejemplo n.º 31
0
 public static Globals MakeGlobal(JsAnalyzer analyzer) {
     return new GlobalBuilder(analyzer).MakeGlobal();
 }
Ejemplo n.º 32
0
 public DDG(JsAnalyzer analyzer)
 {
     _analyzer = analyzer;
 }
Ejemplo n.º 33
0
        internal static ModuleAnalysis ProcessOneText(string text) {
            var sourceUnit = Analysis.GetSourceUnit(text);
            var state = new JsAnalyzer();
            var entry = state.AddModule("fob.js", null);
            Analysis.Prepare(entry, sourceUnit);
            entry.Analyze(CancellationToken.None);

            return entry.Analysis;
        }
Ejemplo n.º 34
0
 private void CreateNewAnalyzer(AnalysisLimits limits) {
     _jsAnalyzer = new JsAnalyzer(limits);
     if (ShouldEnqueue()) {
         _analysisQueue = new AnalysisQueue(this);
     }
     _fullyLoaded = true;
 }
Ejemplo n.º 35
0
 public UndefinedValue(JsAnalyzer analyzer)
     : base(analyzer._builtinEntry)
 {
 }
Ejemplo n.º 36
0
 public NullValue(JsAnalyzer analyzer)
     : base(analyzer._builtinEntry)
 {
     _analyzer = analyzer;
 }
Ejemplo n.º 37
0
 public BooleanValue(bool value, JsAnalyzer javaScriptAnalyzer)
     : base(javaScriptAnalyzer._builtinEntry) {
     _value = value;
     _analyzer = javaScriptAnalyzer;
     javaScriptAnalyzer.AnalysisValueCreated(typeof(BooleanValue));
 }
        private bool LoadCachedAnalysis(AnalysisLimits limits) {
            if (_analysisLevel == AnalysisLevel.NodeLsNone || _analysisLevel == AnalysisLevel.Preview) {
                return false;
            }

            string analysisDb = GetAnalysisPath();
            if (File.Exists(analysisDb) && ShouldEnqueue()) {
                FileStream stream = null;
                bool disposeStream = true;
                try {
                    stream = new FileStream(analysisDb, FileMode.Open);
                    byte[] header = new byte[DbHeader.Length];
                    stream.Read(header, 0, header.Length);
                    if (DbHeader.SequenceEqual(header)) {
                        var statusbar = (IVsStatusbar)NodejsPackage.GetGlobalService(typeof(SVsStatusbar));
                        if (statusbar != null) {
                            statusbar.SetText(SR.GetString(SR.StatusAnalysisLoading));
                        }

                        Task.Run(() => {
                            try {
                                using (new DebugTimer("LoadAnalysis")) {
                                    var serializer = new AnalysisSerializer();
                                    var analyzer = (JsAnalyzer)serializer.Deserialize(stream);
                                    AnalysisQueue queue;
                                    if (analyzer.Limits.Equals(limits)) {
                                        queue = new AnalysisQueue(this);
                                        foreach (var entry in analyzer.AllModules) {
                                            _projectFiles[entry.FilePath] = new ProjectItem(entry);
                                        }
                                        _reparseDateTime = new FileInfo(analysisDb).LastWriteTime;

                                        _analysisQueue = queue;
                                        _jsAnalyzer = analyzer;

                                        if (statusbar != null) {
                                            statusbar.SetText(SR.GetString(SR.StatusAnalysisLoaded));
                                        }
                                    }
                                }
                            } catch (InvalidOperationException) {
                                // corrupt or invalid DB
                                if (statusbar != null) {
                                    statusbar.SetText(SR.GetString(SR.StatusAnalysisLoadFailed));
                                }
                            } catch (Exception e) {
                                Debug.Fail(String.Format("Unexpected exception while loading analysis: {0}", e));
                                // bug in deserialization
                                if (statusbar != null) {
                                    statusbar.SetText(SR.GetString(SR.StatusAnalysisLoadFailed));
                                }
                            } finally {
                                stream.Dispose();

                                // apply any changes 
                                lock (_loadingDeltas) {
                                    if (_jsAnalyzer == null) {
                                        // we failed to load the cached analysis, create a new
                                        // analyzer now...
                                        CreateNewAnalyzer(LoadLimits());
                                    }

                                    _fullyLoaded = true;
                                    foreach (var delta in _loadingDeltas) {
                                        delta();
                                    }
                                }
                            }
                        }).HandleAllExceptions(SR.GetString(SR.NodejsToolsForVisualStudio)).DoNotWait();
                        disposeStream = false;
                        return true;
                    }
                } catch (IOException) {
                } finally {
                    if (stream != null && disposeStream) {
                        stream.Dispose();
                    }
                }
            }
            return false;
        }
Ejemplo n.º 39
0
        private static ProjectEntry CreateProjectEntry()
        {
            var analyzer = new JsAnalyzer();

            return((ProjectEntry)analyzer.AddModule("test.js"));
        }
 private void CreateNewAnalyzer(AnalysisLimits limits) {
     if (_analysisLevel == AnalysisLevel.NodeLsNone || _analysisLevel == AnalysisLevel.Preview) {
         return;
     }
     _jsAnalyzer = new JsAnalyzer(limits);
     if (ShouldEnqueue()) {
         _analysisQueue = new AnalysisQueue(this);
     }
     _fullyLoaded = true;
 }
Ejemplo n.º 41
0
 public StringValue(string value, JsAnalyzer javaScriptAnalyzer)
     : base(javaScriptAnalyzer._builtinEntry) {
     _value = value;
     _analyzer = javaScriptAnalyzer;
     javaScriptAnalyzer.AnalysisValueCreated(typeof(StringValue));
 }
 private static void AssertIsNotVisible(JsAnalyzer analyzer, string from, string to) {
     Assert.IsFalse(
         IsVisible(analyzer, from, to),
         String.Format("{0} can see {1}", from, to)
     );
 }
 public static void Build(string filename, JsAnalyzer analyzer) {
     new NodejsModuleBuilder(filename, analyzer).Build();
 }
 public override IAnalysisSet GetReturnValue(JsAnalyzer analyzer) {
     return analyzer._trueInst.SelfSet;
 }