commit
bb70e9eb12
45 changed files with 2586 additions and 1080 deletions
|
@ -332,10 +332,9 @@ module ts {
|
||||||
// symbol as its sole member. To the rest of the system, this symbol will be indistinguishable
|
// symbol as its sole member. To the rest of the system, this symbol will be indistinguishable
|
||||||
// from an actual type literal symbol you would have gotten had you used the long form.
|
// from an actual type literal symbol you would have gotten had you used the long form.
|
||||||
|
|
||||||
var symbolKind = node.kind === SyntaxKind.FunctionType ? SymbolFlags.CallSignature : SymbolFlags.ConstructSignature;
|
var symbol = createSymbol(SymbolFlags.Signature, getDeclarationName(node));
|
||||||
var symbol = createSymbol(symbolKind, getDeclarationName(node));
|
addDeclarationToSymbol(symbol, node, SymbolFlags.Signature);
|
||||||
addDeclarationToSymbol(symbol, node, symbolKind);
|
bindChildren(node, SymbolFlags.Signature, /*isBlockScopeContainer:*/ false);
|
||||||
bindChildren(node, symbolKind, /*isBlockScopeContainer:*/ false);
|
|
||||||
|
|
||||||
var typeLiteralSymbol = createSymbol(SymbolFlags.TypeLiteral, "__type");
|
var typeLiteralSymbol = createSymbol(SymbolFlags.TypeLiteral, "__type");
|
||||||
addDeclarationToSymbol(typeLiteralSymbol, node, SymbolFlags.TypeLiteral);
|
addDeclarationToSymbol(typeLiteralSymbol, node, SymbolFlags.TypeLiteral);
|
||||||
|
@ -376,10 +375,13 @@ module ts {
|
||||||
}
|
}
|
||||||
declareSymbol(blockScopeContainer.locals, undefined, node, SymbolFlags.BlockScopedVariable, SymbolFlags.BlockScopedVariableExcludes);
|
declareSymbol(blockScopeContainer.locals, undefined, node, SymbolFlags.BlockScopedVariable, SymbolFlags.BlockScopedVariableExcludes);
|
||||||
}
|
}
|
||||||
|
|
||||||
bindChildren(node, SymbolFlags.BlockScopedVariable, /*isBlockScopeContainer*/ false);
|
bindChildren(node, SymbolFlags.BlockScopedVariable, /*isBlockScopeContainer*/ false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getDestructuringParameterName(node: Declaration) {
|
||||||
|
return "__" + indexOf((<SignatureDeclaration>node.parent).parameters, node);
|
||||||
|
}
|
||||||
|
|
||||||
function bind(node: Node) {
|
function bind(node: Node) {
|
||||||
node.parent = parent;
|
node.parent = parent;
|
||||||
switch (node.kind) {
|
switch (node.kind) {
|
||||||
|
@ -387,10 +389,19 @@ module ts {
|
||||||
bindDeclaration(<Declaration>node, SymbolFlags.TypeParameter, SymbolFlags.TypeParameterExcludes, /*isBlockScopeContainer*/ false);
|
bindDeclaration(<Declaration>node, SymbolFlags.TypeParameter, SymbolFlags.TypeParameterExcludes, /*isBlockScopeContainer*/ false);
|
||||||
break;
|
break;
|
||||||
case SyntaxKind.Parameter:
|
case SyntaxKind.Parameter:
|
||||||
|
if (isBindingPattern((<Declaration>node).name)) {
|
||||||
|
bindAnonymousDeclaration(<Declaration>node, SymbolFlags.FunctionScopedVariable, getDestructuringParameterName(<Declaration>node), /*isBlockScopeContainer*/ false);
|
||||||
|
}
|
||||||
|
else {
|
||||||
bindDeclaration(<Declaration>node, SymbolFlags.FunctionScopedVariable, SymbolFlags.ParameterExcludes, /*isBlockScopeContainer*/ false);
|
bindDeclaration(<Declaration>node, SymbolFlags.FunctionScopedVariable, SymbolFlags.ParameterExcludes, /*isBlockScopeContainer*/ false);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case SyntaxKind.VariableDeclaration:
|
case SyntaxKind.VariableDeclaration:
|
||||||
if (node.flags & NodeFlags.BlockScoped) {
|
case SyntaxKind.BindingElement:
|
||||||
|
if (isBindingPattern((<Declaration>node).name)) {
|
||||||
|
bindChildren(node, 0, /*isBlockScopeContainer*/ false);
|
||||||
|
}
|
||||||
|
else if (node.flags & NodeFlags.BlockScoped) {
|
||||||
bindBlockScopedVariableDeclaration(<Declaration>node);
|
bindBlockScopedVariableDeclaration(<Declaration>node);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -399,6 +410,8 @@ module ts {
|
||||||
break;
|
break;
|
||||||
case SyntaxKind.PropertyDeclaration:
|
case SyntaxKind.PropertyDeclaration:
|
||||||
case SyntaxKind.PropertySignature:
|
case SyntaxKind.PropertySignature:
|
||||||
|
bindDeclaration(<Declaration>node, SymbolFlags.Property | ((<PropertyDeclaration>node).questionToken ? SymbolFlags.Optional : 0), SymbolFlags.PropertyExcludes, /*isBlockScopeContainer*/ false);
|
||||||
|
break;
|
||||||
case SyntaxKind.PropertyAssignment:
|
case SyntaxKind.PropertyAssignment:
|
||||||
case SyntaxKind.ShorthandPropertyAssignment:
|
case SyntaxKind.ShorthandPropertyAssignment:
|
||||||
bindDeclaration(<Declaration>node, SymbolFlags.Property, SymbolFlags.PropertyExcludes, /*isBlockScopeContainer*/ false);
|
bindDeclaration(<Declaration>node, SymbolFlags.Property, SymbolFlags.PropertyExcludes, /*isBlockScopeContainer*/ false);
|
||||||
|
@ -407,10 +420,9 @@ module ts {
|
||||||
bindDeclaration(<Declaration>node, SymbolFlags.EnumMember, SymbolFlags.EnumMemberExcludes, /*isBlockScopeContainer*/ false);
|
bindDeclaration(<Declaration>node, SymbolFlags.EnumMember, SymbolFlags.EnumMemberExcludes, /*isBlockScopeContainer*/ false);
|
||||||
break;
|
break;
|
||||||
case SyntaxKind.CallSignature:
|
case SyntaxKind.CallSignature:
|
||||||
bindDeclaration(<Declaration>node, SymbolFlags.CallSignature, 0, /*isBlockScopeContainer*/ false);
|
|
||||||
break;
|
|
||||||
case SyntaxKind.ConstructSignature:
|
case SyntaxKind.ConstructSignature:
|
||||||
bindDeclaration(<Declaration>node, SymbolFlags.ConstructSignature, 0, /*isBlockScopeContainer*/ true);
|
case SyntaxKind.IndexSignature:
|
||||||
|
bindDeclaration(<Declaration>node, SymbolFlags.Signature, 0, /*isBlockScopeContainer*/ false);
|
||||||
break;
|
break;
|
||||||
case SyntaxKind.MethodDeclaration:
|
case SyntaxKind.MethodDeclaration:
|
||||||
case SyntaxKind.MethodSignature:
|
case SyntaxKind.MethodSignature:
|
||||||
|
@ -418,12 +430,9 @@ module ts {
|
||||||
// as other properties in the object literal. So we use SymbolFlags.PropertyExcludes
|
// as other properties in the object literal. So we use SymbolFlags.PropertyExcludes
|
||||||
// so that it will conflict with any other object literal members with the same
|
// so that it will conflict with any other object literal members with the same
|
||||||
// name.
|
// name.
|
||||||
bindDeclaration(<Declaration>node, SymbolFlags.Method,
|
bindDeclaration(<Declaration>node, SymbolFlags.Method | ((<MethodDeclaration>node).questionToken ? SymbolFlags.Optional : 0),
|
||||||
isObjectLiteralMethod(node) ? SymbolFlags.PropertyExcludes : SymbolFlags.MethodExcludes, /*isBlockScopeContainer*/ true);
|
isObjectLiteralMethod(node) ? SymbolFlags.PropertyExcludes : SymbolFlags.MethodExcludes, /*isBlockScopeContainer*/ true);
|
||||||
break;
|
break;
|
||||||
case SyntaxKind.IndexSignature:
|
|
||||||
bindDeclaration(<Declaration>node, SymbolFlags.IndexSignature, 0, /*isBlockScopeContainer*/ false);
|
|
||||||
break;
|
|
||||||
case SyntaxKind.FunctionDeclaration:
|
case SyntaxKind.FunctionDeclaration:
|
||||||
bindDeclaration(<Declaration>node, SymbolFlags.Function, SymbolFlags.FunctionExcludes, /*isBlockScopeContainer*/ true);
|
bindDeclaration(<Declaration>node, SymbolFlags.Function, SymbolFlags.FunctionExcludes, /*isBlockScopeContainer*/ true);
|
||||||
break;
|
break;
|
||||||
|
@ -483,7 +492,6 @@ module ts {
|
||||||
bindAnonymousDeclaration(<SourceFile>node, SymbolFlags.ValueModule, '"' + removeFileExtension((<SourceFile>node).filename) + '"', /*isBlockScopeContainer*/ true);
|
bindAnonymousDeclaration(<SourceFile>node, SymbolFlags.ValueModule, '"' + removeFileExtension((<SourceFile>node).filename) + '"', /*isBlockScopeContainer*/ true);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case SyntaxKind.Block:
|
case SyntaxKind.Block:
|
||||||
case SyntaxKind.TryBlock:
|
case SyntaxKind.TryBlock:
|
||||||
case SyntaxKind.CatchClause:
|
case SyntaxKind.CatchClause:
|
||||||
|
@ -491,9 +499,8 @@ module ts {
|
||||||
case SyntaxKind.ForStatement:
|
case SyntaxKind.ForStatement:
|
||||||
case SyntaxKind.ForInStatement:
|
case SyntaxKind.ForInStatement:
|
||||||
case SyntaxKind.SwitchStatement:
|
case SyntaxKind.SwitchStatement:
|
||||||
bindChildren(node, 0 , true);
|
bindChildren(node, 0, /*isBlockScopeContainer*/ true);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
var saveParent = parent;
|
var saveParent = parent;
|
||||||
parent = node;
|
parent = node;
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -140,6 +140,10 @@ module ts {
|
||||||
Binary_digit_expected: { code: 1177, category: DiagnosticCategory.Error, key: "Binary digit expected." },
|
Binary_digit_expected: { code: 1177, category: DiagnosticCategory.Error, key: "Binary digit expected." },
|
||||||
Octal_digit_expected: { code: 1178, category: DiagnosticCategory.Error, key: "Octal digit expected." },
|
Octal_digit_expected: { code: 1178, category: DiagnosticCategory.Error, key: "Octal digit expected." },
|
||||||
Unexpected_token_expected: { code: 1179, category: DiagnosticCategory.Error, key: "Unexpected token. '{' expected." },
|
Unexpected_token_expected: { code: 1179, category: DiagnosticCategory.Error, key: "Unexpected token. '{' expected." },
|
||||||
|
Property_destructuring_pattern_expected: { code: 1180, category: DiagnosticCategory.Error, key: "Property destructuring pattern expected." },
|
||||||
|
Array_element_destructuring_pattern_expected: { code: 1181, category: DiagnosticCategory.Error, key: "Array element destructuring pattern expected." },
|
||||||
|
A_destructuring_declaration_must_have_an_initializer: { code: 1182, category: DiagnosticCategory.Error, key: "A destructuring declaration must have an initializer." },
|
||||||
|
Destructuring_declarations_are_not_allowed_in_ambient_contexts: { code: 1183, category: DiagnosticCategory.Error, key: "Destructuring declarations are not allowed in ambient contexts." },
|
||||||
Duplicate_identifier_0: { code: 2300, category: DiagnosticCategory.Error, key: "Duplicate identifier '{0}'." },
|
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." },
|
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." },
|
Static_members_cannot_reference_class_type_parameters: { code: 2302, category: DiagnosticCategory.Error, key: "Static members cannot reference class type parameters." },
|
||||||
|
@ -232,8 +236,6 @@ module ts {
|
||||||
Overload_signature_is_not_compatible_with_function_implementation: { code: 2394, category: DiagnosticCategory.Error, key: "Overload signature is not compatible with function implementation." },
|
Overload_signature_is_not_compatible_with_function_implementation: { code: 2394, category: DiagnosticCategory.Error, key: "Overload signature is not compatible with function implementation." },
|
||||||
Individual_declarations_in_merged_declaration_0_must_be_all_exported_or_all_local: { code: 2395, category: DiagnosticCategory.Error, key: "Individual declarations in merged declaration {0} must be all exported or all local." },
|
Individual_declarations_in_merged_declaration_0_must_be_all_exported_or_all_local: { code: 2395, category: DiagnosticCategory.Error, key: "Individual declarations in merged declaration {0} must be all exported or all local." },
|
||||||
Duplicate_identifier_arguments_Compiler_uses_arguments_to_initialize_rest_parameters: { code: 2396, category: DiagnosticCategory.Error, key: "Duplicate identifier 'arguments'. Compiler uses 'arguments' to initialize rest parameters." },
|
Duplicate_identifier_arguments_Compiler_uses_arguments_to_initialize_rest_parameters: { code: 2396, category: DiagnosticCategory.Error, key: "Duplicate identifier 'arguments'. Compiler uses 'arguments' to initialize rest parameters." },
|
||||||
Duplicate_identifier_i_Compiler_uses_i_to_initialize_rest_parameter: { code: 2397, category: DiagnosticCategory.Error, key: "Duplicate identifier '_i'. Compiler uses '_i' to initialize rest parameter." },
|
|
||||||
Expression_resolves_to_variable_declaration_i_that_compiler_uses_to_initialize_rest_parameter: { code: 2398, category: DiagnosticCategory.Error, key: "Expression resolves to variable declaration '_i' that compiler uses to initialize rest parameter." },
|
|
||||||
Duplicate_identifier_this_Compiler_uses_variable_declaration_this_to_capture_this_reference: { code: 2399, category: DiagnosticCategory.Error, key: "Duplicate identifier '_this'. Compiler uses variable declaration '_this' to capture 'this' reference." },
|
Duplicate_identifier_this_Compiler_uses_variable_declaration_this_to_capture_this_reference: { code: 2399, category: DiagnosticCategory.Error, key: "Duplicate identifier '_this'. Compiler uses variable declaration '_this' to capture 'this' reference." },
|
||||||
Expression_resolves_to_variable_declaration_this_that_compiler_uses_to_capture_this_reference: { code: 2400, category: DiagnosticCategory.Error, key: "Expression resolves to variable declaration '_this' that compiler uses to capture 'this' reference." },
|
Expression_resolves_to_variable_declaration_this_that_compiler_uses_to_capture_this_reference: { code: 2400, category: DiagnosticCategory.Error, key: "Expression resolves to variable declaration '_this' that compiler uses to capture 'this' reference." },
|
||||||
Duplicate_identifier_super_Compiler_uses_super_to_capture_base_class_reference: { code: 2401, category: DiagnosticCategory.Error, key: "Duplicate identifier '_super'. Compiler uses '_super' to capture base class reference." },
|
Duplicate_identifier_super_Compiler_uses_super_to_capture_base_class_reference: { code: 2401, category: DiagnosticCategory.Error, key: "Duplicate identifier '_super'. Compiler uses '_super' to capture base class reference." },
|
||||||
|
@ -289,6 +291,9 @@ module ts {
|
||||||
Type_alias_0_circularly_references_itself: { code: 2456, category: DiagnosticCategory.Error, key: "Type alias '{0}' circularly references itself." },
|
Type_alias_0_circularly_references_itself: { code: 2456, category: DiagnosticCategory.Error, key: "Type alias '{0}' circularly references itself." },
|
||||||
Type_alias_name_cannot_be_0: { code: 2457, category: DiagnosticCategory.Error, key: "Type alias name cannot be '{0}'" },
|
Type_alias_name_cannot_be_0: { code: 2457, category: DiagnosticCategory.Error, key: "Type alias name cannot be '{0}'" },
|
||||||
An_AMD_module_cannot_have_multiple_name_assignments: { code: 2458, category: DiagnosticCategory.Error, key: "An AMD module cannot have multiple name assignments." },
|
An_AMD_module_cannot_have_multiple_name_assignments: { code: 2458, category: DiagnosticCategory.Error, key: "An AMD module cannot have multiple name assignments." },
|
||||||
|
Type_0_has_no_property_1_and_no_string_index_signature: { code: 2459, category: DiagnosticCategory.Error, key: "Type '{0}' has no property '{1}' and no string index signature." },
|
||||||
|
Type_0_has_no_property_1: { code: 2460, category: DiagnosticCategory.Error, key: "Type '{0}' has no property '{1}'." },
|
||||||
|
Type_0_is_not_an_array_type: { code: 2461, category: DiagnosticCategory.Error, key: "Type '{0}' is not an array type." },
|
||||||
Import_declaration_0_is_using_private_name_1: { code: 4000, category: DiagnosticCategory.Error, key: "Import declaration '{0}' is using private name '{1}'." },
|
Import_declaration_0_is_using_private_name_1: { code: 4000, category: DiagnosticCategory.Error, key: "Import declaration '{0}' is using private name '{1}'." },
|
||||||
Type_parameter_0_of_exported_class_has_or_is_using_private_name_1: { code: 4002, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of exported class has or is using private name '{1}'." },
|
Type_parameter_0_of_exported_class_has_or_is_using_private_name_1: { code: 4002, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of exported class has or is using private name '{1}'." },
|
||||||
Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1: { code: 4004, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of exported interface has or is using private name '{1}'." },
|
Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1: { code: 4004, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of exported interface has or is using private name '{1}'." },
|
||||||
|
|
|
@ -552,6 +552,22 @@
|
||||||
"category": "Error",
|
"category": "Error",
|
||||||
"code": 1179
|
"code": 1179
|
||||||
},
|
},
|
||||||
|
"Property destructuring pattern expected.": {
|
||||||
|
"category": "Error",
|
||||||
|
"code": 1180
|
||||||
|
},
|
||||||
|
"Array element destructuring pattern expected.": {
|
||||||
|
"category": "Error",
|
||||||
|
"code": 1181
|
||||||
|
},
|
||||||
|
"A destructuring declaration must have an initializer.": {
|
||||||
|
"category": "Error",
|
||||||
|
"code": 1182
|
||||||
|
},
|
||||||
|
"Destructuring declarations are not allowed in ambient contexts.": {
|
||||||
|
"category": "Error",
|
||||||
|
"code": 1183
|
||||||
|
},
|
||||||
|
|
||||||
"Duplicate identifier '{0}'.": {
|
"Duplicate identifier '{0}'.": {
|
||||||
"category": "Error",
|
"category": "Error",
|
||||||
|
@ -921,14 +937,6 @@
|
||||||
"category": "Error",
|
"category": "Error",
|
||||||
"code": 2396
|
"code": 2396
|
||||||
},
|
},
|
||||||
"Duplicate identifier '_i'. Compiler uses '_i' to initialize rest parameter.": {
|
|
||||||
"category": "Error",
|
|
||||||
"code": 2397
|
|
||||||
},
|
|
||||||
"Expression resolves to variable declaration '_i' that compiler uses to initialize rest parameter.": {
|
|
||||||
"category": "Error",
|
|
||||||
"code": 2398
|
|
||||||
},
|
|
||||||
"Duplicate identifier '_this'. Compiler uses variable declaration '_this' to capture 'this' reference.": {
|
"Duplicate identifier '_this'. Compiler uses variable declaration '_this' to capture 'this' reference.": {
|
||||||
"category": "Error",
|
"category": "Error",
|
||||||
"code": 2399
|
"code": 2399
|
||||||
|
@ -1153,6 +1161,18 @@
|
||||||
"category": "Error",
|
"category": "Error",
|
||||||
"code": 2458
|
"code": 2458
|
||||||
},
|
},
|
||||||
|
"Type '{0}' has no property '{1}' and no string index signature.": {
|
||||||
|
"category": "Error",
|
||||||
|
"code": 2459
|
||||||
|
},
|
||||||
|
"Type '{0}' has no property '{1}'.": {
|
||||||
|
"category": "Error",
|
||||||
|
"code": 2460
|
||||||
|
},
|
||||||
|
"Type '{0}' is not an array type.": {
|
||||||
|
"category": "Error",
|
||||||
|
"code": 2461
|
||||||
|
},
|
||||||
|
|
||||||
"Import declaration '{0}' is using private name '{1}'.": {
|
"Import declaration '{0}' is using private name '{1}'.": {
|
||||||
"category": "Error",
|
"category": "Error",
|
||||||
|
|
|
@ -441,7 +441,7 @@ module ts {
|
||||||
handleSymbolAccessibilityError(resolver.isSymbolAccessible(symbol, enclosingDeclaration, meaning));
|
handleSymbolAccessibilityError(resolver.isSymbolAccessible(symbol, enclosingDeclaration, meaning));
|
||||||
}
|
}
|
||||||
|
|
||||||
function writeTypeOfDeclaration(declaration: AccessorDeclaration | VariableOrParameterDeclaration, type: TypeNode | StringLiteralExpression, getSymbolAccessibilityDiagnostic: GetSymbolAccessibilityDiagnostic) {
|
function writeTypeOfDeclaration(declaration: AccessorDeclaration | VariableLikeDeclaration, type: TypeNode | StringLiteralExpression, getSymbolAccessibilityDiagnostic: GetSymbolAccessibilityDiagnostic) {
|
||||||
writer.getSymbolAccessibilityDiagnostic = getSymbolAccessibilityDiagnostic;
|
writer.getSymbolAccessibilityDiagnostic = getSymbolAccessibilityDiagnostic;
|
||||||
write(": ");
|
write(": ");
|
||||||
if (type) {
|
if (type) {
|
||||||
|
@ -1003,7 +1003,7 @@ module ts {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function emitTypeOfVariableDeclarationFromTypeLiteral(node: VariableOrParameterDeclaration) {
|
function emitTypeOfVariableDeclarationFromTypeLiteral(node: VariableLikeDeclaration) {
|
||||||
// if this is property of type literal,
|
// if this is property of type literal,
|
||||||
// or is parameter of method/call/construct/index signature of type literal
|
// or is parameter of method/call/construct/index signature of type literal
|
||||||
// emit only if type is specified
|
// emit only if type is specified
|
||||||
|
@ -1263,7 +1263,12 @@ module ts {
|
||||||
if (node.dotDotDotToken) {
|
if (node.dotDotDotToken) {
|
||||||
write("...");
|
write("...");
|
||||||
}
|
}
|
||||||
|
if (isBindingPattern(node.name)) {
|
||||||
|
write("_" + indexOf((<FunctionLikeDeclaration>node.parent).parameters, node));
|
||||||
|
}
|
||||||
|
else {
|
||||||
writeTextOfNode(currentSourceFile, node.name);
|
writeTextOfNode(currentSourceFile, node.name);
|
||||||
|
}
|
||||||
if (node.initializer || hasQuestionToken(node)) {
|
if (node.initializer || hasQuestionToken(node)) {
|
||||||
write("?");
|
write("?");
|
||||||
}
|
}
|
||||||
|
@ -1490,6 +1495,9 @@ module ts {
|
||||||
var currentSourceFile: SourceFile;
|
var currentSourceFile: SourceFile;
|
||||||
|
|
||||||
var extendsEmitted = false;
|
var extendsEmitted = false;
|
||||||
|
var tempCount = 0;
|
||||||
|
var tempVariables: Identifier[];
|
||||||
|
var tempParameters: Identifier[];
|
||||||
|
|
||||||
/** write emitted output to disk*/
|
/** write emitted output to disk*/
|
||||||
var writeEmittedFiles = writeJavaScriptFile;
|
var writeEmittedFiles = writeJavaScriptFile;
|
||||||
|
@ -1885,6 +1893,44 @@ module ts {
|
||||||
writeFile(compilerHost, diagnostics, jsFilePath, emitOutput, writeByteOrderMark);
|
writeFile(compilerHost, diagnostics, jsFilePath, emitOutput, writeByteOrderMark);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Create a temporary variable with a unique unused name. The forLoopVariable parameter signals that the
|
||||||
|
// name should be one that is appropriate for a for loop variable.
|
||||||
|
function createTempVariable(location: Node, forLoopVariable?: boolean): Identifier {
|
||||||
|
var name = forLoopVariable ? "_i" : undefined;
|
||||||
|
while (true) {
|
||||||
|
if (name && resolver.isUnknownIdentifier(location, name)) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
// _a .. _h, _j ... _z, _0, _1, ...
|
||||||
|
name = "_" + (tempCount < 25 ? String.fromCharCode(tempCount + (tempCount < 8 ? 0: 1) + CharacterCodes.a) : tempCount - 25);
|
||||||
|
tempCount++;
|
||||||
|
}
|
||||||
|
var result = <Identifier>createNode(SyntaxKind.Identifier);
|
||||||
|
result.text = name;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
function recordTempDeclaration(name: Identifier) {
|
||||||
|
if (!tempVariables) {
|
||||||
|
tempVariables = [];
|
||||||
|
}
|
||||||
|
tempVariables.push(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
function emitTempDeclarations(newLine: boolean) {
|
||||||
|
if (tempVariables) {
|
||||||
|
if (newLine) {
|
||||||
|
writeLine();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
write(" ");
|
||||||
|
}
|
||||||
|
write("var ");
|
||||||
|
emitCommaList(tempVariables);
|
||||||
|
write(";");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function emitTokenText(tokenKind: SyntaxKind, startPos: number, emitFn?: () => void) {
|
function emitTokenText(tokenKind: SyntaxKind, startPos: number, emitFn?: () => void) {
|
||||||
var tokenString = tokenToString(tokenKind);
|
var tokenString = tokenToString(tokenKind);
|
||||||
if (emitFn) {
|
if (emitFn) {
|
||||||
|
@ -1903,16 +1949,13 @@ module ts {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function emitTrailingCommaIfPresent(nodeList: NodeArray<Node>, isMultiline: boolean): void {
|
function emitTrailingCommaIfPresent(nodeList: NodeArray<Node>): void {
|
||||||
if (nodeList.hasTrailingComma) {
|
if (nodeList.hasTrailingComma) {
|
||||||
write(",");
|
write(",");
|
||||||
if (isMultiline) {
|
|
||||||
writeLine();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function emitCommaList(nodes: NodeArray<Node>, includeTrailingComma: boolean, count?: number) {
|
function emitCommaList(nodes: Node[], count?: number) {
|
||||||
if (!(count >= 0)) {
|
if (!(count >= 0)) {
|
||||||
count = nodes.length;
|
count = nodes.length;
|
||||||
}
|
}
|
||||||
|
@ -1923,14 +1966,10 @@ module ts {
|
||||||
}
|
}
|
||||||
emit(nodes[i]);
|
emit(nodes[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (includeTrailingComma) {
|
|
||||||
emitTrailingCommaIfPresent(nodes, /*isMultiline*/ false);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function emitMultiLineList(nodes: NodeArray<Node>, includeTrailingComma: boolean) {
|
function emitMultiLineList(nodes: Node[]) {
|
||||||
if (nodes) {
|
if (nodes) {
|
||||||
for (var i = 0; i < nodes.length; i++) {
|
for (var i = 0; i < nodes.length; i++) {
|
||||||
if (i) {
|
if (i) {
|
||||||
|
@ -1939,10 +1978,6 @@ module ts {
|
||||||
writeLine();
|
writeLine();
|
||||||
emit(nodes[i]);
|
emit(nodes[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (includeTrailingComma) {
|
|
||||||
emitTrailingCommaIfPresent(nodes, /*isMultiline*/ true);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1970,8 +2005,9 @@ module ts {
|
||||||
}
|
}
|
||||||
|
|
||||||
function emitLiteral(node: LiteralExpression) {
|
function emitLiteral(node: LiteralExpression) {
|
||||||
var text = getLiteralText();
|
var text = compilerOptions.target < ScriptTarget.ES6 && isTemplateLiteralKind(node.kind) ? getTemplateLiteralAsStringLiteral(node) :
|
||||||
|
node.parent ? getSourceTextOfNodeFromSourceFile(currentSourceFile, node) :
|
||||||
|
node.text;
|
||||||
if (compilerOptions.sourceMap && (node.kind === SyntaxKind.StringLiteral || isTemplateLiteralKind(node.kind))) {
|
if (compilerOptions.sourceMap && (node.kind === SyntaxKind.StringLiteral || isTemplateLiteralKind(node.kind))) {
|
||||||
writer.writeLiteral(text);
|
writer.writeLiteral(text);
|
||||||
}
|
}
|
||||||
|
@ -1982,14 +2018,6 @@ module ts {
|
||||||
else {
|
else {
|
||||||
write(text);
|
write(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getLiteralText() {
|
|
||||||
if (compilerOptions.target < ScriptTarget.ES6 && isTemplateLiteralKind(node.kind)) {
|
|
||||||
return getTemplateLiteralAsStringLiteral(node)
|
|
||||||
}
|
|
||||||
|
|
||||||
return getSourceTextOfNodeFromSourceFile(currentSourceFile, node);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function getTemplateLiteralAsStringLiteral(node: LiteralExpression): string {
|
function getTemplateLiteralAsStringLiteral(node: LiteralExpression): string {
|
||||||
|
@ -2133,6 +2161,7 @@ module ts {
|
||||||
switch (parent.kind) {
|
switch (parent.kind) {
|
||||||
case SyntaxKind.Parameter:
|
case SyntaxKind.Parameter:
|
||||||
case SyntaxKind.VariableDeclaration:
|
case SyntaxKind.VariableDeclaration:
|
||||||
|
case SyntaxKind.BindingElement:
|
||||||
case SyntaxKind.PropertyDeclaration:
|
case SyntaxKind.PropertyDeclaration:
|
||||||
case SyntaxKind.PropertySignature:
|
case SyntaxKind.PropertySignature:
|
||||||
case SyntaxKind.PropertyAssignment:
|
case SyntaxKind.PropertyAssignment:
|
||||||
|
@ -2171,7 +2200,10 @@ module ts {
|
||||||
}
|
}
|
||||||
|
|
||||||
function emitIdentifier(node: Identifier) {
|
function emitIdentifier(node: Identifier) {
|
||||||
if (!isNotExpressionIdentifier(node)) {
|
if (!node.parent) {
|
||||||
|
write(node.text);
|
||||||
|
}
|
||||||
|
else if (!isNotExpressionIdentifier(node)) {
|
||||||
emitExpressionIdentifier(node);
|
emitExpressionIdentifier(node);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -2201,18 +2233,34 @@ module ts {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function emitObjectBindingPattern(node: BindingPattern) {
|
||||||
|
write("{ ");
|
||||||
|
emitCommaList(node.elements);
|
||||||
|
emitTrailingCommaIfPresent(node.elements);
|
||||||
|
write(" }");
|
||||||
|
}
|
||||||
|
|
||||||
|
function emitArrayBindingPattern(node: BindingPattern) {
|
||||||
|
write("[");
|
||||||
|
emitCommaList(node.elements);
|
||||||
|
emitTrailingCommaIfPresent(node.elements);
|
||||||
|
write("]");
|
||||||
|
}
|
||||||
|
|
||||||
function emitArrayLiteral(node: ArrayLiteralExpression) {
|
function emitArrayLiteral(node: ArrayLiteralExpression) {
|
||||||
if (node.flags & NodeFlags.MultiLine) {
|
if (node.flags & NodeFlags.MultiLine) {
|
||||||
write("[");
|
write("[");
|
||||||
increaseIndent();
|
increaseIndent();
|
||||||
emitMultiLineList(node.elements, /*includeTrailingComma*/ true);
|
emitMultiLineList(node.elements);
|
||||||
|
emitTrailingCommaIfPresent(node.elements);
|
||||||
decreaseIndent();
|
decreaseIndent();
|
||||||
writeLine();
|
writeLine();
|
||||||
write("]");
|
write("]");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
write("[");
|
write("[");
|
||||||
emitCommaList(node.elements, /*includeTrailingComma*/ true);
|
emitCommaList(node.elements);
|
||||||
|
emitTrailingCommaIfPresent(node.elements);
|
||||||
write("]");
|
write("]");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2224,14 +2272,20 @@ module ts {
|
||||||
else if (node.flags & NodeFlags.MultiLine) {
|
else if (node.flags & NodeFlags.MultiLine) {
|
||||||
write("{");
|
write("{");
|
||||||
increaseIndent();
|
increaseIndent();
|
||||||
emitMultiLineList(node.properties, /*includeTrailingComma*/ compilerOptions.target >= ScriptTarget.ES5);
|
emitMultiLineList(node.properties);
|
||||||
|
if (compilerOptions.target >= ScriptTarget.ES5) {
|
||||||
|
emitTrailingCommaIfPresent(node.properties);
|
||||||
|
}
|
||||||
decreaseIndent();
|
decreaseIndent();
|
||||||
writeLine();
|
writeLine();
|
||||||
write("}");
|
write("}");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
write("{ ");
|
write("{ ");
|
||||||
emitCommaList(node.properties, /*includeTrailingComma*/ compilerOptions.target >= ScriptTarget.ES5);
|
emitCommaList(node.properties);
|
||||||
|
if (compilerOptions.target >= ScriptTarget.ES5) {
|
||||||
|
emitTrailingCommaIfPresent(node.properties);
|
||||||
|
}
|
||||||
write(" }");
|
write(" }");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2242,26 +2296,15 @@ module ts {
|
||||||
write("]");
|
write("]");
|
||||||
}
|
}
|
||||||
|
|
||||||
function emitDownlevelMethod(node: MethodDeclaration) {
|
|
||||||
if (!isObjectLiteralMethod(node)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
emitLeadingComments(node);
|
|
||||||
emit(node.name);
|
|
||||||
write(": ");
|
|
||||||
write("function ");
|
|
||||||
emitSignatureAndBody(node);
|
|
||||||
emitTrailingComments(node);
|
|
||||||
}
|
|
||||||
|
|
||||||
function emitMethod(node: MethodDeclaration) {
|
function emitMethod(node: MethodDeclaration) {
|
||||||
if (!isObjectLiteralMethod(node)) {
|
if (!isObjectLiteralMethod(node)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
emitLeadingComments(node);
|
emitLeadingComments(node);
|
||||||
emit(node.name);
|
emit(node.name);
|
||||||
|
if (compilerOptions.target < ScriptTarget.ES6) {
|
||||||
|
write(": function ");
|
||||||
|
}
|
||||||
emitSignatureAndBody(node);
|
emitSignatureAndBody(node);
|
||||||
emitTrailingComments(node);
|
emitTrailingComments(node);
|
||||||
}
|
}
|
||||||
|
@ -2274,18 +2317,9 @@ module ts {
|
||||||
emitTrailingComments(node);
|
emitTrailingComments(node);
|
||||||
}
|
}
|
||||||
|
|
||||||
function emitDownlevelShorthandPropertyAssignment(node: ShorthandPropertyAssignment) {
|
|
||||||
emitLeadingComments(node);
|
|
||||||
// Emit identifier as an identifier
|
|
||||||
emit(node.name);
|
|
||||||
write(": ");
|
|
||||||
// Even though this is stored as identifier treat it as an expression
|
|
||||||
// Short-hand, { x }, is equivalent of normal form { x: x }
|
|
||||||
emitExpressionIdentifier(node.name);
|
|
||||||
emitTrailingComments(node);
|
|
||||||
}
|
|
||||||
|
|
||||||
function emitShorthandPropertyAssignment(node: ShorthandPropertyAssignment) {
|
function emitShorthandPropertyAssignment(node: ShorthandPropertyAssignment) {
|
||||||
|
emitLeadingComments(node);
|
||||||
|
emit(node.name);
|
||||||
// If short-hand property has a prefix, then regardless of the target version, we will emit it as normal property assignment. For example:
|
// If short-hand property has a prefix, then regardless of the target version, we will emit it as normal property assignment. For example:
|
||||||
// module m {
|
// module m {
|
||||||
// export var y;
|
// export var y;
|
||||||
|
@ -2294,17 +2328,15 @@ module ts {
|
||||||
// export var obj = { y };
|
// export var obj = { y };
|
||||||
// }
|
// }
|
||||||
// The short-hand property in obj need to emit as such ... = { y : m.y } regardless of the TargetScript version
|
// The short-hand property in obj need to emit as such ... = { y : m.y } regardless of the TargetScript version
|
||||||
var prefix = resolver.getExpressionNamePrefix(node.name);
|
if (compilerOptions.target < ScriptTarget.ES6 || resolver.getExpressionNamePrefix(node.name)) {
|
||||||
if (prefix) {
|
// Emit identifier as an identifier
|
||||||
emitDownlevelShorthandPropertyAssignment(node);
|
write(": ");
|
||||||
|
// Even though this is stored as identifier treat it as an expression
|
||||||
|
// Short-hand, { x }, is equivalent of normal form { x: x }
|
||||||
|
emitExpressionIdentifier(node.name);
|
||||||
}
|
}
|
||||||
// If short-hand property has no prefix, emit it as short-hand.
|
|
||||||
else {
|
|
||||||
emitLeadingComments(node);
|
|
||||||
emit(node.name);
|
|
||||||
emitTrailingComments(node);
|
emitTrailingComments(node);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
function tryEmitConstantValue(node: PropertyAccessExpression | ElementAccessExpression): boolean {
|
function tryEmitConstantValue(node: PropertyAccessExpression | ElementAccessExpression): boolean {
|
||||||
var constantValue = resolver.getConstantValue(node);
|
var constantValue = resolver.getConstantValue(node);
|
||||||
|
@ -2356,13 +2388,13 @@ module ts {
|
||||||
emitThis(node.expression);
|
emitThis(node.expression);
|
||||||
if (node.arguments.length) {
|
if (node.arguments.length) {
|
||||||
write(", ");
|
write(", ");
|
||||||
emitCommaList(node.arguments, /*includeTrailingComma*/ false);
|
emitCommaList(node.arguments);
|
||||||
}
|
}
|
||||||
write(")");
|
write(")");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
write("(");
|
write("(");
|
||||||
emitCommaList(node.arguments, /*includeTrailingComma*/ false);
|
emitCommaList(node.arguments);
|
||||||
write(")");
|
write(")");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2372,7 +2404,7 @@ module ts {
|
||||||
emit(node.expression);
|
emit(node.expression);
|
||||||
if (node.arguments) {
|
if (node.arguments) {
|
||||||
write("(");
|
write("(");
|
||||||
emitCommaList(node.arguments, /*includeTrailingComma*/ false);
|
emitCommaList(node.arguments);
|
||||||
write(")");
|
write(")");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2470,12 +2502,17 @@ module ts {
|
||||||
|
|
||||||
|
|
||||||
function emitBinaryExpression(node: BinaryExpression) {
|
function emitBinaryExpression(node: BinaryExpression) {
|
||||||
|
if (node.operator === SyntaxKind.EqualsToken && (node.left.kind === SyntaxKind.ObjectLiteralExpression || node.left.kind === SyntaxKind.ArrayLiteralExpression)) {
|
||||||
|
emitDestructuring(node);
|
||||||
|
}
|
||||||
|
else {
|
||||||
emit(node.left);
|
emit(node.left);
|
||||||
if (node.operator !== SyntaxKind.CommaToken) write(" ");
|
if (node.operator !== SyntaxKind.CommaToken) write(" ");
|
||||||
write(tokenToString(node.operator));
|
write(tokenToString(node.operator));
|
||||||
write(" ");
|
write(" ");
|
||||||
emit(node.right);
|
emit(node.right);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function emitConditionalExpression(node: ConditionalExpression) {
|
function emitConditionalExpression(node: ConditionalExpression) {
|
||||||
emit(node.condition);
|
emit(node.condition);
|
||||||
|
@ -2494,6 +2531,9 @@ module ts {
|
||||||
emitCaptureThisForNodeIfNecessary(node.parent);
|
emitCaptureThisForNodeIfNecessary(node.parent);
|
||||||
}
|
}
|
||||||
emitLines(node.statements);
|
emitLines(node.statements);
|
||||||
|
if (node.kind === SyntaxKind.ModuleBlock) {
|
||||||
|
emitTempDeclarations(/*newLine*/ true);
|
||||||
|
}
|
||||||
decreaseIndent();
|
decreaseIndent();
|
||||||
writeLine();
|
writeLine();
|
||||||
emitToken(SyntaxKind.CloseBraceToken, node.statements.end);
|
emitToken(SyntaxKind.CloseBraceToken, node.statements.end);
|
||||||
|
@ -2581,7 +2621,7 @@ module ts {
|
||||||
emitToken(SyntaxKind.VarKeyword, endPos);
|
emitToken(SyntaxKind.VarKeyword, endPos);
|
||||||
}
|
}
|
||||||
write(" ");
|
write(" ");
|
||||||
emitCommaList(node.declarations, /*includeTrailingComma*/ false);
|
emitCommaList(node.declarations);
|
||||||
}
|
}
|
||||||
if (node.initializer) {
|
if (node.initializer) {
|
||||||
emit(node.initializer);
|
emit(node.initializer);
|
||||||
|
@ -2738,10 +2778,214 @@ module ts {
|
||||||
emitEnd(node.name);
|
emitEnd(node.name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function emitDestructuring(root: BinaryExpression | VariableDeclaration | ParameterDeclaration, value?: Expression) {
|
||||||
|
var emitCount = 0;
|
||||||
|
// An exported declaration is actually emitted as an assignment (to a property on the module object), so
|
||||||
|
// temporary variables in an exported declaration need to have real declarations elsewhere
|
||||||
|
var isDeclaration = (root.kind === SyntaxKind.VariableDeclaration && !(root.flags & NodeFlags.Export)) || root.kind === SyntaxKind.Parameter;
|
||||||
|
if (root.kind === SyntaxKind.BinaryExpression) {
|
||||||
|
emitAssignmentExpression(<BinaryExpression>root);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
emitBindingElement(<BindingElement>root, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
function emitAssignment(name: Identifier, value: Expression) {
|
||||||
|
if (emitCount++) {
|
||||||
|
write(", ");
|
||||||
|
}
|
||||||
|
if (name.parent && (name.parent.kind === SyntaxKind.VariableDeclaration || name.parent.kind === SyntaxKind.BindingElement)) {
|
||||||
|
emitModuleMemberName(<Declaration>name.parent);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
emit(name);
|
||||||
|
}
|
||||||
|
write(" = ");
|
||||||
|
emit(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
function ensureIdentifier(expr: Expression): Expression {
|
||||||
|
if (expr.kind !== SyntaxKind.Identifier) {
|
||||||
|
var identifier = createTempVariable(root);
|
||||||
|
if (!isDeclaration) {
|
||||||
|
recordTempDeclaration(identifier);
|
||||||
|
}
|
||||||
|
emitAssignment(identifier, expr);
|
||||||
|
expr = identifier;
|
||||||
|
}
|
||||||
|
return expr;
|
||||||
|
}
|
||||||
|
|
||||||
|
function createVoidZero(): Expression {
|
||||||
|
var zero = <LiteralExpression>createNode(SyntaxKind.NumericLiteral);
|
||||||
|
zero.text = "0";
|
||||||
|
var result = <PrefixUnaryExpression>createNode(SyntaxKind.PrefixUnaryExpression);
|
||||||
|
result.operator = SyntaxKind.VoidKeyword;
|
||||||
|
result.operand = zero;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
function createDefaultValueCheck(value: Expression, defaultValue: Expression): Expression {
|
||||||
|
// The value expression will be evaluated twice, so for anything but a simple identifier
|
||||||
|
// we need to generate a temporary variable
|
||||||
|
value = ensureIdentifier(value);
|
||||||
|
// Return the expression 'value === void 0 ? defaultValue : value'
|
||||||
|
var equals = <BinaryExpression>createNode(SyntaxKind.BinaryExpression);
|
||||||
|
equals.left = value;
|
||||||
|
equals.operator = SyntaxKind.EqualsEqualsEqualsToken;
|
||||||
|
equals.right = createVoidZero();
|
||||||
|
var cond = <ConditionalExpression>createNode(SyntaxKind.ConditionalExpression);
|
||||||
|
cond.condition = equals;
|
||||||
|
cond.whenTrue = defaultValue;
|
||||||
|
cond.whenFalse = value;
|
||||||
|
return cond;
|
||||||
|
}
|
||||||
|
|
||||||
|
function createNumericLiteral(value: number) {
|
||||||
|
var node = <LiteralExpression>createNode(SyntaxKind.NumericLiteral);
|
||||||
|
node.text = "" + value;
|
||||||
|
return node;
|
||||||
|
}
|
||||||
|
|
||||||
|
function parenthesizeForAccess(expr: Expression): LeftHandSideExpression {
|
||||||
|
if (expr.kind === SyntaxKind.Identifier || expr.kind === SyntaxKind.PropertyAccessExpression || expr.kind === SyntaxKind.ElementAccessExpression) {
|
||||||
|
return <LeftHandSideExpression>expr;
|
||||||
|
}
|
||||||
|
var node = <ParenthesizedExpression>createNode(SyntaxKind.ParenthesizedExpression);
|
||||||
|
node.expression = expr;
|
||||||
|
return node;
|
||||||
|
}
|
||||||
|
|
||||||
|
function createPropertyAccess(object: Expression, propName: Identifier): Expression {
|
||||||
|
if (propName.kind !== SyntaxKind.Identifier) {
|
||||||
|
return createElementAccess(object, propName);
|
||||||
|
}
|
||||||
|
var node = <PropertyAccessExpression>createNode(SyntaxKind.PropertyAccessExpression);
|
||||||
|
node.expression = parenthesizeForAccess(object);
|
||||||
|
node.name = propName;
|
||||||
|
return node;
|
||||||
|
}
|
||||||
|
|
||||||
|
function createElementAccess(object: Expression, index: Expression): Expression {
|
||||||
|
var node = <ElementAccessExpression>createNode(SyntaxKind.ElementAccessExpression);
|
||||||
|
node.expression = parenthesizeForAccess(object);
|
||||||
|
node.argumentExpression = index;
|
||||||
|
return node;
|
||||||
|
}
|
||||||
|
|
||||||
|
function emitObjectLiteralAssignment(target: ObjectLiteralExpression, value: Expression) {
|
||||||
|
var properties = target.properties;
|
||||||
|
if (properties.length !== 1) {
|
||||||
|
// For anything but a single element destructuring we need to generate a temporary
|
||||||
|
// to ensure value is evaluated exactly once.
|
||||||
|
value = ensureIdentifier(value);
|
||||||
|
}
|
||||||
|
for (var i = 0; i < properties.length; i++) {
|
||||||
|
var p = properties[i];
|
||||||
|
if (p.kind === SyntaxKind.PropertyAssignment || p.kind === SyntaxKind.ShorthandPropertyAssignment) {
|
||||||
|
// TODO(andersh): Computed property support
|
||||||
|
var propName = <Identifier>((<PropertyAssignment>p).name);
|
||||||
|
emitDestructuringAssignment((<PropertyAssignment>p).initializer || propName, createPropertyAccess(value, propName));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function emitArrayLiteralAssignment(target: ArrayLiteralExpression, value: Expression) {
|
||||||
|
var elements = target.elements;
|
||||||
|
if (elements.length !== 1) {
|
||||||
|
// For anything but a single element destructuring we need to generate a temporary
|
||||||
|
// to ensure value is evaluated exactly once.
|
||||||
|
value = ensureIdentifier(value);
|
||||||
|
}
|
||||||
|
for (var i = 0; i < elements.length; i++) {
|
||||||
|
var e = elements[i];
|
||||||
|
if (e.kind !== SyntaxKind.OmittedExpression) {
|
||||||
|
emitDestructuringAssignment(e, createElementAccess(value, createNumericLiteral(i)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function emitDestructuringAssignment(target: Expression, value: Expression) {
|
||||||
|
if (target.kind === SyntaxKind.BinaryExpression && (<BinaryExpression>target).operator === SyntaxKind.EqualsToken) {
|
||||||
|
value = createDefaultValueCheck(value,(<BinaryExpression>target).right);
|
||||||
|
target = (<BinaryExpression>target).left;
|
||||||
|
}
|
||||||
|
if (target.kind === SyntaxKind.ObjectLiteralExpression) {
|
||||||
|
emitObjectLiteralAssignment(<ObjectLiteralExpression>target, value);
|
||||||
|
}
|
||||||
|
else if (target.kind === SyntaxKind.ArrayLiteralExpression) {
|
||||||
|
emitArrayLiteralAssignment(<ArrayLiteralExpression>target, value);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
emitAssignment(<Identifier>target, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function emitAssignmentExpression(root: BinaryExpression) {
|
||||||
|
var target = root.left;
|
||||||
|
var value = root.right;
|
||||||
|
if (root.parent.kind === SyntaxKind.ExpressionStatement) {
|
||||||
|
emitDestructuringAssignment(target, value);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (root.parent.kind !== SyntaxKind.ParenthesizedExpression) {
|
||||||
|
write("(");
|
||||||
|
}
|
||||||
|
value = ensureIdentifier(value);
|
||||||
|
emitDestructuringAssignment(target, value);
|
||||||
|
write(", ");
|
||||||
|
emit(value);
|
||||||
|
if (root.parent.kind !== SyntaxKind.ParenthesizedExpression) {
|
||||||
|
write(")");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function emitBindingElement(target: BindingElement, value: Expression) {
|
||||||
|
if (target.initializer) {
|
||||||
|
// Combine value and initializer
|
||||||
|
value = value ? createDefaultValueCheck(value, target.initializer) : target.initializer;
|
||||||
|
}
|
||||||
|
else if (!value) {
|
||||||
|
// Use 'void 0' in absence of value and initializer
|
||||||
|
value = createVoidZero();
|
||||||
|
}
|
||||||
|
if (isBindingPattern(target.name)) {
|
||||||
|
var pattern = <BindingPattern>target.name;
|
||||||
|
var elements = pattern.elements;
|
||||||
|
if (elements.length !== 1) {
|
||||||
|
// For anything but a single element destructuring we need to generate a temporary
|
||||||
|
// to ensure value is evaluated exactly once.
|
||||||
|
value = ensureIdentifier(value);
|
||||||
|
}
|
||||||
|
for (var i = 0; i < elements.length; i++) {
|
||||||
|
var element = elements[i];
|
||||||
|
if (pattern.kind === SyntaxKind.ObjectBindingPattern) {
|
||||||
|
// Rewrite element to a declaration with an initializer that fetches property
|
||||||
|
var propName = element.propertyName || <Identifier>element.name;
|
||||||
|
emitBindingElement(element, createPropertyAccess(value, propName));
|
||||||
|
}
|
||||||
|
else if (element.kind !== SyntaxKind.OmittedExpression) {
|
||||||
|
// Rewrite element to a declaration that accesses array element at index i
|
||||||
|
emitBindingElement(element, createElementAccess(value, createNumericLiteral(i)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
emitAssignment(<Identifier>target.name, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function emitVariableDeclaration(node: VariableDeclaration) {
|
function emitVariableDeclaration(node: VariableDeclaration) {
|
||||||
emitLeadingComments(node);
|
emitLeadingComments(node);
|
||||||
|
if (isBindingPattern(node.name)) {
|
||||||
|
emitDestructuring(node);
|
||||||
|
}
|
||||||
|
else {
|
||||||
emitModuleMemberName(node);
|
emitModuleMemberName(node);
|
||||||
emitOptional(" = ", node.initializer);
|
emitOptional(" = ", node.initializer);
|
||||||
|
}
|
||||||
emitTrailingComments(node);
|
emitTrailingComments(node);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2758,32 +3002,57 @@ module ts {
|
||||||
write("var ");
|
write("var ");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
emitCommaList(node.declarations, /*includeTrailingComma*/ false);
|
emitCommaList(node.declarations);
|
||||||
write(";");
|
write(";");
|
||||||
emitTrailingComments(node);
|
emitTrailingComments(node);
|
||||||
}
|
}
|
||||||
|
|
||||||
function emitParameter(node: ParameterDeclaration) {
|
function emitParameter(node: ParameterDeclaration) {
|
||||||
emitLeadingComments(node);
|
emitLeadingComments(node);
|
||||||
|
if (isBindingPattern(node.name)) {
|
||||||
|
var name = createTempVariable(node);
|
||||||
|
if (!tempParameters) {
|
||||||
|
tempParameters = [];
|
||||||
|
}
|
||||||
|
tempParameters.push(name);
|
||||||
|
emit(name);
|
||||||
|
}
|
||||||
|
else {
|
||||||
emit(node.name);
|
emit(node.name);
|
||||||
|
}
|
||||||
|
// TODO(andersh): Enable ES6 code generation below
|
||||||
|
//if (node.propertyName) {
|
||||||
|
// emit(node.propertyName);
|
||||||
|
// write(": ");
|
||||||
|
//}
|
||||||
|
//emit(node.name);
|
||||||
|
//emitOptional(" = ", node.initializer);
|
||||||
emitTrailingComments(node);
|
emitTrailingComments(node);
|
||||||
}
|
}
|
||||||
|
|
||||||
function emitDefaultValueAssignments(node: FunctionLikeDeclaration) {
|
function emitDefaultValueAssignments(node: FunctionLikeDeclaration) {
|
||||||
forEach(node.parameters, param => {
|
var tempIndex = 0;
|
||||||
if (param.initializer) {
|
forEach(node.parameters, p => {
|
||||||
|
if (isBindingPattern(p.name)) {
|
||||||
writeLine();
|
writeLine();
|
||||||
emitStart(param);
|
write("var ");
|
||||||
|
emitDestructuring(p, tempParameters[tempIndex]);
|
||||||
|
write(";");
|
||||||
|
tempIndex++;
|
||||||
|
}
|
||||||
|
else if (p.initializer) {
|
||||||
|
writeLine();
|
||||||
|
emitStart(p);
|
||||||
write("if (");
|
write("if (");
|
||||||
emitNode(param.name);
|
emitNode(p.name);
|
||||||
write(" === void 0)");
|
write(" === void 0)");
|
||||||
emitEnd(param);
|
emitEnd(p);
|
||||||
write(" { ");
|
write(" { ");
|
||||||
emitStart(param);
|
emitStart(p);
|
||||||
emitNode(param.name);
|
emitNode(p.name);
|
||||||
write(" = ");
|
write(" = ");
|
||||||
emitNode(param.initializer);
|
emitNode(p.initializer);
|
||||||
emitEnd(param);
|
emitEnd(p);
|
||||||
write("; }");
|
write("; }");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -2793,6 +3062,7 @@ module ts {
|
||||||
if (hasRestParameters(node)) {
|
if (hasRestParameters(node)) {
|
||||||
var restIndex = node.parameters.length - 1;
|
var restIndex = node.parameters.length - 1;
|
||||||
var restParam = node.parameters[restIndex];
|
var restParam = node.parameters[restIndex];
|
||||||
|
var tempName = createTempVariable(node, /*forLoopVariable*/ true).text;
|
||||||
writeLine();
|
writeLine();
|
||||||
emitLeadingComments(restParam);
|
emitLeadingComments(restParam);
|
||||||
emitStart(restParam);
|
emitStart(restParam);
|
||||||
|
@ -2804,22 +3074,22 @@ module ts {
|
||||||
writeLine();
|
writeLine();
|
||||||
write("for (");
|
write("for (");
|
||||||
emitStart(restParam);
|
emitStart(restParam);
|
||||||
write("var _i = " + restIndex + ";");
|
write("var " + tempName + " = " + restIndex + ";");
|
||||||
emitEnd(restParam);
|
emitEnd(restParam);
|
||||||
write(" ");
|
write(" ");
|
||||||
emitStart(restParam);
|
emitStart(restParam);
|
||||||
write("_i < arguments.length;");
|
write(tempName + " < arguments.length;");
|
||||||
emitEnd(restParam);
|
emitEnd(restParam);
|
||||||
write(" ");
|
write(" ");
|
||||||
emitStart(restParam);
|
emitStart(restParam);
|
||||||
write("_i++");
|
write(tempName + "++");
|
||||||
emitEnd(restParam);
|
emitEnd(restParam);
|
||||||
write(") {");
|
write(") {");
|
||||||
increaseIndent();
|
increaseIndent();
|
||||||
writeLine();
|
writeLine();
|
||||||
emitStart(restParam);
|
emitStart(restParam);
|
||||||
emitNode(restParam.name);
|
emitNode(restParam.name);
|
||||||
write("[_i - " + restIndex + "] = arguments[_i];");
|
write("[" + tempName + " - " + restIndex + "] = arguments[" + tempName + "];");
|
||||||
emitEnd(restParam);
|
emitEnd(restParam);
|
||||||
decreaseIndent();
|
decreaseIndent();
|
||||||
writeLine();
|
writeLine();
|
||||||
|
@ -2867,13 +3137,19 @@ module ts {
|
||||||
increaseIndent();
|
increaseIndent();
|
||||||
write("(");
|
write("(");
|
||||||
if (node) {
|
if (node) {
|
||||||
emitCommaList(node.parameters, /*includeTrailingComma*/ false, node.parameters.length - (hasRestParameters(node) ? 1 : 0));
|
emitCommaList(node.parameters, node.parameters.length - (hasRestParameters(node) ? 1 : 0));
|
||||||
}
|
}
|
||||||
write(")");
|
write(")");
|
||||||
decreaseIndent();
|
decreaseIndent();
|
||||||
}
|
}
|
||||||
|
|
||||||
function emitSignatureAndBody(node: FunctionLikeDeclaration) {
|
function emitSignatureAndBody(node: FunctionLikeDeclaration) {
|
||||||
|
var saveTempCount = tempCount;
|
||||||
|
var saveTempVariables = tempVariables;
|
||||||
|
var saveTempParameters = tempParameters;
|
||||||
|
tempCount = 0;
|
||||||
|
tempVariables = undefined;
|
||||||
|
tempParameters = undefined;
|
||||||
emitSignatureParameters(node);
|
emitSignatureParameters(node);
|
||||||
write(" {");
|
write(" {");
|
||||||
scopeEmitStart(node);
|
scopeEmitStart(node);
|
||||||
|
@ -2896,7 +3172,9 @@ module ts {
|
||||||
write("return ");
|
write("return ");
|
||||||
emitNode(node.body);
|
emitNode(node.body);
|
||||||
emitEnd(node.body);
|
emitEnd(node.body);
|
||||||
write("; ");
|
write(";");
|
||||||
|
emitTempDeclarations(/*newLine*/ false);
|
||||||
|
write(" ");
|
||||||
emitStart(node.body);
|
emitStart(node.body);
|
||||||
write("}");
|
write("}");
|
||||||
emitEnd(node.body);
|
emitEnd(node.body);
|
||||||
|
@ -2913,11 +3191,12 @@ module ts {
|
||||||
write(";");
|
write(";");
|
||||||
emitTrailingComments(node.body);
|
emitTrailingComments(node.body);
|
||||||
}
|
}
|
||||||
|
emitTempDeclarations(/*newLine*/ true);
|
||||||
writeLine();
|
writeLine();
|
||||||
if (node.body.kind === SyntaxKind.Block) {
|
if (node.body.kind === SyntaxKind.Block) {
|
||||||
emitLeadingCommentsOfPosition((<Block>node.body).statements.end);
|
emitLeadingCommentsOfPosition((<Block>node.body).statements.end);
|
||||||
decreaseIndent();
|
decreaseIndent();
|
||||||
emitToken(SyntaxKind.CloseBraceToken, (<Block>node.body).statements.end);
|
emitToken(SyntaxKind.CloseBraceToken,(<Block>node.body).statements.end);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
decreaseIndent();
|
decreaseIndent();
|
||||||
|
@ -2936,6 +3215,9 @@ module ts {
|
||||||
emitEnd(node);
|
emitEnd(node);
|
||||||
write(";");
|
write(";");
|
||||||
}
|
}
|
||||||
|
tempCount = saveTempCount;
|
||||||
|
tempVariables = saveTempVariables;
|
||||||
|
tempParameters = saveTempParameters;
|
||||||
}
|
}
|
||||||
|
|
||||||
function findInitialSuperCall(ctor: ConstructorDeclaration): ExpressionStatement {
|
function findInitialSuperCall(ctor: ConstructorDeclaration): ExpressionStatement {
|
||||||
|
@ -3139,6 +3421,12 @@ module ts {
|
||||||
emitTrailingComments(node);
|
emitTrailingComments(node);
|
||||||
|
|
||||||
function emitConstructorOfClass() {
|
function emitConstructorOfClass() {
|
||||||
|
var saveTempCount = tempCount;
|
||||||
|
var saveTempVariables = tempVariables;
|
||||||
|
var saveTempParameters = tempParameters;
|
||||||
|
tempCount = 0;
|
||||||
|
tempVariables = undefined;
|
||||||
|
tempParameters = undefined;
|
||||||
// Emit the constructor overload pinned comments
|
// Emit the constructor overload pinned comments
|
||||||
forEach(node.members, member => {
|
forEach(node.members, member => {
|
||||||
if (member.kind === SyntaxKind.Constructor && !(<ConstructorDeclaration>member).body) {
|
if (member.kind === SyntaxKind.Constructor && !(<ConstructorDeclaration>member).body) {
|
||||||
|
@ -3187,6 +3475,7 @@ module ts {
|
||||||
if (superCall) statements = statements.slice(1);
|
if (superCall) statements = statements.slice(1);
|
||||||
emitLines(statements);
|
emitLines(statements);
|
||||||
}
|
}
|
||||||
|
emitTempDeclarations(/*newLine*/ true);
|
||||||
writeLine();
|
writeLine();
|
||||||
if (ctor) {
|
if (ctor) {
|
||||||
emitLeadingCommentsOfPosition((<Block>ctor.body).statements.end);
|
emitLeadingCommentsOfPosition((<Block>ctor.body).statements.end);
|
||||||
|
@ -3198,6 +3487,9 @@ module ts {
|
||||||
if (ctor) {
|
if (ctor) {
|
||||||
emitTrailingComments(ctor);
|
emitTrailingComments(ctor);
|
||||||
}
|
}
|
||||||
|
tempCount = saveTempCount;
|
||||||
|
tempVariables = saveTempVariables;
|
||||||
|
tempParameters = saveTempParameters;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3305,7 +3597,13 @@ module ts {
|
||||||
emitEnd(node.name);
|
emitEnd(node.name);
|
||||||
write(") ");
|
write(") ");
|
||||||
if (node.body.kind === SyntaxKind.ModuleBlock) {
|
if (node.body.kind === SyntaxKind.ModuleBlock) {
|
||||||
|
var saveTempCount = tempCount;
|
||||||
|
var saveTempVariables = tempVariables;
|
||||||
|
tempCount = 0;
|
||||||
|
tempVariables = undefined;
|
||||||
emit(node.body);
|
emit(node.body);
|
||||||
|
tempCount = saveTempCount;
|
||||||
|
tempVariables = saveTempVariables;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
write("{");
|
write("{");
|
||||||
|
@ -3521,17 +3819,18 @@ module ts {
|
||||||
if (!node) {
|
if (!node) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (node.flags & NodeFlags.Ambient) {
|
if (node.flags & NodeFlags.Ambient) {
|
||||||
return emitPinnedOrTripleSlashComments(node);
|
return emitPinnedOrTripleSlashComments(node);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if the node can be emitted regardless of the ScriptTarget
|
// Check if the node can be emitted regardless of the ScriptTarget
|
||||||
switch (node.kind) {
|
switch (node.kind) {
|
||||||
case SyntaxKind.Identifier:
|
case SyntaxKind.Identifier:
|
||||||
return emitIdentifier(<Identifier>node);
|
return emitIdentifier(<Identifier>node);
|
||||||
case SyntaxKind.Parameter:
|
case SyntaxKind.Parameter:
|
||||||
return emitParameter(<ParameterDeclaration>node);
|
return emitParameter(<ParameterDeclaration>node);
|
||||||
|
case SyntaxKind.MethodDeclaration:
|
||||||
|
case SyntaxKind.MethodSignature:
|
||||||
|
return emitMethod(<MethodDeclaration>node);
|
||||||
case SyntaxKind.GetAccessor:
|
case SyntaxKind.GetAccessor:
|
||||||
case SyntaxKind.SetAccessor:
|
case SyntaxKind.SetAccessor:
|
||||||
return emitAccessor(<AccessorDeclaration>node);
|
return emitAccessor(<AccessorDeclaration>node);
|
||||||
|
@ -3559,12 +3858,18 @@ module ts {
|
||||||
return emitTemplateSpan(<TemplateSpan>node);
|
return emitTemplateSpan(<TemplateSpan>node);
|
||||||
case SyntaxKind.QualifiedName:
|
case SyntaxKind.QualifiedName:
|
||||||
return emitQualifiedName(<QualifiedName>node);
|
return emitQualifiedName(<QualifiedName>node);
|
||||||
|
case SyntaxKind.ObjectBindingPattern:
|
||||||
|
return emitObjectBindingPattern(<BindingPattern>node);
|
||||||
|
case SyntaxKind.ArrayBindingPattern:
|
||||||
|
return emitArrayBindingPattern(<BindingPattern>node);
|
||||||
case SyntaxKind.ArrayLiteralExpression:
|
case SyntaxKind.ArrayLiteralExpression:
|
||||||
return emitArrayLiteral(<ArrayLiteralExpression>node);
|
return emitArrayLiteral(<ArrayLiteralExpression>node);
|
||||||
case SyntaxKind.ObjectLiteralExpression:
|
case SyntaxKind.ObjectLiteralExpression:
|
||||||
return emitObjectLiteral(<ObjectLiteralExpression>node);
|
return emitObjectLiteral(<ObjectLiteralExpression>node);
|
||||||
case SyntaxKind.PropertyAssignment:
|
case SyntaxKind.PropertyAssignment:
|
||||||
return emitPropertyAssignment(<PropertyDeclaration>node);
|
return emitPropertyAssignment(<PropertyDeclaration>node);
|
||||||
|
case SyntaxKind.ShorthandPropertyAssignment:
|
||||||
|
return emitShorthandPropertyAssignment(<ShorthandPropertyAssignment>node);
|
||||||
case SyntaxKind.ComputedPropertyName:
|
case SyntaxKind.ComputedPropertyName:
|
||||||
return emitComputedPropertyName(<ComputedPropertyName>node);
|
return emitComputedPropertyName(<ComputedPropertyName>node);
|
||||||
case SyntaxKind.PropertyAccessExpression:
|
case SyntaxKind.PropertyAccessExpression:
|
||||||
|
@ -3659,29 +3964,6 @@ module ts {
|
||||||
case SyntaxKind.SourceFile:
|
case SyntaxKind.SourceFile:
|
||||||
return emitSourceFile(<SourceFile>node);
|
return emitSourceFile(<SourceFile>node);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Emit node which needs to be emitted differently depended on ScriptTarget
|
|
||||||
if (compilerOptions.target < ScriptTarget.ES6) {
|
|
||||||
// Emit node down-level
|
|
||||||
switch (node.kind) {
|
|
||||||
case SyntaxKind.ShorthandPropertyAssignment:
|
|
||||||
return emitDownlevelShorthandPropertyAssignment(<ShorthandPropertyAssignment>node);
|
|
||||||
case SyntaxKind.MethodDeclaration:
|
|
||||||
case SyntaxKind.MethodSignature:
|
|
||||||
return emitDownlevelMethod(<MethodDeclaration>node);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
// Emit node natively
|
|
||||||
Debug.assert(compilerOptions.target >= ScriptTarget.ES6, "Invalid ScriptTarget. We should emit as ES6 or above");
|
|
||||||
switch (node.kind) {
|
|
||||||
case SyntaxKind.ShorthandPropertyAssignment:
|
|
||||||
return emitShorthandPropertyAssignment(<ShorthandPropertyAssignment>node);
|
|
||||||
case SyntaxKind.MethodDeclaration:
|
|
||||||
case SyntaxKind.MethodSignature:
|
|
||||||
return emitMethod(<MethodDeclaration>node);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function hasDetachedComments(pos: number) {
|
function hasDetachedComments(pos: number) {
|
||||||
|
|
|
@ -40,12 +40,8 @@ module ts {
|
||||||
return nodeConstructors[kind] || (nodeConstructors[kind] = objectAllocator.getNodeConstructor(kind));
|
return nodeConstructors[kind] || (nodeConstructors[kind] = objectAllocator.getNodeConstructor(kind));
|
||||||
}
|
}
|
||||||
|
|
||||||
function createRootNode(kind: SyntaxKind, pos: number, end: number, flags: NodeFlags): Node {
|
export function createNode(kind: SyntaxKind): Node {
|
||||||
var node = new (getNodeConstructor(kind))();
|
return new (getNodeConstructor(kind))();
|
||||||
node.pos = pos;
|
|
||||||
node.end = end;
|
|
||||||
node.flags = flags;
|
|
||||||
return node;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getSourceFileOfNode(node: Node): SourceFile {
|
export function getSourceFileOfNode(node: Node): SourceFile {
|
||||||
|
@ -140,6 +136,7 @@ module ts {
|
||||||
// This list is a work in progress. Add missing node kinds to improve their error
|
// This list is a work in progress. Add missing node kinds to improve their error
|
||||||
// spans.
|
// spans.
|
||||||
case SyntaxKind.VariableDeclaration:
|
case SyntaxKind.VariableDeclaration:
|
||||||
|
case SyntaxKind.BindingElement:
|
||||||
case SyntaxKind.ClassDeclaration:
|
case SyntaxKind.ClassDeclaration:
|
||||||
case SyntaxKind.InterfaceDeclaration:
|
case SyntaxKind.InterfaceDeclaration:
|
||||||
case SyntaxKind.ModuleDeclaration:
|
case SyntaxKind.ModuleDeclaration:
|
||||||
|
@ -260,21 +257,19 @@ module ts {
|
||||||
return child((<TypeParameterDeclaration>node).name) ||
|
return child((<TypeParameterDeclaration>node).name) ||
|
||||||
child((<TypeParameterDeclaration>node).constraint);
|
child((<TypeParameterDeclaration>node).constraint);
|
||||||
case SyntaxKind.Parameter:
|
case SyntaxKind.Parameter:
|
||||||
return children(node.modifiers) ||
|
|
||||||
child((<ParameterDeclaration>node).dotDotDotToken) ||
|
|
||||||
child((<ParameterDeclaration>node).name) ||
|
|
||||||
child((<ParameterDeclaration>node).questionToken) ||
|
|
||||||
child((<ParameterDeclaration>node).type) ||
|
|
||||||
child((<ParameterDeclaration>node).initializer);
|
|
||||||
case SyntaxKind.PropertyDeclaration:
|
case SyntaxKind.PropertyDeclaration:
|
||||||
case SyntaxKind.PropertySignature:
|
case SyntaxKind.PropertySignature:
|
||||||
case SyntaxKind.PropertyAssignment:
|
case SyntaxKind.PropertyAssignment:
|
||||||
case SyntaxKind.ShorthandPropertyAssignment:
|
case SyntaxKind.ShorthandPropertyAssignment:
|
||||||
|
case SyntaxKind.VariableDeclaration:
|
||||||
|
case SyntaxKind.BindingElement:
|
||||||
return children(node.modifiers) ||
|
return children(node.modifiers) ||
|
||||||
child((<PropertyDeclaration>node).name) ||
|
child((<VariableLikeDeclaration>node).propertyName) ||
|
||||||
child((<PropertyDeclaration>node).questionToken) ||
|
child((<VariableLikeDeclaration>node).dotDotDotToken) ||
|
||||||
child((<PropertyDeclaration>node).type) ||
|
child((<VariableLikeDeclaration>node).name) ||
|
||||||
child((<PropertyDeclaration>node).initializer);
|
child((<VariableLikeDeclaration>node).questionToken) ||
|
||||||
|
child((<VariableLikeDeclaration>node).type) ||
|
||||||
|
child((<VariableLikeDeclaration>node).initializer);
|
||||||
case SyntaxKind.FunctionType:
|
case SyntaxKind.FunctionType:
|
||||||
case SyntaxKind.ConstructorType:
|
case SyntaxKind.ConstructorType:
|
||||||
case SyntaxKind.CallSignature:
|
case SyntaxKind.CallSignature:
|
||||||
|
@ -315,6 +310,9 @@ module ts {
|
||||||
return children((<UnionTypeNode>node).types);
|
return children((<UnionTypeNode>node).types);
|
||||||
case SyntaxKind.ParenthesizedType:
|
case SyntaxKind.ParenthesizedType:
|
||||||
return child((<ParenthesizedTypeNode>node).type);
|
return child((<ParenthesizedTypeNode>node).type);
|
||||||
|
case SyntaxKind.ObjectBindingPattern:
|
||||||
|
case SyntaxKind.ArrayBindingPattern:
|
||||||
|
return children((<BindingPattern>node).elements);
|
||||||
case SyntaxKind.ArrayLiteralExpression:
|
case SyntaxKind.ArrayLiteralExpression:
|
||||||
return children((<ArrayLiteralExpression>node).elements);
|
return children((<ArrayLiteralExpression>node).elements);
|
||||||
case SyntaxKind.ObjectLiteralExpression:
|
case SyntaxKind.ObjectLiteralExpression:
|
||||||
|
@ -421,11 +419,6 @@ module ts {
|
||||||
return child((<CatchClause>node).name) ||
|
return child((<CatchClause>node).name) ||
|
||||||
child((<CatchClause>node).type) ||
|
child((<CatchClause>node).type) ||
|
||||||
child((<CatchClause>node).block);
|
child((<CatchClause>node).block);
|
||||||
case SyntaxKind.VariableDeclaration:
|
|
||||||
return children(node.modifiers) ||
|
|
||||||
child((<VariableDeclaration>node).name) ||
|
|
||||||
child((<VariableDeclaration>node).type) ||
|
|
||||||
child((<VariableDeclaration>node).initializer);
|
|
||||||
case SyntaxKind.ClassDeclaration:
|
case SyntaxKind.ClassDeclaration:
|
||||||
return children(node.modifiers) ||
|
return children(node.modifiers) ||
|
||||||
child((<ClassDeclaration>node).name) ||
|
child((<ClassDeclaration>node).name) ||
|
||||||
|
@ -506,6 +499,7 @@ module ts {
|
||||||
export function isAnyFunction(node: Node): boolean {
|
export function isAnyFunction(node: Node): boolean {
|
||||||
if (node) {
|
if (node) {
|
||||||
switch (node.kind) {
|
switch (node.kind) {
|
||||||
|
case SyntaxKind.Constructor:
|
||||||
case SyntaxKind.FunctionExpression:
|
case SyntaxKind.FunctionExpression:
|
||||||
case SyntaxKind.FunctionDeclaration:
|
case SyntaxKind.FunctionDeclaration:
|
||||||
case SyntaxKind.ArrowFunction:
|
case SyntaxKind.ArrowFunction:
|
||||||
|
@ -513,7 +507,14 @@ module ts {
|
||||||
case SyntaxKind.MethodSignature:
|
case SyntaxKind.MethodSignature:
|
||||||
case SyntaxKind.GetAccessor:
|
case SyntaxKind.GetAccessor:
|
||||||
case SyntaxKind.SetAccessor:
|
case SyntaxKind.SetAccessor:
|
||||||
case SyntaxKind.Constructor:
|
case SyntaxKind.CallSignature:
|
||||||
|
case SyntaxKind.ConstructSignature:
|
||||||
|
case SyntaxKind.IndexSignature:
|
||||||
|
case SyntaxKind.FunctionType:
|
||||||
|
case SyntaxKind.ConstructorType:
|
||||||
|
case SyntaxKind.FunctionExpression:
|
||||||
|
case SyntaxKind.ArrowFunction:
|
||||||
|
case SyntaxKind.FunctionDeclaration:
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -522,11 +523,11 @@ module ts {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function isFunctionBlock(node: Node) {
|
export function isFunctionBlock(node: Node) {
|
||||||
return node !== undefined && node.kind === SyntaxKind.Block && isAnyFunction(node.parent);
|
return node && node.kind === SyntaxKind.Block && isAnyFunction(node.parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function isObjectLiteralMethod(node: Node) {
|
export function isObjectLiteralMethod(node: Node) {
|
||||||
return node !== undefined && node.kind === SyntaxKind.MethodDeclaration && node.parent.kind === SyntaxKind.ObjectLiteralExpression;
|
return node && node.kind === SyntaxKind.MethodDeclaration && node.parent.kind === SyntaxKind.ObjectLiteralExpression;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getContainingFunction(node: Node): FunctionLikeDeclaration {
|
export function getContainingFunction(node: Node): FunctionLikeDeclaration {
|
||||||
|
@ -646,7 +647,8 @@ module ts {
|
||||||
case SyntaxKind.PropertySignature:
|
case SyntaxKind.PropertySignature:
|
||||||
case SyntaxKind.EnumMember:
|
case SyntaxKind.EnumMember:
|
||||||
case SyntaxKind.PropertyAssignment:
|
case SyntaxKind.PropertyAssignment:
|
||||||
return (<VariableDeclaration>parent).initializer === node;
|
case SyntaxKind.BindingElement:
|
||||||
|
return (<VariableLikeDeclaration>parent).initializer === node;
|
||||||
case SyntaxKind.ExpressionStatement:
|
case SyntaxKind.ExpressionStatement:
|
||||||
case SyntaxKind.IfStatement:
|
case SyntaxKind.IfStatement:
|
||||||
case SyntaxKind.DoStatement:
|
case SyntaxKind.DoStatement:
|
||||||
|
@ -730,6 +732,10 @@ module ts {
|
||||||
return SyntaxKind.FirstTemplateToken <= kind && kind <= SyntaxKind.LastTemplateToken;
|
return SyntaxKind.FirstTemplateToken <= kind && kind <= SyntaxKind.LastTemplateToken;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function isBindingPattern(node: Node) {
|
||||||
|
return node.kind === SyntaxKind.ArrayBindingPattern || node.kind === SyntaxKind.ObjectBindingPattern;
|
||||||
|
}
|
||||||
|
|
||||||
export function isInAmbientContext(node: Node): boolean {
|
export function isInAmbientContext(node: Node): boolean {
|
||||||
while (node) {
|
while (node) {
|
||||||
if (node.flags & (NodeFlags.Ambient | NodeFlags.DeclarationFile)) return true;
|
if (node.flags & (NodeFlags.Ambient | NodeFlags.DeclarationFile)) return true;
|
||||||
|
@ -743,6 +749,7 @@ module ts {
|
||||||
case SyntaxKind.TypeParameter:
|
case SyntaxKind.TypeParameter:
|
||||||
case SyntaxKind.Parameter:
|
case SyntaxKind.Parameter:
|
||||||
case SyntaxKind.VariableDeclaration:
|
case SyntaxKind.VariableDeclaration:
|
||||||
|
case SyntaxKind.BindingElement:
|
||||||
case SyntaxKind.PropertyDeclaration:
|
case SyntaxKind.PropertyDeclaration:
|
||||||
case SyntaxKind.PropertySignature:
|
case SyntaxKind.PropertySignature:
|
||||||
case SyntaxKind.PropertyAssignment:
|
case SyntaxKind.PropertyAssignment:
|
||||||
|
@ -889,6 +896,8 @@ module ts {
|
||||||
EnumMembers, // Members in enum declaration
|
EnumMembers, // Members in enum declaration
|
||||||
TypeReferences, // Type references in extends or implements clause
|
TypeReferences, // Type references in extends or implements clause
|
||||||
VariableDeclarations, // Variable declarations in variable statement
|
VariableDeclarations, // Variable declarations in variable statement
|
||||||
|
ObjectBindingElements, // Binding elements in object binding list
|
||||||
|
ArrayBindingElements, // Binding elements in array binding list
|
||||||
ArgumentExpressions, // Expressions in argument list
|
ArgumentExpressions, // Expressions in argument list
|
||||||
ObjectLiteralMembers, // Members in object literal
|
ObjectLiteralMembers, // Members in object literal
|
||||||
ArrayLiteralMembers, // Members in array literal
|
ArrayLiteralMembers, // Members in array literal
|
||||||
|
@ -918,6 +927,8 @@ module ts {
|
||||||
case ParsingContext.EnumMembers: return Diagnostics.Enum_member_expected;
|
case ParsingContext.EnumMembers: return Diagnostics.Enum_member_expected;
|
||||||
case ParsingContext.TypeReferences: return Diagnostics.Type_reference_expected;
|
case ParsingContext.TypeReferences: return Diagnostics.Type_reference_expected;
|
||||||
case ParsingContext.VariableDeclarations: return Diagnostics.Variable_declaration_expected;
|
case ParsingContext.VariableDeclarations: return Diagnostics.Variable_declaration_expected;
|
||||||
|
case ParsingContext.ObjectBindingElements: return Diagnostics.Property_destructuring_pattern_expected;
|
||||||
|
case ParsingContext.ArrayBindingElements: return Diagnostics.Array_element_destructuring_pattern_expected;
|
||||||
case ParsingContext.ArgumentExpressions: return Diagnostics.Argument_expression_expected;
|
case ParsingContext.ArgumentExpressions: return Diagnostics.Argument_expression_expected;
|
||||||
case ParsingContext.ObjectLiteralMembers: return Diagnostics.Property_assignment_expected;
|
case ParsingContext.ObjectLiteralMembers: return Diagnostics.Property_assignment_expected;
|
||||||
case ParsingContext.ArrayLiteralMembers: return Diagnostics.Expression_or_comma_expected;
|
case ParsingContext.ArrayLiteralMembers: return Diagnostics.Expression_or_comma_expected;
|
||||||
|
@ -1087,17 +1098,20 @@ module ts {
|
||||||
// Note: any errors at the end of the file that do not precede a regular node, should get
|
// Note: any errors at the end of the file that do not precede a regular node, should get
|
||||||
// attached to the EOF token.
|
// attached to the EOF token.
|
||||||
var parseErrorBeforeNextFinishedNode = false;
|
var parseErrorBeforeNextFinishedNode = false;
|
||||||
var sourceFile = <SourceFile>createRootNode(SyntaxKind.SourceFile, 0, sourceText.length,
|
|
||||||
fileExtensionIs(filename, ".d.ts") ? NodeFlags.DeclarationFile : 0);
|
var sourceFile = <SourceFile>createNode(SyntaxKind.SourceFile, 0);
|
||||||
|
if (fileExtensionIs(filename, ".d.ts")) {
|
||||||
|
sourceFile.flags = NodeFlags.DeclarationFile;
|
||||||
|
}
|
||||||
|
sourceFile.end = sourceText.length;
|
||||||
|
sourceFile.filename = normalizePath(filename);
|
||||||
|
sourceFile.text = sourceText;
|
||||||
|
|
||||||
sourceFile.getLineAndCharacterFromPosition = getLineAndCharacterFromSourcePosition;
|
sourceFile.getLineAndCharacterFromPosition = getLineAndCharacterFromSourcePosition;
|
||||||
sourceFile.getPositionFromLineAndCharacter = getPositionFromSourceLineAndCharacter;
|
sourceFile.getPositionFromLineAndCharacter = getPositionFromSourceLineAndCharacter;
|
||||||
sourceFile.getLineStarts = getLineStarts;
|
sourceFile.getLineStarts = getLineStarts;
|
||||||
sourceFile.getSyntacticDiagnostics = getSyntacticDiagnostics;
|
sourceFile.getSyntacticDiagnostics = getSyntacticDiagnostics;
|
||||||
|
|
||||||
sourceFile.filename = normalizePath(filename);
|
|
||||||
sourceFile.text = sourceText;
|
|
||||||
|
|
||||||
sourceFile.referenceDiagnostics = [];
|
sourceFile.referenceDiagnostics = [];
|
||||||
sourceFile.parseDiagnostics = [];
|
sourceFile.parseDiagnostics = [];
|
||||||
sourceFile.grammarDiagnostics = [];
|
sourceFile.grammarDiagnostics = [];
|
||||||
|
@ -1559,11 +1573,16 @@ module ts {
|
||||||
return token === SyntaxKind.OpenBracketToken || isLiteralPropertyName();
|
return token === SyntaxKind.OpenBracketToken || isLiteralPropertyName();
|
||||||
case ParsingContext.ObjectLiteralMembers:
|
case ParsingContext.ObjectLiteralMembers:
|
||||||
return token === SyntaxKind.OpenBracketToken || token === SyntaxKind.AsteriskToken || isLiteralPropertyName();
|
return token === SyntaxKind.OpenBracketToken || token === SyntaxKind.AsteriskToken || isLiteralPropertyName();
|
||||||
|
case ParsingContext.ObjectBindingElements:
|
||||||
|
return isLiteralPropertyName();
|
||||||
case ParsingContext.TypeReferences:
|
case ParsingContext.TypeReferences:
|
||||||
// We want to make sure that the "extends" in "extends foo" or the "implements" in
|
// We want to make sure that the "extends" in "extends foo" or the "implements" in
|
||||||
// "implements foo" is not considered a type name.
|
// "implements foo" is not considered a type name.
|
||||||
return isIdentifier() && !isNotHeritageClauseTypeName();
|
return isIdentifier() && !isNotHeritageClauseTypeName();
|
||||||
case ParsingContext.VariableDeclarations:
|
case ParsingContext.VariableDeclarations:
|
||||||
|
return isIdentifierOrPattern();
|
||||||
|
case ParsingContext.ArrayBindingElements:
|
||||||
|
return token === SyntaxKind.CommaToken || isIdentifierOrPattern();
|
||||||
case ParsingContext.TypeParameters:
|
case ParsingContext.TypeParameters:
|
||||||
return isIdentifier();
|
return isIdentifier();
|
||||||
case ParsingContext.ArgumentExpressions:
|
case ParsingContext.ArgumentExpressions:
|
||||||
|
@ -1612,6 +1631,7 @@ module ts {
|
||||||
case ParsingContext.ClassMembers:
|
case ParsingContext.ClassMembers:
|
||||||
case ParsingContext.EnumMembers:
|
case ParsingContext.EnumMembers:
|
||||||
case ParsingContext.ObjectLiteralMembers:
|
case ParsingContext.ObjectLiteralMembers:
|
||||||
|
case ParsingContext.ObjectBindingElements:
|
||||||
return token === SyntaxKind.CloseBraceToken;
|
return token === SyntaxKind.CloseBraceToken;
|
||||||
case ParsingContext.SwitchClauseStatements:
|
case ParsingContext.SwitchClauseStatements:
|
||||||
return token === SyntaxKind.CloseBraceToken || token === SyntaxKind.CaseKeyword || token === SyntaxKind.DefaultKeyword;
|
return token === SyntaxKind.CloseBraceToken || token === SyntaxKind.CaseKeyword || token === SyntaxKind.DefaultKeyword;
|
||||||
|
@ -1627,10 +1647,11 @@ module ts {
|
||||||
return token === SyntaxKind.CloseParenToken || token === SyntaxKind.SemicolonToken;
|
return token === SyntaxKind.CloseParenToken || token === SyntaxKind.SemicolonToken;
|
||||||
case ParsingContext.ArrayLiteralMembers:
|
case ParsingContext.ArrayLiteralMembers:
|
||||||
case ParsingContext.TupleElementTypes:
|
case ParsingContext.TupleElementTypes:
|
||||||
|
case ParsingContext.ArrayBindingElements:
|
||||||
return token === SyntaxKind.CloseBracketToken;
|
return token === SyntaxKind.CloseBracketToken;
|
||||||
case ParsingContext.Parameters:
|
case ParsingContext.Parameters:
|
||||||
// Tokens other than ')' and ']' (the latter for index signatures) are here for better error recovery
|
// Tokens other than ')' and ']' (the latter for index signatures) are here for better error recovery
|
||||||
return token === SyntaxKind.CloseParenToken || token === SyntaxKind.CloseBracketToken || token === SyntaxKind.OpenBraceToken;
|
return token === SyntaxKind.CloseParenToken || token === SyntaxKind.CloseBracketToken /*|| token === SyntaxKind.OpenBraceToken*/;
|
||||||
case ParsingContext.TypeArguments:
|
case ParsingContext.TypeArguments:
|
||||||
// Tokens other than '>' are here for better error recovery
|
// Tokens other than '>' are here for better error recovery
|
||||||
return token === SyntaxKind.GreaterThanToken || token === SyntaxKind.OpenParenToken;
|
return token === SyntaxKind.GreaterThanToken || token === SyntaxKind.OpenParenToken;
|
||||||
|
@ -1966,10 +1987,10 @@ module ts {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseParameterType(): TypeNode | StringLiteralExpression {
|
function parseParameterType(): TypeNode {
|
||||||
if (parseOptional(SyntaxKind.ColonToken)) {
|
if (parseOptional(SyntaxKind.ColonToken)) {
|
||||||
return token === SyntaxKind.StringLiteral
|
return token === SyntaxKind.StringLiteral
|
||||||
? <StringLiteralExpression>parseLiteralNode(/*internName:*/ true)
|
? <StringLiteralTypeNode>parseLiteralNode(/*internName:*/ true)
|
||||||
: parseType();
|
: parseType();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1977,7 +1998,7 @@ module ts {
|
||||||
}
|
}
|
||||||
|
|
||||||
function isStartOfParameter(): boolean {
|
function isStartOfParameter(): boolean {
|
||||||
return token === SyntaxKind.DotDotDotToken || isIdentifier() || isModifier(token);
|
return token === SyntaxKind.DotDotDotToken || isIdentifierOrPattern() || isModifier(token);
|
||||||
}
|
}
|
||||||
|
|
||||||
function setModifiers(node: Node, modifiers: ModifiersArray) {
|
function setModifiers(node: Node, modifiers: ModifiersArray) {
|
||||||
|
@ -1996,9 +2017,7 @@ module ts {
|
||||||
// [+GeneratorParameter]BindingIdentifier[Yield]Initializer[In]opt
|
// [+GeneratorParameter]BindingIdentifier[Yield]Initializer[In]opt
|
||||||
// [~GeneratorParameter]BindingIdentifier[?Yield]Initializer[In, ?Yield]opt
|
// [~GeneratorParameter]BindingIdentifier[?Yield]Initializer[In, ?Yield]opt
|
||||||
|
|
||||||
node.name = inGeneratorParameterContext()
|
node.name = inGeneratorParameterContext() ? doInYieldContext(parseIdentifierOrPattern) : parseIdentifierOrPattern();
|
||||||
? doInYieldContext(parseIdentifier)
|
|
||||||
: parseIdentifier();
|
|
||||||
|
|
||||||
if (getFullWidth(node.name) === 0 && node.flags === 0 && isModifier(token)) {
|
if (getFullWidth(node.name) === 0 && node.flags === 0 && isModifier(token)) {
|
||||||
// in cases like
|
// in cases like
|
||||||
|
@ -2014,9 +2033,7 @@ module ts {
|
||||||
|
|
||||||
node.questionToken = parseOptionalToken(SyntaxKind.QuestionToken);
|
node.questionToken = parseOptionalToken(SyntaxKind.QuestionToken);
|
||||||
node.type = parseParameterType();
|
node.type = parseParameterType();
|
||||||
node.initializer = inGeneratorParameterContext()
|
node.initializer = inGeneratorParameterContext() ? doOutsideOfYieldContext(parseParameterInitializer) : parseParameterInitializer();
|
||||||
? doOutsideOfYieldContext(parseParameterInitializer)
|
|
||||||
: parseParameterInitializer();
|
|
||||||
|
|
||||||
// Do not check for initializers in an ambient context for parameters. This is not
|
// Do not check for initializers in an ambient context for parameters. This is not
|
||||||
// a grammar error because the grammar allows arbitrary call signatures in
|
// a grammar error because the grammar allows arbitrary call signatures in
|
||||||
|
@ -3841,20 +3858,81 @@ module ts {
|
||||||
|
|
||||||
// DECLARATIONS
|
// DECLARATIONS
|
||||||
|
|
||||||
|
function parseBindingElement(context: ParsingContext): BindingElement {
|
||||||
|
if (context === ParsingContext.ArrayBindingElements && token === SyntaxKind.CommaToken) {
|
||||||
|
return <BindingElement>createNode(SyntaxKind.OmittedExpression);
|
||||||
|
}
|
||||||
|
var node = <BindingElement>createNode(SyntaxKind.BindingElement);
|
||||||
|
if (context === ParsingContext.ObjectBindingElements) {
|
||||||
|
// TODO(andersh): Handle computed properties
|
||||||
|
var id = parsePropertyName();
|
||||||
|
if (id.kind === SyntaxKind.Identifier && token !== SyntaxKind.ColonToken) {
|
||||||
|
node.name = <Identifier>id;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
parseExpected(SyntaxKind.ColonToken);
|
||||||
|
node.propertyName = <Identifier>id;
|
||||||
|
node.name = parseIdentifierOrPattern();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
node.name = parseIdentifierOrPattern();
|
||||||
|
}
|
||||||
|
node.initializer = parseInitializer(/*inParameter*/ false);
|
||||||
|
return finishNode(node);
|
||||||
|
}
|
||||||
|
|
||||||
|
function parseBindingList(context: ParsingContext): NodeArray<BindingElement> {
|
||||||
|
return parseDelimitedList(context, () => parseBindingElement(context));
|
||||||
|
}
|
||||||
|
|
||||||
|
function parseObjectBindingPattern(): BindingPattern {
|
||||||
|
var node = <BindingPattern>createNode(SyntaxKind.ObjectBindingPattern);
|
||||||
|
parseExpected(SyntaxKind.OpenBraceToken);
|
||||||
|
node.elements = parseBindingList(ParsingContext.ObjectBindingElements);
|
||||||
|
parseExpected(SyntaxKind.CloseBraceToken);
|
||||||
|
return finishNode(node);
|
||||||
|
}
|
||||||
|
|
||||||
|
function parseArrayBindingPattern(): BindingPattern {
|
||||||
|
var node = <BindingPattern>createNode(SyntaxKind.ArrayBindingPattern);
|
||||||
|
parseExpected(SyntaxKind.OpenBracketToken);
|
||||||
|
node.elements = parseBindingList(ParsingContext.ArrayBindingElements);
|
||||||
|
parseExpected(SyntaxKind.CloseBracketToken);
|
||||||
|
return finishNode(node);
|
||||||
|
}
|
||||||
|
|
||||||
|
function isIdentifierOrPattern() {
|
||||||
|
return token === SyntaxKind.OpenBraceToken || token === SyntaxKind.OpenBracketToken || isIdentifier();
|
||||||
|
}
|
||||||
|
|
||||||
|
function parseIdentifierOrPattern(): Identifier | BindingPattern {
|
||||||
|
if (token === SyntaxKind.OpenBracketToken) {
|
||||||
|
return parseArrayBindingPattern();
|
||||||
|
}
|
||||||
|
if (token === SyntaxKind.OpenBraceToken) {
|
||||||
|
return parseObjectBindingPattern();
|
||||||
|
}
|
||||||
|
return parseIdentifier();
|
||||||
|
}
|
||||||
|
|
||||||
function parseVariableDeclaration(): VariableDeclaration {
|
function parseVariableDeclaration(): VariableDeclaration {
|
||||||
var node = <VariableDeclaration>createNode(SyntaxKind.VariableDeclaration);
|
var node = <VariableDeclaration>createNode(SyntaxKind.VariableDeclaration);
|
||||||
node.name = parseIdentifier();
|
node.name = parseIdentifierOrPattern();
|
||||||
node.type = parseTypeAnnotation();
|
node.type = parseTypeAnnotation();
|
||||||
node.initializer = parseInitializer(/*inParameter*/ false);
|
node.initializer = parseInitializer(/*inParameter*/ false);
|
||||||
return finishNode(node);
|
return finishNode(node);
|
||||||
}
|
}
|
||||||
|
|
||||||
function setFlag(array: NodeArray<VariableDeclaration>, flag: NodeFlags): NodeArray<VariableDeclaration> {
|
function setFlag(nodes: NodeArray<VariableDeclaration>, flag: NodeFlags): NodeArray<VariableDeclaration> {
|
||||||
for (var i = 0, n = array.length; i < n; i++) {
|
for (var i = 0; i < nodes.length; i++) {
|
||||||
array[i].flags |= flag;
|
var node = nodes[i];
|
||||||
|
node.flags |= flag;
|
||||||
|
if (node.name && isBindingPattern(node.name)) {
|
||||||
|
setFlag((<BindingPattern>node.name).elements, flag);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return array;
|
return nodes;
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseVariableDeclarationList(): NodeArray<VariableDeclaration> {
|
function parseVariableDeclarationList(): NodeArray<VariableDeclaration> {
|
||||||
|
@ -4562,6 +4640,7 @@ module ts {
|
||||||
|
|
||||||
case SyntaxKind.EnumDeclaration: return checkEnumDeclaration(<EnumDeclaration>node);
|
case SyntaxKind.EnumDeclaration: return checkEnumDeclaration(<EnumDeclaration>node);
|
||||||
case SyntaxKind.BinaryExpression: return checkBinaryExpression(<BinaryExpression>node);
|
case SyntaxKind.BinaryExpression: return checkBinaryExpression(<BinaryExpression>node);
|
||||||
|
case SyntaxKind.BindingElement: return checkBindingElement(<BindingElement>node);
|
||||||
case SyntaxKind.CatchClause: return checkCatchClause(<CatchClause>node);
|
case SyntaxKind.CatchClause: return checkCatchClause(<CatchClause>node);
|
||||||
case SyntaxKind.ClassDeclaration: return checkClassDeclaration(<ClassDeclaration>node);
|
case SyntaxKind.ClassDeclaration: return checkClassDeclaration(<ClassDeclaration>node);
|
||||||
case SyntaxKind.ComputedPropertyName: return checkComputedPropertyName(<ComputedPropertyName>node);
|
case SyntaxKind.ComputedPropertyName: return checkComputedPropertyName(<ComputedPropertyName>node);
|
||||||
|
@ -5386,7 +5465,7 @@ module ts {
|
||||||
// It is a SyntaxError if the identifier eval or arguments appears within a FormalParameterList of a
|
// It is a SyntaxError if the identifier eval or arguments appears within a FormalParameterList of a
|
||||||
// strict mode FunctionLikeDeclaration or FunctionExpression(13.1)
|
// strict mode FunctionLikeDeclaration or FunctionExpression(13.1)
|
||||||
if (node.parserContextFlags & ParserContextFlags.StrictMode && isEvalOrArgumentsIdentifier(node.name)) {
|
if (node.parserContextFlags & ParserContextFlags.StrictMode && isEvalOrArgumentsIdentifier(node.name)) {
|
||||||
return reportInvalidUseInStrictMode(node.name);
|
return reportInvalidUseInStrictMode(<Identifier>node.name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5658,18 +5737,38 @@ module ts {
|
||||||
return checkTypeArguments(node.typeArguments);
|
return checkTypeArguments(node.typeArguments);
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkVariableDeclaration(node: VariableDeclaration) {
|
function checkBindingElement(node: BindingElement) {
|
||||||
if (inAmbientContext && node.initializer) {
|
if (node.parserContextFlags & ParserContextFlags.StrictMode && isEvalOrArgumentsIdentifier(node.name)) {
|
||||||
var equalsPos = node.type ? skipTrivia(sourceText, node.type.end) : skipTrivia(sourceText, node.name.end);
|
// It is a SyntaxError if a VariableDeclaration or VariableDeclarationNoIn occurs within strict code
|
||||||
return grammarErrorAtPos(equalsPos, "=".length, Diagnostics.Initializers_are_not_allowed_in_ambient_contexts);
|
// and its Identifier is eval or arguments
|
||||||
|
return reportInvalidUseInStrictMode(<Identifier>node.name);
|
||||||
}
|
}
|
||||||
if (!inAmbientContext && !node.initializer && isConst(node)) {
|
}
|
||||||
|
|
||||||
|
function checkVariableDeclaration(node: VariableDeclaration) {
|
||||||
|
if (inAmbientContext) {
|
||||||
|
if (isBindingPattern(node.name)) {
|
||||||
|
return grammarErrorOnNode(node, Diagnostics.Destructuring_declarations_are_not_allowed_in_ambient_contexts);
|
||||||
|
}
|
||||||
|
if (node.initializer) {
|
||||||
|
// Error on equals token which immediate precedes the initializer
|
||||||
|
return grammarErrorAtPos(node.initializer.pos - 1, 1, Diagnostics.Initializers_are_not_allowed_in_ambient_contexts);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (!node.initializer) {
|
||||||
|
if (isBindingPattern(node.name) && !isBindingPattern(node.parent)) {
|
||||||
|
return grammarErrorOnNode(node, Diagnostics.A_destructuring_declaration_must_have_an_initializer);
|
||||||
|
}
|
||||||
|
if (isConst(node)) {
|
||||||
return grammarErrorOnNode(node, Diagnostics.const_declarations_must_be_initialized);
|
return grammarErrorOnNode(node, Diagnostics.const_declarations_must_be_initialized);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
if (node.parserContextFlags & ParserContextFlags.StrictMode && isEvalOrArgumentsIdentifier(node.name)) {
|
if (node.parserContextFlags & ParserContextFlags.StrictMode && isEvalOrArgumentsIdentifier(node.name)) {
|
||||||
// It is a SyntaxError if a VariableDeclaration or VariableDeclarationNoIn occurs within strict code
|
// It is a SyntaxError if a VariableDeclaration or VariableDeclarationNoIn occurs within strict code
|
||||||
// and its Identifier is eval or arguments
|
// and its Identifier is eval or arguments
|
||||||
return reportInvalidUseInStrictMode(node.name);
|
return reportInvalidUseInStrictMode(<Identifier>node.name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -167,6 +167,10 @@ module ts {
|
||||||
TupleType,
|
TupleType,
|
||||||
UnionType,
|
UnionType,
|
||||||
ParenthesizedType,
|
ParenthesizedType,
|
||||||
|
// Binding patterns
|
||||||
|
ObjectBindingPattern,
|
||||||
|
ArrayBindingPattern,
|
||||||
|
BindingElement,
|
||||||
// Expression
|
// Expression
|
||||||
ArrayLiteralExpression,
|
ArrayLiteralExpression,
|
||||||
ObjectLiteralExpression,
|
ObjectLiteralExpression,
|
||||||
|
@ -353,7 +357,8 @@ module ts {
|
||||||
}
|
}
|
||||||
|
|
||||||
export type EntityName = Identifier | QualifiedName;
|
export type EntityName = Identifier | QualifiedName;
|
||||||
export type DeclarationName = Identifier | LiteralExpression | ComputedPropertyName;
|
|
||||||
|
export type DeclarationName = Identifier | LiteralExpression | ComputedPropertyName | BindingPattern;
|
||||||
|
|
||||||
export interface Declaration extends Node {
|
export interface Declaration extends Node {
|
||||||
_declarationBrand: any;
|
_declarationBrand: any;
|
||||||
|
@ -378,39 +383,43 @@ module ts {
|
||||||
type?: TypeNode;
|
type?: TypeNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SyntaxKind.VariableDeclaration
|
||||||
export interface VariableDeclaration extends Declaration {
|
export interface VariableDeclaration extends Declaration {
|
||||||
name: Identifier;
|
name: Identifier | BindingPattern; // Declared variable name
|
||||||
type?: TypeNode;
|
type?: TypeNode; // Optional type annotation
|
||||||
initializer?: Expression;
|
initializer?: Expression; // Optional initializer
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SyntaxKind.Parameter
|
||||||
export interface ParameterDeclaration extends Declaration {
|
export interface ParameterDeclaration extends Declaration {
|
||||||
dotDotDotToken?: Node;
|
dotDotDotToken?: Node; // Present on rest parameter
|
||||||
name: Identifier;
|
name: Identifier | BindingPattern; // Declared parameter name
|
||||||
questionToken?: Node;
|
questionToken?: Node; // Present on optional parameter
|
||||||
type?: TypeNode | StringLiteralExpression;
|
type?: TypeNode; // Optional type annotation
|
||||||
initializer?: Expression;
|
initializer?: Expression; // Optional initializer
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SyntaxKind.BindingElement
|
||||||
|
export interface BindingElement extends Declaration {
|
||||||
|
propertyName?: Identifier; // Binding property name (in object binding pattern)
|
||||||
|
dotDotDotToken?: Node; // Present on rest binding element
|
||||||
|
name: Identifier | BindingPattern; // Declared binding element name
|
||||||
|
initializer?: Expression; // Optional initializer
|
||||||
|
}
|
||||||
|
|
||||||
|
// SyntaxKind.Property
|
||||||
export interface PropertyDeclaration extends Declaration, ClassElement {
|
export interface PropertyDeclaration extends Declaration, ClassElement {
|
||||||
_propertyDeclarationBrand: any;
|
name: DeclarationName; // Declared property name
|
||||||
questionToken?: Node;
|
questionToken?: Node; // Present on optional property
|
||||||
type?: TypeNode;
|
type?: TypeNode; // Optional type annotation
|
||||||
initializer?: Expression;
|
initializer?: Expression; // Optional initializer
|
||||||
}
|
}
|
||||||
|
|
||||||
export type VariableOrParameterDeclaration = VariableDeclaration | ParameterDeclaration;
|
|
||||||
export type VariableOrParameterOrPropertyDeclaration = VariableOrParameterDeclaration | PropertyDeclaration;
|
|
||||||
|
|
||||||
export interface ObjectLiteralElement extends Declaration {
|
export interface ObjectLiteralElement extends Declaration {
|
||||||
_objectLiteralBrandBrand: any;
|
_objectLiteralBrandBrand: any;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ShorthandPropertyAssignment extends ObjectLiteralElement {
|
// SyntaxKind.PropertyAssignment
|
||||||
name: Identifier;
|
|
||||||
questionToken?: Node;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface PropertyAssignment extends ObjectLiteralElement {
|
export interface PropertyAssignment extends ObjectLiteralElement {
|
||||||
_propertyAssignmentBrand: any;
|
_propertyAssignmentBrand: any;
|
||||||
name: DeclarationName;
|
name: DeclarationName;
|
||||||
|
@ -418,6 +427,32 @@ module ts {
|
||||||
initializer: Expression;
|
initializer: Expression;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SyntaxKind.ShorthandPropertyAssignment
|
||||||
|
export interface ShorthandPropertyAssignment extends ObjectLiteralElement {
|
||||||
|
name: Identifier;
|
||||||
|
questionToken?: Node;
|
||||||
|
}
|
||||||
|
|
||||||
|
// SyntaxKind.VariableDeclaration
|
||||||
|
// SyntaxKind.Parameter
|
||||||
|
// SyntaxKind.BindingElement
|
||||||
|
// SyntaxKind.Property
|
||||||
|
// SyntaxKind.PropertyAssignment
|
||||||
|
// SyntaxKind.ShorthandPropertyAssignment
|
||||||
|
// SyntaxKind.EnumMember
|
||||||
|
export interface VariableLikeDeclaration extends Declaration {
|
||||||
|
propertyName?: Identifier;
|
||||||
|
dotDotDotToken?: Node;
|
||||||
|
name: DeclarationName;
|
||||||
|
questionToken?: Node;
|
||||||
|
type?: TypeNode;
|
||||||
|
initializer?: Expression;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface BindingPattern extends Node {
|
||||||
|
elements: NodeArray<BindingElement>;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Several node kinds share function-like features such as a signature,
|
* Several node kinds share function-like features such as a signature,
|
||||||
* a name, and a body. These nodes should extend FunctionLikeDeclaration.
|
* a name, and a body. These nodes should extend FunctionLikeDeclaration.
|
||||||
|
@ -505,6 +540,8 @@ module ts {
|
||||||
type: TypeNode;
|
type: TypeNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface StringLiteralTypeNode extends LiteralExpression, TypeNode { }
|
||||||
|
|
||||||
// Note: 'brands' in our syntax nodes serve to give us a small amount of nominal typing.
|
// Note: 'brands' in our syntax nodes serve to give us a small amount of nominal typing.
|
||||||
// Consider 'Expression'. Without the brand, 'Expression' is actually no different
|
// Consider 'Expression'. Without the brand, 'Expression' is actually no different
|
||||||
// (structurally) than 'Node'. Because of this you can pass any Node to a function that
|
// (structurally) than 'Node'. Because of this you can pass any Node to a function that
|
||||||
|
@ -1034,13 +1071,14 @@ module ts {
|
||||||
hasSemanticErrors(sourceFile?: SourceFile): boolean;
|
hasSemanticErrors(sourceFile?: SourceFile): boolean;
|
||||||
isDeclarationVisible(node: Declaration): boolean;
|
isDeclarationVisible(node: Declaration): boolean;
|
||||||
isImplementationOfOverload(node: FunctionLikeDeclaration): boolean;
|
isImplementationOfOverload(node: FunctionLikeDeclaration): boolean;
|
||||||
writeTypeOfDeclaration(declaration: AccessorDeclaration | VariableOrParameterDeclaration, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter): void;
|
writeTypeOfDeclaration(declaration: AccessorDeclaration | VariableLikeDeclaration, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter): void;
|
||||||
writeReturnTypeOfSignatureDeclaration(signatureDeclaration: SignatureDeclaration, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter): void;
|
writeReturnTypeOfSignatureDeclaration(signatureDeclaration: SignatureDeclaration, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter): void;
|
||||||
isSymbolAccessible(symbol: Symbol, enclosingDeclaration: Node, meaning: SymbolFlags): SymbolAccessiblityResult;
|
isSymbolAccessible(symbol: Symbol, enclosingDeclaration: Node, meaning: SymbolFlags): SymbolAccessiblityResult;
|
||||||
isEntityNameVisible(entityName: EntityName, enclosingDeclaration: Node): SymbolVisibilityResult;
|
isEntityNameVisible(entityName: EntityName, enclosingDeclaration: Node): SymbolVisibilityResult;
|
||||||
// Returns the constant value this property access resolves to, or 'undefined' for a non-constant
|
// Returns the constant value this property access resolves to, or 'undefined' for a non-constant
|
||||||
getConstantValue(node: PropertyAccessExpression | ElementAccessExpression): number;
|
getConstantValue(node: PropertyAccessExpression | ElementAccessExpression): number;
|
||||||
isEmitBlocked(sourceFile?: SourceFile): boolean;
|
isEmitBlocked(sourceFile?: SourceFile): boolean;
|
||||||
|
isUnknownIdentifier(location: Node, name: string): boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const enum SymbolFlags {
|
export const enum SymbolFlags {
|
||||||
|
@ -1061,22 +1099,21 @@ module ts {
|
||||||
Constructor = 0x00004000, // Constructor
|
Constructor = 0x00004000, // Constructor
|
||||||
GetAccessor = 0x00008000, // Get accessor
|
GetAccessor = 0x00008000, // Get accessor
|
||||||
SetAccessor = 0x00010000, // Set accessor
|
SetAccessor = 0x00010000, // Set accessor
|
||||||
CallSignature = 0x00020000, // Call signature
|
Signature = 0x00020000, // Call, construct, or index signature
|
||||||
ConstructSignature = 0x00040000, // Construct signature
|
TypeParameter = 0x00040000, // Type parameter
|
||||||
IndexSignature = 0x00080000, // Index signature
|
TypeAlias = 0x00080000, // Type alias
|
||||||
TypeParameter = 0x00100000, // Type parameter
|
|
||||||
TypeAlias = 0x00200000, // Type alias
|
|
||||||
|
|
||||||
// Export markers (see comment in declareModuleMember in binder)
|
// Export markers (see comment in declareModuleMember in binder)
|
||||||
ExportValue = 0x00400000, // Exported value marker
|
ExportValue = 0x00100000, // Exported value marker
|
||||||
ExportType = 0x00800000, // Exported type marker
|
ExportType = 0x00200000, // Exported type marker
|
||||||
ExportNamespace = 0x01000000, // Exported namespace marker
|
ExportNamespace = 0x00400000, // Exported namespace marker
|
||||||
Import = 0x02000000, // Import
|
Import = 0x00800000, // Import
|
||||||
Instantiated = 0x04000000, // Instantiated symbol
|
Instantiated = 0x01000000, // Instantiated symbol
|
||||||
Merged = 0x08000000, // Merged symbol (created during program binding)
|
Merged = 0x02000000, // Merged symbol (created during program binding)
|
||||||
Transient = 0x10000000, // Transient symbol (created during type check)
|
Transient = 0x04000000, // Transient symbol (created during type check)
|
||||||
Prototype = 0x20000000, // Prototype property (no source representation)
|
Prototype = 0x08000000, // Prototype property (no source representation)
|
||||||
UnionProperty = 0x40000000, // Property in union type
|
UnionProperty = 0x10000000, // Property in union type
|
||||||
|
Optional = 0x20000000, // Optional property
|
||||||
|
|
||||||
Enum = RegularEnum | ConstEnum,
|
Enum = RegularEnum | ConstEnum,
|
||||||
Variable = FunctionScopedVariable | BlockScopedVariable,
|
Variable = FunctionScopedVariable | BlockScopedVariable,
|
||||||
|
@ -1085,7 +1122,6 @@ module ts {
|
||||||
Namespace = ValueModule | NamespaceModule,
|
Namespace = ValueModule | NamespaceModule,
|
||||||
Module = ValueModule | NamespaceModule,
|
Module = ValueModule | NamespaceModule,
|
||||||
Accessor = GetAccessor | SetAccessor,
|
Accessor = GetAccessor | SetAccessor,
|
||||||
Signature = CallSignature | ConstructSignature | IndexSignature,
|
|
||||||
|
|
||||||
// Variables can be redeclared, but can not redeclare a block-scoped declaration with the
|
// Variables can be redeclared, but can not redeclare a block-scoped declaration with the
|
||||||
// same name, or any other value that is not a variable, e.g. ValueModule or Class
|
// same name, or any other value that is not a variable, e.g. ValueModule or Class
|
||||||
|
@ -1198,6 +1234,7 @@ module ts {
|
||||||
Union = 0x00004000, // Union
|
Union = 0x00004000, // Union
|
||||||
Anonymous = 0x00008000, // Anonymous
|
Anonymous = 0x00008000, // Anonymous
|
||||||
FromSignature = 0x00010000, // Created for signature assignment check
|
FromSignature = 0x00010000, // Created for signature assignment check
|
||||||
|
Unwidened = 0x00020000, // Unwidened type (is or contains Undefined or Null type)
|
||||||
|
|
||||||
Intrinsic = Any | String | Number | Boolean | Void | Undefined | Null,
|
Intrinsic = Any | String | Number | Boolean | Void | Undefined | Null,
|
||||||
StringLike = String | StringLiteral,
|
StringLike = String | StringLiteral,
|
||||||
|
|
|
@ -41,22 +41,46 @@ module ts.NavigationBar {
|
||||||
function getChildNodes(nodes: Node[]): Node[] {
|
function getChildNodes(nodes: Node[]): Node[] {
|
||||||
var childNodes: Node[] = [];
|
var childNodes: Node[] = [];
|
||||||
|
|
||||||
for (var i = 0, n = nodes.length; i < n; i++) {
|
function visit(node: Node) {
|
||||||
var node = nodes[i];
|
switch (node.kind) {
|
||||||
|
case SyntaxKind.VariableStatement:
|
||||||
if (node.kind === SyntaxKind.ClassDeclaration ||
|
forEach((<VariableStatement>node).declarations, visit);
|
||||||
node.kind === SyntaxKind.EnumDeclaration ||
|
break;
|
||||||
node.kind === SyntaxKind.InterfaceDeclaration ||
|
case SyntaxKind.ObjectBindingPattern:
|
||||||
node.kind === SyntaxKind.ModuleDeclaration ||
|
case SyntaxKind.ArrayBindingPattern:
|
||||||
node.kind === SyntaxKind.FunctionDeclaration) {
|
forEach((<BindingPattern>node).elements, visit);
|
||||||
|
break;
|
||||||
|
case SyntaxKind.VariableDeclaration:
|
||||||
|
if (isBindingPattern(node)) {
|
||||||
|
visit((<VariableDeclaration>node).name);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
// Fall through
|
||||||
|
case SyntaxKind.ClassDeclaration:
|
||||||
|
case SyntaxKind.EnumDeclaration:
|
||||||
|
case SyntaxKind.InterfaceDeclaration:
|
||||||
|
case SyntaxKind.ModuleDeclaration:
|
||||||
|
case SyntaxKind.FunctionDeclaration:
|
||||||
childNodes.push(node);
|
childNodes.push(node);
|
||||||
}
|
}
|
||||||
else if (node.kind === SyntaxKind.VariableStatement) {
|
|
||||||
childNodes.push.apply(childNodes, (<VariableStatement>node).declarations);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//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, (<VariableStatement>node).declarations);
|
||||||
|
// }
|
||||||
|
//}
|
||||||
|
forEach(nodes, visit);
|
||||||
return sortNodes(childNodes);
|
return sortNodes(childNodes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -200,6 +224,9 @@ module ts.NavigationBar {
|
||||||
function createChildItem(node: Node): ts.NavigationBarItem {
|
function createChildItem(node: Node): ts.NavigationBarItem {
|
||||||
switch (node.kind) {
|
switch (node.kind) {
|
||||||
case SyntaxKind.Parameter:
|
case SyntaxKind.Parameter:
|
||||||
|
if (isBindingPattern((<ParameterDeclaration>node).name)) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
if ((node.flags & NodeFlags.Modifier) === 0) {
|
if ((node.flags & NodeFlags.Modifier) === 0) {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
@ -235,6 +262,9 @@ module ts.NavigationBar {
|
||||||
return createItem(node, getTextOfNode((<FunctionLikeDeclaration>node).name), ts.ScriptElementKind.functionElement);
|
return createItem(node, getTextOfNode((<FunctionLikeDeclaration>node).name), ts.ScriptElementKind.functionElement);
|
||||||
|
|
||||||
case SyntaxKind.VariableDeclaration:
|
case SyntaxKind.VariableDeclaration:
|
||||||
|
if (isBindingPattern((<VariableDeclaration>node).name)) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
if (isConst(node)) {
|
if (isConst(node)) {
|
||||||
return createItem(node, getTextOfNode((<VariableDeclaration>node).name), ts.ScriptElementKind.constElement);
|
return createItem(node, getTextOfNode((<VariableDeclaration>node).name), ts.ScriptElementKind.constElement);
|
||||||
}
|
}
|
||||||
|
|
|
@ -806,6 +806,8 @@ module ts {
|
||||||
// fall through
|
// fall through
|
||||||
case SyntaxKind.Constructor:
|
case SyntaxKind.Constructor:
|
||||||
case SyntaxKind.VariableStatement:
|
case SyntaxKind.VariableStatement:
|
||||||
|
case SyntaxKind.ObjectBindingPattern:
|
||||||
|
case SyntaxKind.ArrayBindingPattern:
|
||||||
case SyntaxKind.ModuleBlock:
|
case SyntaxKind.ModuleBlock:
|
||||||
forEachChild(node, visit);
|
forEachChild(node, visit);
|
||||||
break;
|
break;
|
||||||
|
@ -823,6 +825,11 @@ module ts {
|
||||||
}
|
}
|
||||||
// fall through
|
// fall through
|
||||||
case SyntaxKind.VariableDeclaration:
|
case SyntaxKind.VariableDeclaration:
|
||||||
|
case SyntaxKind.BindingElement:
|
||||||
|
if (isBindingPattern((<VariableDeclaration>node).name)) {
|
||||||
|
forEachChild((<VariableDeclaration>node).name, visit);
|
||||||
|
break;
|
||||||
|
}
|
||||||
case SyntaxKind.EnumMember:
|
case SyntaxKind.EnumMember:
|
||||||
case SyntaxKind.PropertyDeclaration:
|
case SyntaxKind.PropertyDeclaration:
|
||||||
case SyntaxKind.PropertySignature:
|
case SyntaxKind.PropertySignature:
|
||||||
|
@ -4746,6 +4753,7 @@ module ts {
|
||||||
switch (node.kind) {
|
switch (node.kind) {
|
||||||
case SyntaxKind.Parameter:
|
case SyntaxKind.Parameter:
|
||||||
case SyntaxKind.VariableDeclaration:
|
case SyntaxKind.VariableDeclaration:
|
||||||
|
case SyntaxKind.BindingElement:
|
||||||
case SyntaxKind.PropertyDeclaration:
|
case SyntaxKind.PropertyDeclaration:
|
||||||
case SyntaxKind.PropertySignature:
|
case SyntaxKind.PropertySignature:
|
||||||
case SyntaxKind.PropertyAssignment:
|
case SyntaxKind.PropertyAssignment:
|
||||||
|
|
|
@ -19,7 +19,8 @@ tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(2
|
||||||
tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(30,1): error TS2364: Invalid left-hand side of assignment expression.
|
tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(30,1): error TS2364: Invalid left-hand side of assignment expression.
|
||||||
tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(31,1): error TS2364: Invalid left-hand side of assignment expression.
|
tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(31,1): error TS2364: Invalid left-hand side of assignment expression.
|
||||||
tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(32,1): error TS2364: Invalid left-hand side of assignment expression.
|
tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(32,1): error TS2364: Invalid left-hand side of assignment expression.
|
||||||
tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(38,1): error TS2364: Invalid left-hand side of assignment expression.
|
tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(38,2): error TS2364: Invalid left-hand side of assignment expression.
|
||||||
|
tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(38,6): error TS2364: Invalid left-hand side of assignment expression.
|
||||||
tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(54,1): error TS2364: Invalid left-hand side of assignment expression.
|
tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(54,1): error TS2364: Invalid left-hand side of assignment expression.
|
||||||
tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(57,1): error TS2364: Invalid left-hand side of assignment expression.
|
tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(57,1): error TS2364: Invalid left-hand side of assignment expression.
|
||||||
tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(58,1): error TS2364: Invalid left-hand side of assignment expression.
|
tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(58,1): error TS2364: Invalid left-hand side of assignment expression.
|
||||||
|
@ -37,7 +38,7 @@ tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(6
|
||||||
tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(70,1): error TS2364: Invalid left-hand side of assignment expression.
|
tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(70,1): error TS2364: Invalid left-hand side of assignment expression.
|
||||||
|
|
||||||
|
|
||||||
==== tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts (37 errors) ====
|
==== tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts (38 errors) ====
|
||||||
// expected error for all the LHS of assignments
|
// expected error for all the LHS of assignments
|
||||||
var value;
|
var value;
|
||||||
|
|
||||||
|
@ -108,7 +109,9 @@ tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(7
|
||||||
|
|
||||||
// array literals
|
// array literals
|
||||||
['', ''] = value;
|
['', ''] = value;
|
||||||
~~~~~~~~
|
~~
|
||||||
|
!!! error TS2364: Invalid left-hand side of assignment expression.
|
||||||
|
~~
|
||||||
!!! error TS2364: Invalid left-hand side of assignment expression.
|
!!! error TS2364: Invalid left-hand side of assignment expression.
|
||||||
|
|
||||||
// super
|
// super
|
||||||
|
|
|
@ -1,19 +0,0 @@
|
||||||
tests/cases/compiler/collisionRestParameterArrowFunctions.ts(1,11): error TS2397: Duplicate identifier '_i'. Compiler uses '_i' to initialize rest parameter.
|
|
||||||
|
|
||||||
|
|
||||||
==== tests/cases/compiler/collisionRestParameterArrowFunctions.ts (1 errors) ====
|
|
||||||
var f1 = (_i: number, ...restParameters) => { //_i is error
|
|
||||||
~~~~~~~~~~
|
|
||||||
!!! error TS2397: Duplicate identifier '_i'. Compiler uses '_i' to initialize rest parameter.
|
|
||||||
var _i = 10; // no error
|
|
||||||
}
|
|
||||||
var f1NoError = (_i: number) => { // no error
|
|
||||||
var _i = 10; // no error
|
|
||||||
}
|
|
||||||
|
|
||||||
var f2 = (...restParameters) => {
|
|
||||||
var _i = 10; // No Error
|
|
||||||
}
|
|
||||||
var f2NoError = () => {
|
|
||||||
var _i = 10; // no error
|
|
||||||
}
|
|
|
@ -16,8 +16,8 @@ var f2NoError = () => {
|
||||||
//// [collisionRestParameterArrowFunctions.js]
|
//// [collisionRestParameterArrowFunctions.js]
|
||||||
var f1 = function (_i) {
|
var f1 = function (_i) {
|
||||||
var restParameters = [];
|
var restParameters = [];
|
||||||
for (var _i = 1; _i < arguments.length; _i++) {
|
for (var _a = 1; _a < arguments.length; _a++) {
|
||||||
restParameters[_i - 1] = arguments[_i];
|
restParameters[_a - 1] = arguments[_a];
|
||||||
}
|
}
|
||||||
var _i = 10; // no error
|
var _i = 10; // no error
|
||||||
};
|
};
|
||||||
|
@ -26,8 +26,8 @@ var f1NoError = function (_i) {
|
||||||
};
|
};
|
||||||
var f2 = function () {
|
var f2 = function () {
|
||||||
var restParameters = [];
|
var restParameters = [];
|
||||||
for (var _i = 0; _i < arguments.length; _i++) {
|
for (var _a = 0; _a < arguments.length; _a++) {
|
||||||
restParameters[_i - 0] = arguments[_i];
|
restParameters[_a - 0] = arguments[_a];
|
||||||
}
|
}
|
||||||
var _i = 10; // No Error
|
var _i = 10; // No Error
|
||||||
};
|
};
|
||||||
|
|
|
@ -0,0 +1,34 @@
|
||||||
|
=== tests/cases/compiler/collisionRestParameterArrowFunctions.ts ===
|
||||||
|
var f1 = (_i: number, ...restParameters) => { //_i is error
|
||||||
|
>f1 : (_i: number, ...restParameters: any[]) => void
|
||||||
|
>(_i: number, ...restParameters) => { //_i is error var _i = 10; // no error} : (_i: number, ...restParameters: any[]) => void
|
||||||
|
>_i : number
|
||||||
|
>restParameters : any[]
|
||||||
|
|
||||||
|
var _i = 10; // no error
|
||||||
|
>_i : number
|
||||||
|
}
|
||||||
|
var f1NoError = (_i: number) => { // no error
|
||||||
|
>f1NoError : (_i: number) => void
|
||||||
|
>(_i: number) => { // no error var _i = 10; // no error} : (_i: number) => void
|
||||||
|
>_i : number
|
||||||
|
|
||||||
|
var _i = 10; // no error
|
||||||
|
>_i : number
|
||||||
|
}
|
||||||
|
|
||||||
|
var f2 = (...restParameters) => {
|
||||||
|
>f2 : (...restParameters: any[]) => void
|
||||||
|
>(...restParameters) => { var _i = 10; // No Error} : (...restParameters: any[]) => void
|
||||||
|
>restParameters : any[]
|
||||||
|
|
||||||
|
var _i = 10; // No Error
|
||||||
|
>_i : number
|
||||||
|
}
|
||||||
|
var f2NoError = () => {
|
||||||
|
>f2NoError : () => void
|
||||||
|
>() => { var _i = 10; // no error} : () => void
|
||||||
|
|
||||||
|
var _i = 10; // no error
|
||||||
|
>_i : number
|
||||||
|
}
|
|
@ -1,78 +0,0 @@
|
||||||
tests/cases/compiler/collisionRestParameterClassConstructor.ts(3,17): error TS2397: Duplicate identifier '_i'. Compiler uses '_i' to initialize rest parameter.
|
|
||||||
tests/cases/compiler/collisionRestParameterClassConstructor.ts(25,17): error TS2397: Duplicate identifier '_i'. Compiler uses '_i' to initialize rest parameter.
|
|
||||||
tests/cases/compiler/collisionRestParameterClassConstructor.ts(45,17): error TS2397: Duplicate identifier '_i'. Compiler uses '_i' to initialize rest parameter.
|
|
||||||
|
|
||||||
|
|
||||||
==== tests/cases/compiler/collisionRestParameterClassConstructor.ts (3 errors) ====
|
|
||||||
// Constructors
|
|
||||||
class c1 {
|
|
||||||
constructor(_i: number, ...restParameters) { //_i is error
|
|
||||||
~~~~~~~~~~
|
|
||||||
!!! error TS2397: Duplicate identifier '_i'. Compiler uses '_i' to initialize rest parameter.
|
|
||||||
var _i = 10; // no error
|
|
||||||
}
|
|
||||||
}
|
|
||||||
class c1NoError {
|
|
||||||
constructor(_i: number) { // no error
|
|
||||||
var _i = 10; // no error
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class c2 {
|
|
||||||
constructor(...restParameters) {
|
|
||||||
var _i = 10; // no error
|
|
||||||
}
|
|
||||||
}
|
|
||||||
class c2NoError {
|
|
||||||
constructor() {
|
|
||||||
var _i = 10; // no error
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class c3 {
|
|
||||||
constructor(public _i: number, ...restParameters) { //_i is error
|
|
||||||
~~~~~~~~~~~~~~~~~
|
|
||||||
!!! error TS2397: Duplicate identifier '_i'. Compiler uses '_i' to initialize rest parameter.
|
|
||||||
var _i = 10; // no error
|
|
||||||
}
|
|
||||||
}
|
|
||||||
class c3NoError {
|
|
||||||
constructor(public _i: number) { // no error
|
|
||||||
var _i = 10; // no error
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
declare class c4 {
|
|
||||||
constructor(_i: number, ...restParameters); // No error - no code gen
|
|
||||||
}
|
|
||||||
declare class c4NoError {
|
|
||||||
constructor(_i: number); // no error
|
|
||||||
}
|
|
||||||
|
|
||||||
class c5 {
|
|
||||||
constructor(_i: number, ...rest); // no codegen no error
|
|
||||||
constructor(_i: string, ...rest); // no codegen no error
|
|
||||||
constructor(_i: any, ...rest) { // error
|
|
||||||
~~~~~~~
|
|
||||||
!!! error TS2397: Duplicate identifier '_i'. Compiler uses '_i' to initialize rest parameter.
|
|
||||||
var _i: any; // no error
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class c5NoError {
|
|
||||||
constructor(_i: number); // no error
|
|
||||||
constructor(_i: string); // no error
|
|
||||||
constructor(_i: any) { // no error
|
|
||||||
var _i: any; // no error
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
declare class c6 {
|
|
||||||
constructor(_i: number, ...rest); // no codegen no error
|
|
||||||
constructor(_i: string, ...rest); // no codegen no error
|
|
||||||
}
|
|
||||||
|
|
||||||
declare class c6NoError {
|
|
||||||
constructor(_i: number); // no error
|
|
||||||
constructor(_i: string); // no error
|
|
||||||
}
|
|
|
@ -71,8 +71,8 @@ declare class c6NoError {
|
||||||
var c1 = (function () {
|
var c1 = (function () {
|
||||||
function c1(_i) {
|
function c1(_i) {
|
||||||
var restParameters = [];
|
var restParameters = [];
|
||||||
for (var _i = 1; _i < arguments.length; _i++) {
|
for (var _a = 1; _a < arguments.length; _a++) {
|
||||||
restParameters[_i - 1] = arguments[_i];
|
restParameters[_a - 1] = arguments[_a];
|
||||||
}
|
}
|
||||||
var _i = 10; // no error
|
var _i = 10; // no error
|
||||||
}
|
}
|
||||||
|
@ -87,8 +87,8 @@ var c1NoError = (function () {
|
||||||
var c2 = (function () {
|
var c2 = (function () {
|
||||||
function c2() {
|
function c2() {
|
||||||
var restParameters = [];
|
var restParameters = [];
|
||||||
for (var _i = 0; _i < arguments.length; _i++) {
|
for (var _a = 0; _a < arguments.length; _a++) {
|
||||||
restParameters[_i - 0] = arguments[_i];
|
restParameters[_a - 0] = arguments[_a];
|
||||||
}
|
}
|
||||||
var _i = 10; // no error
|
var _i = 10; // no error
|
||||||
}
|
}
|
||||||
|
@ -103,8 +103,8 @@ var c2NoError = (function () {
|
||||||
var c3 = (function () {
|
var c3 = (function () {
|
||||||
function c3(_i) {
|
function c3(_i) {
|
||||||
var restParameters = [];
|
var restParameters = [];
|
||||||
for (var _i = 1; _i < arguments.length; _i++) {
|
for (var _a = 1; _a < arguments.length; _a++) {
|
||||||
restParameters[_i - 1] = arguments[_i];
|
restParameters[_a - 1] = arguments[_a];
|
||||||
}
|
}
|
||||||
this._i = _i;
|
this._i = _i;
|
||||||
var _i = 10; // no error
|
var _i = 10; // no error
|
||||||
|
@ -121,8 +121,8 @@ var c3NoError = (function () {
|
||||||
var c5 = (function () {
|
var c5 = (function () {
|
||||||
function c5(_i) {
|
function c5(_i) {
|
||||||
var rest = [];
|
var rest = [];
|
||||||
for (var _i = 1; _i < arguments.length; _i++) {
|
for (var _a = 1; _a < arguments.length; _a++) {
|
||||||
rest[_i - 1] = arguments[_i];
|
rest[_a - 1] = arguments[_a];
|
||||||
}
|
}
|
||||||
var _i; // no error
|
var _i; // no error
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,137 @@
|
||||||
|
=== tests/cases/compiler/collisionRestParameterClassConstructor.ts ===
|
||||||
|
// Constructors
|
||||||
|
class c1 {
|
||||||
|
>c1 : c1
|
||||||
|
|
||||||
|
constructor(_i: number, ...restParameters) { //_i is error
|
||||||
|
>_i : number
|
||||||
|
>restParameters : any[]
|
||||||
|
|
||||||
|
var _i = 10; // no error
|
||||||
|
>_i : number
|
||||||
|
}
|
||||||
|
}
|
||||||
|
class c1NoError {
|
||||||
|
>c1NoError : c1NoError
|
||||||
|
|
||||||
|
constructor(_i: number) { // no error
|
||||||
|
>_i : number
|
||||||
|
|
||||||
|
var _i = 10; // no error
|
||||||
|
>_i : number
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class c2 {
|
||||||
|
>c2 : c2
|
||||||
|
|
||||||
|
constructor(...restParameters) {
|
||||||
|
>restParameters : any[]
|
||||||
|
|
||||||
|
var _i = 10; // no error
|
||||||
|
>_i : number
|
||||||
|
}
|
||||||
|
}
|
||||||
|
class c2NoError {
|
||||||
|
>c2NoError : c2NoError
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
var _i = 10; // no error
|
||||||
|
>_i : number
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class c3 {
|
||||||
|
>c3 : c3
|
||||||
|
|
||||||
|
constructor(public _i: number, ...restParameters) { //_i is error
|
||||||
|
>_i : number
|
||||||
|
>restParameters : any[]
|
||||||
|
|
||||||
|
var _i = 10; // no error
|
||||||
|
>_i : number
|
||||||
|
}
|
||||||
|
}
|
||||||
|
class c3NoError {
|
||||||
|
>c3NoError : c3NoError
|
||||||
|
|
||||||
|
constructor(public _i: number) { // no error
|
||||||
|
>_i : number
|
||||||
|
|
||||||
|
var _i = 10; // no error
|
||||||
|
>_i : number
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
declare class c4 {
|
||||||
|
>c4 : c4
|
||||||
|
|
||||||
|
constructor(_i: number, ...restParameters); // No error - no code gen
|
||||||
|
>_i : number
|
||||||
|
>restParameters : any[]
|
||||||
|
}
|
||||||
|
declare class c4NoError {
|
||||||
|
>c4NoError : c4NoError
|
||||||
|
|
||||||
|
constructor(_i: number); // no error
|
||||||
|
>_i : number
|
||||||
|
}
|
||||||
|
|
||||||
|
class c5 {
|
||||||
|
>c5 : c5
|
||||||
|
|
||||||
|
constructor(_i: number, ...rest); // no codegen no error
|
||||||
|
>_i : number
|
||||||
|
>rest : any[]
|
||||||
|
|
||||||
|
constructor(_i: string, ...rest); // no codegen no error
|
||||||
|
>_i : string
|
||||||
|
>rest : any[]
|
||||||
|
|
||||||
|
constructor(_i: any, ...rest) { // error
|
||||||
|
>_i : any
|
||||||
|
>rest : any[]
|
||||||
|
|
||||||
|
var _i: any; // no error
|
||||||
|
>_i : any
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class c5NoError {
|
||||||
|
>c5NoError : c5NoError
|
||||||
|
|
||||||
|
constructor(_i: number); // no error
|
||||||
|
>_i : number
|
||||||
|
|
||||||
|
constructor(_i: string); // no error
|
||||||
|
>_i : string
|
||||||
|
|
||||||
|
constructor(_i: any) { // no error
|
||||||
|
>_i : any
|
||||||
|
|
||||||
|
var _i: any; // no error
|
||||||
|
>_i : any
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
declare class c6 {
|
||||||
|
>c6 : c6
|
||||||
|
|
||||||
|
constructor(_i: number, ...rest); // no codegen no error
|
||||||
|
>_i : number
|
||||||
|
>rest : any[]
|
||||||
|
|
||||||
|
constructor(_i: string, ...rest); // no codegen no error
|
||||||
|
>_i : string
|
||||||
|
>rest : any[]
|
||||||
|
}
|
||||||
|
|
||||||
|
declare class c6NoError {
|
||||||
|
>c6NoError : c6NoError
|
||||||
|
|
||||||
|
constructor(_i: number); // no error
|
||||||
|
>_i : number
|
||||||
|
|
||||||
|
constructor(_i: string); // no error
|
||||||
|
>_i : string
|
||||||
|
}
|
|
@ -1,47 +0,0 @@
|
||||||
tests/cases/compiler/collisionRestParameterClassMethod.ts(2,16): error TS2397: Duplicate identifier '_i'. Compiler uses '_i' to initialize rest parameter.
|
|
||||||
tests/cases/compiler/collisionRestParameterClassMethod.ts(10,15): error TS2397: Duplicate identifier '_i'. Compiler uses '_i' to initialize rest parameter.
|
|
||||||
|
|
||||||
|
|
||||||
==== tests/cases/compiler/collisionRestParameterClassMethod.ts (2 errors) ====
|
|
||||||
class c1 {
|
|
||||||
public foo(_i: number, ...restParameters) { //_i is error
|
|
||||||
~~~~~~~~~~
|
|
||||||
!!! error TS2397: Duplicate identifier '_i'. Compiler uses '_i' to initialize rest parameter.
|
|
||||||
var _i = 10; // no error
|
|
||||||
}
|
|
||||||
public fooNoError(_i: number) { // no error
|
|
||||||
var _i = 10; // no error
|
|
||||||
}
|
|
||||||
public f4(_i: number, ...rest); // no codegen no error
|
|
||||||
public f4(_i: string, ...rest); // no codegen no error
|
|
||||||
public f4(_i: any, ...rest) { // error
|
|
||||||
~~~~~~~
|
|
||||||
!!! error TS2397: Duplicate identifier '_i'. Compiler uses '_i' to initialize rest parameter.
|
|
||||||
var _i: any; // no error
|
|
||||||
}
|
|
||||||
|
|
||||||
public f4NoError(_i: number); // no error
|
|
||||||
public f4NoError(_i: string); // no error
|
|
||||||
public f4NoError(_i: any) { // no error
|
|
||||||
var _i: any; // no error
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
declare class c2 {
|
|
||||||
public foo(_i: number, ...restParameters); // No error - no code gen
|
|
||||||
public fooNoError(_i: number); // no error
|
|
||||||
|
|
||||||
public f4(_i: number, ...rest); // no codegen no error
|
|
||||||
public f4(_i: string, ...rest); // no codegen no error
|
|
||||||
public f4NoError(_i: number); // no error
|
|
||||||
public f4NoError(_i: string); // no error
|
|
||||||
}
|
|
||||||
|
|
||||||
class c3 {
|
|
||||||
public foo(...restParameters) {
|
|
||||||
var _i = 10; // no error
|
|
||||||
}
|
|
||||||
public fooNoError() {
|
|
||||||
var _i = 10; // no error
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -44,8 +44,8 @@ var c1 = (function () {
|
||||||
}
|
}
|
||||||
c1.prototype.foo = function (_i) {
|
c1.prototype.foo = function (_i) {
|
||||||
var restParameters = [];
|
var restParameters = [];
|
||||||
for (var _i = 1; _i < arguments.length; _i++) {
|
for (var _a = 1; _a < arguments.length; _a++) {
|
||||||
restParameters[_i - 1] = arguments[_i];
|
restParameters[_a - 1] = arguments[_a];
|
||||||
}
|
}
|
||||||
var _i = 10; // no error
|
var _i = 10; // no error
|
||||||
};
|
};
|
||||||
|
@ -54,8 +54,8 @@ var c1 = (function () {
|
||||||
};
|
};
|
||||||
c1.prototype.f4 = function (_i) {
|
c1.prototype.f4 = function (_i) {
|
||||||
var rest = [];
|
var rest = [];
|
||||||
for (var _i = 1; _i < arguments.length; _i++) {
|
for (var _a = 1; _a < arguments.length; _a++) {
|
||||||
rest[_i - 1] = arguments[_i];
|
rest[_a - 1] = arguments[_a];
|
||||||
}
|
}
|
||||||
var _i; // no error
|
var _i; // no error
|
||||||
};
|
};
|
||||||
|
@ -69,8 +69,8 @@ var c3 = (function () {
|
||||||
}
|
}
|
||||||
c3.prototype.foo = function () {
|
c3.prototype.foo = function () {
|
||||||
var restParameters = [];
|
var restParameters = [];
|
||||||
for (var _i = 0; _i < arguments.length; _i++) {
|
for (var _a = 0; _a < arguments.length; _a++) {
|
||||||
restParameters[_i - 0] = arguments[_i];
|
restParameters[_a - 0] = arguments[_a];
|
||||||
}
|
}
|
||||||
var _i = 10; // no error
|
var _i = 10; // no error
|
||||||
};
|
};
|
||||||
|
|
|
@ -0,0 +1,103 @@
|
||||||
|
=== tests/cases/compiler/collisionRestParameterClassMethod.ts ===
|
||||||
|
class c1 {
|
||||||
|
>c1 : c1
|
||||||
|
|
||||||
|
public foo(_i: number, ...restParameters) { //_i is error
|
||||||
|
>foo : (_i: number, ...restParameters: any[]) => void
|
||||||
|
>_i : number
|
||||||
|
>restParameters : any[]
|
||||||
|
|
||||||
|
var _i = 10; // no error
|
||||||
|
>_i : number
|
||||||
|
}
|
||||||
|
public fooNoError(_i: number) { // no error
|
||||||
|
>fooNoError : (_i: number) => void
|
||||||
|
>_i : number
|
||||||
|
|
||||||
|
var _i = 10; // no error
|
||||||
|
>_i : number
|
||||||
|
}
|
||||||
|
public f4(_i: number, ...rest); // no codegen no error
|
||||||
|
>f4 : { (_i: number, ...rest: any[]): any; (_i: string, ...rest: any[]): any; }
|
||||||
|
>_i : number
|
||||||
|
>rest : any[]
|
||||||
|
|
||||||
|
public f4(_i: string, ...rest); // no codegen no error
|
||||||
|
>f4 : { (_i: number, ...rest: any[]): any; (_i: string, ...rest: any[]): any; }
|
||||||
|
>_i : string
|
||||||
|
>rest : any[]
|
||||||
|
|
||||||
|
public f4(_i: any, ...rest) { // error
|
||||||
|
>f4 : { (_i: number, ...rest: any[]): any; (_i: string, ...rest: any[]): any; }
|
||||||
|
>_i : any
|
||||||
|
>rest : any[]
|
||||||
|
|
||||||
|
var _i: any; // no error
|
||||||
|
>_i : any
|
||||||
|
}
|
||||||
|
|
||||||
|
public f4NoError(_i: number); // no error
|
||||||
|
>f4NoError : { (_i: number): any; (_i: string): any; }
|
||||||
|
>_i : number
|
||||||
|
|
||||||
|
public f4NoError(_i: string); // no error
|
||||||
|
>f4NoError : { (_i: number): any; (_i: string): any; }
|
||||||
|
>_i : string
|
||||||
|
|
||||||
|
public f4NoError(_i: any) { // no error
|
||||||
|
>f4NoError : { (_i: number): any; (_i: string): any; }
|
||||||
|
>_i : any
|
||||||
|
|
||||||
|
var _i: any; // no error
|
||||||
|
>_i : any
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
declare class c2 {
|
||||||
|
>c2 : c2
|
||||||
|
|
||||||
|
public foo(_i: number, ...restParameters); // No error - no code gen
|
||||||
|
>foo : (_i: number, ...restParameters: any[]) => any
|
||||||
|
>_i : number
|
||||||
|
>restParameters : any[]
|
||||||
|
|
||||||
|
public fooNoError(_i: number); // no error
|
||||||
|
>fooNoError : (_i: number) => any
|
||||||
|
>_i : number
|
||||||
|
|
||||||
|
public f4(_i: number, ...rest); // no codegen no error
|
||||||
|
>f4 : { (_i: number, ...rest: any[]): any; (_i: string, ...rest: any[]): any; }
|
||||||
|
>_i : number
|
||||||
|
>rest : any[]
|
||||||
|
|
||||||
|
public f4(_i: string, ...rest); // no codegen no error
|
||||||
|
>f4 : { (_i: number, ...rest: any[]): any; (_i: string, ...rest: any[]): any; }
|
||||||
|
>_i : string
|
||||||
|
>rest : any[]
|
||||||
|
|
||||||
|
public f4NoError(_i: number); // no error
|
||||||
|
>f4NoError : { (_i: number): any; (_i: string): any; }
|
||||||
|
>_i : number
|
||||||
|
|
||||||
|
public f4NoError(_i: string); // no error
|
||||||
|
>f4NoError : { (_i: number): any; (_i: string): any; }
|
||||||
|
>_i : string
|
||||||
|
}
|
||||||
|
|
||||||
|
class c3 {
|
||||||
|
>c3 : c3
|
||||||
|
|
||||||
|
public foo(...restParameters) {
|
||||||
|
>foo : (...restParameters: any[]) => void
|
||||||
|
>restParameters : any[]
|
||||||
|
|
||||||
|
var _i = 10; // no error
|
||||||
|
>_i : number
|
||||||
|
}
|
||||||
|
public fooNoError() {
|
||||||
|
>fooNoError : () => void
|
||||||
|
|
||||||
|
var _i = 10; // no error
|
||||||
|
>_i : number
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,42 +0,0 @@
|
||||||
tests/cases/compiler/collisionRestParameterFunction.ts(2,13): error TS2397: Duplicate identifier '_i'. Compiler uses '_i' to initialize rest parameter.
|
|
||||||
tests/cases/compiler/collisionRestParameterFunction.ts(21,13): error TS2397: Duplicate identifier '_i'. Compiler uses '_i' to initialize rest parameter.
|
|
||||||
|
|
||||||
|
|
||||||
==== tests/cases/compiler/collisionRestParameterFunction.ts (2 errors) ====
|
|
||||||
// Functions
|
|
||||||
function f1(_i: number, ...restParameters) { //_i is error
|
|
||||||
~~~~~~~~~~
|
|
||||||
!!! error TS2397: Duplicate identifier '_i'. Compiler uses '_i' to initialize rest parameter.
|
|
||||||
var _i = 10; // no error
|
|
||||||
}
|
|
||||||
function f1NoError(_i: number) { // no error
|
|
||||||
var _i = 10; // no error
|
|
||||||
}
|
|
||||||
|
|
||||||
declare function f2(_i: number, ...restParameters); // no error - no code gen
|
|
||||||
declare function f2NoError(_i: number); // no error
|
|
||||||
|
|
||||||
function f3(...restParameters) {
|
|
||||||
var _i = 10; // no error
|
|
||||||
}
|
|
||||||
function f3NoError() {
|
|
||||||
var _i = 10; // no error
|
|
||||||
}
|
|
||||||
|
|
||||||
function f4(_i: number, ...rest); // no codegen no error
|
|
||||||
function f4(_i: string, ...rest); // no codegen no error
|
|
||||||
function f4(_i: any, ...rest) { // error
|
|
||||||
~~~~~~~
|
|
||||||
!!! error TS2397: Duplicate identifier '_i'. Compiler uses '_i' to initialize rest parameter.
|
|
||||||
}
|
|
||||||
|
|
||||||
function f4NoError(_i: number); // no error
|
|
||||||
function f4NoError(_i: string); // no error
|
|
||||||
function f4NoError(_i: any) { // no error
|
|
||||||
}
|
|
||||||
|
|
||||||
declare function f5(_i: number, ...rest); // no codegen no error
|
|
||||||
declare function f5(_i: string, ...rest); // no codegen no error
|
|
||||||
|
|
||||||
declare function f6(_i: number); // no codegen no error
|
|
||||||
declare function f6(_i: string); // no codegen no error
|
|
|
@ -37,8 +37,8 @@ declare function f6(_i: string); // no codegen no error
|
||||||
// Functions
|
// Functions
|
||||||
function f1(_i) {
|
function f1(_i) {
|
||||||
var restParameters = [];
|
var restParameters = [];
|
||||||
for (var _i = 1; _i < arguments.length; _i++) {
|
for (var _a = 1; _a < arguments.length; _a++) {
|
||||||
restParameters[_i - 1] = arguments[_i];
|
restParameters[_a - 1] = arguments[_a];
|
||||||
}
|
}
|
||||||
var _i = 10; // no error
|
var _i = 10; // no error
|
||||||
}
|
}
|
||||||
|
@ -47,8 +47,8 @@ function f1NoError(_i) {
|
||||||
}
|
}
|
||||||
function f3() {
|
function f3() {
|
||||||
var restParameters = [];
|
var restParameters = [];
|
||||||
for (var _i = 0; _i < arguments.length; _i++) {
|
for (var _a = 0; _a < arguments.length; _a++) {
|
||||||
restParameters[_i - 0] = arguments[_i];
|
restParameters[_a - 0] = arguments[_a];
|
||||||
}
|
}
|
||||||
var _i = 10; // no error
|
var _i = 10; // no error
|
||||||
}
|
}
|
||||||
|
@ -57,8 +57,8 @@ function f3NoError() {
|
||||||
}
|
}
|
||||||
function f4(_i) {
|
function f4(_i) {
|
||||||
var rest = [];
|
var rest = [];
|
||||||
for (var _i = 1; _i < arguments.length; _i++) {
|
for (var _a = 1; _a < arguments.length; _a++) {
|
||||||
rest[_i - 1] = arguments[_i];
|
rest[_a - 1] = arguments[_a];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
function f4NoError(_i) {
|
function f4NoError(_i) {
|
||||||
|
|
|
@ -0,0 +1,88 @@
|
||||||
|
=== tests/cases/compiler/collisionRestParameterFunction.ts ===
|
||||||
|
// Functions
|
||||||
|
function f1(_i: number, ...restParameters) { //_i is error
|
||||||
|
>f1 : (_i: number, ...restParameters: any[]) => void
|
||||||
|
>_i : number
|
||||||
|
>restParameters : any[]
|
||||||
|
|
||||||
|
var _i = 10; // no error
|
||||||
|
>_i : number
|
||||||
|
}
|
||||||
|
function f1NoError(_i: number) { // no error
|
||||||
|
>f1NoError : (_i: number) => void
|
||||||
|
>_i : number
|
||||||
|
|
||||||
|
var _i = 10; // no error
|
||||||
|
>_i : number
|
||||||
|
}
|
||||||
|
|
||||||
|
declare function f2(_i: number, ...restParameters); // no error - no code gen
|
||||||
|
>f2 : (_i: number, ...restParameters: any[]) => any
|
||||||
|
>_i : number
|
||||||
|
>restParameters : any[]
|
||||||
|
|
||||||
|
declare function f2NoError(_i: number); // no error
|
||||||
|
>f2NoError : (_i: number) => any
|
||||||
|
>_i : number
|
||||||
|
|
||||||
|
function f3(...restParameters) {
|
||||||
|
>f3 : (...restParameters: any[]) => void
|
||||||
|
>restParameters : any[]
|
||||||
|
|
||||||
|
var _i = 10; // no error
|
||||||
|
>_i : number
|
||||||
|
}
|
||||||
|
function f3NoError() {
|
||||||
|
>f3NoError : () => void
|
||||||
|
|
||||||
|
var _i = 10; // no error
|
||||||
|
>_i : number
|
||||||
|
}
|
||||||
|
|
||||||
|
function f4(_i: number, ...rest); // no codegen no error
|
||||||
|
>f4 : { (_i: number, ...rest: any[]): any; (_i: string, ...rest: any[]): any; }
|
||||||
|
>_i : number
|
||||||
|
>rest : any[]
|
||||||
|
|
||||||
|
function f4(_i: string, ...rest); // no codegen no error
|
||||||
|
>f4 : { (_i: number, ...rest: any[]): any; (_i: string, ...rest: any[]): any; }
|
||||||
|
>_i : string
|
||||||
|
>rest : any[]
|
||||||
|
|
||||||
|
function f4(_i: any, ...rest) { // error
|
||||||
|
>f4 : { (_i: number, ...rest: any[]): any; (_i: string, ...rest: any[]): any; }
|
||||||
|
>_i : any
|
||||||
|
>rest : any[]
|
||||||
|
}
|
||||||
|
|
||||||
|
function f4NoError(_i: number); // no error
|
||||||
|
>f4NoError : { (_i: number): any; (_i: string): any; }
|
||||||
|
>_i : number
|
||||||
|
|
||||||
|
function f4NoError(_i: string); // no error
|
||||||
|
>f4NoError : { (_i: number): any; (_i: string): any; }
|
||||||
|
>_i : string
|
||||||
|
|
||||||
|
function f4NoError(_i: any) { // no error
|
||||||
|
>f4NoError : { (_i: number): any; (_i: string): any; }
|
||||||
|
>_i : any
|
||||||
|
}
|
||||||
|
|
||||||
|
declare function f5(_i: number, ...rest); // no codegen no error
|
||||||
|
>f5 : { (_i: number, ...rest: any[]): any; (_i: string, ...rest: any[]): any; }
|
||||||
|
>_i : number
|
||||||
|
>rest : any[]
|
||||||
|
|
||||||
|
declare function f5(_i: string, ...rest); // no codegen no error
|
||||||
|
>f5 : { (_i: number, ...rest: any[]): any; (_i: string, ...rest: any[]): any; }
|
||||||
|
>_i : string
|
||||||
|
>rest : any[]
|
||||||
|
|
||||||
|
declare function f6(_i: number); // no codegen no error
|
||||||
|
>f6 : { (_i: number): any; (_i: string): any; }
|
||||||
|
>_i : number
|
||||||
|
|
||||||
|
declare function f6(_i: string); // no codegen no error
|
||||||
|
>f6 : { (_i: number): any; (_i: string): any; }
|
||||||
|
>_i : string
|
||||||
|
|
|
@ -1,33 +0,0 @@
|
||||||
tests/cases/compiler/collisionRestParameterFunctionExpressions.ts(2,17): error TS2397: Duplicate identifier '_i'. Compiler uses '_i' to initialize rest parameter.
|
|
||||||
tests/cases/compiler/collisionRestParameterFunctionExpressions.ts(17,17): error TS2397: Duplicate identifier '_i'. Compiler uses '_i' to initialize rest parameter.
|
|
||||||
|
|
||||||
|
|
||||||
==== tests/cases/compiler/collisionRestParameterFunctionExpressions.ts (2 errors) ====
|
|
||||||
function foo() {
|
|
||||||
function f1(_i: number, ...restParameters) { //_i is error
|
|
||||||
~~~~~~~~~~
|
|
||||||
!!! error TS2397: Duplicate identifier '_i'. Compiler uses '_i' to initialize rest parameter.
|
|
||||||
var _i = 10; // no error
|
|
||||||
}
|
|
||||||
function f1NoError(_i: number) { // no error
|
|
||||||
var _i = 10; // no error
|
|
||||||
}
|
|
||||||
function f3(...restParameters) {
|
|
||||||
var _i = 10; // no error
|
|
||||||
}
|
|
||||||
function f3NoError() {
|
|
||||||
var _i = 10; // no error
|
|
||||||
}
|
|
||||||
|
|
||||||
function f4(_i: number, ...rest); // no codegen no error
|
|
||||||
function f4(_i: string, ...rest); // no codegen no error
|
|
||||||
function f4(_i: any, ...rest) { // error
|
|
||||||
~~~~~~~
|
|
||||||
!!! error TS2397: Duplicate identifier '_i'. Compiler uses '_i' to initialize rest parameter.
|
|
||||||
}
|
|
||||||
|
|
||||||
function f4NoError(_i: number); // no error
|
|
||||||
function f4NoError(_i: string); // no error
|
|
||||||
function f4NoError(_i: any) { // no error
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -28,8 +28,8 @@ function foo() {
|
||||||
function foo() {
|
function foo() {
|
||||||
function f1(_i) {
|
function f1(_i) {
|
||||||
var restParameters = [];
|
var restParameters = [];
|
||||||
for (var _i = 1; _i < arguments.length; _i++) {
|
for (var _a = 1; _a < arguments.length; _a++) {
|
||||||
restParameters[_i - 1] = arguments[_i];
|
restParameters[_a - 1] = arguments[_a];
|
||||||
}
|
}
|
||||||
var _i = 10; // no error
|
var _i = 10; // no error
|
||||||
}
|
}
|
||||||
|
@ -38,8 +38,8 @@ function foo() {
|
||||||
}
|
}
|
||||||
function f3() {
|
function f3() {
|
||||||
var restParameters = [];
|
var restParameters = [];
|
||||||
for (var _i = 0; _i < arguments.length; _i++) {
|
for (var _a = 0; _a < arguments.length; _a++) {
|
||||||
restParameters[_i - 0] = arguments[_i];
|
restParameters[_a - 0] = arguments[_a];
|
||||||
}
|
}
|
||||||
var _i = 10; // no error
|
var _i = 10; // no error
|
||||||
}
|
}
|
||||||
|
@ -48,8 +48,8 @@ function foo() {
|
||||||
}
|
}
|
||||||
function f4(_i) {
|
function f4(_i) {
|
||||||
var rest = [];
|
var rest = [];
|
||||||
for (var _i = 1; _i < arguments.length; _i++) {
|
for (var _a = 1; _a < arguments.length; _a++) {
|
||||||
rest[_i - 1] = arguments[_i];
|
rest[_a - 1] = arguments[_a];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
function f4NoError(_i) {
|
function f4NoError(_i) {
|
||||||
|
|
|
@ -0,0 +1,62 @@
|
||||||
|
=== tests/cases/compiler/collisionRestParameterFunctionExpressions.ts ===
|
||||||
|
function foo() {
|
||||||
|
>foo : () => void
|
||||||
|
|
||||||
|
function f1(_i: number, ...restParameters) { //_i is error
|
||||||
|
>f1 : (_i: number, ...restParameters: any[]) => void
|
||||||
|
>_i : number
|
||||||
|
>restParameters : any[]
|
||||||
|
|
||||||
|
var _i = 10; // no error
|
||||||
|
>_i : number
|
||||||
|
}
|
||||||
|
function f1NoError(_i: number) { // no error
|
||||||
|
>f1NoError : (_i: number) => void
|
||||||
|
>_i : number
|
||||||
|
|
||||||
|
var _i = 10; // no error
|
||||||
|
>_i : number
|
||||||
|
}
|
||||||
|
function f3(...restParameters) {
|
||||||
|
>f3 : (...restParameters: any[]) => void
|
||||||
|
>restParameters : any[]
|
||||||
|
|
||||||
|
var _i = 10; // no error
|
||||||
|
>_i : number
|
||||||
|
}
|
||||||
|
function f3NoError() {
|
||||||
|
>f3NoError : () => void
|
||||||
|
|
||||||
|
var _i = 10; // no error
|
||||||
|
>_i : number
|
||||||
|
}
|
||||||
|
|
||||||
|
function f4(_i: number, ...rest); // no codegen no error
|
||||||
|
>f4 : { (_i: number, ...rest: any[]): any; (_i: string, ...rest: any[]): any; }
|
||||||
|
>_i : number
|
||||||
|
>rest : any[]
|
||||||
|
|
||||||
|
function f4(_i: string, ...rest); // no codegen no error
|
||||||
|
>f4 : { (_i: number, ...rest: any[]): any; (_i: string, ...rest: any[]): any; }
|
||||||
|
>_i : string
|
||||||
|
>rest : any[]
|
||||||
|
|
||||||
|
function f4(_i: any, ...rest) { // error
|
||||||
|
>f4 : { (_i: number, ...rest: any[]): any; (_i: string, ...rest: any[]): any; }
|
||||||
|
>_i : any
|
||||||
|
>rest : any[]
|
||||||
|
}
|
||||||
|
|
||||||
|
function f4NoError(_i: number); // no error
|
||||||
|
>f4NoError : { (_i: number): any; (_i: string): any; }
|
||||||
|
>_i : number
|
||||||
|
|
||||||
|
function f4NoError(_i: string); // no error
|
||||||
|
>f4NoError : { (_i: number): any; (_i: string): any; }
|
||||||
|
>_i : string
|
||||||
|
|
||||||
|
function f4NoError(_i: any) { // no error
|
||||||
|
>f4NoError : { (_i: number): any; (_i: string): any; }
|
||||||
|
>_i : any
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,14 +0,0 @@
|
||||||
tests/cases/compiler/collisionRestParameterUnderscoreIUsage.ts(5,21): error TS2398: Expression resolves to variable declaration '_i' that compiler uses to initialize rest parameter.
|
|
||||||
|
|
||||||
|
|
||||||
==== tests/cases/compiler/collisionRestParameterUnderscoreIUsage.ts (1 errors) ====
|
|
||||||
declare var console: { log(msg?: string): void; };
|
|
||||||
var _i = "This is what I'd expect to see";
|
|
||||||
class Foo {
|
|
||||||
constructor(...args: any[]) {
|
|
||||||
console.log(_i); // This should result in error
|
|
||||||
~~
|
|
||||||
!!! error TS2398: Expression resolves to variable declaration '_i' that compiler uses to initialize rest parameter.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
new Foo();
|
|
|
@ -13,8 +13,8 @@ var _i = "This is what I'd expect to see";
|
||||||
var Foo = (function () {
|
var Foo = (function () {
|
||||||
function Foo() {
|
function Foo() {
|
||||||
var args = [];
|
var args = [];
|
||||||
for (var _i = 0; _i < arguments.length; _i++) {
|
for (var _a = 0; _a < arguments.length; _a++) {
|
||||||
args[_i - 0] = arguments[_i];
|
args[_a - 0] = arguments[_a];
|
||||||
}
|
}
|
||||||
console.log(_i); // This should result in error
|
console.log(_i); // This should result in error
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,27 @@
|
||||||
|
=== tests/cases/compiler/collisionRestParameterUnderscoreIUsage.ts ===
|
||||||
|
declare var console: { log(msg?: string): void; };
|
||||||
|
>console : { log(msg?: string): void; }
|
||||||
|
>log : (msg?: string) => void
|
||||||
|
>msg : string
|
||||||
|
|
||||||
|
var _i = "This is what I'd expect to see";
|
||||||
|
>_i : string
|
||||||
|
|
||||||
|
class Foo {
|
||||||
|
>Foo : Foo
|
||||||
|
|
||||||
|
constructor(...args: any[]) {
|
||||||
|
>args : any[]
|
||||||
|
|
||||||
|
console.log(_i); // This should result in error
|
||||||
|
>console.log(_i) : void
|
||||||
|
>console.log : (msg?: string) => void
|
||||||
|
>console : { log(msg?: string): void; }
|
||||||
|
>log : (msg?: string) => void
|
||||||
|
>_i : string
|
||||||
|
}
|
||||||
|
}
|
||||||
|
new Foo();
|
||||||
|
>new Foo() : Foo
|
||||||
|
>Foo : typeof Foo
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
tests/cases/conformance/es6/destructuring/declarationInAmbientContext.ts(1,13): error TS1183: Destructuring declarations are not allowed in ambient contexts.
|
||||||
|
tests/cases/conformance/es6/destructuring/declarationInAmbientContext.ts(2,13): error TS1183: Destructuring declarations are not allowed in ambient contexts.
|
||||||
|
|
||||||
|
|
||||||
|
==== tests/cases/conformance/es6/destructuring/declarationInAmbientContext.ts (2 errors) ====
|
||||||
|
declare var [a, b]; // Error, destructuring declaration not allowed in ambient context
|
||||||
|
~~~~~~
|
||||||
|
!!! error TS1183: Destructuring declarations are not allowed in ambient contexts.
|
||||||
|
declare var {c, d}; // Error, destructuring declaration not allowed in ambient context
|
||||||
|
~~~~~~
|
||||||
|
!!! error TS1183: Destructuring declarations are not allowed in ambient contexts.
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
tests/cases/conformance/es6/destructuring/declarationWithNoInitializer.ts(1,5): error TS1182: A destructuring declaration must have an initializer.
|
||||||
|
tests/cases/conformance/es6/destructuring/declarationWithNoInitializer.ts(2,5): error TS1182: A destructuring declaration must have an initializer.
|
||||||
|
|
||||||
|
|
||||||
|
==== tests/cases/conformance/es6/destructuring/declarationWithNoInitializer.ts (2 errors) ====
|
||||||
|
var [a, b]; // Error, no initializer
|
||||||
|
~~~~~~
|
||||||
|
!!! error TS1182: A destructuring declaration must have an initializer.
|
||||||
|
var {c, d}; // Error, no initializer
|
||||||
|
~~~~~~
|
||||||
|
!!! error TS1182: A destructuring declaration must have an initializer.
|
||||||
|
|
202
tests/baselines/reference/declarationsAndAssignments.errors.txt
Normal file
202
tests/baselines/reference/declarationsAndAssignments.errors.txt
Normal file
|
@ -0,0 +1,202 @@
|
||||||
|
tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(5,16): error TS2460: Type '[number, string]' has no property '2'.
|
||||||
|
tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(56,17): error TS2322: Type 'number' is not assignable to type 'string'.
|
||||||
|
tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(63,13): error TS2460: Type '[number]' has no property '1'.
|
||||||
|
tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(63,16): error TS2460: Type '[number]' has no property '2'.
|
||||||
|
tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(67,9): error TS2461: Type '{ [x: number]: undefined; }' is not an array type.
|
||||||
|
tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(68,9): error TS2461: Type '{ [x: number]: number; 0: number; 1: number; }' is not an array type.
|
||||||
|
tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(73,11): error TS2459: Type '{}' has no property 'a' and no string index signature.
|
||||||
|
tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(73,14): error TS2459: Type '{}' has no property 'b' and no string index signature.
|
||||||
|
tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(74,11): error TS2459: Type 'undefined[]' has no property 'a' and no string index signature.
|
||||||
|
tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(74,14): error TS2459: Type 'undefined[]' has no property 'b' and no string index signature.
|
||||||
|
tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(106,5): error TS2345: Argument of type '[number, [string, { y: boolean; }]]' is not assignable to parameter of type '[number, [string, { x: any; y?: boolean; }]]'.
|
||||||
|
Types of property '1' are incompatible.
|
||||||
|
Type '[string, { y: boolean; }]' is not assignable to type '[string, { x: any; y?: boolean; }]'.
|
||||||
|
Types of property '1' are incompatible.
|
||||||
|
Type '{ y: boolean; }' is not assignable to type '{ x: any; y?: boolean; }'.
|
||||||
|
Property 'x' is missing in type '{ y: boolean; }'.
|
||||||
|
tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(138,6): error TS2322: Type 'string' is not assignable to type 'number'.
|
||||||
|
tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(138,9): error TS2322: Type 'number' is not assignable to type 'string'.
|
||||||
|
|
||||||
|
|
||||||
|
==== tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts (13 errors) ====
|
||||||
|
function f0() {
|
||||||
|
var [] = [1, "hello"];
|
||||||
|
var [x] = [1, "hello"];
|
||||||
|
var [x, y] = [1, "hello"];
|
||||||
|
var [x, y, z] = [1, "hello"]; // Error
|
||||||
|
~
|
||||||
|
!!! error TS2460: Type '[number, string]' has no property '2'.
|
||||||
|
var [,, z] = [0, 1, 2];
|
||||||
|
var x: number;
|
||||||
|
var y: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
function f1() {
|
||||||
|
var a = [1, "hello"];
|
||||||
|
var [x] = a;
|
||||||
|
var [x, y] = a;
|
||||||
|
var [x, y, z] = a;
|
||||||
|
var x: number | string;
|
||||||
|
var y: number | string;
|
||||||
|
var z: number | string;
|
||||||
|
}
|
||||||
|
|
||||||
|
function f2() {
|
||||||
|
var { } = { x: 5, y: "hello" };
|
||||||
|
var { x } = { x: 5, y: "hello" };
|
||||||
|
var { y } = { x: 5, y: "hello" };
|
||||||
|
var { x, y } = { x: 5, y: "hello" };
|
||||||
|
var x: number;
|
||||||
|
var y: string;
|
||||||
|
var { x: a } = { x: 5, y: "hello" };
|
||||||
|
var { y: b } = { x: 5, y: "hello" };
|
||||||
|
var { x: a, y: b } = { x: 5, y: "hello" };
|
||||||
|
var a: number;
|
||||||
|
var b: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
function f3() {
|
||||||
|
var [x, [y, [z]]] = [1, ["hello", [true]]];
|
||||||
|
var x: number;
|
||||||
|
var y: string;
|
||||||
|
var z: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
function f4() {
|
||||||
|
var { a: x, b: { a: y, b: { a: z }}} = { a: 1, b: { a: "hello", b: { a: true } } };
|
||||||
|
var x: number;
|
||||||
|
var y: string;
|
||||||
|
var z: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
function f6() {
|
||||||
|
var [x = 0, y = ""] = [1, "hello"];
|
||||||
|
var x: number;
|
||||||
|
var y: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
function f7() {
|
||||||
|
var [x = 0, y = 1] = [1, "hello"]; // Error, initializer for y must be string
|
||||||
|
~
|
||||||
|
!!! error TS2322: Type 'number' is not assignable to type 'string'.
|
||||||
|
var x: number;
|
||||||
|
var y: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
function f8() {
|
||||||
|
var [a, b, c] = []; // Ok, [] is an array
|
||||||
|
var [d, e, f] = [1]; // Error, [1] is a tuple
|
||||||
|
~
|
||||||
|
!!! error TS2460: Type '[number]' has no property '1'.
|
||||||
|
~
|
||||||
|
!!! error TS2460: Type '[number]' has no property '2'.
|
||||||
|
}
|
||||||
|
|
||||||
|
function f9() {
|
||||||
|
var [a, b] = {}; // Error, not array type
|
||||||
|
~~~~~~
|
||||||
|
!!! error TS2461: Type '{ [x: number]: undefined; }' is not an array type.
|
||||||
|
var [c, d] = { 0: 10, 1: 20 }; // Error, not array type
|
||||||
|
~~~~~~
|
||||||
|
!!! error TS2461: Type '{ [x: number]: number; 0: number; 1: number; }' is not an array type.
|
||||||
|
var [e, f] = [10, 20];
|
||||||
|
}
|
||||||
|
|
||||||
|
function f10() {
|
||||||
|
var { a, b } = {}; // Error
|
||||||
|
~
|
||||||
|
!!! error TS2459: Type '{}' has no property 'a' and no string index signature.
|
||||||
|
~
|
||||||
|
!!! error TS2459: Type '{}' has no property 'b' and no string index signature.
|
||||||
|
var { a, b } = []; // Error
|
||||||
|
~
|
||||||
|
!!! error TS2459: Type 'undefined[]' has no property 'a' and no string index signature.
|
||||||
|
~
|
||||||
|
!!! error TS2459: Type 'undefined[]' has no property 'b' and no string index signature.
|
||||||
|
}
|
||||||
|
|
||||||
|
function f11() {
|
||||||
|
var { x: a, y: b } = { x: 10, y: "hello" };
|
||||||
|
var { 0: a, 1: b } = { 0: 10, 1: "hello" };
|
||||||
|
var { "<": a, ">": b } = { "<": 10, ">": "hello" };
|
||||||
|
var { 0: a, 1: b } = [10, "hello"];
|
||||||
|
var a: number;
|
||||||
|
var b: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
function f12() {
|
||||||
|
var [a, [b, { x, y: c }] = ["abc", { x: 10, y: false }]] = [1, ["hello", { x: 5, y: true }]];
|
||||||
|
var a: number;
|
||||||
|
var b: string;
|
||||||
|
var x: number;
|
||||||
|
var c: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
function f13() {
|
||||||
|
var [x, y] = [1, "hello"];
|
||||||
|
var [a, b] = [[x, y], { x: x, y: y }];
|
||||||
|
}
|
||||||
|
|
||||||
|
function f14([a = 1, [b = "hello", { x, y: c = false }]]) {
|
||||||
|
var a: number;
|
||||||
|
var b: string;
|
||||||
|
var c: boolean;
|
||||||
|
}
|
||||||
|
f14([2, ["abc", { x: 0, y: true }]]);
|
||||||
|
f14([2, ["abc", { x: 0 }]]);
|
||||||
|
f14([2, ["abc", { y: false }]]); // Error, no x
|
||||||
|
~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
!!! error TS2345: Argument of type '[number, [string, { y: boolean; }]]' is not assignable to parameter of type '[number, [string, { x: any; y?: boolean; }]]'.
|
||||||
|
!!! error TS2345: Types of property '1' are incompatible.
|
||||||
|
!!! error TS2345: Type '[string, { y: boolean; }]' is not assignable to type '[string, { x: any; y?: boolean; }]'.
|
||||||
|
!!! error TS2345: Types of property '1' are incompatible.
|
||||||
|
!!! error TS2345: Type '{ y: boolean; }' is not assignable to type '{ x: any; y?: boolean; }'.
|
||||||
|
!!! error TS2345: Property 'x' is missing in type '{ y: boolean; }'.
|
||||||
|
|
||||||
|
module M {
|
||||||
|
export var [a, b] = [1, 2];
|
||||||
|
}
|
||||||
|
|
||||||
|
function f15() {
|
||||||
|
var a = "hello";
|
||||||
|
var b = 1;
|
||||||
|
var c = true;
|
||||||
|
return { a, b, c };
|
||||||
|
}
|
||||||
|
|
||||||
|
function f16() {
|
||||||
|
var { a, b, c } = f15();
|
||||||
|
}
|
||||||
|
|
||||||
|
function f17({ a = "", b = 0, c = false }) {
|
||||||
|
}
|
||||||
|
|
||||||
|
f17({});
|
||||||
|
f17({ a: "hello" });
|
||||||
|
f17({ c: true });
|
||||||
|
f17(f15());
|
||||||
|
|
||||||
|
function g4() {
|
||||||
|
var a: number;
|
||||||
|
var b: string;
|
||||||
|
var aa: number[];
|
||||||
|
({ a, b } = { a, b });
|
||||||
|
({ a, b } = { b, a });
|
||||||
|
[aa[0], b] = [a, b];
|
||||||
|
[a, b] = [b, a]; // Error
|
||||||
|
~
|
||||||
|
!!! error TS2322: Type 'string' is not assignable to type 'number'.
|
||||||
|
~
|
||||||
|
!!! error TS2322: Type 'number' is not assignable to type 'string'.
|
||||||
|
[a = 1, b = "abc"] = [2, "def"];
|
||||||
|
}
|
||||||
|
|
||||||
|
function g5() {
|
||||||
|
var a, b;
|
||||||
|
[a, b] = [1, 2];
|
||||||
|
[a, b] = [b, a];
|
||||||
|
({ a, b } = { b, a });
|
||||||
|
[[a, b] = [1, 2]] = [[2, 3]];
|
||||||
|
var x = ([a, b] = [1, 2]);
|
||||||
|
}
|
||||||
|
|
288
tests/baselines/reference/declarationsAndAssignments.js
Normal file
288
tests/baselines/reference/declarationsAndAssignments.js
Normal file
|
@ -0,0 +1,288 @@
|
||||||
|
//// [declarationsAndAssignments.ts]
|
||||||
|
function f0() {
|
||||||
|
var [] = [1, "hello"];
|
||||||
|
var [x] = [1, "hello"];
|
||||||
|
var [x, y] = [1, "hello"];
|
||||||
|
var [x, y, z] = [1, "hello"]; // Error
|
||||||
|
var [,, z] = [0, 1, 2];
|
||||||
|
var x: number;
|
||||||
|
var y: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
function f1() {
|
||||||
|
var a = [1, "hello"];
|
||||||
|
var [x] = a;
|
||||||
|
var [x, y] = a;
|
||||||
|
var [x, y, z] = a;
|
||||||
|
var x: number | string;
|
||||||
|
var y: number | string;
|
||||||
|
var z: number | string;
|
||||||
|
}
|
||||||
|
|
||||||
|
function f2() {
|
||||||
|
var { } = { x: 5, y: "hello" };
|
||||||
|
var { x } = { x: 5, y: "hello" };
|
||||||
|
var { y } = { x: 5, y: "hello" };
|
||||||
|
var { x, y } = { x: 5, y: "hello" };
|
||||||
|
var x: number;
|
||||||
|
var y: string;
|
||||||
|
var { x: a } = { x: 5, y: "hello" };
|
||||||
|
var { y: b } = { x: 5, y: "hello" };
|
||||||
|
var { x: a, y: b } = { x: 5, y: "hello" };
|
||||||
|
var a: number;
|
||||||
|
var b: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
function f3() {
|
||||||
|
var [x, [y, [z]]] = [1, ["hello", [true]]];
|
||||||
|
var x: number;
|
||||||
|
var y: string;
|
||||||
|
var z: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
function f4() {
|
||||||
|
var { a: x, b: { a: y, b: { a: z }}} = { a: 1, b: { a: "hello", b: { a: true } } };
|
||||||
|
var x: number;
|
||||||
|
var y: string;
|
||||||
|
var z: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
function f6() {
|
||||||
|
var [x = 0, y = ""] = [1, "hello"];
|
||||||
|
var x: number;
|
||||||
|
var y: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
function f7() {
|
||||||
|
var [x = 0, y = 1] = [1, "hello"]; // Error, initializer for y must be string
|
||||||
|
var x: number;
|
||||||
|
var y: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
function f8() {
|
||||||
|
var [a, b, c] = []; // Ok, [] is an array
|
||||||
|
var [d, e, f] = [1]; // Error, [1] is a tuple
|
||||||
|
}
|
||||||
|
|
||||||
|
function f9() {
|
||||||
|
var [a, b] = {}; // Error, not array type
|
||||||
|
var [c, d] = { 0: 10, 1: 20 }; // Error, not array type
|
||||||
|
var [e, f] = [10, 20];
|
||||||
|
}
|
||||||
|
|
||||||
|
function f10() {
|
||||||
|
var { a, b } = {}; // Error
|
||||||
|
var { a, b } = []; // Error
|
||||||
|
}
|
||||||
|
|
||||||
|
function f11() {
|
||||||
|
var { x: a, y: b } = { x: 10, y: "hello" };
|
||||||
|
var { 0: a, 1: b } = { 0: 10, 1: "hello" };
|
||||||
|
var { "<": a, ">": b } = { "<": 10, ">": "hello" };
|
||||||
|
var { 0: a, 1: b } = [10, "hello"];
|
||||||
|
var a: number;
|
||||||
|
var b: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
function f12() {
|
||||||
|
var [a, [b, { x, y: c }] = ["abc", { x: 10, y: false }]] = [1, ["hello", { x: 5, y: true }]];
|
||||||
|
var a: number;
|
||||||
|
var b: string;
|
||||||
|
var x: number;
|
||||||
|
var c: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
function f13() {
|
||||||
|
var [x, y] = [1, "hello"];
|
||||||
|
var [a, b] = [[x, y], { x: x, y: y }];
|
||||||
|
}
|
||||||
|
|
||||||
|
function f14([a = 1, [b = "hello", { x, y: c = false }]]) {
|
||||||
|
var a: number;
|
||||||
|
var b: string;
|
||||||
|
var c: boolean;
|
||||||
|
}
|
||||||
|
f14([2, ["abc", { x: 0, y: true }]]);
|
||||||
|
f14([2, ["abc", { x: 0 }]]);
|
||||||
|
f14([2, ["abc", { y: false }]]); // Error, no x
|
||||||
|
|
||||||
|
module M {
|
||||||
|
export var [a, b] = [1, 2];
|
||||||
|
}
|
||||||
|
|
||||||
|
function f15() {
|
||||||
|
var a = "hello";
|
||||||
|
var b = 1;
|
||||||
|
var c = true;
|
||||||
|
return { a, b, c };
|
||||||
|
}
|
||||||
|
|
||||||
|
function f16() {
|
||||||
|
var { a, b, c } = f15();
|
||||||
|
}
|
||||||
|
|
||||||
|
function f17({ a = "", b = 0, c = false }) {
|
||||||
|
}
|
||||||
|
|
||||||
|
f17({});
|
||||||
|
f17({ a: "hello" });
|
||||||
|
f17({ c: true });
|
||||||
|
f17(f15());
|
||||||
|
|
||||||
|
function g4() {
|
||||||
|
var a: number;
|
||||||
|
var b: string;
|
||||||
|
var aa: number[];
|
||||||
|
({ a, b } = { a, b });
|
||||||
|
({ a, b } = { b, a });
|
||||||
|
[aa[0], b] = [a, b];
|
||||||
|
[a, b] = [b, a]; // Error
|
||||||
|
[a = 1, b = "abc"] = [2, "def"];
|
||||||
|
}
|
||||||
|
|
||||||
|
function g5() {
|
||||||
|
var a, b;
|
||||||
|
[a, b] = [1, 2];
|
||||||
|
[a, b] = [b, a];
|
||||||
|
({ a, b } = { b, a });
|
||||||
|
[[a, b] = [1, 2]] = [[2, 3]];
|
||||||
|
var x = ([a, b] = [1, 2]);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//// [declarationsAndAssignments.js]
|
||||||
|
function f0() {
|
||||||
|
var _a = [1, "hello"];
|
||||||
|
var x = ([1, "hello"])[0];
|
||||||
|
var _b = [1, "hello"], x = _b[0], y = _b[1];
|
||||||
|
var _c = [1, "hello"], x = _c[0], y = _c[1], z = _c[2]; // Error
|
||||||
|
var _d = [0, 1, 2], z = _d[2];
|
||||||
|
var x;
|
||||||
|
var y;
|
||||||
|
}
|
||||||
|
function f1() {
|
||||||
|
var a = [1, "hello"];
|
||||||
|
var x = a[0];
|
||||||
|
var x = a[0], y = a[1];
|
||||||
|
var x = a[0], y = a[1], z = a[2];
|
||||||
|
var x;
|
||||||
|
var y;
|
||||||
|
var z;
|
||||||
|
}
|
||||||
|
function f2() {
|
||||||
|
var _a = { x: 5, y: "hello" };
|
||||||
|
var x = ({ x: 5, y: "hello" }).x;
|
||||||
|
var y = ({ x: 5, y: "hello" }).y;
|
||||||
|
var _b = { x: 5, y: "hello" }, x = _b.x, y = _b.y;
|
||||||
|
var x;
|
||||||
|
var y;
|
||||||
|
var a = ({ x: 5, y: "hello" }).x;
|
||||||
|
var b = ({ x: 5, y: "hello" }).y;
|
||||||
|
var _c = { x: 5, y: "hello" }, a = _c.x, b = _c.y;
|
||||||
|
var a;
|
||||||
|
var b;
|
||||||
|
}
|
||||||
|
function f3() {
|
||||||
|
var _a = [1, ["hello", [true]]], x = _a[0], _b = _a[1], y = _b[0], z = _b[1][0];
|
||||||
|
var x;
|
||||||
|
var y;
|
||||||
|
var z;
|
||||||
|
}
|
||||||
|
function f4() {
|
||||||
|
var _a = { a: 1, b: { a: "hello", b: { a: true } } }, x = _a.a, _b = _a.b, y = _b.a, z = _b.b.a;
|
||||||
|
var x;
|
||||||
|
var y;
|
||||||
|
var z;
|
||||||
|
}
|
||||||
|
function f6() {
|
||||||
|
var _a = [1, "hello"], _b = _a[0], x = _b === void0 ? 0 : _b, _c = _a[1], y = _c === void0 ? "" : _c;
|
||||||
|
var x;
|
||||||
|
var y;
|
||||||
|
}
|
||||||
|
function f7() {
|
||||||
|
var _a = [1, "hello"], _b = _a[0], x = _b === void0 ? 0 : _b, _c = _a[1], y = _c === void0 ? 1 : _c; // Error, initializer for y must be string
|
||||||
|
var x;
|
||||||
|
var y;
|
||||||
|
}
|
||||||
|
function f8() {
|
||||||
|
var _a = [], a = _a[0], b = _a[1], c = _a[2]; // Ok, [] is an array
|
||||||
|
var _b = [1], d = _b[0], e = _b[1], f = _b[2]; // Error, [1] is a tuple
|
||||||
|
}
|
||||||
|
function f9() {
|
||||||
|
var _a = {}, a = _a[0], b = _a[1]; // Error, not array type
|
||||||
|
var _b = { 0: 10, 1: 20 }, c = _b[0], d = _b[1]; // Error, not array type
|
||||||
|
var _c = [10, 20], e = _c[0], f = _c[1];
|
||||||
|
}
|
||||||
|
function f10() {
|
||||||
|
var _a = {}, a = _a.a, b = _a.b; // Error
|
||||||
|
var _b = [], a = _b.a, b = _b.b; // Error
|
||||||
|
}
|
||||||
|
function f11() {
|
||||||
|
var _a = { x: 10, y: "hello" }, a = _a.x, b = _a.y;
|
||||||
|
var _b = { 0: 10, 1: "hello" }, a = _b[0], b = _b[1];
|
||||||
|
var _c = { "<": 10, ">": "hello" }, a = _c["<"], b = _c[">"];
|
||||||
|
var _d = [10, "hello"], a = _d[0], b = _d[1];
|
||||||
|
var a;
|
||||||
|
var b;
|
||||||
|
}
|
||||||
|
function f12() {
|
||||||
|
var _a = [1, ["hello", { x: 5, y: true }]], a = _a[0], _b = _a[1], _c = _b === void0 ? ["abc", { x: 10, y: false }] : _b, b = _c[0], _d = _c[1], x = _d.x, c = _d.y;
|
||||||
|
var a;
|
||||||
|
var b;
|
||||||
|
var x;
|
||||||
|
var c;
|
||||||
|
}
|
||||||
|
function f13() {
|
||||||
|
var _a = [1, "hello"], x = _a[0], y = _a[1];
|
||||||
|
var _b = [[x, y], { x: x, y: y }], a = _b[0], b = _b[1];
|
||||||
|
}
|
||||||
|
function f14(_a) {
|
||||||
|
var _b = _a[0], a = _b === void0 ? 1 : _b, _c = _a[1], _d = _c[0], b = _d === void0 ? "hello" : _d, _e = _c[1], x = _e.x, _f = _e.y, c = _f === void0 ? false : _f;
|
||||||
|
var a;
|
||||||
|
var b;
|
||||||
|
var c;
|
||||||
|
}
|
||||||
|
f14([2, ["abc", { x: 0, y: true }]]);
|
||||||
|
f14([2, ["abc", { x: 0 }]]);
|
||||||
|
f14([2, ["abc", { y: false }]]); // Error, no x
|
||||||
|
var M;
|
||||||
|
(function (M) {
|
||||||
|
_a = [1, 2], M.a = _a[0], M.b = _a[1];
|
||||||
|
var _a;
|
||||||
|
})(M || (M = {}));
|
||||||
|
function f15() {
|
||||||
|
var a = "hello";
|
||||||
|
var b = 1;
|
||||||
|
var c = true;
|
||||||
|
return { a: a, b: b, c: c };
|
||||||
|
}
|
||||||
|
function f16() {
|
||||||
|
var _a = f15(), a = _a.a, b = _a.b, c = _a.c;
|
||||||
|
}
|
||||||
|
function f17(_a) {
|
||||||
|
var _b = _a.a, a = _b === void0 ? "" : _b, _c = _a.b, b = _c === void0 ? 0 : _c, _d = _a.c, c = _d === void0 ? false : _d;
|
||||||
|
}
|
||||||
|
f17({});
|
||||||
|
f17({ a: "hello" });
|
||||||
|
f17({ c: true });
|
||||||
|
f17(f15());
|
||||||
|
function g4() {
|
||||||
|
var a;
|
||||||
|
var b;
|
||||||
|
var aa;
|
||||||
|
(_a = { a: a, b: b }, a = _a.a, b = _a.b, _a);
|
||||||
|
(_b = { b: b, a: a }, a = _b.a, b = _b.b, _b);
|
||||||
|
_c = [a, b], aa[0] = _c[0], b = _c[1];
|
||||||
|
_d = [b, a], a = _d[0], b = _d[1]; // Error
|
||||||
|
_e = [2, "def"], _f = _e[0], a = _f === void0 ? 1 : _f, _g = _e[1], b = _g === void0 ? "abc" : _g;
|
||||||
|
var _a, _b, _c, _d, _e, _f, _g;
|
||||||
|
}
|
||||||
|
function g5() {
|
||||||
|
var a, b;
|
||||||
|
_a = [1, 2], a = _a[0], b = _a[1];
|
||||||
|
_b = [b, a], a = _b[0], b = _b[1];
|
||||||
|
(_c = { b: b, a: a }, a = _c.a, b = _c.b, _c);
|
||||||
|
_d = ([[2, 3]])[0], _e = _d === void0 ? [1, 2] : _d, a = _e[0], b = _e[1];
|
||||||
|
var x = (_f = [1, 2], a = _f[0], b = _f[1], _f);
|
||||||
|
var _a, _b, _c, _d, _e, _f;
|
||||||
|
}
|
|
@ -56,7 +56,7 @@ var r = f({ x: new Derived(), y: new Derived2() }); // {}[]
|
||||||
>Derived2 : typeof Derived2
|
>Derived2 : typeof Derived2
|
||||||
|
|
||||||
var r2 = f({ x: new Base(), y: new Derived2() }); // {}[]
|
var r2 = f({ x: new Base(), y: new Derived2() }); // {}[]
|
||||||
>r2 : Base[]
|
>r2 : (Base | Derived2)[]
|
||||||
>f({ x: new Base(), y: new Derived2() }) : (Base | Derived2)[]
|
>f({ x: new Base(), y: new Derived2() }) : (Base | Derived2)[]
|
||||||
>f : <T extends Base, U extends Base>(a: { x: T; y: U; }) => (T | U)[]
|
>f : <T extends Base, U extends Base>(a: { x: T; y: U; }) => (T | U)[]
|
||||||
>{ x: new Base(), y: new Derived2() } : { x: Base; y: Derived2; }
|
>{ x: new Base(), y: new Derived2() } : { x: Base; y: Derived2; }
|
||||||
|
|
|
@ -1,8 +1,14 @@
|
||||||
tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ParameterLists/parserErrorRecovery_ParameterList1.ts(1,14): error TS1005: ')' expected.
|
tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ParameterLists/parserErrorRecovery_ParameterList1.ts(1,14): error TS1005: ',' expected.
|
||||||
|
tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ParameterLists/parserErrorRecovery_ParameterList1.ts(2,2): error TS1005: ')' expected.
|
||||||
|
tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ParameterLists/parserErrorRecovery_ParameterList1.ts(1,10): error TS2391: Function implementation is missing or not immediately following the declaration.
|
||||||
|
|
||||||
|
|
||||||
==== tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ParameterLists/parserErrorRecovery_ParameterList1.ts (1 errors) ====
|
==== tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ParameterLists/parserErrorRecovery_ParameterList1.ts (3 errors) ====
|
||||||
function f(a {
|
function f(a {
|
||||||
~
|
~
|
||||||
!!! error TS1005: ')' expected.
|
!!! error TS1005: ',' expected.
|
||||||
|
~
|
||||||
|
!!! error TS2391: Function implementation is missing or not immediately following the declaration.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
!!! error TS1005: ')' expected.
|
|
@ -1,8 +1,11 @@
|
||||||
tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ParameterLists/parserErrorRecovery_ParameterList2.ts(1,15): error TS1005: ')' expected.
|
tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ParameterLists/parserErrorRecovery_ParameterList2.ts(2,2): error TS1005: ')' expected.
|
||||||
|
tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ParameterLists/parserErrorRecovery_ParameterList2.ts(1,10): error TS2391: Function implementation is missing or not immediately following the declaration.
|
||||||
|
|
||||||
|
|
||||||
==== tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ParameterLists/parserErrorRecovery_ParameterList2.ts (1 errors) ====
|
==== tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ParameterLists/parserErrorRecovery_ParameterList2.ts (2 errors) ====
|
||||||
function f(a, {
|
function f(a, {
|
||||||
~
|
~
|
||||||
!!! error TS1005: ')' expected.
|
!!! error TS2391: Function implementation is missing or not immediately following the declaration.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
!!! error TS1005: ')' expected.
|
|
@ -1,10 +1,10 @@
|
||||||
tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ParameterLists/parserErrorRecovery_ParameterList5.ts(1,11): error TS1005: ',' expected.
|
tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ParameterLists/parserErrorRecovery_ParameterList5.ts(1,11): error TS1005: ',' expected.
|
||||||
tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ParameterLists/parserErrorRecovery_ParameterList5.ts(1,14): error TS1005: ')' expected.
|
tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ParameterLists/parserErrorRecovery_ParameterList5.ts(1,17): error TS1005: ')' expected.
|
||||||
|
|
||||||
|
|
||||||
==== tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ParameterLists/parserErrorRecovery_ParameterList5.ts (2 errors) ====
|
==== tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ParameterLists/parserErrorRecovery_ParameterList5.ts (2 errors) ====
|
||||||
(a:number => { }
|
(a:number => { }
|
||||||
~~
|
~~
|
||||||
!!! error TS1005: ',' expected.
|
!!! error TS1005: ',' expected.
|
||||||
~
|
|
||||||
!!! error TS1005: ')' expected.
|
!!! error TS1005: ')' expected.
|
25
tests/baselines/reference/unionTypeEquivalence.errors.txt
Normal file
25
tests/baselines/reference/unionTypeEquivalence.errors.txt
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
tests/cases/conformance/types/union/unionTypeEquivalence.ts(5,5): error TS2403: Subsequent variable declarations must have the same type. Variable 'x' must be of type 'C', but here has type 'C | D'.
|
||||||
|
|
||||||
|
|
||||||
|
==== tests/cases/conformance/types/union/unionTypeEquivalence.ts (1 errors) ====
|
||||||
|
// A | B is equivalent to A if B is a subtype of A
|
||||||
|
class C { }
|
||||||
|
class D extends C { foo() { } }
|
||||||
|
var x: C;
|
||||||
|
var x : C | D;
|
||||||
|
~
|
||||||
|
!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'x' must be of type 'C', but here has type 'C | D'.
|
||||||
|
|
||||||
|
// A | B is equivalent to B | A.
|
||||||
|
var y: string | number;
|
||||||
|
var y : number | string;
|
||||||
|
|
||||||
|
// AB | C is equivalent to A | BC, where AB is A | B and BC is B | C.
|
||||||
|
var z : string | number | boolean;
|
||||||
|
var z : (string | number) | boolean;
|
||||||
|
var z : string | (number | boolean);
|
||||||
|
var AB : string | number;
|
||||||
|
var BC : number | boolean;
|
||||||
|
var z1: typeof AB | boolean;
|
||||||
|
var z1: string | typeof BC;
|
||||||
|
|
|
@ -1,50 +0,0 @@
|
||||||
=== tests/cases/conformance/types/union/unionTypeEquivalence.ts ===
|
|
||||||
// A | B is equivalent to A if B is a subtype of A
|
|
||||||
class C { }
|
|
||||||
>C : C
|
|
||||||
|
|
||||||
class D extends C { foo() { } }
|
|
||||||
>D : D
|
|
||||||
>C : C
|
|
||||||
>foo : () => void
|
|
||||||
|
|
||||||
var x: C;
|
|
||||||
>x : C
|
|
||||||
>C : C
|
|
||||||
|
|
||||||
var x : C | D;
|
|
||||||
>x : C
|
|
||||||
>C : C
|
|
||||||
>D : D
|
|
||||||
|
|
||||||
// A | B is equivalent to B | A.
|
|
||||||
var y: string | number;
|
|
||||||
>y : string | number
|
|
||||||
|
|
||||||
var y : number | string;
|
|
||||||
>y : string | number
|
|
||||||
|
|
||||||
// AB | C is equivalent to A | BC, where AB is A | B and BC is B | C.
|
|
||||||
var z : string | number | boolean;
|
|
||||||
>z : string | number | boolean
|
|
||||||
|
|
||||||
var z : (string | number) | boolean;
|
|
||||||
>z : string | number | boolean
|
|
||||||
|
|
||||||
var z : string | (number | boolean);
|
|
||||||
>z : string | number | boolean
|
|
||||||
|
|
||||||
var AB : string | number;
|
|
||||||
>AB : string | number
|
|
||||||
|
|
||||||
var BC : number | boolean;
|
|
||||||
>BC : number | boolean
|
|
||||||
|
|
||||||
var z1: typeof AB | boolean;
|
|
||||||
>z1 : string | number | boolean
|
|
||||||
>AB : string | number
|
|
||||||
|
|
||||||
var z1: string | typeof BC;
|
|
||||||
>z1 : string | number | boolean
|
|
||||||
>BC : number | boolean
|
|
||||||
|
|
24
tests/baselines/reference/unionTypeLiterals.errors.txt
Normal file
24
tests/baselines/reference/unionTypeLiterals.errors.txt
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
tests/cases/conformance/types/specifyingTypes/typeLiterals/unionTypeLiterals.ts(11,5): error TS2403: Subsequent variable declarations must have the same type. Variable 'unionOfFunctionType' must be of type '(() => string) | (() => number)', but here has type '() => string | number'.
|
||||||
|
tests/cases/conformance/types/specifyingTypes/typeLiterals/unionTypeLiterals.ts(15,5): error TS2403: Subsequent variable declarations must have the same type. Variable 'unionOfConstructorType' must be of type '(new () => string) | (new () => number)', but here has type 'new () => string | number'.
|
||||||
|
|
||||||
|
|
||||||
|
==== tests/cases/conformance/types/specifyingTypes/typeLiterals/unionTypeLiterals.ts (2 errors) ====
|
||||||
|
// basic valid forms of union literals
|
||||||
|
|
||||||
|
var simpleUnion: string | number;
|
||||||
|
var unionOfUnion: string | number | boolean;
|
||||||
|
|
||||||
|
var arrayOfUnions: (string | number)[];
|
||||||
|
var arrayOfUnions: Array<string | number>;
|
||||||
|
|
||||||
|
var unionOfFunctionType: (() => string) | (() => number);
|
||||||
|
var unionOfFunctionType: { (): string } | { (): number };
|
||||||
|
var unionOfFunctionType: () => string | number;
|
||||||
|
~~~~~~~~~~~~~~~~~~~
|
||||||
|
!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'unionOfFunctionType' must be of type '(() => string) | (() => number)', but here has type '() => string | number'.
|
||||||
|
|
||||||
|
var unionOfConstructorType: (new () => string) | (new () => number);
|
||||||
|
var unionOfConstructorType: { new (): string } | { new (): number };
|
||||||
|
var unionOfConstructorType: new () => string | number;
|
||||||
|
~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'unionOfConstructorType' must be of type '(new () => string) | (new () => number)', but here has type 'new () => string | number'.
|
|
@ -1,34 +0,0 @@
|
||||||
=== tests/cases/conformance/types/specifyingTypes/typeLiterals/unionTypeLiterals.ts ===
|
|
||||||
// basic valid forms of union literals
|
|
||||||
|
|
||||||
var simpleUnion: string | number;
|
|
||||||
>simpleUnion : string | number
|
|
||||||
|
|
||||||
var unionOfUnion: string | number | boolean;
|
|
||||||
>unionOfUnion : string | number | boolean
|
|
||||||
|
|
||||||
var arrayOfUnions: (string | number)[];
|
|
||||||
>arrayOfUnions : (string | number)[]
|
|
||||||
|
|
||||||
var arrayOfUnions: Array<string | number>;
|
|
||||||
>arrayOfUnions : (string | number)[]
|
|
||||||
>Array : T[]
|
|
||||||
|
|
||||||
var unionOfFunctionType: (() => string) | (() => number);
|
|
||||||
>unionOfFunctionType : (() => string) | (() => number)
|
|
||||||
|
|
||||||
var unionOfFunctionType: { (): string } | { (): number };
|
|
||||||
>unionOfFunctionType : (() => string) | (() => number)
|
|
||||||
|
|
||||||
var unionOfFunctionType: () => string | number;
|
|
||||||
>unionOfFunctionType : (() => string) | (() => number)
|
|
||||||
|
|
||||||
var unionOfConstructorType: (new () => string) | (new () => number);
|
|
||||||
>unionOfConstructorType : (new () => string) | (new () => number)
|
|
||||||
|
|
||||||
var unionOfConstructorType: { new (): string } | { new (): number };
|
|
||||||
>unionOfConstructorType : (new () => string) | (new () => number)
|
|
||||||
|
|
||||||
var unionOfConstructorType: new () => string | number;
|
|
||||||
>unionOfConstructorType : (new () => string) | (new () => number)
|
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
declare var [a, b]; // Error, destructuring declaration not allowed in ambient context
|
||||||
|
declare var {c, d}; // Error, destructuring declaration not allowed in ambient context
|
|
@ -0,0 +1,2 @@
|
||||||
|
var [a, b]; // Error, no initializer
|
||||||
|
var {c, d}; // Error, no initializer
|
|
@ -0,0 +1,149 @@
|
||||||
|
function f0() {
|
||||||
|
var [] = [1, "hello"];
|
||||||
|
var [x] = [1, "hello"];
|
||||||
|
var [x, y] = [1, "hello"];
|
||||||
|
var [x, y, z] = [1, "hello"]; // Error
|
||||||
|
var [,, z] = [0, 1, 2];
|
||||||
|
var x: number;
|
||||||
|
var y: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
function f1() {
|
||||||
|
var a = [1, "hello"];
|
||||||
|
var [x] = a;
|
||||||
|
var [x, y] = a;
|
||||||
|
var [x, y, z] = a;
|
||||||
|
var x: number | string;
|
||||||
|
var y: number | string;
|
||||||
|
var z: number | string;
|
||||||
|
}
|
||||||
|
|
||||||
|
function f2() {
|
||||||
|
var { } = { x: 5, y: "hello" };
|
||||||
|
var { x } = { x: 5, y: "hello" };
|
||||||
|
var { y } = { x: 5, y: "hello" };
|
||||||
|
var { x, y } = { x: 5, y: "hello" };
|
||||||
|
var x: number;
|
||||||
|
var y: string;
|
||||||
|
var { x: a } = { x: 5, y: "hello" };
|
||||||
|
var { y: b } = { x: 5, y: "hello" };
|
||||||
|
var { x: a, y: b } = { x: 5, y: "hello" };
|
||||||
|
var a: number;
|
||||||
|
var b: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
function f3() {
|
||||||
|
var [x, [y, [z]]] = [1, ["hello", [true]]];
|
||||||
|
var x: number;
|
||||||
|
var y: string;
|
||||||
|
var z: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
function f4() {
|
||||||
|
var { a: x, b: { a: y, b: { a: z }}} = { a: 1, b: { a: "hello", b: { a: true } } };
|
||||||
|
var x: number;
|
||||||
|
var y: string;
|
||||||
|
var z: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
function f6() {
|
||||||
|
var [x = 0, y = ""] = [1, "hello"];
|
||||||
|
var x: number;
|
||||||
|
var y: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
function f7() {
|
||||||
|
var [x = 0, y = 1] = [1, "hello"]; // Error, initializer for y must be string
|
||||||
|
var x: number;
|
||||||
|
var y: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
function f8() {
|
||||||
|
var [a, b, c] = []; // Ok, [] is an array
|
||||||
|
var [d, e, f] = [1]; // Error, [1] is a tuple
|
||||||
|
}
|
||||||
|
|
||||||
|
function f9() {
|
||||||
|
var [a, b] = {}; // Error, not array type
|
||||||
|
var [c, d] = { 0: 10, 1: 20 }; // Error, not array type
|
||||||
|
var [e, f] = [10, 20];
|
||||||
|
}
|
||||||
|
|
||||||
|
function f10() {
|
||||||
|
var { a, b } = {}; // Error
|
||||||
|
var { a, b } = []; // Error
|
||||||
|
}
|
||||||
|
|
||||||
|
function f11() {
|
||||||
|
var { x: a, y: b } = { x: 10, y: "hello" };
|
||||||
|
var { 0: a, 1: b } = { 0: 10, 1: "hello" };
|
||||||
|
var { "<": a, ">": b } = { "<": 10, ">": "hello" };
|
||||||
|
var { 0: a, 1: b } = [10, "hello"];
|
||||||
|
var a: number;
|
||||||
|
var b: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
function f12() {
|
||||||
|
var [a, [b, { x, y: c }] = ["abc", { x: 10, y: false }]] = [1, ["hello", { x: 5, y: true }]];
|
||||||
|
var a: number;
|
||||||
|
var b: string;
|
||||||
|
var x: number;
|
||||||
|
var c: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
function f13() {
|
||||||
|
var [x, y] = [1, "hello"];
|
||||||
|
var [a, b] = [[x, y], { x: x, y: y }];
|
||||||
|
}
|
||||||
|
|
||||||
|
function f14([a = 1, [b = "hello", { x, y: c = false }]]) {
|
||||||
|
var a: number;
|
||||||
|
var b: string;
|
||||||
|
var c: boolean;
|
||||||
|
}
|
||||||
|
f14([2, ["abc", { x: 0, y: true }]]);
|
||||||
|
f14([2, ["abc", { x: 0 }]]);
|
||||||
|
f14([2, ["abc", { y: false }]]); // Error, no x
|
||||||
|
|
||||||
|
module M {
|
||||||
|
export var [a, b] = [1, 2];
|
||||||
|
}
|
||||||
|
|
||||||
|
function f15() {
|
||||||
|
var a = "hello";
|
||||||
|
var b = 1;
|
||||||
|
var c = true;
|
||||||
|
return { a, b, c };
|
||||||
|
}
|
||||||
|
|
||||||
|
function f16() {
|
||||||
|
var { a, b, c } = f15();
|
||||||
|
}
|
||||||
|
|
||||||
|
function f17({ a = "", b = 0, c = false }) {
|
||||||
|
}
|
||||||
|
|
||||||
|
f17({});
|
||||||
|
f17({ a: "hello" });
|
||||||
|
f17({ c: true });
|
||||||
|
f17(f15());
|
||||||
|
|
||||||
|
function g4() {
|
||||||
|
var a: number;
|
||||||
|
var b: string;
|
||||||
|
var aa: number[];
|
||||||
|
({ a, b } = { a, b });
|
||||||
|
({ a, b } = { b, a });
|
||||||
|
[aa[0], b] = [a, b];
|
||||||
|
[a, b] = [b, a]; // Error
|
||||||
|
[a = 1, b = "abc"] = [2, "def"];
|
||||||
|
}
|
||||||
|
|
||||||
|
function g5() {
|
||||||
|
var a, b;
|
||||||
|
[a, b] = [1, 2];
|
||||||
|
[a, b] = [b, a];
|
||||||
|
({ a, b } = { b, a });
|
||||||
|
[[a, b] = [1, 2]] = [[2, 3]];
|
||||||
|
var x = ([a, b] = [1, 2]);
|
||||||
|
}
|
|
@ -18,8 +18,8 @@
|
||||||
|
|
||||||
goTo.marker("propertyReference");
|
goTo.marker("propertyReference");
|
||||||
goTo.definition(0);
|
goTo.definition(0);
|
||||||
verify.caretAtMarker("propertyDefinition1");
|
verify.caretAtMarker("propertyDefinition2");
|
||||||
|
|
||||||
goTo.marker("propertyReference");
|
goTo.marker("propertyReference");
|
||||||
goTo.definition(1);
|
goTo.definition(1);
|
||||||
verify.caretAtMarker("propertyDefinition2");
|
verify.caretAtMarker("propertyDefinition1");
|
||||||
|
|
|
@ -1,8 +0,0 @@
|
||||||
/// <reference path="fourslash.ts" />
|
|
||||||
|
|
||||||
////function alpha( {}
|
|
||||||
/////**/
|
|
||||||
////function beta() { alpha(); }
|
|
||||||
////
|
|
||||||
|
|
||||||
verify.not.errorExistsAfterMarker();
|
|
Loading…
Reference in a new issue