();
25 | }
26 |
27 | ///
28 | /// Get the IsEmpty flag. If so then result is empty - probably service returned empty result when there is not need to update previous.
29 | ///
30 | public bool IsEmpty
31 | {
32 | get { return string.IsNullOrEmpty(FileName); }
33 | }
34 | }
35 |
36 | public class ErrorMessage
37 | {
38 | public string Message { get; set; }
39 |
40 | public int StartLine { get; set; }
41 |
42 | public int StartColumn { get; set; }
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/source/JsParser.Test/Parser/ExpectedResult/HtmlScriptBlocks.txt:
--------------------------------------------------------------------------------
1 | Alias: All
2 | StartLine: 0
3 | EndLine: 0
4 | NodeType: Function
5 |
6 | Alias: Function_In_The_Head(param1,param2)
7 | StartLine: 8
8 | EndLine: 11
9 | NodeType: Function
10 | Comment: This is the function in the head
11 |
12 | Alias: DefaultScriptFunction()
13 | StartLine: 19
14 | EndLine: 21
15 | NodeType: Function
16 | Comment: script without type considered as javascript
17 |
18 | Alias: Function_In_The_Javascript(param1,param2)
19 | StartLine: 29
20 | EndLine: 33
21 | NodeType: Function
22 |
23 | Alias: Function_In_The_Bottom(param1,param2)
24 | StartLine: 44
25 | EndLine: 47
26 | NodeType: Function
27 | Comment: This is the function in the bottomD;A;TODO: Not forget to remove this hack!
28 |
29 | Alias: Class1(param1,param2)
30 | StartLine: 50
31 | EndLine: 74
32 | NodeType: Function
33 | Comment: This is another sample of JS class
34 |
35 | Alias: Method1()
36 | StartLine: 57
37 | EndLine: 59
38 | NodeType: Function
39 | Comment: This is First method
40 |
41 | Alias: Method2(param1)
42 | StartLine: 62
43 | EndLine: 64
44 | NodeType: Function
45 | Comment: This is Second method
46 |
47 | Alias: Method3(param1,param2)
48 | StartLine: 67
49 | EndLine: 73
50 | NodeType: Function
51 | Comment: This is Third method
52 |
53 | Alias: delegate()
54 | StartLine: 70
55 | EndLine: 72
56 | NodeType: Function
57 | Comment: delegate method
58 |
59 |
--------------------------------------------------------------------------------
/source/JsParser.Test/Parser/JSParserTests_Frameworks.cs:
--------------------------------------------------------------------------------
1 | using NUnit.Framework;
2 |
3 | namespace JsParser.Test.Parser
4 | {
5 | [TestFixture]
6 | public class JsParserTests_Frameworks
7 | {
8 | [Test]
9 | public void Frameworks_JustHeavyLoadTest_JQuery()
10 | {
11 | for (var i = 0; i < 10; i++)
12 | {
13 | Frameworks_JQuery();
14 | }
15 | }
16 |
17 | [Test]
18 | public void Frameworks_JQuery()
19 | {
20 | TestRunner.RunTest("Frameworks.jquery-2.1.4.js", "Frameworks.jquery-2.1.4.txt");
21 | }
22 |
23 | [Test]
24 | public void Frameworks_Angular()
25 | {
26 | TestRunner.RunTest("Frameworks.angular_v1.4.0-rc.2.js", "Frameworks.angular_v1.4.0-rc.2.txt");
27 | }
28 |
29 | [Test]
30 | public void Frameworks_UiBootstrap()
31 | {
32 | TestRunner.RunTest("Frameworks.ui-bootstrap-tpls-0.13.0.js", "Frameworks.ui-bootstrap-tpls-0.13.0.txt");
33 | }
34 |
35 | [Test]
36 | public void Frameworks_Knockout()
37 | {
38 | TestRunner.RunTest("Frameworks.knockout-3.3.0.debug.js", "Frameworks.knockout-3.3.0.debug.txt");
39 | }
40 |
41 | [Test]
42 | public void Frameworks_Bootstrap()
43 | {
44 | TestRunner.RunTest("Frameworks.bootstrap.js", "Frameworks.bootstrap.txt");
45 | }
46 |
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/source/JsParser.Test/Parser/Source/Test_ReservedWords_Goto.js:
--------------------------------------------------------------------------------
1 |
2 | Pen = function (tag) {
3 | this.dir = -90;
4 | this.x = 0;
5 | this.y = 0;
6 |
7 | this.tag = document.getElementById(tag) || tag;
8 |
9 | this.canvas = this.tag.getContext("2d");
10 | this.strokeStyle = this.canvas.strokeStyle = "#000";
11 | this.lineWidth = this.canvas.lineWidth = 1;
12 | this.fillStyle = this.canvas.fillStyle = "";
13 |
14 | this.ox = 0;
15 | this.oy = 0;
16 |
17 | this.pen = true;
18 |
19 | this.canvas.clearRect(0, 0, this.tag.width, this.tag.height);
20 | var w = this.tag.width;
21 | this.tag.width = 1;
22 | this.tag.width = w;
23 |
24 | this.canvas.beginPath();
25 | };
26 | Pen.prototype = {
27 | height: function () {
28 | return this.tag.height;
29 | },
30 |
31 | goto: function (x, y) {
32 | this.x = x;
33 | this.y = y;
34 |
35 | if (!this.pen)
36 | this.canvas.moveTo(x, y);
37 | else
38 | this.canvas.lineTo(x, y);
39 |
40 | return this;
41 | },
42 |
43 | jump: function (x, y) {
44 | this.canvas.beginPath();
45 |
46 | var p = this.pen;
47 | this.pen = true;
48 | this.goto(x, y);
49 | this.pen = p;
50 |
51 | return this;
52 | },
53 |
54 | height: function () {
55 | return this.tag.height;
56 | },
57 |
58 | center: function () {
59 | return this.goto(this.width() / 2, this.height() / 2);
60 | }
61 | };
--------------------------------------------------------------------------------
/source/Jint.Parser/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.InteropServices;
3 |
4 | // General Information about an assembly is controlled through the following
5 | // set of attributes. Change these attribute values to modify the information
6 | // associated with an assembly.
7 | [assembly: AssemblyTitle("Jint.Parser")]
8 | [assembly: AssemblyDescription("")]
9 | [assembly: AssemblyConfiguration("")]
10 | [assembly: AssemblyCompany("")]
11 | [assembly: AssemblyProduct("Jint.Parser")]
12 | [assembly: AssemblyCopyright("Copyright © 2015")]
13 | [assembly: AssemblyTrademark("")]
14 | [assembly: AssemblyCulture("")]
15 |
16 | // Setting ComVisible to false makes the types in this assembly not visible
17 | // to COM components. If you need to access a type in this assembly from
18 | // COM, set the ComVisible attribute to true on that type.
19 | [assembly: ComVisible(false)]
20 |
21 | // The following GUID is for the ID of the typelib if this project is exposed to COM
22 | [assembly: Guid("e34fe255-d28c-42af-8c66-3656e8cf6af9")]
23 |
24 | // Version information for an assembly consists of the following four values:
25 | //
26 | // Major Version
27 | // Minor Version
28 | // Build Number
29 | // Revision
30 | //
31 | // You can specify all the values or you can default the Build and Revision Numbers
32 | // by using the '*' as shown below:
33 | // [assembly: AssemblyVersion("1.0.*")]
34 | [assembly: AssemblyVersion("1.0.0.0")]
35 | [assembly: AssemblyFileVersion("1.0.0.0")]
36 |
--------------------------------------------------------------------------------
/source/JsParser.Test/Parser/Source/Test_RazorSyntax.cshtml:
--------------------------------------------------------------------------------
1 | @using Newtonsoft.Json
2 | @model PageModel_Test
3 | @{
4 | ViewBag.Title = Model.Title;
5 | }
6 |
7 | @section head
8 | {
9 |
10 |
13 | }
14 |
15 | @ViewBag.Title
16 |
17 |
18 | Content goes here...
19 |
20 |
21 | @section scripts
22 | {
23 |
24 |
25 |
26 |
27 |
28 |
50 | }
--------------------------------------------------------------------------------
/source/JsParser.UI/Helpers/ExpandedNodesManager.cs:
--------------------------------------------------------------------------------
1 | using JsParser.UI.UI;
2 | using System.Collections.Generic;
3 |
4 | namespace JsParser.UI.Helpers
5 | {
6 | class ExpandedNodesManager
7 | {
8 | private Dictionary> _storage = new Dictionary>();
9 | private string _activeDocName;
10 | private Dictionary _activeStorage;
11 |
12 | public void SetFile(string activeDocumentName )
13 | {
14 | _activeDocName = activeDocumentName;
15 | if (!HasDocumentInStorage(_activeDocName))
16 | {
17 | _storage.Add(_activeDocName, new Dictionary());
18 | }
19 |
20 | _activeStorage = _storage[_activeDocName];
21 | }
22 |
23 | public bool HasDocumentInStorage(string docName)
24 | {
25 | return _storage.ContainsKey(docName);
26 | }
27 |
28 | public Dictionary ActiveStorage
29 | {
30 | get
31 | {
32 | return _activeStorage;
33 | }
34 | }
35 |
36 | public bool? IsNoteExpanded(CustomTreeNode node)
37 | {
38 | var storage = ActiveStorage;
39 | var nodeKey = GetNodeKey(node);
40 | if (storage.ContainsKey(nodeKey))
41 | {
42 | return storage[nodeKey];
43 | }
44 |
45 | return null;
46 | }
47 |
48 | public void SetExpandedState(CustomTreeNode node)
49 | {
50 | ActiveStorage[GetNodeKey(node)] = node.IsExpanded;
51 | }
52 |
53 | private string GetNodeKey(CustomTreeNode node)
54 | {
55 | return node.CodeNode.StartLine + "_(" + node.Text + ")";
56 | }
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/source/JsParser.NppPlugin/Helpers/TimerHelper.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Threading;
4 |
5 | namespace JsMapParser.NppPlugin.Helpers
6 | {
7 | public static class TimerHelper
8 | {
9 | ///
10 | /// Storage to keep references to timer objects. We need them to call dispose later and Garbage Collector will not dispose any timers in meantime
11 | ///
12 | private static readonly Dictionary timerReferences = new Dictionary();
13 |
14 | ///
15 | /// Creates timer to execute action after delay only once
16 | ///
17 | ///
18 | ///
19 | public static Guid SetTimeOut(Action action, TimeSpan delay)
20 | {
21 | lock (timerReferences)
22 | {
23 | var timerId = Guid.NewGuid();
24 | var timer = new Timer(_ =>
25 | {
26 | action();
27 | Timer timerInstance;
28 | if (timerReferences.TryGetValue(timerId, out timerInstance))
29 | {
30 | timerInstance.Dispose();
31 | timerReferences.Remove(timerId);
32 | }
33 | }, null, delay, TimeSpan.FromMilliseconds(-1));
34 | timerReferences[timerId] = timer;
35 | return timerId;
36 | }
37 | }
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/source/Jint.Parser/Ast/UnaryExpression.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace Jint.Parser.Ast
4 | {
5 | public enum UnaryOperator
6 | {
7 | Plus,
8 | Minus,
9 | BitwiseNot,
10 | LogicalNot,
11 | Delete,
12 | Void,
13 | TypeOf,
14 | Increment,
15 | Decrement,
16 | }
17 |
18 | public class UnaryExpression : Expression
19 | {
20 | public UnaryOperator Operator;
21 | public Expression Argument;
22 | public bool Prefix;
23 |
24 | public static UnaryOperator ParseUnaryOperator(string op)
25 | {
26 | switch (op)
27 | {
28 | case "+":
29 | return UnaryOperator.Plus;
30 | case "-":
31 | return UnaryOperator.Minus;
32 | case "++":
33 | return UnaryOperator.Increment;
34 | case "--":
35 | return UnaryOperator.Decrement;
36 | case "~":
37 | return UnaryOperator.BitwiseNot;
38 | case "!":
39 | return UnaryOperator.LogicalNot;
40 | case "delete":
41 | return UnaryOperator.Delete;
42 | case "void":
43 | return UnaryOperator.Void;
44 | case "typeof":
45 | return UnaryOperator.TypeOf;
46 |
47 | default:
48 | throw new ArgumentOutOfRangeException("Invalid unary operator: " + op);
49 |
50 | }
51 | }
52 | }
53 | }
--------------------------------------------------------------------------------
/source/JsParser.VsExtension/UI/ErrorsNotificationControl.xaml:
--------------------------------------------------------------------------------
1 |
8 |
9 |
10 |
15 |
17 |
27 |
28 |
29 |
30 |
--------------------------------------------------------------------------------
/source/JsParser.Core/Parsers/TaskListAggregator.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 |
5 | namespace JsParser.Core.Parsers
6 | {
7 | public static class TaskListAggregator
8 | {
9 | public static IEnumerable GetTaskList(IEnumerable comments, IEnumerable todokeywords)
10 | {
11 | return comments.
12 | Select(c => {
13 | foreach (var kw in todokeywords)
14 | {
15 | var todoIndex = c.Spelling.IndexOf(kw, StringComparison.InvariantCultureIgnoreCase);
16 | if (todoIndex >= 0)
17 | {
18 | var todoClause = c.Spelling.Substring(todoIndex);
19 | var endIndex = todoClause.IndexOfAny(new[] { '\r', '\n' });
20 | if (endIndex >= 0)
21 | {
22 | todoClause = todoClause.Substring(0, endIndex);
23 | }
24 |
25 | return new TaskListItem
26 | {
27 | Description = todoClause,
28 | StartLine = c.StartLine,
29 | StartColumn = 0
30 | };
31 | }
32 | }
33 |
34 | return null;
35 | })
36 | .Where(c => c != null);
37 | }
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/source/JsParser.Core/Helpers/HierarchyComparer.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 |
3 | namespace JsParser.Core.Helpers
4 | {
5 | public static class HierarchyComparer
6 | {
7 | ///
8 | /// Compares two hierarchies
9 | ///
10 | /// Type of hierarchy item
11 | /// One hierarchy
12 | /// Other hierarchy
13 | /// True if equals, false otherwise
14 | public static bool Compare(Hierarchy one, Hierarchy other, IComparer comparer)
15 | {
16 | if (one == null || other == null)
17 | {
18 | return false;
19 | }
20 |
21 | if (comparer.Compare(one.Item, other.Item) != 0)
22 | {
23 | return false;
24 | }
25 |
26 | int oneCount = one.Children != null ? one.Children.Count : 0;
27 | int otherCount = other.Children != null ? other.Children.Count : 0;
28 |
29 | if (oneCount == 0 && otherCount == 0)
30 | {
31 | return true;
32 | }
33 |
34 | if (oneCount != otherCount)
35 | {
36 | return false;
37 | }
38 |
39 | for (int index = 0; index < oneCount; ++index)
40 | {
41 | if (!HierarchyComparer.Compare(one.Children[index], other.Children[index], comparer))
42 | {
43 | return false;
44 | }
45 | }
46 |
47 | return true;
48 | }
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/source/JsParser.NppPlugin/DllExport/NppPlugin.DllExport.targets:
--------------------------------------------------------------------------------
1 |
3 |
5 |
8 |
9 |
11 | $(DevEnvDir)\..\..\VC\bin
12 |
13 |
28 |
29 |
30 |
--------------------------------------------------------------------------------
/source/JsParser.NppPlugin/NppCodeProvider.cs:
--------------------------------------------------------------------------------
1 | using JsParser.Core.Code;
2 | using System;
3 | using System.IO;
4 |
5 | namespace JsMapParser.NppPlugin
6 | {
7 | internal class NppCodeProvider : ICodeProvider
8 | {
9 | private JsMapParserPlugin _plugin;
10 |
11 | public string Path { get; private set; }
12 | public string Name { get; private set; }
13 | public string FullName { get; private set; }
14 | public string ContainerName { get; set; }
15 |
16 | public NppCodeProvider(JsMapParserPlugin plugin, string fileName)
17 | {
18 | _plugin = plugin;
19 |
20 | FullName = fileName;
21 | Path = System.IO.Path.GetDirectoryName(fileName);
22 | Name = System.IO.Path.GetFileName(fileName);
23 |
24 | ContainerName = "Notepad++ " + _plugin.GetNppVersion();
25 | }
26 |
27 | public string LoadCode()
28 | {
29 | try
30 | {
31 | return File.ReadAllText(FullName);
32 | }
33 | catch (Exception)
34 | {
35 | return "function Failed_To_Load_File(){};";
36 | }
37 | }
38 |
39 | public void SelectionMoveToLineAndOffset(int startLine, int startColumn)
40 | {
41 | _plugin.GoToPosition(startLine, startColumn);
42 | }
43 |
44 | public void SetFocus()
45 | {
46 | _plugin.SetFocus();
47 | }
48 |
49 | public void GetCursorPos(out int line, out int column)
50 | {
51 | _plugin.GetCursorPos(out line, out column);
52 | }
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/source/JsParser.UI/UI/CustomTreeView.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.ComponentModel;
3 | using System.Windows.Forms;
4 |
5 | namespace JsParser.UI.UI
6 | {
7 | public class CustomTreeView : TreeView
8 | {
9 | private const int WM_HSCROL = 0x114;
10 | private const int WM_VSCROLL = 0x115;
11 | private const int WM_MOUSEWHEEL = 0x20A;
12 |
13 | public enum ScrollType
14 | {
15 | Vertical,
16 | Horizontal
17 | }
18 |
19 | public class ScrollEventArgs: EventArgs
20 | {
21 | public ScrollType ScrollType{get;set;}
22 | }
23 |
24 | public delegate void ScrollEventHandler(object sender, ScrollEventArgs e);
25 |
26 | [Description("UserControlOnLoadDescr")]
27 | [Category("CatBehavior")]
28 | public event ScrollEventHandler OnScroll;
29 |
30 | public CustomTreeView()
31 | : base()
32 | {
33 | SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
34 | }
35 |
36 | protected override void WndProc(ref Message m)
37 | {
38 | var scrollType = ScrollType.Vertical;
39 | switch (m.Msg)
40 | {
41 | case WM_HSCROL:
42 | scrollType = ScrollType.Horizontal;
43 | goto action;
44 | case WM_MOUSEWHEEL:
45 | case WM_VSCROLL:
46 | action:;
47 | OnScroll.Invoke(
48 | this,
49 | new ScrollEventArgs { ScrollType = scrollType });
50 | break;
51 | }
52 |
53 | base.WndProc(ref m);
54 | }
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/source/JsParser.Core/Parsers/ParserContext.cs:
--------------------------------------------------------------------------------
1 | using JsParser.Core.Code;
2 | using JsParser.Core.Helpers;
3 | using System.Collections.Generic;
4 | using System.Text;
5 |
6 | namespace JsParser.Core.Parsers
7 | {
8 | public class ParserContext
9 | {
10 | public ParserContext(ParserContext context, bool copyNames = false)
11 | :this(context.Nodes)
12 | {
13 | if (copyNames)
14 | {
15 | NameStack.AddRange(context.NameStack);
16 | }
17 | }
18 |
19 | public ParserContext(Hierarchy nodes)
20 | {
21 | Nodes = nodes;
22 | NameStack = new List();
23 | }
24 |
25 | public Hierarchy Nodes { get; set; }
26 |
27 | public List NameStack { get; set; }
28 |
29 | public string GetNameFromStack()
30 | {
31 | if (NameStack != null && NameStack.Count > 0)
32 | {
33 | if (NameStack.Count == 1)
34 | {
35 | return NameStack[0];
36 | }
37 |
38 | var sb = new StringBuilder();
39 | for (var i = NameStack.Count - 1; i > 0; i--)
40 | {
41 | sb.Append(NameStack[i]);
42 | if (NameStack[i - 1] == "?")
43 | {
44 | sb.Append(">");
45 | }
46 | else
47 | {
48 | sb.Append(".");
49 | }
50 | }
51 |
52 | sb.Append(NameStack[0]);
53 | return sb.ToString();
54 | }
55 | else
56 | {
57 | return "?";
58 | }
59 | }
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/source/JsParser.Test/Helpers/StringExtText.cs:
--------------------------------------------------------------------------------
1 | using JsParser.Core.Parsers;
2 | using NUnit.Framework;
3 | using System.Diagnostics;
4 |
5 | namespace JsParserTest.Helpers
6 | {
7 | [TestFixture]
8 | public class StringExtText
9 | {
10 | [Test]
11 | public void TestShortenize()
12 | {
13 | RunSample("string", 6, 6);
14 | RunSample("string", 5, 5);
15 | RunSample("string", 4, 4);
16 | RunSample("string", 3, 3);
17 | RunSample("string", 2, 2);
18 | RunSample("string", 1, 1);
19 | RunSample("string", 0, 0);
20 | RunSample("string", -1, 0);
21 | }
22 |
23 | private void RunSample(string s, int targetLen, int expectedLen)
24 | {
25 | var r = s.Shortenize(targetLen);
26 | Trace.WriteLine(s + " => " + r);
27 | Assert.AreEqual(expectedLen, r.Length);
28 | }
29 |
30 | private void TracingAssert(string expected, string actual)
31 | {
32 | Trace.WriteLine("Comparing `" + expected + "` and `" + actual + "`");
33 | Assert.AreEqual(expected, actual, "Not equal");
34 | }
35 |
36 | [Test]
37 | public void TestSplitWordsByCamelCase()
38 | {
39 | TracingAssert("This Words Should Be Separated", "ThisWordsShouldBeSeparated".SplitWordsByCamelCase());
40 | TracingAssert("", "".SplitWordsByCamelCase());
41 | string test = null;
42 | TracingAssert(null, test.SplitWordsByCamelCase());
43 | TracingAssert("1", "1".SplitWordsByCamelCase());
44 | TracingAssert("nothing", "nothing".SplitWordsByCamelCase());
45 | TracingAssert("A B C", "ABC".SplitWordsByCamelCase());
46 | TracingAssert("A", "A".SplitWordsByCamelCase());
47 | }
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/source/JsParser.Test/Parser/Source/HtmlScriptBlocks.htm:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Test 10
5 |
6 |
13 |
14 |
15 | This is the test HTM page
16 |
17 |
18 |
23 |
24 |
27 |
28 |
35 |
36 |
40 |
41 |
76 |
--------------------------------------------------------------------------------
/source/Jint.Parser/StringPrototype.cs:
--------------------------------------------------------------------------------
1 | namespace Jint.Native.String
2 | {
3 | ///
4 | /// http://www.ecma-international.org/ecma-262/5.1/#sec-15.5.4
5 | ///
6 | public sealed class StringPrototype
7 | {
8 | // http://msdn.microsoft.com/en-us/library/system.char.iswhitespace(v=vs.110).aspx
9 | // http://en.wikipedia.org/wiki/Byte_order_mark
10 | const char BOM_CHAR = '\uFEFF';
11 | const char MONGOLIAN_VOWEL_SEPARATOR = '\u180E';
12 |
13 | private static bool IsWhiteSpaceEx(char c)
14 | {
15 | return
16 | char.IsWhiteSpace(c) ||
17 | c == BOM_CHAR ||
18 | // In .NET 4.6 this was removed from WS based on Unicode 6.3 changes
19 | c == MONGOLIAN_VOWEL_SEPARATOR;
20 | }
21 |
22 | public static string TrimEndEx(string s)
23 | {
24 | if (s.Length == 0)
25 | return string.Empty;
26 |
27 | var i = s.Length - 1;
28 | while (i >= 0)
29 | {
30 | if (IsWhiteSpaceEx(s[i]))
31 | i--;
32 | else
33 | break;
34 | }
35 | if (i >= 0)
36 | return s.Substring(0, i + 1);
37 | else
38 | return string.Empty;
39 | }
40 |
41 | public static string TrimStartEx(string s)
42 | {
43 | if (s.Length == 0)
44 | return string.Empty;
45 |
46 | var i = 0;
47 | while (i < s.Length)
48 | {
49 | if (IsWhiteSpaceEx(s[i]))
50 | i++;
51 | else
52 | break;
53 | }
54 | if (i >= s.Length)
55 | return string.Empty;
56 | else
57 | return s.Substring(i);
58 | }
59 |
60 | public static string TrimEx(string s)
61 | {
62 | return TrimEndEx(TrimStartEx(s));
63 | }
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/source/JsParser.NppPlugin/JsMapParserPluginSettings.cs:
--------------------------------------------------------------------------------
1 | using fastJSON;
2 | using System.IO;
3 |
4 | namespace JsMapParser.NppPlugin
5 | {
6 | public class JsMapParserPluginSettings
7 | {
8 | private string _configPath;
9 |
10 | public bool ShowToolWindow { get; set; }
11 | public bool ToolWindowVisible { get; set; }
12 |
13 | public JsMapParserPluginSettings()
14 | {
15 | }
16 |
17 | private static string GetConfigFilePath(string configPath)
18 | {
19 | // if path doesn't exist, we create it
20 | if (!Directory.Exists(configPath))
21 | {
22 | Directory.CreateDirectory(configPath);
23 | }
24 | // make your file full file path name
25 | return Path.Combine(configPath, "JsMapParser.json");
26 | }
27 |
28 | public static JsMapParserPluginSettings Load(string configPath)
29 | {
30 | var filePath = GetConfigFilePath(configPath);
31 | if (File.Exists(filePath))
32 | {
33 | try
34 | {
35 | var settingsJson = File.ReadAllText(filePath);
36 | var settings = JSON.ToObject(settingsJson);
37 | settings._configPath = configPath;
38 | return settings;
39 | }
40 | catch
41 | {
42 | }
43 | }
44 |
45 | return new JsMapParserPluginSettings() { _configPath = configPath };
46 | }
47 |
48 | public void Save()
49 | {
50 | try
51 | {
52 | var serialized = JSON.ToNiceJSON(this, new JSONParameters()
53 | {
54 | UseExtensions = false
55 | });
56 | File.WriteAllText(GetConfigFilePath(_configPath), serialized);
57 | }
58 | catch
59 | {
60 | }
61 | }
62 | }
63 | }
--------------------------------------------------------------------------------
/source/JsParser.UI/UI/ColorPicker.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.ComponentModel;
3 | using System.Drawing;
4 | using System.Windows.Forms;
5 |
6 | namespace JsParser.UI.UI
7 | {
8 | public partial class ColorPicker : UserControl
9 | {
10 | private bool _skipTextBoxEvent = false;
11 |
12 | [Description("SelectedColorChanged")]
13 | [Category("CatBehavior")]
14 | public event EventHandler SelectedColorChanged;
15 |
16 | public Color SelectedColor
17 | {
18 | get { return panel1.BackColor; }
19 | set
20 | {
21 | panel1.BackColor = value;
22 | _skipTextBoxEvent = true;
23 | textBox1.Text = ColorTranslator.ToHtml(panel1.BackColor);
24 | _skipTextBoxEvent = false;
25 | if (SelectedColorChanged != null)
26 | {
27 | SelectedColorChanged(this, EventArgs.Empty);
28 | }
29 | }
30 | }
31 |
32 | public ColorPicker()
33 | {
34 | InitializeComponent();
35 | }
36 |
37 | private void panel1_Paint(object sender, PaintEventArgs e)
38 | {
39 |
40 | }
41 |
42 | private void panel1_Click(object sender, EventArgs e)
43 | {
44 | colorDialog1.Color = SelectedColor;
45 | if (colorDialog1.ShowDialog() == DialogResult.OK)
46 | {
47 | SelectedColor = colorDialog1.Color;
48 | }
49 | }
50 |
51 | private void textBox1_TextChanged(object sender, EventArgs e)
52 | {
53 | if (_skipTextBoxEvent)
54 | {
55 | return;
56 | }
57 |
58 | var text = textBox1.Text;
59 | try
60 | {
61 | var color = ColorTranslator.FromHtml(text);
62 | panel1.BackColor = color;
63 | }
64 | catch
65 | {
66 | }
67 | }
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/source/Jint.Parser/Ast/AssignmentExpression.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace Jint.Parser.Ast
4 | {
5 | public enum AssignmentOperator
6 | {
7 | Assign,
8 | PlusAssign,
9 | MinusAssign,
10 | TimesAssign,
11 | DivideAssign,
12 | ModuloAssign,
13 | BitwiseAndAssign,
14 | BitwiseOrAssign,
15 | BitwiseXOrAssign,
16 | LeftShiftAssign,
17 | RightShiftAssign,
18 | UnsignedRightShiftAssign,
19 | }
20 |
21 | public class AssignmentExpression : Expression
22 | {
23 | public AssignmentOperator Operator;
24 | public Expression Left;
25 | public Expression Right;
26 |
27 | public static AssignmentOperator ParseAssignmentOperator(string op)
28 | {
29 | switch (op)
30 | {
31 | case "=":
32 | return AssignmentOperator.Assign;
33 | case "+=":
34 | return AssignmentOperator.PlusAssign;
35 | case "-=":
36 | return AssignmentOperator.MinusAssign;
37 | case "*=":
38 | return AssignmentOperator.TimesAssign;
39 | case "/=":
40 | return AssignmentOperator.DivideAssign;
41 | case "%=":
42 | return AssignmentOperator.ModuloAssign;
43 | case "&=":
44 | return AssignmentOperator.BitwiseAndAssign;
45 | case "|=":
46 | return AssignmentOperator.BitwiseOrAssign;
47 | case "^=":
48 | return AssignmentOperator.BitwiseXOrAssign;
49 | case "<<=":
50 | return AssignmentOperator.LeftShiftAssign;
51 | case ">>=":
52 | return AssignmentOperator.RightShiftAssign;
53 | case ">>>=":
54 | return AssignmentOperator.UnsignedRightShiftAssign;
55 |
56 | default:
57 | throw new ArgumentOutOfRangeException("Invalid assignment operator: " + op);
58 | }
59 | }
60 | }
61 | }
--------------------------------------------------------------------------------
/source/JsParser.UI/Helpers/StatisticsSender.cs:
--------------------------------------------------------------------------------
1 | using JsParser.UI.Properties;
2 | using JsParser.UI.UI;
3 | using System;
4 |
5 | namespace JsParser.UI.Helpers
6 | {
7 | public static class StatisticsSender
8 | {
9 | public static void Send()
10 | {
11 | if (Settings.Default.SendStatistics && Settings.Default.SendStatisticsPolitic == "Approved")
12 | {
13 | //all is OK - just send it
14 | StatisticsManager.Instance.SubmitStatisticsToServer();
15 | return;
16 | }
17 |
18 | //Ask user if it is normal to send statistics
19 | if (Settings.Default.SendStatisticsPolitic == "Ask"
20 | && StatisticsManager.Instance.Statistics.FirstDateUse.AddDays(3) < DateTime.UtcNow
21 | && StatisticsManager.Instance.Statistics.NavigateFromFunctionsTreeCount > 10)
22 | {
23 | var askForm = new Form_SendStatisticsConfirmation();
24 | var result = askForm.ShowDialog();
25 | if (result == System.Windows.Forms.DialogResult.OK)
26 | {
27 | //set OK settings
28 | Settings.Default.SendStatisticsPolitic = "Approved";
29 | Settings.Default.SendStatistics = true;
30 | Settings.Default.Save();
31 |
32 | //call self recursively
33 | Send();
34 | return;
35 | }
36 |
37 | if (result == System.Windows.Forms.DialogResult.Cancel)
38 | {
39 | //no - user don't want this shit
40 | Settings.Default.SendStatisticsPolitic = "Not allowed";
41 | Settings.Default.SendStatistics = false;
42 | Settings.Default.Save();
43 |
44 | return;
45 | }
46 |
47 | if (result == System.Windows.Forms.DialogResult.Ignore)
48 | {
49 | //just do nothing - only update Last submitting time
50 | StatisticsManager.Instance.Statistics.LastSubmittedTime = DateTime.UtcNow;
51 | Settings.Default.Save();
52 | return;
53 | }
54 | }
55 | }
56 | }
57 | }
--------------------------------------------------------------------------------
/source/JsParser.VsExtension/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/source/JsParser.Core/Infrastructure/JsParserService.cs:
--------------------------------------------------------------------------------
1 | using JsParser.Core.Code;
2 | using JsParser.Core.Parsers;
3 | using System;
4 | using System.IO;
5 | using System.Security.Cryptography;
6 | using System.Text;
7 |
8 | namespace JsParser.Core.Infrastructure
9 | {
10 | public class JsParserService
11 | {
12 | private string _loadedCodeHash;
13 | private readonly IJavascriptParserSettings _settings;
14 |
15 | public JsParserService(IJavascriptParserSettings settings)
16 | {
17 | _settings = settings;
18 | }
19 |
20 | ///
21 | /// Gets Code.
22 | ///
23 | public ICodeProvider Code { get; private set; }
24 |
25 | public void InvalidateCash()
26 | {
27 | _loadedCodeHash = null;
28 | }
29 |
30 | public JSParserResult Process(ICodeProvider codeProvider, bool skipHashCheck = false)
31 | {
32 | Code = codeProvider;
33 | string docName = Path.Combine(Code.Path, Code.Name);
34 |
35 | if (!CheckExt(docName))
36 | {
37 | return null;
38 | }
39 |
40 | var code = Code.LoadCode();
41 | var hash = Convert.ToBase64String(MD5.Create().ComputeHash(Encoding.Default.GetBytes(code)));
42 | if (!skipHashCheck && _loadedCodeHash == hash)
43 | {
44 | return new JSParserResult();
45 | }
46 | _loadedCodeHash = hash;
47 |
48 | var result = (new JavascriptParser(_settings)).Parse(code, docName);
49 | result.FileName = docName;
50 | return result;
51 | }
52 |
53 | private bool CheckExt(string fileName)
54 | {
55 | if (_settings.Extensions.Count > 0)
56 | {
57 | var currentExt = Path.GetExtension(fileName).SafeTrimStart('.');
58 | foreach (var ext in _settings.Extensions)
59 | {
60 | if (string.Compare(currentExt, ext, StringComparison.InvariantCultureIgnoreCase) == 0)
61 | {
62 | return true;
63 | }
64 | }
65 |
66 | return false;
67 | }
68 |
69 | return true;
70 | }
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/source/JsParser.VsExtension/source.extension.vsixmanifest:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | JavaScript Map Parser
5 | Oleksandr Boiko
6 | 4.1
7 | Extension for Visual Studio that shows a map for JavaScript code in a separate panel.
8 | 1033
9 | https://github.com/megaboich/js-map-parser/wiki
10 | License.txt
11 | https://github.com/megaboich/js-map-parser/wiki/Getting-Started
12 | jsparser_icon.png
13 | screen_shot_mini.png
14 | false
15 |
16 |
17 | Ultimate
18 | Premium
19 | Pro
20 |
21 |
22 | Ultimate
23 | Premium
24 | Pro
25 |
26 |
27 | Ultimate
28 | Premium
29 | Pro
30 |
31 |
32 | Ultimate
33 | Premium
34 | Pro
35 |
36 |
37 | Ultimate
38 | Premium
39 | Pro
40 |
41 |
42 |
43 |
44 |
45 |
46 | Visual Studio MPF
47 |
48 |
49 |
50 | |%CurrentProject%;PkgdefProjectOutputGroup|
51 | |%CurrentProject%|
52 |
53 |
54 |
--------------------------------------------------------------------------------
/source/JsParser.NppPlugin/Forms/PluginUiPanel.designer.cs:
--------------------------------------------------------------------------------
1 | namespace JsMapParser.NppPlugin.Forms
2 | {
3 | partial class PluginUiPanel
4 | {
5 | ///
6 | /// Required designer variable.
7 | ///
8 | private System.ComponentModel.IContainer components = null;
9 |
10 | ///
11 | /// Clean up any resources being used.
12 | ///
13 | /// true if managed resources should be disposed; otherwise, false.
14 | protected override void Dispose(bool disposing)
15 | {
16 | if (disposing && (components != null))
17 | {
18 | components.Dispose();
19 | }
20 | base.Dispose(disposing);
21 | }
22 |
23 | #region Windows Form Designer generated code
24 |
25 | ///
26 | /// Required method for Designer support - do not modify
27 | /// the contents of this method with the code editor.
28 | ///
29 | private void InitializeComponent()
30 | {
31 | this.navigationTreeView1 = new JsParser.UI.UI.NavigationTreeView();
32 | this.SuspendLayout();
33 | //
34 | // navigationTreeView1
35 | //
36 | this.navigationTreeView1.Dock = System.Windows.Forms.DockStyle.Fill;
37 | this.navigationTreeView1.Location = new System.Drawing.Point(0, 0);
38 | this.navigationTreeView1.Name = "navigationTreeView1";
39 | this.navigationTreeView1.Size = new System.Drawing.Size(197, 420);
40 | this.navigationTreeView1.TabIndex = 0;
41 | //
42 | // PluginPanel
43 | //
44 | this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
45 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
46 | this.ClientSize = new System.Drawing.Size(197, 420);
47 | this.Controls.Add(this.navigationTreeView1);
48 | this.DoubleBuffered = true;
49 | this.Name = "PluginUiPanel";
50 | this.Text = "PluginPanel";
51 | this.ResumeLayout(false);
52 |
53 | }
54 |
55 | #endregion
56 |
57 | public JsParser.UI.UI.NavigationTreeView navigationTreeView1;
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 | }
66 | }
--------------------------------------------------------------------------------
/source/JsParser.Core/Parsers/JSParserExtensions.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Collections.Specialized;
4 | using System.Linq;
5 |
6 | namespace JsParser.Core.Parsers
7 | {
8 | public static class JsParserExtensions
9 | {
10 | public static string SafeTrimStart(this string s, char symbol)
11 | {
12 | if (string.IsNullOrEmpty(s))
13 | {
14 | return string.Empty;
15 | }
16 |
17 | return s.TrimStart(symbol);
18 | }
19 |
20 | public static string Shortenize(this String s, int targetLength)
21 | {
22 | if (targetLength <= 0)
23 | {
24 | return string.Empty;
25 | }
26 |
27 | if (s.Length > targetLength)
28 | {
29 | var si = (int) 2*(targetLength/3);
30 | s = s.Substring(0, si) + '\x2026' + s.Substring(s.Length + 1 - targetLength + si);
31 | }
32 |
33 | return s;
34 | }
35 |
36 | ///
37 | /// Transform input string by adding spaces where words should be separeated.
38 | /// Example: "ThisStringShouldBeSeparated" => "This String Shoud Be Separated"
39 | ///
40 | ///
41 | ///
42 | public static string SplitWordsByCamelCase(this String s)
43 | {
44 | if (string.IsNullOrEmpty(s))
45 | {
46 | return s;
47 | }
48 |
49 | var chars = s.ToList();
50 | for (int charIndex = 0; charIndex < chars.Count; charIndex++)
51 | {
52 | if (char.IsUpper(chars[charIndex]))
53 | {
54 | chars.Insert(charIndex, ' ');
55 | charIndex++;
56 | }
57 | }
58 |
59 | return new string(chars.ToArray()).Trim();
60 | }
61 |
62 | public static StringCollection ToStringCollection(this string[] strings)
63 | {
64 | var sc = new StringCollection();
65 | sc.AddRange(strings);
66 | return sc;
67 | }
68 |
69 | public static IEnumerable GetEnumerable(this StringCollection sc)
70 | {
71 | foreach (var s in sc)
72 | {
73 | yield return s;
74 | }
75 | }
76 | }
77 | }
78 |
--------------------------------------------------------------------------------
/source/JsParser.Core/Parsers/CommentsAgregator.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 |
5 | namespace JsParser.Core.Parsers
6 | {
7 | internal class CommentsAgregator
8 | {
9 | private List _comments;
10 |
11 | public IList Comments
12 | {
13 | get
14 | {
15 | return _comments.AsReadOnly();
16 | }
17 | }
18 |
19 | public void ProcessComments(IEnumerable rawComments)
20 | {
21 | _comments = new List();
22 | CommentWrapper prevCom = null;
23 |
24 | // Combine comments on neighbour lines to comment groups
25 | foreach(var currentCom in rawComments)
26 | {
27 | if (prevCom != null)
28 | {
29 | if (prevCom.EndLine == currentCom.StartLine - 1)
30 | {
31 | prevCom.Spelling = prevCom.Spelling + Environment.NewLine + currentCom.Spelling;
32 | prevCom.EndLine = currentCom.EndLine;
33 | }
34 | else
35 | {
36 | _comments.Add(currentCom);
37 | prevCom = currentCom;
38 | }
39 | }
40 | else
41 | {
42 | _comments.Add(currentCom);
43 | prevCom = currentCom;
44 | }
45 | }
46 | }
47 |
48 | public string GetComment(int startline, int endline)
49 | {
50 | var result = new List();
51 | foreach (var comment in _comments.Where(c => !c.Processed))
52 | {
53 | if (comment.EndLine == startline // The same line
54 | || comment.EndLine == startline - 1 // The prev line
55 | || comment.StartLine == startline + 1 // The next line
56 | )
57 | {
58 | result.Add(comment.Spelling);
59 | comment.Processed = true;
60 | }
61 | }
62 |
63 | var r = string.Join(Environment.NewLine, result.ToArray());
64 | if (string.IsNullOrEmpty(r.Trim()))
65 | {
66 | return null;
67 | }
68 |
69 | return r.Trim();
70 | }
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/source/JsParser.Test/SimpleCodeProvider.cs:
--------------------------------------------------------------------------------
1 | using JsParser.Core.Code;
2 | using System.Linq;
3 | using System.Windows.Forms;
4 |
5 | namespace JsParser.Test
6 | {
7 | public class SimpleCodeProvider :ICodeProvider
8 | {
9 | private string _name;
10 | private string _path;
11 | private RichTextBox _textBox;
12 |
13 | public SimpleCodeProvider(RichTextBox textBox, string path, string name)
14 | {
15 | _textBox = textBox;
16 | _name = name;
17 | _path = path;
18 | ContainerName = typeof(SimpleCodeProvider).Assembly.FullName;
19 | }
20 |
21 | #region ICodeProvider Members
22 |
23 | public string LoadCode()
24 | {
25 | return _textBox.Text;
26 | }
27 |
28 | public string Path
29 | {
30 | get { return _path; }
31 | }
32 |
33 | public string Name
34 | {
35 | get { return _name; }
36 | }
37 |
38 | public string FullName
39 | {
40 | get
41 | {
42 | return System.IO.Path.Combine(Path, Name);
43 | }
44 | }
45 |
46 | public void SelectionMoveToLineAndOffset(int startLine, int startColumn)
47 | {
48 | if (startLine == 1)
49 | {
50 | _textBox.Select(startLine + startColumn - 1, 0);
51 | }
52 | else
53 | {
54 | var textLen = _textBox.Lines.Take(startLine - 1).Select(l => l.Length + 1).Aggregate((t, l) => t += l);
55 | _textBox.Select(textLen + startColumn - 1, 0);
56 | }
57 | }
58 |
59 | public void SetFocus()
60 | {
61 | _textBox.Focus();
62 | }
63 |
64 | public void GetCursorPos(out int line, out int column)
65 | {
66 | try
67 | {
68 | var cursorPos = _textBox.SelectionStart;
69 | line = 1 + _textBox.GetLineFromCharIndex(cursorPos);
70 | column = 1;
71 | }
72 |
73 | /*
74 | var cumLength = 0;
75 | int i = 0;
76 | var cursorPos = _textBox.SelectionStart;
77 | for (; i < _textBox.Lines.Length; ++i)
78 | {
79 | var curLineLength = _textBox.Lines[i].Length + 1;
80 | cumLength += curLineLength;
81 |
82 | if (cumLength > cursorPos)
83 | {
84 | line = i + 1; //one-based index
85 | column = cursorPos - cumLength + curLineLength;
86 | return;
87 | }
88 | }*/
89 |
90 | catch
91 | {
92 | line = -1;
93 | column = -1;
94 | }
95 | }
96 |
97 | #endregion
98 |
99 |
100 | public string ContainerName {get; set;}
101 | }
102 | }
103 |
--------------------------------------------------------------------------------
/source/JsParser.Core/Parsers/JavascriptParser.cs:
--------------------------------------------------------------------------------
1 | using JsParser.Core.Code;
2 | using System.IO;
3 |
4 | namespace JsParser.Core.Parsers
5 | {
6 | ///
7 | /// The JavaScript parser.
8 | ///
9 | public class JavascriptParser : IJavascriptParser
10 | {
11 | private readonly IJavascriptParserSettings _settings;
12 |
13 | public JavascriptParser(IJavascriptParserSettings settings)
14 | {
15 | _settings = settings;
16 | }
17 |
18 | ///
19 | /// Parse JavaScript
20 | ///
21 | public JSParserResult Parse(string code, string filename)
22 | {
23 | // Get extension
24 | var ext = Path.GetExtension(filename).ToLower();
25 | if (ext.StartsWith("."))
26 | {
27 | ext = ext.Substring(1);
28 | }
29 |
30 | code = CodeTransformer.ApplyJSParserSkip(code);
31 |
32 | code = CodeTransformer.FixStringScriptBlocks(code);
33 |
34 | if (_settings.FixAspNetTags && _settings.FixAspNetTagsExtensions.Contains(ext))
35 | {
36 | code = CodeTransformer.KillAspNetTags(code);
37 | }
38 | if (_settings.FixRazorSyntax && _settings.FixRazorSyntaxExtensions.Contains(ext))
39 | {
40 | code = CodeTransformer.FixRazorSyntax(code);
41 | }
42 |
43 | if (_settings.ScriptStripEnabled && _settings.ScriptStripExtensions.Contains(ext))
44 | {
45 | var foundScriptBlocks = CodeTransformer.ExtractJsFromSource(ref code);
46 |
47 | if (!foundScriptBlocks) //empty file
48 | {
49 | return ParseInternal(string.Empty);
50 | }
51 | }
52 |
53 | var result = ParseInternal(code);
54 |
55 | if (_settings.HideAnonymousFunctions)
56 | {
57 | NodesPostProcessor.HideAnonymousFunctions(result.Nodes);
58 | }
59 |
60 | return result;
61 | }
62 |
63 | ///
64 | /// The parse.
65 | ///
66 | ///
67 | /// The JavaScript script.
68 | ///
69 | ///
70 | /// Hierarchy with code structure.
71 | ///
72 | private JSParserResult ParseInternal(string sourceCode)
73 | {
74 | var parser = new JavascriptStructureParserV2(_settings);
75 | return parser.Parse(sourceCode);
76 | }
77 | }
78 | }
--------------------------------------------------------------------------------
/source/JsParser.Test/Parser/JsParserTests_New.cs:
--------------------------------------------------------------------------------
1 | using NUnit.Framework;
2 |
3 | namespace JsParser.Test.Parser
4 | {
5 | [TestFixture]
6 | public class JsParserTests_New
7 | {
8 | [Test]
9 | public void ArrayChain()
10 | {
11 | TestRunner.RunTest("New.ArrayChain.js", "New.ArrayChain.txt");
12 | }
13 |
14 | [Test]
15 | public void Assignment()
16 | {
17 | TestRunner.RunTest("New.Assignment.js", "New.Assignment.txt");
18 | }
19 |
20 | [Test]
21 | public void CallbackChain()
22 | {
23 | TestRunner.RunTest("New.CallbackChain.js", "New.CallbackChain.txt");
24 | }
25 |
26 | [Test]
27 | public void Comments()
28 | {
29 | TestRunner.RunTest("New.Comments.js", "New.Comments.txt");
30 | }
31 |
32 | [Test]
33 | public void DebuggerKeyword()
34 | {
35 | TestRunner.RunTest("New.DebuggerKeyword.js", "New.DebuggerKeyword.txt");
36 | }
37 |
38 | [Test]
39 | public void FunctionsHierarchy()
40 | {
41 | TestRunner.RunTest("New.FunctionsHierarchy.js", "New.FunctionsHierarchy.txt");
42 | }
43 |
44 | [Test]
45 | public void FunctionsHierarchy2()
46 | {
47 | TestRunner.RunTest("New.FunctionsHierarchy2.js", "New.FunctionsHierarchy2.txt");
48 | }
49 |
50 | [Test]
51 | public void InlineOrDecralation()
52 | {
53 | TestRunner.RunTest("New.InlineOrDecralation.js", "New.InlineOrDecralation.txt");
54 | }
55 |
56 | [Test]
57 | public void ReturnStatement()
58 | {
59 | TestRunner.RunTest("New.ReturnStatement.js", "New.ReturnStatement.txt");
60 | }
61 |
62 | [Test]
63 | public void TodoList()
64 | {
65 | var result = TestRunner.RunTest("New.TodoList.js", "New.TodoList.txt");
66 |
67 | Assert.AreEqual(2, result.TaskList.Count);
68 | Assert.AreEqual("TODO: write some code here", result.TaskList[0].Description);
69 | Assert.AreEqual(6, result.TaskList[0].StartLine);
70 |
71 | Assert.AreEqual("to do: Another todo line", result.TaskList[1].Description);
72 | Assert.AreEqual(9, result.TaskList[1].StartLine);
73 | }
74 |
75 | [Test]
76 | public void Es6_GetSet()
77 | {
78 | TestRunner.RunTest("New.Es6_GetSet.js", "New.Es6_GetSet.txt");
79 | }
80 |
81 | [Test]
82 | public void Es6_GetSet2()
83 | {
84 | TestRunner.RunTest("New.Es6_GetSet2.js", "New.Es6_GetSet2.txt");
85 | }
86 | }
87 | }
88 |
--------------------------------------------------------------------------------
/source/JsParser.Core/Helpers/Hierachy.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 |
4 | namespace JsParser.Core.Helpers
5 | {
6 | ///
7 | /// Represents a hierarchy template.
8 | ///
9 | ///
10 | /// Type of objects used in hierarchy.
11 | ///
12 | [Serializable]
13 | public class Hierarchy
14 | {
15 | ///
16 | /// Initializes a new instance of the class.
17 | ///
18 | ///
19 | /// The item to be stored.
20 | ///
21 | ///
22 | /// The parent.
23 | ///
24 | public Hierarchy(T item)
25 | {
26 | Item = item;
27 | }
28 |
29 | ///
30 | /// Prevents a default instance of the class from being created.
31 | ///
32 | private Hierarchy()
33 | {
34 | }
35 |
36 | ///
37 | /// Gets or sets Item.
38 | ///
39 | public T Item { get; set; }
40 |
41 | ///
42 | /// Gets or sets Childrens.
43 | ///
44 | public List> Children { get; set; }
45 |
46 | ///
47 | /// Gets a value indicating whether HasChildren.
48 | ///
49 | public bool HasChildren
50 | {
51 | get
52 | {
53 | return Children != null && Children.Count > 0;
54 | }
55 | }
56 |
57 | ///
58 | /// Adds set of childrens to current hierarchy node.
59 | ///
60 | ///
61 | /// The childs.
62 | ///
63 | public void Add(IEnumerable childs)
64 | {
65 | foreach (T child in childs)
66 | {
67 | Add(child);
68 | }
69 | }
70 |
71 | ///
72 | /// Adds one child to current hierarchy node.
73 | ///
74 | ///
75 | /// The child.
76 | ///
77 | ///
78 | /// The add children.
79 | ///
80 | public Hierarchy Add(T child)
81 | {
82 | var h = new Hierarchy(child);
83 |
84 | if (Children == null)
85 | {
86 | Children = new List>();
87 | }
88 |
89 | Children.Add(h);
90 | return h;
91 | }
92 | }
93 | }
--------------------------------------------------------------------------------
/source/JsParser.VsExtension/OptionsUI/OptionsPageCustom.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Drawing;
3 | using System.Windows.Forms;
4 | using System.ComponentModel;
5 | using Microsoft.VisualStudio.Shell;
6 | using System.Runtime.InteropServices;
7 | using JsParser.UI.UI;
8 | using System.Diagnostics;
9 |
10 | namespace JsParser.VsExtension
11 | {
12 | ///
13 | /// Extends a standard dialog functionality for implementing ToolsOptions pages,
14 | /// with support for the Visual Studio automation model, Windows Forms, and state
15 | /// persistence through the Visual Studio settings mechanism.
16 | ///
17 | [Guid("C5B955B9-6220-4DC9-9B46-C3ECE0D66B69")]
18 | public class OptionsPageCustom : DialogPage
19 | {
20 | #region Fields
21 |
22 | private JsParserSettingsControl _settingsUI;
23 | private bool _needReinitOnActivate = false;
24 |
25 | #endregion Fields
26 |
27 | #region Properties
28 | ///
29 | /// Gets the window an instance of DialogPage that it uses as its user interface.
30 | ///
31 | ///
32 | /// The window this dialog page will use for its UI.
33 | /// This window handle must be constant, so if you are
34 | /// returning a Windows Forms control you must make sure
35 | /// it does not recreate its handle. If the window object
36 | /// implements IComponent it will be sited by the
37 | /// dialog page so it can get access to global services.
38 | ///
39 | [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
40 | protected override IWin32Window Window
41 | {
42 | get
43 | {
44 | return SettingsUI;
45 | }
46 | }
47 |
48 | protected JsParserSettingsControl SettingsUI
49 | {
50 | get
51 | {
52 | if (_settingsUI == null)
53 | {
54 | _settingsUI = new JsParser.UI.UI.JsParserSettingsControl();
55 | _settingsUI.Location = new Point(0, 0);
56 | _settingsUI.Dock = DockStyle.Fill;
57 | _settingsUI.InitSettings();
58 | }
59 |
60 | return _settingsUI;
61 | }
62 | }
63 |
64 | protected override void OnApply(PageApplyEventArgs e)
65 | {
66 | SettingsUI.SaveSettings();
67 | _needReinitOnActivate = true;
68 | base.OnApply(e);
69 | }
70 |
71 | protected override void OnClosed(EventArgs e)
72 | {
73 | SettingsUI.InitSettings();
74 | _needReinitOnActivate = true;
75 | base.OnClosed(e);
76 | }
77 |
78 | protected override void OnActivate(CancelEventArgs e)
79 | {
80 | if (_needReinitOnActivate)
81 | {
82 | SettingsUI.InitSettings();
83 | }
84 |
85 | _needReinitOnActivate = false;
86 | base.OnActivate(e);
87 | }
88 |
89 | protected override void OnDeactivate(CancelEventArgs e)
90 | {
91 | base.OnDeactivate(e);
92 | }
93 |
94 | #endregion Properties
95 | }
96 | }
97 |
--------------------------------------------------------------------------------
/source/JsParser.Test/Find/SearchFinalTest.cs:
--------------------------------------------------------------------------------
1 | using JsParser.Core.Search;
2 | using NUnit.Framework;
3 | using System.Collections.Generic;
4 | using System.Linq;
5 |
6 | namespace JsParserTest.UnitTests
7 | {
8 | [TestFixture]
9 | public class SearchFinalTest
10 | {
11 | private static string[] _source = { //first goes the test case index - to simplify test cases
12 | "0|this.Method1()",
13 | "1|this.Method2()",
14 | "2|this.longMethodDescription()",
15 | "3|this.withParam('btn1')",
16 | "4|this.withParamChain('btn1', 'btn2', 'btn3')",
17 | "5|ABBR.bigLetters.EAContainer()"
18 | };
19 |
20 | private static IEnumerable> TransformSource(string[] source)
21 | {
22 | return _source.Select(i =>
23 | {
24 | var d = i.Split(new char[] { '|' });
25 | return new KeyValuePair(int.Parse(d[0]), d[1]);
26 | });
27 | }
28 |
29 | private void AssertIndexes(KeyValuePair[] data, int[] indexes)
30 | {
31 | var dic = data.ToDictionary(k => k.Key);
32 | Assert.AreEqual(indexes.Length, data.Length, "Found wrong amount");
33 | for (int i = 0; i < data.Length; ++i)
34 | {
35 | Assert.AreEqual(indexes[i], dic[indexes[i]].Key, "Wrong index found at position " + i);
36 | }
37 | }
38 |
39 | [Test]
40 | public void CheckBaseSearch()
41 | {
42 | var src = TransformSource(_source).ToArray();
43 | var matches = SearchHelper.GetMatches(src, i => i.Value, "method").ToArray();
44 | AssertIndexes(matches, new[] { 0, 1, 2 });
45 |
46 | matches = SearchHelper.GetMatches(src, i => i.Value, "btn1").ToArray();
47 | AssertIndexes(matches, new[] { 3, 4 });
48 |
49 | matches = SearchHelper.GetMatches(src, i => i.Value, "btn2").ToArray();
50 | AssertIndexes(matches, new[] { 4 });
51 |
52 | matches = SearchHelper.GetMatches(src, i => i.Value, "Chain").ToArray();
53 | AssertIndexes(matches, new[] { 4 });
54 |
55 | matches = SearchHelper.GetMatches(src, i => i.Value, "ABBR").ToArray();
56 | AssertIndexes(matches, new[] { 5 });
57 |
58 | matches = SearchHelper.GetMatches(src, i => i.Value, "EAContainer").ToArray();
59 | AssertIndexes(matches, new[] { 5 });
60 |
61 | matches = SearchHelper.GetMatches(src, i => i.Value, "EACont").ToArray();
62 | AssertIndexes(matches, new[] { 5 });
63 | }
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/source/JsParser.Test/Find/FindDialogTest.cs:
--------------------------------------------------------------------------------
1 | using JsParser.Core.Search;
2 | using NUnit.Framework;
3 | using System;
4 | using System.Linq;
5 |
6 | namespace JsParserTest.UnitTests
7 | {
8 | [TestFixture]
9 | public class FindDialogTest
10 | {
11 | [Test]
12 | public void TestSplitting()
13 | {
14 | ValidateSplitting(
15 | new[] {
16 | new[]{"TestFunction", "Test | Function"},
17 | new[]{"TestCreepyFunction", "Test | Creepy | Function"},
18 | new[]{"TestFunkyFunction", "Test | Funky | Function"},
19 | new[]{"LongFunctionTestName", "Long | Function | Test | Name"},
20 | new[]{"LongSuperDuperFunctionName", "Long | Super | Duper | Function | Name"},
21 | new[]{"longSuperDuperFunctionName", "long | Super | Duper | Function | Name"},
22 | new[]{"A", "A"},
23 | new[]{"AB", "A | B"},
24 | new[]{"ABC", "A | B | C"},
25 | new[]{"aBC", "a | B | C"},
26 | new[]{"AaBbCc", "Aa | Bb | Cc"},
27 | new[]{"aaBbCc", "aa | Bb | Cc"},
28 | new[]{"A1B2C3", "A | 1 | B | 2 | C | 3"},
29 | new[]{"A123", "A | 1 | 2 | 3"},
30 | new[]{"123", "1 | 2 | 3"},
31 | new[]{"1A2B3C", "1 | A | 2 | B | 3 | C"},
32 | new[]{"1a2b3c", "1a | 2b | 3c"},
33 | });
34 |
35 | ValidateSplitting(
36 | new[] {
37 | new[]{"this.Method('btn1')", "this | Method | btn | 1"},
38 | new[]{"this.Method('btn1', 'btn2', 'btn3')", "this | Method | btn | 1 | btn | 2 | btn | 3"},
39 | });
40 | }
41 |
42 | [Test]
43 | public void TestMatching()
44 | {
45 | //Check match
46 | ValidateMatch(
47 | "AB",
48 | new[] {"aaBbCc",
49 | "ABC",
50 | "AB"
51 | },
52 | true);
53 |
54 | //Check not match
55 | ValidateMatch(
56 | "ABD",
57 | new[] {
58 | "aaBbCc",
59 | "A",
60 | "CBD",
61 | "AB",
62 | },
63 | false);
64 | }
65 |
66 | private void ValidateMatch(string pattern, string[] fnames, bool isMatch)
67 | {
68 | if (isMatch)
69 | {
70 | fnames.ToList().ForEach(p => { var r = TestMatch(pattern, p); if (!r) Assert.Fail("Pattern not match: " + pattern + "=>" + p); });
71 | }
72 | else
73 | {
74 | fnames.ToList().ForEach(p => { var r = TestMatch(pattern, p); if (r) Assert.Fail("Pattern match: " + pattern + "=>" + p); });
75 | }
76 | }
77 |
78 | private bool TestMatch(string pattern, string fname)
79 | {
80 | var p = SearchHelper.SplitFunctionName(pattern).ToList();
81 | var f = SearchHelper.SplitFunctionName(fname).ToList();
82 | return SearchHelper.CompareEntities(p, f) > 0;
83 | }
84 |
85 | private static string GetFunctionNameTestTransform(string originalFName)
86 | {
87 | return String.Join(" | ", SearchHelper.SplitFunctionName(originalFName).ToArray());
88 | }
89 |
90 | private void ValidateSplitting(string[][] input)
91 | {
92 | input.ToList().ForEach(p => Assert.AreEqual(p[1], GetFunctionNameTestTransform(p[0])));
93 | }
94 | }
95 | }
96 |
--------------------------------------------------------------------------------
/source/JsParser.Core/Code/CodeNode.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 |
4 | namespace JsParser.Core.Code
5 | {
6 | ///
7 | /// The code node.
8 | ///
9 | public class CodeNode : IEquatable
10 | {
11 | ///
12 | /// Gets or sets Alias.
13 | ///
14 | public string Alias { get; set; }
15 |
16 | ///
17 | /// Gets or sets StartLine.
18 | ///
19 | public int StartLine { get; set; }
20 |
21 | ///
22 | /// Gets or sets EndLine.
23 | ///
24 | public int EndLine { get; set; }
25 |
26 | ///
27 | /// Gets or sets EndColumn.
28 | ///
29 | public int EndColumn { get; set; }
30 |
31 | ///
32 | /// Gets or sets StartPosition.
33 | ///
34 | public int StartColumn { get; set; }
35 |
36 | ///
37 | /// Gets or sets type of node
38 | ///
39 | public CodeNodeType NodeType { get; set; }
40 |
41 | ///
42 | /// Gets or sets The Comment.
43 | ///
44 | public string Comment { get; set; }
45 |
46 | private static IComparer _comparer = new CodeNodeComparer();
47 |
48 | public CodeNode()
49 | {
50 | }
51 |
52 | public CodeNode(string alias, int startLine, int endLine, string comment = null, CodeNodeType type = CodeNodeType.Function)
53 | {
54 | Alias = alias;
55 | StartLine = startLine;
56 | EndLine = endLine;
57 | Comment = comment;
58 | NodeType = type;
59 | }
60 |
61 | public bool Equals(CodeNode other)
62 | {
63 | return _comparer.Compare(this, other) == 0;
64 | }
65 |
66 | public override bool Equals(Object obj)
67 | {
68 | return Equals(obj as CodeNode);
69 | }
70 |
71 | public override int GetHashCode()
72 | {
73 | unchecked // Overflow is fine, just wrap
74 | {
75 | int hash = 17;
76 | // Suitable nullity checks etc, of course :)
77 | hash = hash * 23 + StartLine.GetHashCode();
78 | hash = hash * 23 + EndLine.GetHashCode();
79 | hash = hash * 23 + (Alias ?? string.Empty).GetHashCode();
80 | hash = hash * 23 + (Comment ?? string.Empty).GetHashCode();
81 | hash = hash * 23 + NodeType.GetHashCode();
82 | return hash;
83 | }
84 | }
85 |
86 | public static IComparer GetDefaultComparer()
87 | {
88 | return _comparer;
89 | }
90 | }
91 | }
--------------------------------------------------------------------------------
/source/JsParser.VsExtension/Infrastructure/VS2010CodeProvider.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using JsParser.Core.Code;
6 | using EnvDTE80;
7 | using EnvDTE;
8 | using System.Threading;
9 |
10 | namespace JsParser.VsExtension.Infrastructure
11 | {
12 | public class VS2010CodeProvider : ICodeProvider
13 | {
14 | private readonly Document _activeDocument;
15 |
16 | public VS2010CodeProvider(Document activeDocument)
17 | {
18 | _activeDocument = activeDocument;
19 |
20 | ContainerName = "Visual Studio " + activeDocument.DTE.Version;
21 | }
22 |
23 | private Document Doc
24 | {
25 | get
26 | {
27 | return _activeDocument;
28 | }
29 | }
30 |
31 | #region ICodeProvider Members
32 |
33 | public string LoadCode()
34 | {
35 | try
36 | {
37 | var textDocument = (TextDocument)Doc.Object("TextDocument");
38 | var docContent = textDocument.CreateEditPoint(textDocument.StartPoint).GetText(textDocument.EndPoint);
39 | return docContent;
40 | }
41 | catch
42 | {
43 | return "function Error_Loading_Document(){}";
44 | }
45 | }
46 |
47 | public string FullName
48 | {
49 | get
50 | {
51 | return System.IO.Path.Combine(Path, Name);
52 | }
53 | }
54 |
55 | public string Path
56 | {
57 | get { return Doc != null ? Doc.Path : string.Empty; }
58 | }
59 |
60 | public string Name
61 | {
62 | get { return Doc != null ? Doc.Name : string.Empty; }
63 | }
64 |
65 | public void SelectionMoveToLineAndOffset(int StartLine, int StartColumn)
66 | {
67 | try
68 | {
69 | var textDocument = (TextDocument)Doc.Object("TextDocument");
70 | textDocument.Selection.MoveToLineAndOffset(StartLine, StartColumn, false);
71 | }
72 | catch
73 | {
74 | }
75 | }
76 |
77 | public void SetFocus()
78 | {
79 | if (Doc == null)
80 | {
81 | return;
82 | }
83 |
84 | Doc.Activate();
85 | //ThreadPool.QueueUserWorkItem((state) =>
86 | //{
87 | // try
88 | // {
89 | // Doc.Activate();
90 | // }
91 | // catch { }
92 | //}, null);
93 | }
94 |
95 | public void GetCursorPos(out int line, out int column)
96 | {
97 | line = -1;
98 | column = -1;
99 | try
100 | {
101 | var textDocument = (TextDocument)Doc.Object("TextDocument");
102 | if (textDocument != null)
103 | {
104 | line = textDocument.Selection.ActivePoint.Line;
105 | column = textDocument.Selection.ActivePoint.DisplayColumn;
106 | }
107 | }
108 | catch
109 | {
110 | line = -1;
111 | column = -1;
112 | }
113 | }
114 |
115 | #endregion
116 |
117 |
118 | public string ContainerName {get; set;}
119 | }
120 | }
121 |
--------------------------------------------------------------------------------
/source/Jint.Parser/Ast/BinaryExpression.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace Jint.Parser.Ast
4 | {
5 | public enum BinaryOperator
6 | {
7 | Plus,
8 | Minus,
9 | Times,
10 | Divide,
11 | Modulo,
12 | Equal,
13 | NotEqual,
14 | Greater,
15 | GreaterOrEqual,
16 | Less,
17 | LessOrEqual,
18 | StrictlyEqual,
19 | StricltyNotEqual,
20 | BitwiseAnd,
21 | BitwiseOr,
22 | BitwiseXOr,
23 | LeftShift,
24 | RightShift,
25 | UnsignedRightShift,
26 | InstanceOf,
27 | In,
28 | }
29 |
30 | public class BinaryExpression : Expression
31 | {
32 | public BinaryOperator Operator;
33 | public Expression Left;
34 | public Expression Right;
35 |
36 | public static BinaryOperator ParseBinaryOperator(string op)
37 | {
38 | switch (op)
39 | {
40 | case "+":
41 | return BinaryOperator.Plus;
42 | case "-":
43 | return BinaryOperator.Minus;
44 | case "*":
45 | return BinaryOperator.Times;
46 | case "/":
47 | return BinaryOperator.Divide;
48 | case "%":
49 | return BinaryOperator.Modulo;
50 | case "==":
51 | return BinaryOperator.Equal;
52 | case "!=":
53 | return BinaryOperator.NotEqual;
54 | case ">":
55 | return BinaryOperator.Greater;
56 | case ">=":
57 | return BinaryOperator.GreaterOrEqual;
58 | case "<":
59 | return BinaryOperator.Less;
60 | case "<=":
61 | return BinaryOperator.LessOrEqual;
62 | case "===":
63 | return BinaryOperator.StrictlyEqual;
64 | case "!==":
65 | return BinaryOperator.StricltyNotEqual;
66 | case "&":
67 | return BinaryOperator.BitwiseAnd;
68 | case "|":
69 | return BinaryOperator.BitwiseOr;
70 | case "^":
71 | return BinaryOperator.BitwiseXOr;
72 | case "<<":
73 | return BinaryOperator.LeftShift;
74 | case ">>":
75 | return BinaryOperator.RightShift;
76 | case ">>>":
77 | return BinaryOperator.UnsignedRightShift;
78 | case "instanceof":
79 | return BinaryOperator.InstanceOf;
80 | case "in":
81 | return BinaryOperator.In;
82 |
83 | default:
84 | throw new ArgumentOutOfRangeException("Invalid binary operator: " + op);
85 | }
86 | }
87 | }
88 | }
--------------------------------------------------------------------------------
/source/JsParser.UI/Infrastructure/JsParserToolWindowManager.cs:
--------------------------------------------------------------------------------
1 | using JsParser.Core.Code;
2 | using JsParser.Core.Infrastructure;
3 | using JsParser.UI.UI;
4 | using System;
5 |
6 | namespace JsParser.UI.Infrastructure
7 | {
8 | public class JsParserToolWindowManager
9 | {
10 | string _activeDocFullName;
11 | JsParserService _jsParserService;
12 | Func _findWindowDelegate;
13 |
14 | public JsParserToolWindowManager(
15 | JsParserService jsParserService,
16 | Func findWindowDelegate)
17 |
18 | {
19 | _jsParserService = jsParserService;
20 | _findWindowDelegate = findWindowDelegate;
21 | }
22 |
23 | public string ActiveDocFullName
24 | {
25 | get
26 | {
27 | return _activeDocFullName;
28 | }
29 | }
30 |
31 | public void PerformInitialParsing(NavigationTreeView navTree = null)
32 | {
33 | if (navTree == null)
34 | {
35 | navTree = _findWindowDelegate().NavigationTreeView;
36 | }
37 | if (_jsParserService.Code != null)
38 | {
39 | var result = _jsParserService.Process(_jsParserService.Code, skipHashCheck: true);
40 | if (navTree != null)
41 | {
42 | navTree.UpdateTree(result, _jsParserService.Code);
43 | }
44 | }
45 | }
46 |
47 | public void CallParserForDocument(ICodeProvider codeProvider)
48 | {
49 | _activeDocFullName = codeProvider.FullName;
50 |
51 | var result = _jsParserService.Process(codeProvider);
52 |
53 | var toolWindow = _findWindowDelegate();
54 |
55 | if (result == null)
56 | {
57 | // Not JS case - need to clean tree
58 | _jsParserService.InvalidateCash();
59 | if (toolWindow != null)
60 | {
61 | toolWindow.NavigationTreeView.Clear();
62 | }
63 |
64 | return;
65 | }
66 |
67 | if (result.IsEmpty)
68 | {
69 | // skip - cached result
70 | return;
71 | }
72 |
73 | JsParserEventsBroadcaster.FireActionsForDoc(
74 | _activeDocFullName,
75 | new JsParserErrorsNotificationArgs
76 | {
77 | Code = codeProvider,
78 | FullFileName = _activeDocFullName,
79 | Errors = result.Errors
80 | });
81 |
82 | if (toolWindow != null)
83 | {
84 | toolWindow.NavigationTreeView.UpdateTree(result, codeProvider);
85 | }
86 | }
87 | }
88 | }
89 |
--------------------------------------------------------------------------------
/source/JsParser.Core/Search/SearchHelper.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 |
5 | namespace JsParser.Core.Search
6 | {
7 | public static class SearchHelper
8 | {
9 | static char[] _separators = new[] { '.', '|', '^', '?', '!', '$', '(', ')', '\'', '"', ',', ';', ' ', '-', '>', '<' };
10 |
11 | public static IEnumerable SplitFunctionName(string fname)
12 | {
13 | var res = fname
14 | .Split(_separators, StringSplitOptions.RemoveEmptyEntries)
15 | .Where(ch => !string.IsNullOrEmpty(ch.Trim()));
16 |
17 | return res
18 | .SelectMany(r => SplitByUpperCaseWording(r))
19 | .Where(s => !string.IsNullOrEmpty(s.Trim()));
20 | }
21 |
22 | private static IEnumerable SplitByUpperCaseWording(string fname)
23 | {
24 | var lastUpperIndex = 0;
25 | var counter = 0;
26 | for (int index = 0; index < fname.Length; ++index)
27 | {
28 | if (char.IsUpper(fname[index]) ||
29 | char.IsDigit(fname[index]))
30 | {
31 | var tl = lastUpperIndex;
32 | lastUpperIndex = index;
33 | ++counter;
34 | yield return fname.Substring(tl, index - tl);
35 | }
36 | }
37 |
38 | yield return fname.Substring(lastUpperIndex, fname.Length - lastUpperIndex);
39 | }
40 |
41 | public static IEnumerable GetMatches(IEnumerable source, Func nameDelegate, string input)
42 | {
43 | var inputSet = SearchHelper.SplitFunctionName(input).ToList();
44 |
45 | var res = source
46 | .Select(item => new {
47 | item = item,
48 | count = CompareEntities(inputSet, SearchHelper.SplitFunctionName(nameDelegate(item)).ToList())
49 | })
50 | .Where(i => i.count > 0)
51 | .OrderByDescending(i => i.count)
52 | .Select(i => i.item);
53 |
54 | return res;
55 | }
56 |
57 | public static int CompareEntities(IList input, IList test)
58 | {
59 | int encounters = 0;
60 | foreach (var inputPart in input)
61 | {
62 | bool hasMatch = false;
63 | foreach (var testPart in test)
64 | {
65 | if (testPart.StartsWith(inputPart, StringComparison.InvariantCultureIgnoreCase))
66 | {
67 | ++encounters;
68 | hasMatch = true;
69 | }
70 | }
71 |
72 | if (!hasMatch)
73 | {
74 | // all input tokens must be present in test
75 | return 0;
76 | }
77 | }
78 |
79 | return encounters;
80 | }
81 | }
82 | }
83 |
--------------------------------------------------------------------------------
/source/JsParser.Test/Parser/TestRunner.cs:
--------------------------------------------------------------------------------
1 | using JsParser.Core.Code;
2 | using JsParser.Core.Helpers;
3 | using JsParser.Core.Parsers;
4 | using JsParser.Test.Helpers;
5 | using JsParserTest.Helpers;
6 | using NUnit.Framework;
7 | using System.Collections.Generic;
8 | using System.IO;
9 |
10 | namespace JsParser.Test.Parser
11 | {
12 | public static class TestRunner
13 | {
14 | ///
15 | /// The comparer for code node.
16 | ///
17 | public class CodeNodeAssertComparer : Comparer
18 | {
19 | public override int Compare(CodeNode x, CodeNode y)
20 | {
21 | Assert.IsNotNull(x);
22 | Assert.IsNotNull(y);
23 |
24 | Assert.AreEqual(x.StartLine, y.StartLine);
25 | Assert.AreEqual(x.EndLine, y.EndLine);
26 | Assert.AreEqual(x.Alias, y.Alias);
27 | Assert.AreEqual(x.Comment, y.Comment);
28 | Assert.AreEqual(x.NodeType, y.NodeType);
29 |
30 | return 0;
31 | }
32 | }
33 |
34 | public static JSParserResult RunTest(string sourceName, string resultName)
35 | {
36 | var source = TestsHelper.GetEmbeddedText("JsParser.Test.Parser.Source." + sourceName);
37 |
38 | // Fix line endings in test files. All should be unix way, but on some GIT clients it is updated automatically.
39 | source = source.Replace("\r\n", "\n");
40 |
41 | var settings = new JavascriptParserSettings();
42 | var actualResult = (new JavascriptParser(settings)).Parse(source, sourceName);
43 |
44 | var outDir = "C:\\js_parser_units_output";
45 | Directory.CreateDirectory(outDir);
46 |
47 | // Save actual hierarchy xml
48 | var serialized = SimpleHierarchySerializer.Serialize(actualResult.Nodes);
49 | File.WriteAllText(outDir + "\\" + resultName, serialized);
50 |
51 | // Load test data
52 | var resName = "JsParser.Test.Parser.ExpectedResult." + resultName;
53 |
54 | var passed = false;
55 | if (TestsHelper.CheckEmbeddedRes(resName))
56 | {
57 | File.WriteAllText(outDir + "\\" + resultName, SimpleHierarchySerializer.Serialize(actualResult.Nodes));
58 |
59 | var expectedresultSerialized = TestsHelper.GetEmbeddedText(resName);
60 | var expectedresult = SimpleHierarchySerializer.Deserialize(expectedresultSerialized);
61 |
62 | // Save expected hierarchy serialized
63 | File.WriteAllText(outDir + "\\" + resultName + ".ex", expectedresultSerialized);
64 |
65 | if (HierarchyComparer.Compare(actualResult.Nodes, expectedresult, new CodeNodeAssertComparer()))
66 | {
67 | passed = true;
68 | }
69 | }
70 |
71 | Assert.IsTrue(passed);
72 |
73 | return actualResult;
74 | }
75 | }
76 | }
77 |
--------------------------------------------------------------------------------