Skip to content

Commit fa9e0fa

Browse files
dragomirtitianjessetrinity
authored andcommitted
Better outlining spans for prototype methods (microsoft#32782)
* Changed outlining to better outline ES5 classes (functions assigned to prototype) * Changed outlining to better outline ES5 classes (properties assigned to functions) * Fixed some small bugs when merging es5 class nodes. Added tests for new es5 class outline. * Added support for interlaced ES5 classes (where an ES5 class's members are mixed with other declarations). * Fixed crash in outline when assigning {} to the prototype. * Added support for nested es5 declarations. * Added support for prototype assignment for es5 classes.
1 parent cd371da commit fa9e0fa

8 files changed

+1089
-29
lines changed

src/services/navigationBar.ts

Lines changed: 236 additions & 18 deletions
Large diffs are not rendered by default.

tests/cases/fourslash/navigationBarFunctionPrototype.ts

Lines changed: 81 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,69 @@
33
// @Filename: foo.js
44
////function f() {}
55
////f.prototype.x = 0;
6+
////f.y = 0;
7+
////f.prototype.method = function () {};
8+
////Object.defineProperty(f, 'staticProp', {
9+
//// set: function() {},
10+
//// get: function(){
11+
//// }
12+
////});
13+
////Object.defineProperty(f.prototype, 'name', {
14+
//// set: function() {},
15+
//// get: function(){
16+
//// }
17+
////});
618

719
verify.navigationTree({
820
"text": "<global>",
921
"kind": "script",
1022
"childItems": [
1123
{
1224
"text": "f",
13-
"kind": "function"
14-
},
15-
{
16-
"text": "x",
17-
"kind": "property"
25+
"kind": "class",
26+
"childItems": [
27+
{
28+
"text": "constructor",
29+
"kind": "constructor"
30+
},
31+
{
32+
"text": "x",
33+
"kind": "property"
34+
},
35+
{
36+
"text": "y"
37+
},
38+
{
39+
"text": "method",
40+
"kind": "function"
41+
},
42+
{
43+
"text": "staticProp",
44+
"childItems": [
45+
{
46+
"text": "get",
47+
"kind": "function"
48+
},
49+
{
50+
"text": "set",
51+
"kind": "function"
52+
}
53+
]
54+
},
55+
{
56+
"text": "name",
57+
"childItems": [
58+
{
59+
"text": "get",
60+
"kind": "function"
61+
},
62+
{
63+
"text": "set",
64+
"kind": "function"
65+
}
66+
]
67+
}
68+
]
1869
}
1970
]
2071
});
@@ -26,17 +77,36 @@ verify.navigationBar([
2677
"childItems": [
2778
{
2879
"text": "f",
29-
"kind": "function"
30-
},
31-
{
32-
"text": "x",
33-
"kind": "property"
80+
"kind": "class"
3481
}
3582
]
3683
},
3784
{
3885
"text": "f",
39-
"kind": "function",
86+
"kind": "class",
87+
"childItems": [
88+
{
89+
"text": "constructor",
90+
"kind": "constructor"
91+
},
92+
{
93+
"text": "x",
94+
"kind": "property"
95+
},
96+
{
97+
"text": "y"
98+
},
99+
{
100+
"text": "method",
101+
"kind": "function"
102+
},
103+
{
104+
"text": "staticProp"
105+
},
106+
{
107+
"text": "name"
108+
}
109+
],
40110
"indent": 1
41111
}
42112
]);
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/// <reference path="fourslash.ts"/>
2+
3+
// @Filename: foo.js
4+
5+
////A.prototype.a = function() { };
6+
////A.prototype.b = function() { };
7+
////function A() {}
8+
9+
verify.navigationTree({
10+
"text": "<global>",
11+
"kind": "script",
12+
"childItems": [
13+
{
14+
"text": "A",
15+
"kind": "class",
16+
"childItems": [
17+
{
18+
"text": "a",
19+
"kind": "function"
20+
},
21+
{
22+
"text": "b",
23+
"kind": "function"
24+
},
25+
{
26+
"text": "constructor",
27+
"kind": "constructor"
28+
}
29+
]
30+
}
31+
]
32+
});
33+
34+
verify.navigationBar([
35+
{
36+
"text": "<global>",
37+
"kind": "script",
38+
"childItems": [
39+
{
40+
"text": "A",
41+
"kind": "class"
42+
}
43+
]
44+
},
45+
{
46+
"text": "A",
47+
"kind": "class",
48+
"childItems": [
49+
{
50+
"text": "a",
51+
"kind": "function"
52+
},
53+
{
54+
"text": "b",
55+
"kind": "function"
56+
},
57+
{
58+
"text": "constructor",
59+
"kind": "constructor"
60+
}
61+
],
62+
"indent": 1
63+
}
64+
]);
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/// <reference path="fourslash.ts"/>
2+
3+
// @Filename: foo.js
4+
5+
////var A;
6+
////A.prototype.a = function() { };
7+
////A.b = function() { };
8+
9+
verify.navigationTree({
10+
"text": "<global>",
11+
"kind": "script",
12+
"childItems": [
13+
{
14+
"text": "A",
15+
"kind": "class",
16+
"childItems": [
17+
{
18+
"text": "constructor",
19+
"kind": "constructor"
20+
},
21+
{
22+
"text": "a",
23+
"kind": "function"
24+
},
25+
{
26+
"text": "b",
27+
"kind": "function"
28+
}
29+
]
30+
}
31+
]
32+
});
33+
34+
verify.navigationBar([
35+
{
36+
"text": "<global>",
37+
"kind": "script",
38+
"childItems": [
39+
{
40+
"text": "A",
41+
"kind": "class"
42+
}
43+
]
44+
},
45+
{
46+
"text": "A",
47+
"kind": "class",
48+
"childItems": [
49+
{
50+
"text": "constructor",
51+
"kind": "constructor"
52+
},
53+
{
54+
"text": "a",
55+
"kind": "function"
56+
},
57+
{
58+
"text": "b",
59+
"kind": "function"
60+
}
61+
],
62+
"indent": 1
63+
}
64+
]);
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/// <reference path="fourslash.ts"/>
2+
3+
// @Filename: foo.js
4+
5+
////var A;
6+
////A.prototype = { };
7+
////A.prototype = { m() {} };
8+
////A.prototype.a = function() { };
9+
////A.b = function() { };
10+
11+
verify.navigationTree({
12+
"text": "<global>",
13+
"kind": "script",
14+
"childItems": [
15+
{
16+
"text": "A",
17+
"kind": "class",
18+
"childItems": [
19+
{
20+
"text": "constructor",
21+
"kind": "constructor"
22+
},
23+
{
24+
"text": "m",
25+
"kind": "method"
26+
},
27+
{
28+
"text": "a",
29+
"kind": "function"
30+
},
31+
{
32+
"text": "b",
33+
"kind": "function"
34+
}
35+
]
36+
}
37+
]
38+
});
39+
40+
verify.navigationBar([
41+
{
42+
"text": "<global>",
43+
"kind": "script",
44+
"childItems": [
45+
{
46+
"text": "A",
47+
"kind": "class"
48+
}
49+
]
50+
},
51+
{
52+
"text": "A",
53+
"kind": "class",
54+
"childItems": [
55+
{
56+
"text": "constructor",
57+
"kind": "constructor"
58+
},
59+
{
60+
"text": "m",
61+
"kind": "method"
62+
},
63+
{
64+
"text": "a",
65+
"kind": "function"
66+
},
67+
{
68+
"text": "b",
69+
"kind": "function"
70+
}
71+
],
72+
"indent": 1
73+
}
74+
]);

0 commit comments

Comments
 (0)