Skip to content

Better outlining spans for prototype methods #32782

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

254 changes: 236 additions & 18 deletions src/services/navigationBar.ts

Large diffs are not rendered by default.

92 changes: 81 additions & 11 deletions tests/cases/fourslash/navigationBarFunctionPrototype.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,69 @@
// @Filename: foo.js
////function f() {}
////f.prototype.x = 0;
////f.y = 0;
////f.prototype.method = function () {};
////Object.defineProperty(f, 'staticProp', {
//// set: function() {},
//// get: function(){
//// }
////});
////Object.defineProperty(f.prototype, 'name', {
//// set: function() {},
//// get: function(){
//// }
////});

verify.navigationTree({
"text": "<global>",
"kind": "script",
"childItems": [
{
"text": "f",
"kind": "function"
},
{
"text": "x",
"kind": "property"
"kind": "class",
"childItems": [
{
"text": "constructor",
"kind": "constructor"
},
{
"text": "x",
"kind": "property"
},
{
"text": "y"
},
{
"text": "method",
"kind": "function"
},
{
"text": "staticProp",
"childItems": [
{
"text": "get",
"kind": "function"
},
{
"text": "set",
"kind": "function"
}
]
},
{
"text": "name",
"childItems": [
{
"text": "get",
"kind": "function"
},
{
"text": "set",
"kind": "function"
}
]
}
]
}
]
});
Expand All @@ -26,17 +77,36 @@ verify.navigationBar([
"childItems": [
{
"text": "f",
"kind": "function"
},
{
"text": "x",
"kind": "property"
"kind": "class"
}
]
},
{
"text": "f",
"kind": "function",
"kind": "class",
"childItems": [
{
"text": "constructor",
"kind": "constructor"
},
{
"text": "x",
"kind": "property"
},
{
"text": "y"
},
{
"text": "method",
"kind": "function"
},
{
"text": "staticProp"
},
{
"text": "name"
}
],
"indent": 1
}
]);
64 changes: 64 additions & 0 deletions tests/cases/fourslash/navigationBarFunctionPrototype2.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/// <reference path="fourslash.ts"/>

// @Filename: foo.js

////A.prototype.a = function() { };
////A.prototype.b = function() { };
////function A() {}

verify.navigationTree({
"text": "<global>",
"kind": "script",
"childItems": [
{
"text": "A",
"kind": "class",
"childItems": [
{
"text": "a",
"kind": "function"
},
{
"text": "b",
"kind": "function"
},
{
"text": "constructor",
"kind": "constructor"
}
]
}
]
});

verify.navigationBar([
{
"text": "<global>",
"kind": "script",
"childItems": [
{
"text": "A",
"kind": "class"
}
]
},
{
"text": "A",
"kind": "class",
"childItems": [
{
"text": "a",
"kind": "function"
},
{
"text": "b",
"kind": "function"
},
{
"text": "constructor",
"kind": "constructor"
}
],
"indent": 1
}
]);
64 changes: 64 additions & 0 deletions tests/cases/fourslash/navigationBarFunctionPrototype3.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/// <reference path="fourslash.ts"/>

// @Filename: foo.js

////var A;
////A.prototype.a = function() { };
////A.b = function() { };

verify.navigationTree({
"text": "<global>",
"kind": "script",
"childItems": [
{
"text": "A",
"kind": "class",
"childItems": [
{
"text": "constructor",
"kind": "constructor"
},
{
"text": "a",
"kind": "function"
},
{
"text": "b",
"kind": "function"
}
]
}
]
});

verify.navigationBar([
{
"text": "<global>",
"kind": "script",
"childItems": [
{
"text": "A",
"kind": "class"
}
]
},
{
"text": "A",
"kind": "class",
"childItems": [
{
"text": "constructor",
"kind": "constructor"
},
{
"text": "a",
"kind": "function"
},
{
"text": "b",
"kind": "function"
}
],
"indent": 1
}
]);
74 changes: 74 additions & 0 deletions tests/cases/fourslash/navigationBarFunctionPrototype4.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/// <reference path="fourslash.ts"/>

// @Filename: foo.js

////var A;
////A.prototype = { };
////A.prototype = { m() {} };
////A.prototype.a = function() { };
////A.b = function() { };

verify.navigationTree({
"text": "<global>",
"kind": "script",
"childItems": [
{
"text": "A",
"kind": "class",
"childItems": [
{
"text": "constructor",
"kind": "constructor"
},
{
"text": "m",
"kind": "method"
},
{
"text": "a",
"kind": "function"
},
{
"text": "b",
"kind": "function"
}
]
}
]
});

verify.navigationBar([
{
"text": "<global>",
"kind": "script",
"childItems": [
{
"text": "A",
"kind": "class"
}
]
},
{
"text": "A",
"kind": "class",
"childItems": [
{
"text": "constructor",
"kind": "constructor"
},
{
"text": "m",
"kind": "method"
},
{
"text": "a",
"kind": "function"
},
{
"text": "b",
"kind": "function"
}
],
"indent": 1
}
]);
Loading