Skip to content

Commit

Permalink
Better outlining spans for prototype methods (microsoft#32782)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
dragomirtitian authored and jessetrinity committed Aug 29, 2019
1 parent cd371da commit fa9e0fa
Show file tree
Hide file tree
Showing 8 changed files with 1,089 additions and 29 deletions.
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
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
@@ -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
@@ -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
@@ -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
}
]);

0 comments on commit fa9e0fa

Please sign in to comment.