From b5d9fa5dd6d6f35b95bd4d7440f5aca169b13f0b Mon Sep 17 00:00:00 2001 From: Paul van Brenk Date: Thu, 5 Mar 2015 17:37:40 -0800 Subject: [PATCH 1/2] Add assert for unexpected syntaxkind and a conservative temporary fix. --- src/services/navigationBar.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/services/navigationBar.ts b/src/services/navigationBar.ts index 771fe48219f1c..8bec8f62de6f6 100644 --- a/src/services/navigationBar.ts +++ b/src/services/navigationBar.ts @@ -96,7 +96,16 @@ module ts.NavigationBar { function sortNodes(nodes: Node[]): Node[] { return nodes.slice(0).sort((n1: Declaration, n2: Declaration) => { - if (n1.name && n2.name) { + + Debug.assert(n1.name.kind === SyntaxKind.Identifier || n1.name.kind === SyntaxKind.StringLiteral, `Expected n1.name is a ${n1.name.kind},\ + where SyntaxKind.ComputedPropertyName is ${SyntaxKind.ComputedPropertyName} and SyntaxKind.BindingPattern is ${SyntaxKind.ArrayBindingPattern} or\ + ${SyntaxKind.ObjectBindingPattern}`); + + Debug.assert(n2.name.kind === SyntaxKind.Identifier || n2.name.kind === SyntaxKind.StringLiteral, `Expected n2.name is a ${n2.name.kind},\ + where SyntaxKind.ComputedPropertyName is ${SyntaxKind.ComputedPropertyName} and SyntaxKind.BindingPattern is ${SyntaxKind.ArrayBindingPattern} or\ + ${SyntaxKind.ObjectBindingPattern}`); + + if (n1.name && (n1.name).text && n2.name) { // TODO(jfreeman): How do we sort declarations with computed names? return (n1.name).text.localeCompare((n2.name).text); } From 839d92f766020477a9a67dbfca74fdef17c7e1ba Mon Sep 17 00:00:00 2001 From: Paul van Brenk Date: Thu, 5 Mar 2015 18:04:31 -0800 Subject: [PATCH 2/2] Add checks so we don't crash on undefined in the asserts. --- src/services/navigationBar.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/services/navigationBar.ts b/src/services/navigationBar.ts index 8bec8f62de6f6..cfeb7bbb0b7cc 100644 --- a/src/services/navigationBar.ts +++ b/src/services/navigationBar.ts @@ -97,13 +97,17 @@ module ts.NavigationBar { function sortNodes(nodes: Node[]): Node[] { return nodes.slice(0).sort((n1: Declaration, n2: Declaration) => { - Debug.assert(n1.name.kind === SyntaxKind.Identifier || n1.name.kind === SyntaxKind.StringLiteral, `Expected n1.name is a ${n1.name.kind},\ + if (n1.name) { + Debug.assert(n1.name.kind === SyntaxKind.Identifier || n1.name.kind === SyntaxKind.StringLiteral, `Expected n1.name is a ${n1.name.kind},\ where SyntaxKind.ComputedPropertyName is ${SyntaxKind.ComputedPropertyName} and SyntaxKind.BindingPattern is ${SyntaxKind.ArrayBindingPattern} or\ ${SyntaxKind.ObjectBindingPattern}`); + } - Debug.assert(n2.name.kind === SyntaxKind.Identifier || n2.name.kind === SyntaxKind.StringLiteral, `Expected n2.name is a ${n2.name.kind},\ + if (n2.name) { + Debug.assert(n2.name.kind === SyntaxKind.Identifier || n2.name.kind === SyntaxKind.StringLiteral, `Expected n2.name is a ${n2.name.kind},\ where SyntaxKind.ComputedPropertyName is ${SyntaxKind.ComputedPropertyName} and SyntaxKind.BindingPattern is ${SyntaxKind.ArrayBindingPattern} or\ ${SyntaxKind.ObjectBindingPattern}`); + } if (n1.name && (n1.name).text && n2.name) { // TODO(jfreeman): How do we sort declarations with computed names?