diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index 8292565f000..35d173b4fdf 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -124,6 +124,8 @@ module ts { Tagged_templates_are_only_available_when_targeting_ECMAScript_6_and_higher: { code: 1159, category: DiagnosticCategory.Error, key: "Tagged templates are only available when targeting ECMAScript 6 and higher." }, Property_destructuring_pattern_expected: { code: 1160, category: DiagnosticCategory.Error, key: "Property destructuring pattern expected." }, Array_element_destructuring_pattern_expected: { code: 1161, category: DiagnosticCategory.Error, key: "Array element destructuring pattern expected." }, + A_destructuring_declaration_must_have_an_initializer: { code: 1162, category: DiagnosticCategory.Error, key: "A destructuring declaration must have an initializer." }, + Destructuring_declarations_are_not_allowed_in_ambient_contexts: { code: 1163, category: DiagnosticCategory.Error, key: "Destructuring declarations are not allowed in ambient contexts." }, Duplicate_identifier_0: { code: 2300, category: DiagnosticCategory.Error, key: "Duplicate identifier '{0}'." }, Initializer_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor: { code: 2301, category: DiagnosticCategory.Error, key: "Initializer of instance member variable '{0}' cannot reference identifier '{1}' declared in the constructor." }, Static_members_cannot_reference_class_type_parameters: { code: 2302, category: DiagnosticCategory.Error, key: "Static members cannot reference class type parameters." }, diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 1859bc9841a..97bfba31d0a 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -487,6 +487,14 @@ "category": "Error", "code": 1161 }, + "A destructuring declaration must have an initializer.": { + "category": "Error", + "code": 1162 + }, + "Destructuring declarations are not allowed in ambient contexts.": { + "category": "Error", + "code": 1163 + }, "Duplicate identifier '{0}'.": { "category": "Error", diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 69199b2b75b..d48f6489c8e 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -3466,11 +3466,25 @@ module ts { var initializerFirstTokenLength = scanner.getTextPos() - initializerStart; node.initializer = parseInitializer(/*inParameter*/ false, noIn); - if (inAmbientContext && node.initializer && errorCountBeforeVariableDeclaration === file.syntacticErrors.length) { - grammarErrorAtPos(initializerStart, initializerFirstTokenLength, Diagnostics.Initializers_are_not_allowed_in_ambient_contexts); - } - if (!inAmbientContext && !node.initializer && flags & NodeFlags.Const) { - grammarErrorOnNode(node, Diagnostics.const_declarations_must_be_initialized); + if (errorCountBeforeVariableDeclaration === file.syntacticErrors.length) { + if (inAmbientContext) { + if (isBindingPattern(node.name)) { + grammarErrorOnNode(node, Diagnostics.Destructuring_declarations_are_not_allowed_in_ambient_contexts); + } + else if (node.initializer) { + grammarErrorAtPos(initializerStart, initializerFirstTokenLength, Diagnostics.Initializers_are_not_allowed_in_ambient_contexts); + } + } + else { + if (!node.initializer) { + if (isBindingPattern(node.name)) { + grammarErrorOnNode(node, Diagnostics.A_destructuring_declaration_must_have_an_initializer); + } + else if (flags & NodeFlags.Const) { + grammarErrorOnNode(node, Diagnostics.const_declarations_must_be_initialized); + } + } + } } return finishNode(node); } diff --git a/src/services/navigationBar.ts b/src/services/navigationBar.ts index ba7cf7243e2..95d9b346255 100644 --- a/src/services/navigationBar.ts +++ b/src/services/navigationBar.ts @@ -38,26 +38,45 @@ module ts.NavigationBar { return indent; } - + function getChildNodes(nodes: Node[]): Node[] { - var childNodes: Node[] = []; + var childNodes: Node[] = []; - for (var i = 0, n = nodes.length; i < n; i++) { - var node = nodes[i]; - - if (node.kind === SyntaxKind.ClassDeclaration || - node.kind === SyntaxKind.EnumDeclaration || - node.kind === SyntaxKind.InterfaceDeclaration || - node.kind === SyntaxKind.ModuleDeclaration || - node.kind === SyntaxKind.FunctionDeclaration) { - - childNodes.push(node); - } - else if (node.kind === SyntaxKind.VariableStatement) { - childNodes.push.apply(childNodes, (node).declarations); + function visit(node: Node) { + switch (node.kind) { + case SyntaxKind.VariableStatement: + forEach((node).declarations, visit); + break; + case SyntaxKind.VariableDeclaration: + if (isBindingPattern(node)) { + forEach(((node).name).elements, visit); + break; + } + case SyntaxKind.ClassDeclaration: + case SyntaxKind.EnumDeclaration: + case SyntaxKind.InterfaceDeclaration: + case SyntaxKind.ModuleDeclaration: + case SyntaxKind.FunctionDeclaration: + childNodes.push(node); } } + //for (var i = 0, n = nodes.length; i < n; i++) { + // var node = nodes[i]; + + // if (node.kind === SyntaxKind.ClassDeclaration || + // node.kind === SyntaxKind.EnumDeclaration || + // node.kind === SyntaxKind.InterfaceDeclaration || + // node.kind === SyntaxKind.ModuleDeclaration || + // node.kind === SyntaxKind.FunctionDeclaration) { + + // childNodes.push(node); + // } + // else if (node.kind === SyntaxKind.VariableStatement) { + // childNodes.push.apply(childNodes, (node).declarations); + // } + //} + forEach(nodes, visit); return sortNodes(childNodes); }