Skip to content
Closed
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/compiler/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,17 @@ namespace ts {
return result;
}

export function filterMutate<T>(array: T[], f: (x: T) => boolean): void {
let outIndex = 0;
for (const item of array) {
if (f(item)) {
array[outIndex] = item;
outIndex++;
}
}
array.length = outIndex;
}

export function map<T, U>(array: T[], f: (x: T) => U): U[] {
let result: U[];
if (array) {
Expand Down
1,207 changes: 451 additions & 756 deletions src/services/navigationBar.ts

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/services/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6881,7 +6881,7 @@ namespace ts {
function getNavigationBarItems(fileName: string): NavigationBarItem[] {
const sourceFile = syntaxTreeCache.getCurrentSourceFile(fileName);

return NavigationBar.getNavigationBarItems(sourceFile, host.getCompilationSettings());
return NavigationBar.getNavigationBarItems(sourceFile);
}

function getSemanticClassifications(fileName: string, span: TextSpan): ClassifiedSpan[] {
Expand Down
8 changes: 4 additions & 4 deletions tests/cases/fourslash/navbar_contains-no-duplicates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,13 @@ verify.navigationBar([
"kindModifiers": "export,declare"
},
{
"text": "Test",
"kind": "class",
"text": "B",
"kind": "var",
"kindModifiers": "export,declare"
},
{
"text": "B",
"kind": "var",
"text": "Test",
"kind": "class",
"kindModifiers": "export,declare"
},
{
Expand Down
16 changes: 15 additions & 1 deletion tests/cases/fourslash/navbar_exportDefault.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,14 @@ goTo.file("a.ts");
verify.navigationBar([
{
"text": "\"a\"",
"kind": "module"
"kind": "module",
"childItems": [
{
"text": "default",
"kind": "class",
"kindModifiers": "export"
}
]
},
{
"text": "default",
Expand Down Expand Up @@ -52,6 +59,13 @@ verify.navigationBar([
{
"text": "\"c\"",
"kind": "module",
"childItems": [
{
"text": "default",
"kind": "function",
"kindModifiers": "export"
}
]
},
{
"text": "default",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
/// <reference path="fourslash.ts" />

////global.cls = class { };
////(function() {
//// const x = () => {
//// // Presence of inner function causes x to be a top-level function.
//// function xx() {}
//// };
//// const y = {
//// // This is not a top-level function (contains nothing, but shows up in childItems of its parent.)
//// foo: function() {}
//// };
//// (function nest() {
//// function moreNest() {}
//// })();
////})();
////(function() { // Different anonymous functions are not merged
//// // These will only show up as childItems.
//// function z() {}
//// console.log(function() {})
////})
////(function classes() {
//// // Classes show up in top-level regardless of whether they have names or inner declarations.
//// const cls2 = class { };
//// console.log(class cls3 {});
//// (class { });
////})

verify.navigationBar([
{
"text": "<global>",
"kind": "module",
"childItems": [
{
"text": "<function>",
"kind": "function"
},
{
"text": "<function>",
"kind": "function"
},
{
"text": "classes",
"kind": "function"
},
{
"text": "global.cls",
"kind": "class"
}
]
},
{
"text": "<function>",
"kind": "function",
"childItems": [
{
"text": "nest",
"kind": "function"
},
{
"text": "x",
"kind": "function"
},
{
"text": "y",
"kind": "const"
}
],
"indent": 1
},
{
"text": "nest",
"kind": "function",
"childItems": [
{
"text": "moreNest",
"kind": "function"
}
],
"indent": 2
},
{
"text": "x",
"kind": "function",
"childItems": [
{
"text": "xx",
"kind": "function"
}
],
"indent": 2
},
{
"text": "<function>",
"kind": "function",
"childItems": [
{
"text": "<function>",
"kind": "function"
},
{
"text": "z",
"kind": "function"
}
],
"indent": 1
},
{
"text": "classes",
"kind": "function",
"childItems": [
{
"text": "<class>",
"kind": "class"
},
{
"text": "cls2",
"kind": "class"
},
{
"text": "cls3",
"kind": "class"
}
],
"indent": 1
},
{
"text": "<class>",
"kind": "class",
"indent": 2
},
{
"text": "cls2",
"kind": "class",
"indent": 2
},
{
"text": "cls3",
"kind": "class",
"indent": 2
},
{
"text": "global.cls",
"kind": "class",
"indent": 1
}
]);
64 changes: 64 additions & 0 deletions tests/cases/fourslash/navigationBarDeclarationExpressions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/// <reference path="fourslash.ts" />

////console.log(console.log(class Y {}, class X {}), console.log(class B {}, class A {}));
////console.log(class Cls { meth() {} });

verify.navigationBar([
{
"text": "<global>",
"kind": "module",
"childItems": [
{
"text": "A",
"kind": "class"
},
{
"text": "B",
"kind": "class"
},
{
"text": "Cls",
"kind": "class"
},
{
"text": "X",
"kind": "class"
},
{
"text": "Y",
"kind": "class"
}
]
},
{
"text": "A",
"kind": "class",
"indent": 1
},
{
"text": "B",
"kind": "class",
"indent": 1
},
{
"text": "Cls",
"kind": "class",
"childItems": [
{
"text": "meth",
"kind": "method"
}
],
"indent": 1
},
{
"text": "X",
"kind": "class",
"indent": 1
},
{
"text": "Y",
"kind": "class",
"indent": 1
}
]);
48 changes: 48 additions & 0 deletions tests/cases/fourslash/navigationBarGetterAndSetter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/// <reference path="fourslash.ts" />

////class X {
//// get x() {}
//// set x(value) {
//// // Inner declaration should make the setter top-level.
//// function f() {}
//// }
////}

verify.navigationBar([
{
"text": "<global>",
"kind": "module",
"childItems": [
{
"text": "X",
"kind": "class"
}
]
},
{
"text": "X",
"kind": "class",
"childItems": [
{
"text": "x",
"kind": "getter"
},
{
"text": "x",
"kind": "setter"
}
],
"indent": 1
},
{
"text": "x",
"kind": "setter",
"childItems": [
{
"text": "f",
"kind": "function"
}
],
"indent": 2
}
]);
30 changes: 30 additions & 0 deletions tests/cases/fourslash/navigationBarImports.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/// <reference path="fourslash.ts"/>

////import a, {b} from "m";
////import c = require("m");
////import * as d from "m";

verify.navigationBar([
{
"text": "\"navigationBarImports\"",
"kind": "module",
"childItems": [
{
"text": "a",
"kind": "alias"
},
{
"text": "b",
"kind": "alias"
},
{
"text": "c",
"kind": "alias"
},
{
"text": "d",
"kind": "alias"
}
]
}
]);
Loading