diff --git a/scripts/processDiagnosticMessages.ts b/scripts/processDiagnosticMessages.ts index 6a4aaad9f93ee..eccfb821bb220 100644 --- a/scripts/processDiagnosticMessages.ts +++ b/scripts/processDiagnosticMessages.ts @@ -3,6 +3,7 @@ interface DiagnosticDetails { category: string; code: number; + isEarly?: boolean; } interface InputDiagnosticMessageTable { @@ -63,8 +64,9 @@ function buildInfoFileOutput(messageTable: InputDiagnosticMessageTable, nameMap: ' ' + convertPropertyName(nameMap[name]) + ': { code: ' + diagnosticDetails.code + ', category: DiagnosticCategory.' + diagnosticDetails.category + - ', key: "' + name.replace('"', '\\"') + - '" },\r\n'; + ', key: "' + name.replace('"', '\\"') + '"' + + (diagnosticDetails.isEarly ? ', isEarly: true' : '') + + ' },\r\n'; } result += ' };\r\n}'; diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index c9f9d6bf6e3de..accb46504dc5f 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -31,13 +31,14 @@ module ts { var parent: Node; var container: Declaration; + var blockScopeContainer: Node; var lastContainer: Declaration; var symbolCount = 0; var Symbol = objectAllocator.getSymbolConstructor(); if (!file.locals) { file.locals = {}; - container = file; + container = blockScopeContainer = file; bind(file); file.symbolCount = symbolCount; } @@ -86,10 +87,11 @@ module ts { } // Report errors every position with duplicate declaration // Report errors on previous encountered declarations + var message = symbol.flags & SymbolFlags.BlockScopedVariable ? Diagnostics.Cannot_redeclare_block_scoped_variable_0 : Diagnostics.Duplicate_identifier_0; forEach(symbol.declarations, (declaration) => { - file.semanticErrors.push(createDiagnosticForNode(declaration.name, Diagnostics.Duplicate_identifier_0, getDisplayName(declaration))); + file.semanticErrors.push(createDiagnosticForNode(declaration.name, message, getDisplayName(declaration))); }); - file.semanticErrors.push(createDiagnosticForNode(node.name, Diagnostics.Duplicate_identifier_0, getDisplayName(node))); + file.semanticErrors.push(createDiagnosticForNode(node.name, message, getDisplayName(node))); symbol = createSymbol(0, name); } @@ -167,12 +169,13 @@ module ts { // All container nodes are kept on a linked list in declaration order. This list is used by the getLocalNameOfContainer function // in the type checker to validate that the local name used for a container is unique. - function bindChildren(node: Declaration, symbolKind: SymbolFlags) { + function bindChildren(node: Declaration, symbolKind: SymbolFlags, isBlockScopeContainer: boolean) { if (symbolKind & SymbolFlags.HasLocals) { node.locals = {}; } var saveParent = parent; var saveContainer = container; + var savedBlockScopeContainer = blockScopeContainer; parent = node; if (symbolKind & SymbolFlags.IsContainer) { container = node; @@ -184,12 +187,16 @@ module ts { lastContainer = container; } } + if (isBlockScopeContainer) { + blockScopeContainer = node; + } forEachChild(node, bind); container = saveContainer; parent = saveParent; + blockScopeContainer = savedBlockScopeContainer; } - function bindDeclaration(node: Declaration, symbolKind: SymbolFlags, symbolExcludes: SymbolFlags) { + function bindDeclaration(node: Declaration, symbolKind: SymbolFlags, symbolExcludes: SymbolFlags, isBlockScopeContainer: boolean) { switch (container.kind) { case SyntaxKind.ModuleDeclaration: declareModuleMember(node, symbolKind, symbolExcludes); @@ -225,121 +232,159 @@ module ts { declareSymbol(container.symbol.exports, container.symbol, node, symbolKind, symbolExcludes); break; } - bindChildren(node, symbolKind); + bindChildren(node, symbolKind, isBlockScopeContainer); } function bindConstructorDeclaration(node: ConstructorDeclaration) { - bindDeclaration(node, SymbolFlags.Constructor, 0); + bindDeclaration(node, SymbolFlags.Constructor, 0, /*isBlockScopeContainer*/ true); forEach(node.parameters, p => { if (p.flags & (NodeFlags.Public | NodeFlags.Private | NodeFlags.Protected)) { - bindDeclaration(p, SymbolFlags.Property, SymbolFlags.PropertyExcludes); + bindDeclaration(p, SymbolFlags.Property, SymbolFlags.PropertyExcludes, /*isBlockScopeContainer*/ false); } }); } function bindModuleDeclaration(node: ModuleDeclaration) { if (node.name.kind === SyntaxKind.StringLiteral) { - bindDeclaration(node, SymbolFlags.ValueModule, SymbolFlags.ValueModuleExcludes); + bindDeclaration(node, SymbolFlags.ValueModule, SymbolFlags.ValueModuleExcludes, /*isBlockScopeContainer*/ true); } else if (isInstantiated(node)) { - bindDeclaration(node, SymbolFlags.ValueModule, SymbolFlags.ValueModuleExcludes); + bindDeclaration(node, SymbolFlags.ValueModule, SymbolFlags.ValueModuleExcludes, /*isBlockScopeContainer*/ true); } else { - bindDeclaration(node, SymbolFlags.NamespaceModule, SymbolFlags.NamespaceModuleExcludes); + bindDeclaration(node, SymbolFlags.NamespaceModule, SymbolFlags.NamespaceModuleExcludes, /*isBlockScopeContainer*/ true); } } - function bindAnonymousDeclaration(node: Node, symbolKind: SymbolFlags, name: string) { + function bindAnonymousDeclaration(node: Node, symbolKind: SymbolFlags, name: string, isBlockScopeContainer: boolean) { var symbol = createSymbol(symbolKind, name); addDeclarationToSymbol(symbol, node, symbolKind); - bindChildren(node, symbolKind); + bindChildren(node, symbolKind, isBlockScopeContainer); } function bindCatchVariableDeclaration(node: CatchBlock) { - var symbol = createSymbol(SymbolFlags.Variable, node.variable.text || "__missing"); - addDeclarationToSymbol(symbol, node, SymbolFlags.Variable); + var symbol = createSymbol(SymbolFlags.FunctionScopedVariable, node.variable.text || "__missing"); + addDeclarationToSymbol(symbol, node, SymbolFlags.FunctionScopedVariable); var saveParent = parent; - parent = node; + var savedBlockScopeContainer = blockScopeContainer; + parent = blockScopeContainer = node; forEachChild(node, bind); parent = saveParent; + blockScopeContainer = savedBlockScopeContainer; + } + + function bindBlockScopedVariableDeclaration(node: Declaration) { + switch (blockScopeContainer.kind) { + case SyntaxKind.ModuleDeclaration: + declareModuleMember(node, SymbolFlags.BlockScopedVariable, SymbolFlags.BlockScopedVariableExcludes); + break; + case SyntaxKind.SourceFile: + if (isExternalModule(container)) { + declareModuleMember(node, SymbolFlags.BlockScopedVariable, SymbolFlags.BlockScopedVariableExcludes); + break; + } + default: + if (!blockScopeContainer.locals) { + blockScopeContainer.locals = {}; + } + declareSymbol(blockScopeContainer.locals, undefined, node, SymbolFlags.BlockScopedVariable, SymbolFlags.BlockScopedVariableExcludes); + } + + bindChildren(node, SymbolFlags.BlockScopedVariable, /*isBlockScopeContainer*/ false); } function bind(node: Node) { node.parent = parent; switch (node.kind) { case SyntaxKind.TypeParameter: - bindDeclaration(node, SymbolFlags.TypeParameter, SymbolFlags.TypeParameterExcludes); + bindDeclaration(node, SymbolFlags.TypeParameter, SymbolFlags.TypeParameterExcludes, /*isBlockScopeContainer*/ false); break; case SyntaxKind.Parameter: - bindDeclaration(node, SymbolFlags.Variable, SymbolFlags.ParameterExcludes); + bindDeclaration(node, SymbolFlags.FunctionScopedVariable, SymbolFlags.ParameterExcludes, /*isBlockScopeContainer*/ false); break; case SyntaxKind.VariableDeclaration: - bindDeclaration(node, SymbolFlags.Variable, SymbolFlags.VariableExcludes); + if (node.flags & NodeFlags.BlockScoped) { + bindBlockScopedVariableDeclaration(node); + } + else { + bindDeclaration(node, SymbolFlags.FunctionScopedVariable, SymbolFlags.FunctionScopedVariableExcludes, /*isBlockScopeContainer*/ false); + } break; case SyntaxKind.Property: case SyntaxKind.PropertyAssignment: - bindDeclaration(node, SymbolFlags.Property, SymbolFlags.PropertyExcludes); + bindDeclaration(node, SymbolFlags.Property, SymbolFlags.PropertyExcludes, /*isBlockScopeContainer*/ false); break; case SyntaxKind.EnumMember: - bindDeclaration(node, SymbolFlags.EnumMember, SymbolFlags.EnumMemberExcludes); + bindDeclaration(node, SymbolFlags.EnumMember, SymbolFlags.EnumMemberExcludes, /*isBlockScopeContainer*/ false); break; case SyntaxKind.CallSignature: - bindDeclaration(node, SymbolFlags.CallSignature, 0); + bindDeclaration(node, SymbolFlags.CallSignature, 0, /*isBlockScopeContainer*/ false); break; case SyntaxKind.Method: - bindDeclaration(node, SymbolFlags.Method, SymbolFlags.MethodExcludes); + bindDeclaration(node, SymbolFlags.Method, SymbolFlags.MethodExcludes, /*isBlockScopeContainer*/ true); break; case SyntaxKind.ConstructSignature: - bindDeclaration(node, SymbolFlags.ConstructSignature, 0); + bindDeclaration(node, SymbolFlags.ConstructSignature, 0, /*isBlockScopeContainer*/ true); break; case SyntaxKind.IndexSignature: - bindDeclaration(node, SymbolFlags.IndexSignature, 0); + bindDeclaration(node, SymbolFlags.IndexSignature, 0, /*isBlockScopeContainer*/ false); break; case SyntaxKind.FunctionDeclaration: - bindDeclaration(node, SymbolFlags.Function, SymbolFlags.FunctionExcludes); + bindDeclaration(node, SymbolFlags.Function, SymbolFlags.FunctionExcludes, /*isBlockScopeContainer*/ true); break; case SyntaxKind.Constructor: bindConstructorDeclaration(node); break; case SyntaxKind.GetAccessor: - bindDeclaration(node, SymbolFlags.GetAccessor, SymbolFlags.GetAccessorExcludes); + bindDeclaration(node, SymbolFlags.GetAccessor, SymbolFlags.GetAccessorExcludes, /*isBlockScopeContainer*/ true); break; case SyntaxKind.SetAccessor: - bindDeclaration(node, SymbolFlags.SetAccessor, SymbolFlags.SetAccessorExcludes); + bindDeclaration(node, SymbolFlags.SetAccessor, SymbolFlags.SetAccessorExcludes, /*isBlockScopeContainer*/ true); break; case SyntaxKind.TypeLiteral: - bindAnonymousDeclaration(node, SymbolFlags.TypeLiteral, "__type"); + bindAnonymousDeclaration(node, SymbolFlags.TypeLiteral, "__type", /*isBlockScopeContainer*/ false); break; case SyntaxKind.ObjectLiteral: - bindAnonymousDeclaration(node, SymbolFlags.ObjectLiteral, "__object"); + bindAnonymousDeclaration(node, SymbolFlags.ObjectLiteral, "__object", /*isBlockScopeContainer*/ false); break; case SyntaxKind.FunctionExpression: case SyntaxKind.ArrowFunction: - bindAnonymousDeclaration(node, SymbolFlags.Function, "__function"); + bindAnonymousDeclaration(node, SymbolFlags.Function, "__function", /*isBlockScopeContainer*/ true); break; case SyntaxKind.CatchBlock: bindCatchVariableDeclaration(node); break; case SyntaxKind.ClassDeclaration: - bindDeclaration(node, SymbolFlags.Class, SymbolFlags.ClassExcludes); + bindDeclaration(node, SymbolFlags.Class, SymbolFlags.ClassExcludes, /*isBlockScopeContainer*/ false); break; case SyntaxKind.InterfaceDeclaration: - bindDeclaration(node, SymbolFlags.Interface, SymbolFlags.InterfaceExcludes); + bindDeclaration(node, SymbolFlags.Interface, SymbolFlags.InterfaceExcludes, /*isBlockScopeContainer*/ false); break; case SyntaxKind.EnumDeclaration: - bindDeclaration(node, SymbolFlags.Enum, SymbolFlags.EnumExcludes); + bindDeclaration(node, SymbolFlags.Enum, SymbolFlags.EnumExcludes, /*isBlockScopeContainer*/ false); break; case SyntaxKind.ModuleDeclaration: bindModuleDeclaration(node); break; case SyntaxKind.ImportDeclaration: - bindDeclaration(node, SymbolFlags.Import, SymbolFlags.ImportExcludes); + bindDeclaration(node, SymbolFlags.Import, SymbolFlags.ImportExcludes, /*isBlockScopeContainer*/ false); break; case SyntaxKind.SourceFile: if (isExternalModule(node)) { - bindAnonymousDeclaration(node, SymbolFlags.ValueModule, '"' + removeFileExtension((node).filename) + '"'); + bindAnonymousDeclaration(node, SymbolFlags.ValueModule, '"' + removeFileExtension((node).filename) + '"', /*isBlockScopeContainer*/ true); break; } + + case SyntaxKind.Block: + case SyntaxKind.TryBlock: + case SyntaxKind.CatchBlock: + case SyntaxKind.FinallyBlock: + case SyntaxKind.ForStatement: + case SyntaxKind.ForInStatement: + case SyntaxKind.SwitchStatement: + bindChildren(node, 0 , true); + break; + default: var saveParent = parent; parent = node; diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 67421879caec2..7a959c0dbfc4a 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -108,7 +108,8 @@ module ts { isImplementationOfOverload: isImplementationOfOverload, getAliasedSymbol: resolveImport, isUndefinedSymbol: symbol => symbol === undefinedSymbol, - isArgumentsSymbol: symbol => symbol === argumentsSymbol + isArgumentsSymbol: symbol => symbol === argumentsSymbol, + hasEarlyErrors: hasEarlyErrors }; var undefinedSymbol = createSymbol(SymbolFlags.Property | SymbolFlags.Transient, "undefined"); @@ -176,7 +177,8 @@ module ts { function getExcludedSymbolFlags(flags: SymbolFlags): SymbolFlags { var result: SymbolFlags = 0; - if (flags & SymbolFlags.Variable) result |= SymbolFlags.VariableExcludes; + if (flags & SymbolFlags.BlockScopedVariable) result |= SymbolFlags.BlockScopedVariableExcludes; + if (flags & SymbolFlags.FunctionScopedVariable) result |= SymbolFlags.FunctionScopedVariableExcludes; if (flags & SymbolFlags.Property) result |= SymbolFlags.PropertyExcludes; if (flags & SymbolFlags.EnumMember) result |= SymbolFlags.EnumMemberExcludes; if (flags & SymbolFlags.Function) result |= SymbolFlags.FunctionExcludes; @@ -226,8 +228,13 @@ module ts { recordMergedSymbol(target, source); } else { + var message = target.flags & SymbolFlags.BlockScopedVariable || source.flags & SymbolFlags.BlockScopedVariable + ? Diagnostics.Cannot_redeclare_block_scoped_variable_0 : Diagnostics.Duplicate_identifier_0; forEach(source.declarations, node => { - error(node.name ? node.name : node, Diagnostics.Duplicate_identifier_0, symbolToString(source)); + error(node.name ? node.name : node, message, symbolToString(source)); + }); + forEach(target.declarations, node => { + error(node.name ? node.name : node, message, symbolToString(source)); }); } } @@ -318,6 +325,25 @@ module ts { if (!s && nameNotFoundMessage) { error(errorLocation, nameNotFoundMessage, nameArg); } + + if (s && s.flags & SymbolFlags.BlockScopedVariable) { + // Block-scoped variables can not be used before their definition + var declaration = forEach(s.declarations, d => d.flags & NodeFlags.BlockScoped ? d : undefined); + Debug.assert(declaration, "Block-scoped variable declaration is undefined"); + var declarationSourceFile = getSourceFileOfNode(declaration); + var referenceSourceFile = getSourceFileOfNode(errorLocation); + if (declarationSourceFile === referenceSourceFile) { + if (declaration.pos > errorLocation.pos) { + error(errorLocation, Diagnostics.Block_scoped_variable_0_used_before_its_declaration, identifierToString(declaration.name)); + } + } + else if (compilerOptions.out) { + var sourceFiles = program.getSourceFiles(); + if (sourceFiles.indexOf(referenceSourceFile) < sourceFiles.indexOf(declarationSourceFile)) { + error(errorLocation, Diagnostics.Block_scoped_variable_0_used_before_its_declaration, identifierToString(declaration.name)); + } + } + } return s; } @@ -5597,7 +5623,7 @@ module ts { return true; } - function checkReferenceExpression(n: Node, message: DiagnosticMessage): boolean { + function checkReferenceExpression(n: Node, invalidReferenceMessage: DiagnosticMessage, constantVarianleMessage: DiagnosticMessage): boolean { function findSymbol(n: Node): Symbol { var symbol = getNodeLinks(n).resolvedSymbol; // Because we got the symbol from the resolvedSymbol property, it might be of kind @@ -5636,8 +5662,34 @@ module ts { } } + function isConstVariableReference(n: Node): boolean { + switch (n.kind) { + case SyntaxKind.Identifier: + case SyntaxKind.PropertyAccess: + var symbol = findSymbol(n); + return symbol && (symbol.flags & SymbolFlags.Variable) !== 0 && (getDeclarationFlagsFromSymbol(symbol) & NodeFlags.Const) !== 0; + case SyntaxKind.IndexedAccess: + var index = (n).index; + var symbol = findSymbol((n).object); + if (symbol && index.kind === SyntaxKind.StringLiteral) { + var name = (index).text; + var prop = getPropertyOfType(getTypeOfSymbol(symbol), name); + return prop && (prop.flags & SymbolFlags.Variable) !== 0 && (getDeclarationFlagsFromSymbol(prop) & NodeFlags.Const) !== 0; + } + return false; + case SyntaxKind.ParenExpression: + return isConstVariableReference((n).expression); + default: + return false; + } + } + if (!isReferenceOrErrorExpression(n)) { - error(n, message); + error(n, invalidReferenceMessage); + return false; + } + if (isConstVariableReference(n)) { + error(n, constantVarianleMessage); return false; } return true; @@ -5662,7 +5714,9 @@ module ts { var ok = checkArithmeticOperandType(node.operand, operandType, Diagnostics.An_arithmetic_operand_must_be_of_type_any_number_or_an_enum_type); if (ok) { // run check only if former checks succeeded to avoid reporting cascading errors - checkReferenceExpression(node.operand, Diagnostics.The_operand_of_an_increment_or_decrement_operator_must_be_a_variable_property_or_indexer); + checkReferenceExpression(node.operand, + Diagnostics.The_operand_of_an_increment_or_decrement_operator_must_be_a_variable_property_or_indexer, + Diagnostics.The_operand_of_an_increment_or_decrement_operator_cannot_be_a_constant); } return numberType; } @@ -5674,7 +5728,9 @@ module ts { var ok = checkArithmeticOperandType(node.operand, operandType, Diagnostics.An_arithmetic_operand_must_be_of_type_any_number_or_an_enum_type); if (ok) { // run check only if former checks succeeded to avoid reporting cascading errors - checkReferenceExpression(node.operand, Diagnostics.The_operand_of_an_increment_or_decrement_operator_must_be_a_variable_property_or_indexer); + checkReferenceExpression(node.operand, + Diagnostics.The_operand_of_an_increment_or_decrement_operator_must_be_a_variable_property_or_indexer, + Diagnostics.The_operand_of_an_increment_or_decrement_operator_cannot_be_a_constant); } return numberType; } @@ -5855,7 +5911,7 @@ module ts { // requires VarExpr to be classified as a reference // A compound assignment furthermore requires VarExpr to be classified as a reference (section 4.1) // and the type of the non - compound operation to be assignable to the type of VarExpr. - var ok = checkReferenceExpression(node.left, Diagnostics.Invalid_left_hand_side_of_assignment_expression); + var ok = checkReferenceExpression(node.left, Diagnostics.Invalid_left_hand_side_of_assignment_expression, Diagnostics.Left_hand_side_of_assignment_expression_cannot_be_a_constant); // Use default messages if (ok) { // to avoid cascading errors check assignability only if 'isReference' check succeeded and no errors were reported @@ -6829,6 +6885,38 @@ module ts { } } + function checkCollisionWithConstDeclarations(node: VariableDeclaration) { + // Variable declarations are hoisted to the top of their function scope. They can shadow + // block scoped declarations, which bind tighter. this will not be flagged as duplicate definition + // by the binder as the declaration scope is different. + // A non-initialized declaration is a no-op as the block declaration will resolve before the var + // declaration. the problem is if the declaration has an initializer. this will act as a write to the + // block declared value. this is fine for let, but not const. + // + // Only consider declarations with initializers, uninitialized var declarations will not + // step on a const variable. + // Do not consider let and const declarations, as duplicate block-scoped declarations + // are handled by the binder. + // We are only looking for var declarations that step on const declarations from a + // different scope. e.g.: + // var x = 0; + // { + // const x = 0; + // var x = 0; + // } + if (node.initializer && (node.flags & NodeFlags.BlockScoped) === 0) { + var symbol = getSymbolOfNode(node); + if (symbol.flags & SymbolFlags.FunctionScopedVariable) { + var localDeclarationSymbol = resolveName(node, node.name.text, SymbolFlags.Variable, /*nodeNotFoundErrorMessage*/ undefined, /*nameArg*/ undefined); + if (localDeclarationSymbol && localDeclarationSymbol !== symbol && localDeclarationSymbol.flags & SymbolFlags.BlockScopedVariable) { + if (getDeclarationFlagsFromSymbol(localDeclarationSymbol) & NodeFlags.Const) { + error(node, Diagnostics.Cannot_redeclare_block_scoped_variable_0, symbolToString(localDeclarationSymbol)); + } + } + } + } + } + function checkVariableDeclaration(node: VariableDeclaration) { checkSourceElement(node.type); checkExportsOnMergedDeclarations(node); @@ -6852,6 +6940,7 @@ module ts { // Use default messages checkTypeAssignableTo(checkAndMarkExpression(node.initializer), type, node, /*chainedMessage*/ undefined, /*terminalMessage*/ undefined); } + checkCollisionWithConstDeclarations(node); } checkCollisionWithCapturedSuperVariable(node, node.name); @@ -6925,7 +7014,7 @@ module ts { } else { // run check only former check succeeded to avoid cascading errors - checkReferenceExpression(node.variable, Diagnostics.Invalid_left_hand_side_in_for_in_statement); + checkReferenceExpression(node.variable, Diagnostics.Invalid_left_hand_side_in_for_in_statement, Diagnostics.Left_hand_side_of_assignment_expression_cannot_be_a_constant); } } @@ -8227,6 +8316,10 @@ module ts { return getDiagnostics().length > 0 || getGlobalDiagnostics().length > 0; } + function hasEarlyErrors(sourceFile?: SourceFile): boolean { + return forEach(getDiagnostics(sourceFile), d => d.isEarly); + } + function isReferencedImportDeclaration(node: ImportDeclaration): boolean { var symbol = getSymbolOfNode(node); if (getSymbolLinks(symbol).referenced) { @@ -8310,6 +8403,7 @@ module ts { getEnumMemberValue: getEnumMemberValue, isTopLevelValueImportedViaEntityName: isTopLevelValueImportedViaEntityName, hasSemanticErrors: hasSemanticErrors, + hasEarlyErrors: hasEarlyErrors, isDeclarationVisible: isDeclarationVisible, isImplementationOfOverload: isImplementationOfOverload, writeTypeAtLocation: writeTypeAtLocation, diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index 0e48953eaa7d5..a7993484c647d 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -102,10 +102,10 @@ module ts { { name: "target", shortName: "t", - type: { "es3": ScriptTarget.ES3, "es5": ScriptTarget.ES5 }, - description: Diagnostics.Specify_ECMAScript_target_version_Colon_ES3_default_or_ES5, + type: { "es3": ScriptTarget.ES3, "es5": ScriptTarget.ES5 , "es6": ScriptTarget.ES6 }, + description: Diagnostics.Specify_ECMAScript_target_version_Colon_ES3_default_ES5_or_ES6_experimental, paramType: Diagnostics.VERSION, - error: Diagnostics.Argument_for_target_option_must_be_es3_or_es5 + error: Diagnostics.Argument_for_target_option_must_be_es3_es5_or_es6 }, { name: "version", diff --git a/src/compiler/core.ts b/src/compiler/core.ts index ee7f4701d19d9..ae2cf05312376 100644 --- a/src/compiler/core.ts +++ b/src/compiler/core.ts @@ -232,7 +232,8 @@ module ts { messageText: text, category: message.category, - code: message.code + code: message.code, + isEarly: message.isEarly }; } @@ -251,7 +252,8 @@ module ts { messageText: text, category: message.category, - code: message.code + code: message.code, + isEarly: message.isEarly }; } diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index ac2a79c603d5f..a5dda0b1f4b71 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -114,7 +114,12 @@ module ts { Cannot_compile_external_modules_unless_the_module_flag_is_provided: { code: 1148, category: DiagnosticCategory.Error, key: "Cannot compile external modules unless the '--module' flag is provided." }, Filename_0_differs_from_already_included_filename_1_only_in_casing: { code: 1149, category: DiagnosticCategory.Error, key: "Filename '{0}' differs from already included filename '{1}' only in casing" }, new_T_cannot_be_used_to_create_an_array_Use_new_Array_T_instead: { code: 1150, category: DiagnosticCategory.Error, key: "'new T[]' cannot be used to create an array. Use 'new Array()' instead." }, - An_enum_member_cannot_have_a_numeric_name: { code: 1151, category: DiagnosticCategory.Error, key: "An enum member cannot have a numeric name." }, + var_let_or_const_expected: { code: 1152, category: DiagnosticCategory.Error, key: "'var', 'let' or 'const' expected." }, + let_declarations_are_only_available_when_targeting_ECMAScript_6_and_higher: { code: 1153, category: DiagnosticCategory.Error, key: "'let' declarations are only available when targeting ECMAScript 6 and higher." }, + const_declarations_are_only_available_when_targeting_ECMAScript_6_and_higher: { code: 1154, category: DiagnosticCategory.Error, key: "'const' declarations are only available when targeting ECMAScript 6 and higher." }, + const_declarations_must_be_initialized: { code: 1155, category: DiagnosticCategory.Error, key: "'const' declarations must be initialized" }, + const_declarations_can_only_be_declared_inside_a_block: { code: 1156, category: DiagnosticCategory.Error, key: "'const' declarations can only be declared inside a block." }, + let_declarations_can_only_be_declared_inside_a_block: { code: 1157, category: DiagnosticCategory.Error, key: "'let' declarations can only be declared inside a block." }, Duplicate_identifier_0: { code: 2300, category: DiagnosticCategory.Error, key: "Duplicate identifier '{0}'." }, Initializer_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor: { code: 2301, category: DiagnosticCategory.Error, key: "Initializer of instance member variable '{0}' cannot reference identifier '{1}' declared in the constructor." }, Static_members_cannot_reference_class_type_parameters: { code: 2302, category: DiagnosticCategory.Error, key: "Static members cannot reference class type parameters." }, @@ -261,6 +266,11 @@ module ts { Property_0_is_protected_and_only_accessible_within_class_1_and_its_subclasses: { code: 2445, category: DiagnosticCategory.Error, key: "Property '{0}' is protected and only accessible within class '{1}' and its subclasses." }, Property_0_is_protected_and_only_accessible_through_an_instance_of_class_1: { code: 2446, category: DiagnosticCategory.Error, key: "Property '{0}' is protected and only accessible through an instance of class '{1}'." }, The_0_operator_is_not_allowed_for_boolean_types_Consider_using_1_instead: { code: 2447, category: DiagnosticCategory.Error, key: "The '{0}' operator is not allowed for boolean types. Consider using '{1}' instead." }, + Block_scoped_variable_0_used_before_its_declaration: { code: 2448, category: DiagnosticCategory.Error, key: "Block-scoped variable '{0}' used before its declaration.", isEarly: true }, + The_operand_of_an_increment_or_decrement_operator_cannot_be_a_constant: { code: 2449, category: DiagnosticCategory.Error, key: "The operand of an increment or decrement operator cannot be a constant.", isEarly: true }, + Left_hand_side_of_assignment_expression_cannot_be_a_constant: { code: 2450, category: DiagnosticCategory.Error, key: "Left-hand side of assignment expression cannot be a constant.", isEarly: true }, + Cannot_redeclare_block_scoped_variable_0: { code: 2451, category: DiagnosticCategory.Error, key: "Cannot redeclare block-scoped variable '{0}'.", isEarly: true }, + An_enum_member_cannot_have_a_numeric_name: { code: 2452, category: DiagnosticCategory.Error, key: "An enum member cannot have a numeric name." }, 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_name_1_from_private_module_2: { code: 4001, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of exported class has or is using name '{1}' from private module '{2}'." }, 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}'." }, @@ -355,7 +365,7 @@ module ts { Watch_input_files: { code: 6005, category: DiagnosticCategory.Message, key: "Watch input files." }, Redirect_output_structure_to_the_directory: { code: 6006, category: DiagnosticCategory.Message, key: "Redirect output structure to the directory." }, Do_not_emit_comments_to_output: { code: 6009, category: DiagnosticCategory.Message, key: "Do not emit comments to output." }, - Specify_ECMAScript_target_version_Colon_ES3_default_or_ES5: { code: 6015, category: DiagnosticCategory.Message, key: "Specify ECMAScript target version: 'ES3' (default), or 'ES5'" }, + Specify_ECMAScript_target_version_Colon_ES3_default_ES5_or_ES6_experimental: { code: 6015, category: DiagnosticCategory.Message, key: "Specify ECMAScript target version: 'ES3' (default), 'ES5', or 'ES6' (experimental)" }, Specify_module_code_generation_Colon_commonjs_or_amd: { code: 6016, category: DiagnosticCategory.Message, key: "Specify module code generation: 'commonjs' or 'amd'" }, Print_this_message: { code: 6017, category: DiagnosticCategory.Message, key: "Print this message." }, Print_the_compiler_s_version: { code: 6019, category: DiagnosticCategory.Message, key: "Print the compiler's version." }, @@ -377,7 +387,7 @@ module ts { Compiler_option_0_expects_an_argument: { code: 6044, category: DiagnosticCategory.Error, key: "Compiler option '{0}' expects an argument." }, Unterminated_quoted_string_in_response_file_0: { code: 6045, category: DiagnosticCategory.Error, key: "Unterminated quoted string in response file '{0}'." }, Argument_for_module_option_must_be_commonjs_or_amd: { code: 6046, category: DiagnosticCategory.Error, key: "Argument for '--module' option must be 'commonjs' or 'amd'." }, - Argument_for_target_option_must_be_es3_or_es5: { code: 6047, category: DiagnosticCategory.Error, key: "Argument for '--target' option must be 'es3' or 'es5'." }, + Argument_for_target_option_must_be_es3_es5_or_es6: { code: 6047, category: DiagnosticCategory.Error, key: "Argument for '--target' option must be 'es3', 'es5', or 'es6'." }, Locale_must_be_of_the_form_language_or_language_territory_For_example_0_or_1: { code: 6048, category: DiagnosticCategory.Error, key: "Locale must be of the form or -. For example '{0}' or '{1}'." }, Unsupported_locale_0: { code: 6049, category: DiagnosticCategory.Error, key: "Unsupported locale '{0}'." }, Unable_to_open_file_0: { code: 6050, category: DiagnosticCategory.Error, key: "Unable to open file '{0}'." }, diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index d8895d151442a..1336af21aaf80 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -447,9 +447,29 @@ "category": "Error", "code": 1150 }, - "An enum member cannot have a numeric name.": { + "'var', 'let' or 'const' expected.": { + "category": "Error", + "code": 1152 + }, + "'let' declarations are only available when targeting ECMAScript 6 and higher.": { + "category": "Error", + "code": 1153 + }, + "'const' declarations are only available when targeting ECMAScript 6 and higher.": { + "category": "Error", + "code": 1154 + }, + "'const' declarations must be initialized": { + "category": "Error", + "code": 1155 + }, + "'const' declarations can only be declared inside a block.": { + "category": "Error", + "code": 1156 + }, + "'let' declarations can only be declared inside a block.": { "category": "Error", - "code": 1151 + "code": 1157 }, "Duplicate identifier '{0}'.": { @@ -1036,6 +1056,30 @@ "category": "Error", "code": 2447 }, + "Block-scoped variable '{0}' used before its declaration.": { + "category": "Error", + "code": 2448, + "isEarly": true + }, + "The operand of an increment or decrement operator cannot be a constant.": { + "category": "Error", + "code": 2449, + "isEarly": true + }, + "Left-hand side of assignment expression cannot be a constant.": { + "category": "Error", + "code": 2450, + "isEarly": true + }, + "Cannot redeclare block-scoped variable '{0}'.": { + "category": "Error", + "code": 2451, + "isEarly": true + }, + "An enum member cannot have a numeric name.": { + "category": "Error", + "code": 2452 + }, "Import declaration '{0}' is using private name '{1}'.": { "category": "Error", @@ -1416,7 +1460,7 @@ "category": "Message", "code": 6009 }, - "Specify ECMAScript target version: 'ES3' (default), or 'ES5'": { + "Specify ECMAScript target version: 'ES3' (default), 'ES5', or 'ES6' (experimental)": { "category": "Message", "code": 6015 }, @@ -1504,7 +1548,7 @@ "category": "Error", "code": 6046 }, - "Argument for '--target' option must be 'es3' or 'es5'.": { + "Argument for '--target' option must be 'es3', 'es5', or 'es6'.": { "category": "Error", "code": 6047 }, diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 4dda5c92ca72b..1517584e4c85f 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -1143,7 +1143,15 @@ module ts { write(" "); endPos = emitToken(SyntaxKind.OpenParenToken, endPos); if (node.declarations) { - emitToken(SyntaxKind.VarKeyword, endPos); + if (node.declarations[0] && node.declarations[0].flags & NodeFlags.Let) { + emitToken(SyntaxKind.LetKeyword, endPos); + } + else if (node.declarations[0] && node.declarations[0].flags & NodeFlags.Const) { + emitToken(SyntaxKind.ConstKeyword, endPos); + } + else { + emitToken(SyntaxKind.VarKeyword, endPos); + } write(" "); emitCommaList(node.declarations, /*includeTrailingComma*/ false); } @@ -1163,7 +1171,12 @@ module ts { write(" "); endPos = emitToken(SyntaxKind.OpenParenToken, endPos); if (node.declaration) { - emitToken(SyntaxKind.VarKeyword, endPos); + if (node.declaration.flags & NodeFlags.Let) { + emitToken(SyntaxKind.LetKeyword, endPos); + } + else { + emitToken(SyntaxKind.VarKeyword, endPos); + } write(" "); emit(node.declaration); } @@ -1292,7 +1305,17 @@ module ts { function emitVariableStatement(node: VariableStatement) { emitLeadingComments(node); - if (!(node.flags & NodeFlags.Export)) write("var "); + if (!(node.flags & NodeFlags.Export)) { + if (node.flags & NodeFlags.Let) { + write("let "); + } + else if (node.flags & NodeFlags.Const) { + write("const "); + } + else { + write("var "); + } + } emitCommaList(node.declarations, /*includeTrailingComma*/ false); write(";"); emitTrailingComments(node); @@ -2829,7 +2852,15 @@ module ts { if (hasDeclarationWithEmit) { emitJsDocComments(node); emitDeclarationFlags(node); - write("var "); + if (node.flags & NodeFlags.Let) { + write("let "); + } + else if (node.flags & NodeFlags.Const) { + write("const "); + } + else { + write("var "); + } emitCommaList(node.declarations, emitVariableDeclaration); write(";"); writeLine(); @@ -3240,11 +3271,14 @@ module ts { } var hasSemanticErrors = resolver.hasSemanticErrors(); + var hasEarlyErrors = resolver.hasEarlyErrors(targetSourceFile); function emitFile(jsFilePath: string, sourceFile?: SourceFile) { - emitJavaScript(jsFilePath, sourceFile); - if (!hasSemanticErrors && compilerOptions.declaration) { - emitDeclarations(jsFilePath, sourceFile); + if (!hasEarlyErrors) { + emitJavaScript(jsFilePath, sourceFile); + if (!hasSemanticErrors && compilerOptions.declaration) { + emitDeclarations(jsFilePath, sourceFile); + } } } @@ -3284,7 +3318,9 @@ module ts { // Check and update returnCode for syntactic and semantic var returnCode: EmitReturnStatus; - if (hasEmitterError) { + if (hasEarlyErrors) { + returnCode = EmitReturnStatus.AllOutputGenerationSkipped; + } else if (hasEmitterError) { returnCode = EmitReturnStatus.EmitErrorsEncountered; } else if (hasSemanticErrors && compilerOptions.declaration) { returnCode = EmitReturnStatus.DeclarationGenerationSkipped; diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 46717d3df0f0b..15383a0031b2f 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -2696,11 +2696,14 @@ module ts { } // STATEMENTS + function parseStatementAllowingLetDeclaration() { + return parseStatement(/*allowLetAndConstDeclarations*/ true); + } function parseBlock(ignoreMissingOpenBrace: boolean, checkForStrictMode: boolean): Block { var node = createNode(SyntaxKind.Block); if (parseExpected(SyntaxKind.OpenBraceToken) || ignoreMissingOpenBrace) { - node.statements = parseList(ParsingContext.BlockStatements,checkForStrictMode, parseStatement); + node.statements = parseList(ParsingContext.BlockStatements, checkForStrictMode, parseStatementAllowingLetDeclaration); parseExpected(SyntaxKind.CloseBraceToken); } else { @@ -2746,8 +2749,8 @@ module ts { parseExpected(SyntaxKind.OpenParenToken); node.expression = parseExpression(); parseExpected(SyntaxKind.CloseParenToken); - node.thenStatement = parseStatement(); - node.elseStatement = parseOptional(SyntaxKind.ElseKeyword) ? parseStatement() : undefined; + node.thenStatement = parseStatement(/*allowLetAndConstDeclarations*/ false); + node.elseStatement = parseOptional(SyntaxKind.ElseKeyword) ? parseStatement(/*allowLetAndConstDeclarations*/ false) : undefined; return finishNode(node); } @@ -2757,7 +2760,7 @@ module ts { var saveInIterationStatement = inIterationStatement; inIterationStatement = ControlBlockContext.Nested; - node.statement = parseStatement(); + node.statement = parseStatement(/*allowLetAndConstDeclarations*/ false); inIterationStatement = saveInIterationStatement; parseExpected(SyntaxKind.WhileKeyword); @@ -2782,7 +2785,7 @@ module ts { var saveInIterationStatement = inIterationStatement; inIterationStatement = ControlBlockContext.Nested; - node.statement = parseStatement(); + node.statement = parseStatement(/*allowLetAndConstDeclarations*/ false); inIterationStatement = saveInIterationStatement; return finishNode(node); @@ -2794,10 +2797,28 @@ module ts { parseExpected(SyntaxKind.OpenParenToken); if (token !== SyntaxKind.SemicolonToken) { if (parseOptional(SyntaxKind.VarKeyword)) { - var declarations = parseVariableDeclarationList(0, true); + var declarations = parseVariableDeclarationList(0, /*noIn*/ true); + if (!declarations.length) { + error(Diagnostics.Variable_declaration_list_cannot_be_empty); + } + } + else if (parseOptional(SyntaxKind.LetKeyword)) { + var declarations = parseVariableDeclarationList(NodeFlags.Let, /*noIn*/ true); + if (!declarations.length) { + error(Diagnostics.Variable_declaration_list_cannot_be_empty); + } + if (languageVersion < ScriptTarget.ES6) { + grammarErrorAtPos(declarations.pos, declarations.end - declarations.pos, Diagnostics.let_declarations_are_only_available_when_targeting_ECMAScript_6_and_higher); + } + } + else if (parseOptional(SyntaxKind.ConstKeyword)) { + var declarations = parseVariableDeclarationList(NodeFlags.Const, /*noIn*/ true); if (!declarations.length) { error(Diagnostics.Variable_declaration_list_cannot_be_empty); } + if (languageVersion < ScriptTarget.ES6) { + grammarErrorAtPos(declarations.pos, declarations.end - declarations.pos, Diagnostics.const_declarations_are_only_available_when_targeting_ECMAScript_6_and_higher); + } } else { var varOrInit = parseExpression(true); @@ -2837,7 +2858,7 @@ module ts { var saveInIterationStatement = inIterationStatement; inIterationStatement = ControlBlockContext.Nested; - forOrForInStatement.statement = parseStatement(); + forOrForInStatement.statement = parseStatement(/*allowLetAndConstDeclarations*/ false); inIterationStatement = saveInIterationStatement; return finishNode(forOrForInStatement); @@ -2948,7 +2969,7 @@ module ts { parseExpected(SyntaxKind.OpenParenToken); node.expression = parseExpression(); parseExpected(SyntaxKind.CloseParenToken); - node.statement = parseStatement(); + node.statement = parseStatement(/*allowLetAndConstDeclarations*/ false); node = finishNode(node); if (isInStrictMode) { // Strict mode code may not include a WithStatement. The occurrence of a WithStatement in such @@ -2963,7 +2984,7 @@ module ts { parseExpected(SyntaxKind.CaseKeyword); node.expression = parseExpression(); parseExpected(SyntaxKind.ColonToken); - node.statements = parseList(ParsingContext.SwitchClauseStatements, /*checkForStrictMode*/ false, parseStatement); + node.statements = parseList(ParsingContext.SwitchClauseStatements, /*checkForStrictMode*/ false, parseStatementAllowingLetDeclaration); return finishNode(node); } @@ -2971,7 +2992,7 @@ module ts { var node = createNode(SyntaxKind.DefaultClause); parseExpected(SyntaxKind.DefaultKeyword); parseExpected(SyntaxKind.ColonToken); - node.statements = parseList(ParsingContext.SwitchClauseStatements, /*checkForStrictMode*/ false, parseStatement); + node.statements = parseList(ParsingContext.SwitchClauseStatements, /*checkForStrictMode*/ false, parseStatementAllowingLetDeclaration); return finishNode(node); } @@ -3078,9 +3099,9 @@ module ts { return token === SyntaxKind.WhileKeyword || token === SyntaxKind.DoKeyword || token === SyntaxKind.ForKeyword; } - function parseStatementWithLabelSet(): Statement { + function parseStatementWithLabelSet(allowLetAndConstDeclarations: boolean): Statement { labelledStatementInfo.pushCurrentLabelSet(isIterationStatementStart()); - var statement = parseStatement(); + var statement = parseStatement(allowLetAndConstDeclarations); labelledStatementInfo.pop(); return statement; } @@ -3089,7 +3110,7 @@ module ts { return isIdentifier() && lookAhead(() => nextToken() === SyntaxKind.ColonToken); } - function parseLabelledStatement(): LabeledStatement { + function parseLabeledStatement(allowLetAndConstDeclarations: boolean): LabeledStatement { var node = createNode(SyntaxKind.LabeledStatement); node.label = parseIdentifier(); parseExpected(SyntaxKind.ColonToken); @@ -3101,7 +3122,7 @@ module ts { // We only want to call parseStatementWithLabelSet when the label set is complete // Therefore, keep parsing labels until we know we're done. - node.statement = isLabel() ? parseLabelledStatement() : parseStatementWithLabelSet(); + node.statement = isLabel() ? parseLabeledStatement(allowLetAndConstDeclarations) : parseStatementWithLabelSet(allowLetAndConstDeclarations); return finishNode(node); } @@ -3124,6 +3145,8 @@ module ts { return !inErrorRecovery; case SyntaxKind.OpenBraceToken: case SyntaxKind.VarKeyword: + case SyntaxKind.LetKeyword: + case SyntaxKind.ConstKeyword: case SyntaxKind.FunctionKeyword: case SyntaxKind.IfKeyword: case SyntaxKind.DoKeyword: @@ -3165,12 +3188,14 @@ module ts { } } - function parseStatement(): Statement { + function parseStatement(allowLetAndConstDeclarations: boolean): Statement { switch (token) { case SyntaxKind.OpenBraceToken: return parseBlock(/* ignoreMissingOpenBrace */ false, /*checkForStrictMode*/ false); case SyntaxKind.VarKeyword: - return parseVariableStatement(); + case SyntaxKind.LetKeyword: + case SyntaxKind.ConstKeyword: + return parseVariableStatement(allowLetAndConstDeclarations); case SyntaxKind.FunctionKeyword: return parseFunctionDeclaration(); case SyntaxKind.SemicolonToken: @@ -3204,16 +3229,12 @@ module ts { return parseDebuggerStatement(); default: if (isLabel()) { - return parseLabelledStatement(); + return parseLabeledStatement(allowLetAndConstDeclarations); } return parseExpressionStatement(); } } - function parseStatementOrFunction(): Statement { - return token === SyntaxKind.FunctionKeyword ? parseFunctionDeclaration() : parseStatement(); - } - function parseAndCheckFunctionBody(isConstructor: boolean): Block { var initialPosition = scanner.getTokenPos(); var errorCountBeforeBody = file.syntacticErrors.length; @@ -3249,6 +3270,9 @@ module ts { if (inAmbientContext && node.initializer && errorCountBeforeVariableDeclaration === file.syntacticErrors.length) { grammarErrorAtPos(initializerStart, initializerFirstTokenLength, Diagnostics.Initializers_are_not_allowed_in_ambient_contexts); } + if (!inAmbientContext && !node.initializer && flags & NodeFlags.Const) { + grammarErrorOnNode(node, Diagnostics.const_declarations_must_be_initialized); + } if (isInStrictMode && isEvalOrArgumentsIdentifier(node.name)) { // It is a SyntaxError if a VariableDeclaration or VariableDeclarationNoIn occurs within strict code // and its Identifier is eval or arguments @@ -3262,17 +3286,42 @@ module ts { () => parseVariableDeclaration(flags, noIn), /*allowTrailingComma*/ false); } - function parseVariableStatement(pos?: number, flags?: NodeFlags): VariableStatement { + function parseVariableStatement(allowLetAndConstDeclarations: boolean, pos?: number, flags?: NodeFlags): VariableStatement { var node = createNode(SyntaxKind.VariableStatement, pos); if (flags) node.flags = flags; var errorCountBeforeVarStatement = file.syntacticErrors.length; - parseExpected(SyntaxKind.VarKeyword); - node.declarations = parseVariableDeclarationList(flags, /*noIn*/false); + if (token === SyntaxKind.LetKeyword) { + node.flags |= NodeFlags.Let; + } + else if (token === SyntaxKind.ConstKeyword) { + node.flags |= NodeFlags.Const; + } + else if (token !== SyntaxKind.VarKeyword) { + error(Diagnostics.var_let_or_const_expected); + } + nextToken(); + node.declarations = parseVariableDeclarationList(node.flags, /*noIn*/false); parseSemicolon(); finishNode(node); if (!node.declarations.length && file.syntacticErrors.length === errorCountBeforeVarStatement) { grammarErrorOnNode(node, Diagnostics.Variable_declaration_list_cannot_be_empty); } + if (languageVersion < ScriptTarget.ES6) { + if (node.flags & NodeFlags.Let) { + grammarErrorOnNode(node, Diagnostics.let_declarations_are_only_available_when_targeting_ECMAScript_6_and_higher); + } + else if (node.flags & NodeFlags.Const) { + grammarErrorOnNode(node, Diagnostics.const_declarations_are_only_available_when_targeting_ECMAScript_6_and_higher); + } + } + else if (!allowLetAndConstDeclarations) { + if (node.flags & NodeFlags.Let) { + grammarErrorOnNode(node, Diagnostics.let_declarations_can_only_be_declared_inside_a_block); + } + else if (node.flags & NodeFlags.Const) { + grammarErrorOnNode(node, Diagnostics.const_declarations_can_only_be_declared_inside_a_block); + } + } return node; } @@ -3851,6 +3900,8 @@ module ts { function isDeclaration(): boolean { switch (token) { case SyntaxKind.VarKeyword: + case SyntaxKind.LetKeyword: + case SyntaxKind.ConstKeyword: case SyntaxKind.FunctionKeyword: return true; case SyntaxKind.ClassKeyword: @@ -3901,7 +3952,9 @@ module ts { var result: Declaration; switch (token) { case SyntaxKind.VarKeyword: - result = parseVariableStatement(pos, flags); + case SyntaxKind.LetKeyword: + case SyntaxKind.ConstKeyword: + result = parseVariableStatement(/*allowLetAndConstDeclarations*/ true, pos, flags); break; case SyntaxKind.FunctionKeyword: result = parseFunctionDeclaration(pos, flags); @@ -3949,7 +4002,7 @@ module ts { var statementStart = scanner.getTokenPos(); var statementFirstTokenLength = scanner.getTextPos() - statementStart; var errorCountBeforeStatement = file.syntacticErrors.length; - var statement = parseStatement(); + var statement = parseStatement(/*allowLetAndConstDeclarations*/ true); if (inAmbientContext && file.syntacticErrors.length === errorCountBeforeStatement) { grammarErrorAtPos(statementStart, statementFirstTokenLength, Diagnostics.Statements_are_not_allowed_in_ambient_contexts); diff --git a/src/compiler/tsc.ts b/src/compiler/tsc.ts index 52dac9695de17..15f231bc74ea9 100644 --- a/src/compiler/tsc.ts +++ b/src/compiler/tsc.ts @@ -361,13 +361,18 @@ module ts { else { var checker = program.getTypeChecker(/*fullTypeCheckMode*/ true); var checkStart = new Date().getTime(); - var semanticErrors = checker.getDiagnostics(); - var emitStart = new Date().getTime(); - var emitOutput = checker.emitFiles(); - var emitErrors = emitOutput.errors; - exitStatus = emitOutput.emitResultStatus; - var reportStart = new Date().getTime(); - errors = concatenate(semanticErrors, emitErrors); + errors = checker.getDiagnostics(); + if (!checker.hasEarlyErrors()) { + var emitStart = new Date().getTime(); + var emitOutput = checker.emitFiles(); + var emitErrors = emitOutput.errors; + exitStatus = emitOutput.emitResultStatus; + var reportStart = new Date().getTime(); + errors = concatenate(errors, emitErrors); + } + else { + exitStatus = EmitReturnStatus.AllOutputGenerationSkipped; + } } reportDiagnostics(errors); diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 48c74d8f2af3e..aa2ca3b4ba83a 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -247,9 +247,12 @@ module ts { MultiLine = 0x00000100, // Multi-line array or object literal Synthetic = 0x00000200, // Synthetic node (for full fidelity) DeclarationFile = 0x00000400, // Node is a .d.ts file + Let = 0x00000800, // Variable declaration + Const = 0x00001000, // Variable declaration Modifier = Export | Ambient | Public | Private | Protected | Static, - AccessibilityModifier = Public | Private | Protected + AccessibilityModifier = Public | Private | Protected, + BlockScoped = Let | Const } export interface Node extends TextRange { @@ -663,6 +666,7 @@ module ts { isImplementationOfOverload(node: FunctionDeclaration): boolean; isUndefinedSymbol(symbol: Symbol): boolean; isArgumentsSymbol(symbol: Symbol): boolean; + hasEarlyErrors(sourceFile?: SourceFile): boolean; // Returns the constant value of this enum member, or 'undefined' if the enum member has a // computed value. @@ -758,51 +762,62 @@ module ts { // Returns the constant value this property access resolves to, or 'undefined' if it does // resolve to a constant. getConstantValue(node: PropertyAccess): number; + hasEarlyErrors(sourceFile?: SourceFile): boolean; } export enum SymbolFlags { - Variable = 0x00000001, // Variable or parameter - Property = 0x00000002, // Property or enum member - EnumMember = 0x00000004, // Enum member - Function = 0x00000008, // Function - Class = 0x00000010, // Class - Interface = 0x00000020, // Interface - Enum = 0x00000040, // Enum - ValueModule = 0x00000080, // Instantiated module - NamespaceModule = 0x00000100, // Uninstantiated module - TypeLiteral = 0x00000200, // Type Literal - ObjectLiteral = 0x00000400, // Object Literal - Method = 0x00000800, // Method - Constructor = 0x00001000, // Constructor - GetAccessor = 0x00002000, // Get accessor - SetAccessor = 0x00004000, // Set accessor - CallSignature = 0x00008000, // Call signature - ConstructSignature = 0x00010000, // Construct signature - IndexSignature = 0x00020000, // Index signature - TypeParameter = 0x00040000, // Type parameter + FunctionScopedVariable = 0x00000001, // Variable (var) or parameter + Property = 0x00000002, // Property or enum member + EnumMember = 0x00000004, // Enum member + Function = 0x00000008, // Function + Class = 0x00000010, // Class + Interface = 0x00000020, // Interface + Enum = 0x00000040, // Enum + ValueModule = 0x00000080, // Instantiated module + NamespaceModule = 0x00000100, // Uninstantiated module + TypeLiteral = 0x00000200, // Type Literal + ObjectLiteral = 0x00000400, // Object Literal + Method = 0x00000800, // Method + Constructor = 0x00001000, // Constructor + GetAccessor = 0x00002000, // Get accessor + SetAccessor = 0x00004000, // Set accessor + CallSignature = 0x00008000, // Call signature + ConstructSignature = 0x00010000, // Construct signature + IndexSignature = 0x00020000, // Index signature + TypeParameter = 0x00040000, // Type parameter // Export markers (see comment in declareModuleMember in binder) - ExportValue = 0x00080000, // Exported value marker - ExportType = 0x00100000, // Exported type marker - ExportNamespace = 0x00200000, // Exported namespace marker + ExportValue = 0x00080000, // Exported value marker + ExportType = 0x00100000, // Exported type marker + ExportNamespace = 0x00200000, // Exported namespace marker - Import = 0x00400000, // Import - Instantiated = 0x00800000, // Instantiated symbol - Merged = 0x01000000, // Merged symbol (created during program binding) - Transient = 0x02000000, // Transient symbol (created during type check) - Prototype = 0x04000000, // Prototype property (no source representation) - UnionProperty = 0x08000000, // Property in union type + Import = 0x00400000, // Import + Instantiated = 0x00800000, // Instantiated symbol + Merged = 0x01000000, // Merged symbol (created during program binding) + Transient = 0x02000000, // Transient symbol (created during type check) + Prototype = 0x04000000, // Prototype property (no source representation) + UnionProperty = 0x08000000, // Property in union type + BlockScopedVariable = 0x10000000, // A block-scoped variable (let ot const) + + Variable = FunctionScopedVariable | BlockScopedVariable, Value = Variable | Property | EnumMember | Function | Class | Enum | ValueModule | Method | GetAccessor | SetAccessor, - Type = Class | Interface | Enum | TypeLiteral | ObjectLiteral | TypeParameter, Namespace = ValueModule | NamespaceModule, Module = ValueModule | NamespaceModule, Accessor = GetAccessor | SetAccessor, Signature = CallSignature | ConstructSignature | IndexSignature, + + // 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 + FunctionScopedVariableExcludes = Value & ~FunctionScopedVariable, + + // Block-scoped declarations are not allowed to be re-declared + // they can not merge with anything in the value space + BlockScopedVariableExcludes = Value, + ParameterExcludes = Value, - VariableExcludes = Value & ~Variable, PropertyExcludes = Value, EnumMemberExcludes = Value, FunctionExcludes = Value & ~(Function | ValueModule), @@ -816,8 +831,9 @@ module ts { SetAccessorExcludes = Value & ~GetAccessor, TypeParameterExcludes = Type & ~TypeParameter, + // Imports collide with all other imports with the same name. - ImportExcludes = Import, + ImportExcludes = Import, ModuleMember = Variable | Function | Class | Interface | Enum | Module | Import, @@ -1024,6 +1040,7 @@ module ts { key: string; category: DiagnosticCategory; code: number; + isEarly?: boolean; } // A linked list of formatted diagnostic messages to be used as part of a multiline message. @@ -1044,6 +1061,7 @@ module ts { messageText: string; category: DiagnosticCategory; code: number; + isEarly?: boolean; } export enum DiagnosticCategory { @@ -1096,6 +1114,8 @@ module ts { export enum ScriptTarget { ES3, ES5, + ES6, + Latest = ES6, } export interface ParsedCommandLine { diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index aede75d51da01..33f435ce76b2b 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -2220,7 +2220,7 @@ module FourSlash { var host = Harness.Compiler.createCompilerHost([{ unitName: Harness.Compiler.fourslashFilename, content: undefined }, { unitName: fileName, content: content }], (fn, contents) => result = contents, - ts.ScriptTarget.ES5, + ts.ScriptTarget.Latest, sys.useCaseSensitiveFileNames); var program = ts.createProgram([Harness.Compiler.fourslashFilename, fileName], { out: "fourslashTestOutput.js" }, host); var checker = ts.createTypeChecker(program, /*fullTypeCheckMode*/ true); diff --git a/src/harness/harness.ts b/src/harness/harness.ts index 2f7bf780b4187..60c5da5a1a68a 100644 --- a/src/harness/harness.ts +++ b/src/harness/harness.ts @@ -540,7 +540,7 @@ module Harness { } export var defaultLibFileName = 'lib.d.ts'; - export var defaultLibSourceFile = ts.createSourceFile(defaultLibFileName, IO.readFile(libFolder + 'lib.core.d.ts'), /*languageVersion*/ ts.ScriptTarget.ES5, /*version:*/ "0"); + export var defaultLibSourceFile = ts.createSourceFile(defaultLibFileName, IO.readFile(libFolder + 'lib.core.d.ts'), /*languageVersion*/ ts.ScriptTarget.Latest, /*version:*/ "0"); // Cache these between executions so we don't have to re-parse them for every test export var fourslashFilename = 'fourslash.ts'; @@ -693,6 +693,8 @@ module Harness { options.target = ts.ScriptTarget.ES3; } else if (setting.value.toLowerCase() === 'es5') { options.target = ts.ScriptTarget.ES5; + } else if (setting.value.toLowerCase() === 'es6') { + options.target = ts.ScriptTarget.ES6; } else { throw new Error('Unknown compile target ' + setting.value); } @@ -799,9 +801,11 @@ module Harness { var checker = program.getTypeChecker(/*fullTypeCheckMode*/ true); checker.checkProgram(); + var hasEarlyErrors = checker.hasEarlyErrors(); + // only emit if there weren't parse errors var emitResult: ts.EmitResult; - if (!hadParseErrors) { + if (!hadParseErrors && !hasEarlyErrors) { emitResult = checker.emitFiles(); } diff --git a/src/harness/harnessLanguageService.ts b/src/harness/harnessLanguageService.ts index 647d0729cbb5f..6307c4d1e78ff 100644 --- a/src/harness/harnessLanguageService.ts +++ b/src/harness/harnessLanguageService.ts @@ -260,7 +260,7 @@ module Harness.LanguageService { /** Parse file given its source text */ public parseSourceText(fileName: string, sourceText: TypeScript.IScriptSnapshot): TypeScript.SourceUnitSyntax { - return TypeScript.Parser.parse(fileName, TypeScript.SimpleText.fromScriptSnapshot(sourceText), ts.ScriptTarget.ES5, TypeScript.isDTSFile(fileName)).sourceUnit(); + return TypeScript.Parser.parse(fileName, TypeScript.SimpleText.fromScriptSnapshot(sourceText), ts.ScriptTarget.Latest, TypeScript.isDTSFile(fileName)).sourceUnit(); } /** Parse a file on disk given its fileName */ diff --git a/src/services/compiler/precompile.ts b/src/services/compiler/precompile.ts index 3ff23d85bea1c..08a919a65b58a 100644 --- a/src/services/compiler/precompile.ts +++ b/src/services/compiler/precompile.ts @@ -184,7 +184,7 @@ module TypeScript { export function preProcessFile(fileName: string, sourceText: IScriptSnapshot, readImportFiles = true): IPreProcessedFileInfo { var text = SimpleText.fromScriptSnapshot(sourceText); - var scanner = Scanner.createScanner(ts.ScriptTarget.ES5, text, reportDiagnostic); + var scanner = Scanner.createScanner(ts.ScriptTarget.Latest, text, reportDiagnostic); var firstToken = scanner.scan(/*allowRegularExpression:*/ false); diff --git a/src/services/navigationBar.ts b/src/services/navigationBar.ts index 9f16fa57741d9..6918097412035 100644 --- a/src/services/navigationBar.ts +++ b/src/services/navigationBar.ts @@ -233,7 +233,12 @@ module ts.NavigationBar { return createItem(node, getTextOfNode((node).name), ts.ScriptElementKind.functionElement); case SyntaxKind.VariableDeclaration: - return createItem(node, getTextOfNode((node).name), ts.ScriptElementKind.variableElement); + if (node.flags & NodeFlags.Const) { + return createItem(node, getTextOfNode((node).name), ts.ScriptElementKind.constantElement); + } + else { + return createItem(node, getTextOfNode((node).name), ts.ScriptElementKind.variableElement); + } case SyntaxKind.Constructor: return createItem(node, "constructor", ts.ScriptElementKind.constructorImplementationElement); diff --git a/src/services/services.ts b/src/services/services.ts index 75afa46248ce7..d853d06d68e8a 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -77,7 +77,7 @@ module ts { update(scriptSnapshot: TypeScript.IScriptSnapshot, version: string, isOpen: boolean, textChangeRange: TypeScript.TextChangeRange): SourceFile; } - var scanner: Scanner = createScanner(ScriptTarget.ES5, /*skipTrivia*/ true); + var scanner: Scanner = createScanner(ScriptTarget.Latest, /*skipTrivia*/ true); var emptyArray: any[] = []; @@ -1235,7 +1235,9 @@ module ts { static label = "label"; - static alias = "alias" + static alias = "alias"; + + static constantElement = "constant"; } export class ScriptElementKindModifier { @@ -1486,9 +1488,9 @@ module ts { } export function getDefaultCompilerOptions(): CompilerOptions { - // Set "ES5" target by default for language service + // Set "ScriptTarget.Latest" target by default for language service return { - target: ScriptTarget.ES5, + target: ScriptTarget.Latest, module: ModuleKind.None, }; } @@ -2733,6 +2735,9 @@ module ts { if (isFirstDeclarationOfSymbolParameter(symbol)) { return ScriptElementKind.parameterElement; } + else if(symbol.valueDeclaration && symbol.valueDeclaration.flags & NodeFlags.Const) { + return ScriptElementKind.constantElement; + } return isLocalVariableOrFunction(symbol) ? ScriptElementKind.localVariableElement : ScriptElementKind.variableElement; } if (flags & SymbolFlags.Function) return isLocalVariableOrFunction(symbol) ? ScriptElementKind.localFunctionElement : ScriptElementKind.functionElement; @@ -2778,7 +2783,7 @@ module ts { case SyntaxKind.ClassDeclaration: return ScriptElementKind.classElement; case SyntaxKind.InterfaceDeclaration: return ScriptElementKind.interfaceElement; case SyntaxKind.EnumDeclaration: return ScriptElementKind.enumElement; - case SyntaxKind.VariableDeclaration: return ScriptElementKind.variableElement; + case SyntaxKind.VariableDeclaration: return node.flags & NodeFlags.Const ? ScriptElementKind.constantElement: ScriptElementKind.variableElement; case SyntaxKind.FunctionDeclaration: return ScriptElementKind.functionElement; case SyntaxKind.GetAccessor: return ScriptElementKind.memberGetAccessorElement; case SyntaxKind.SetAccessor: return ScriptElementKind.memberSetAccessorElement; @@ -2867,6 +2872,7 @@ module ts { switch (symbolKind) { case ScriptElementKind.memberVariableElement: case ScriptElementKind.variableElement: + case ScriptElementKind.constantElement: case ScriptElementKind.parameterElement: case ScriptElementKind.localVariableElement: // If it is call or construct signature of lambda's write type name @@ -3891,8 +3897,8 @@ module ts { // before and after it have to be a non-identifier char). var endPosition = position + symbolNameLength; - if ((position === 0 || !isIdentifierPart(text.charCodeAt(position - 1), ScriptTarget.ES5)) && - (endPosition === sourceLength || !isIdentifierPart(text.charCodeAt(endPosition), ScriptTarget.ES5))) { + if ((position === 0 || !isIdentifierPart(text.charCodeAt(position - 1), ScriptTarget.Latest)) && + (endPosition === sourceLength || !isIdentifierPart(text.charCodeAt(endPosition), ScriptTarget.Latest))) { // Found a real match. Keep searching. positions.push(position); } @@ -5333,7 +5339,7 @@ module ts { /// Classifier export function createClassifier(host: Logger): Classifier { - var scanner = createScanner(ScriptTarget.ES5, /*skipTrivia*/ false); + var scanner = createScanner(ScriptTarget.Latest, /*skipTrivia*/ false); /// We do not have a full parser support to know when we should parse a regex or not /// If we consider every slash token to be a regex, we could be missing cases like "1/2/3", where diff --git a/src/services/shims.ts b/src/services/shims.ts index fdea0202323fb..a6bf421b09566 100644 --- a/src/services/shims.ts +++ b/src/services/shims.ts @@ -174,6 +174,7 @@ module ts { export enum LanguageVersion { EcmaScript3 = 0, EcmaScript5 = 1, + EcmaScript6 = 2, } export enum ModuleGenTarget { @@ -213,6 +214,7 @@ module ts { switch (languageVersion) { case LanguageVersion.EcmaScript3: return ScriptTarget.ES3 case LanguageVersion.EcmaScript5: return ScriptTarget.ES5; + case LanguageVersion.EcmaScript6: return ScriptTarget.ES6; default: throw Error("unsupported LanguageVersion value: " + languageVersion); } } @@ -234,6 +236,7 @@ module ts { switch (scriptTarget) { case ScriptTarget.ES3: return LanguageVersion.EcmaScript3; case ScriptTarget.ES5: return LanguageVersion.EcmaScript5; + case ScriptTarget.ES6: return LanguageVersion.EcmaScript6; default: throw Error("unsupported ScriptTarget value: " + scriptTarget); } } diff --git a/src/services/syntax/scanner.ts b/src/services/syntax/scanner.ts index 45cc151e2d5ba..29ced029f1cca 100644 --- a/src/services/syntax/scanner.ts +++ b/src/services/syntax/scanner.ts @@ -186,7 +186,7 @@ module TypeScript.Scanner { var lastTokenInfo = { leadingTriviaWidth: -1, width: -1 }; var lastTokenInfoTokenID: number = -1; - var triviaScanner = createScannerInternal(ts.ScriptTarget.ES5, SimpleText.fromString(""), () => { }); + var triviaScanner = createScannerInternal(ts.ScriptTarget.Latest, SimpleText.fromString(""), () => { }); interface IScannerToken extends ISyntaxToken { } diff --git a/src/services/syntax/unicode.ts b/src/services/syntax/unicode.ts index df2f88b74c576..b1e94090de743 100644 --- a/src/services/syntax/unicode.ts +++ b/src/services/syntax/unicode.ts @@ -84,7 +84,7 @@ module TypeScript { if (languageVersion === ts.ScriptTarget.ES3) { return Unicode.lookupInUnicodeMap(code, Unicode.unicodeES3IdentifierStart); } - else if (languageVersion === ts.ScriptTarget.ES5) { + else if (languageVersion >= ts.ScriptTarget.ES5) { return Unicode.lookupInUnicodeMap(code, Unicode.unicodeES5IdentifierStart); } else { @@ -96,7 +96,7 @@ module TypeScript { if (languageVersion === ts.ScriptTarget.ES3) { return Unicode.lookupInUnicodeMap(code, Unicode.unicodeES3IdentifierPart); } - else if (languageVersion === ts.ScriptTarget.ES5) { + else if (languageVersion >= ts.ScriptTarget.ES5) { return Unicode.lookupInUnicodeMap(code, Unicode.unicodeES5IdentifierPart); } else { diff --git a/tests/baselines/reference/constDeclarationShadowedByVarDeclaration.errors.txt b/tests/baselines/reference/constDeclarationShadowedByVarDeclaration.errors.txt new file mode 100644 index 0000000000000..629cf7f75af7e --- /dev/null +++ b/tests/baselines/reference/constDeclarationShadowedByVarDeclaration.errors.txt @@ -0,0 +1,35 @@ +tests/cases/compiler/constDeclarationShadowedByVarDeclaration.ts(7,9): error TS2451: Cannot redeclare block-scoped variable 'x'. +tests/cases/compiler/constDeclarationShadowedByVarDeclaration.ts(15,13): error TS2451: Cannot redeclare block-scoped variable 'y'. +tests/cases/compiler/constDeclarationShadowedByVarDeclaration.ts(22,7): error TS2451: Cannot redeclare block-scoped variable 'z'. + + +==== tests/cases/compiler/constDeclarationShadowedByVarDeclaration.ts (3 errors) ==== + + // Error as declaration of var would cause a write to the const value + var x = 0; + { + const x = 0; + + var x = 0; + ~ +!!! error TS2451: Cannot redeclare block-scoped variable 'x'. + } + + + var y = 0; + { + const y = 0; + { + var y = 0; + ~ +!!! error TS2451: Cannot redeclare block-scoped variable 'y'. + } + } + + + { + const z = 0; + var z = 0 + ~ +!!! error TS2451: Cannot redeclare block-scoped variable 'z'. + } \ No newline at end of file diff --git a/tests/baselines/reference/constDeclarationShadowedByVarDeclaration2.js b/tests/baselines/reference/constDeclarationShadowedByVarDeclaration2.js new file mode 100644 index 0000000000000..67d3e688075ad --- /dev/null +++ b/tests/baselines/reference/constDeclarationShadowedByVarDeclaration2.js @@ -0,0 +1,18 @@ +//// [constDeclarationShadowedByVarDeclaration2.ts] + +// No errors, const declaration is not shadowed +function outer() { + const x = 0; + function inner() { + var x = "inner"; + } +} + +//// [constDeclarationShadowedByVarDeclaration2.js] +// No errors, const declaration is not shadowed +function outer() { + const x = 0; + function inner() { + var x = "inner"; + } +} diff --git a/tests/baselines/reference/constDeclarationShadowedByVarDeclaration2.types b/tests/baselines/reference/constDeclarationShadowedByVarDeclaration2.types new file mode 100644 index 0000000000000..4217db455095a --- /dev/null +++ b/tests/baselines/reference/constDeclarationShadowedByVarDeclaration2.types @@ -0,0 +1,16 @@ +=== tests/cases/compiler/constDeclarationShadowedByVarDeclaration2.ts === + +// No errors, const declaration is not shadowed +function outer() { +>outer : () => void + + const x = 0; +>x : number + + function inner() { +>inner : () => void + + var x = "inner"; +>x : string + } +} diff --git a/tests/baselines/reference/constDeclarationShadowedByVarDeclaration3.js b/tests/baselines/reference/constDeclarationShadowedByVarDeclaration3.js new file mode 100644 index 0000000000000..6f5b898c5ff56 --- /dev/null +++ b/tests/baselines/reference/constDeclarationShadowedByVarDeclaration3.js @@ -0,0 +1,21 @@ +//// [constDeclarationShadowedByVarDeclaration3.ts] +// Ensure only checking for const declarations shadowed by vars +class Rule { + public regex: RegExp = new RegExp(''); + public name: string = ''; + + constructor(name: string) { + this.name = name; + } +} + +//// [constDeclarationShadowedByVarDeclaration3.js] +// Ensure only checking for const declarations shadowed by vars +var Rule = (function () { + function Rule(name) { + this.regex = new RegExp(''); + this.name = ''; + this.name = name; + } + return Rule; +})(); diff --git a/tests/baselines/reference/constDeclarationShadowedByVarDeclaration3.types b/tests/baselines/reference/constDeclarationShadowedByVarDeclaration3.types new file mode 100644 index 0000000000000..89490567f1449 --- /dev/null +++ b/tests/baselines/reference/constDeclarationShadowedByVarDeclaration3.types @@ -0,0 +1,25 @@ +=== tests/cases/compiler/constDeclarationShadowedByVarDeclaration3.ts === +// Ensure only checking for const declarations shadowed by vars +class Rule { +>Rule : Rule + + public regex: RegExp = new RegExp(''); +>regex : RegExp +>RegExp : RegExp +>new RegExp('') : RegExp +>RegExp : { (pattern: string, flags?: string): RegExp; new (pattern: string, flags?: string): RegExp; $1: string; $2: string; $3: string; $4: string; $5: string; $6: string; $7: string; $8: string; $9: string; lastMatch: string; } + + public name: string = ''; +>name : string + + constructor(name: string) { +>name : string + + this.name = name; +>this.name = name : string +>this.name : string +>this : Rule +>name : string +>name : string + } +} diff --git a/tests/baselines/reference/constDeclarations-access.errors.txt b/tests/baselines/reference/constDeclarations-access.errors.txt new file mode 100644 index 0000000000000..04b942aec09ef --- /dev/null +++ b/tests/baselines/reference/constDeclarations-access.errors.txt @@ -0,0 +1,11 @@ +tests/cases/compiler/file2.ts(1,1): error TS2449: The operand of an increment or decrement operator cannot be a constant. + + +==== tests/cases/compiler/file1.ts (0 errors) ==== + + const x = 0 + +==== tests/cases/compiler/file2.ts (1 errors) ==== + x++; + ~ +!!! error TS2449: The operand of an increment or decrement operator cannot be a constant. \ No newline at end of file diff --git a/tests/baselines/reference/constDeclarations-access2.errors.txt b/tests/baselines/reference/constDeclarations-access2.errors.txt new file mode 100644 index 0000000000000..6a360e11014e8 --- /dev/null +++ b/tests/baselines/reference/constDeclarations-access2.errors.txt @@ -0,0 +1,94 @@ +tests/cases/compiler/constDeclarations-access2.ts(5,1): error TS2450: Left-hand side of assignment expression cannot be a constant. +tests/cases/compiler/constDeclarations-access2.ts(6,1): error TS2450: Left-hand side of assignment expression cannot be a constant. +tests/cases/compiler/constDeclarations-access2.ts(7,1): error TS2450: Left-hand side of assignment expression cannot be a constant. +tests/cases/compiler/constDeclarations-access2.ts(8,1): error TS2450: Left-hand side of assignment expression cannot be a constant. +tests/cases/compiler/constDeclarations-access2.ts(9,1): error TS2450: Left-hand side of assignment expression cannot be a constant. +tests/cases/compiler/constDeclarations-access2.ts(10,1): error TS2450: Left-hand side of assignment expression cannot be a constant. +tests/cases/compiler/constDeclarations-access2.ts(11,1): error TS2450: Left-hand side of assignment expression cannot be a constant. +tests/cases/compiler/constDeclarations-access2.ts(12,1): error TS2450: Left-hand side of assignment expression cannot be a constant. +tests/cases/compiler/constDeclarations-access2.ts(13,1): error TS2450: Left-hand side of assignment expression cannot be a constant. +tests/cases/compiler/constDeclarations-access2.ts(14,1): error TS2450: Left-hand side of assignment expression cannot be a constant. +tests/cases/compiler/constDeclarations-access2.ts(15,1): error TS2450: Left-hand side of assignment expression cannot be a constant. +tests/cases/compiler/constDeclarations-access2.ts(16,1): error TS2450: Left-hand side of assignment expression cannot be a constant. +tests/cases/compiler/constDeclarations-access2.ts(18,1): error TS2449: The operand of an increment or decrement operator cannot be a constant. +tests/cases/compiler/constDeclarations-access2.ts(19,1): error TS2449: The operand of an increment or decrement operator cannot be a constant. +tests/cases/compiler/constDeclarations-access2.ts(20,3): error TS2449: The operand of an increment or decrement operator cannot be a constant. +tests/cases/compiler/constDeclarations-access2.ts(21,3): error TS2449: The operand of an increment or decrement operator cannot be a constant. +tests/cases/compiler/constDeclarations-access2.ts(23,3): error TS2449: The operand of an increment or decrement operator cannot be a constant. + + +==== tests/cases/compiler/constDeclarations-access2.ts (17 errors) ==== + + const x = 0 + + // Errors + x = 1; + ~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant. + x += 2; + ~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant. + x -= 3; + ~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant. + x *= 4; + ~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant. + x /= 5; + ~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant. + x %= 6; + ~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant. + x <<= 7; + ~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant. + x >>= 8; + ~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant. + x >>>= 9; + ~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant. + x &= 10; + ~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant. + x |= 11; + ~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant. + x ^= 12; + ~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant. + + x++; + ~ +!!! error TS2449: The operand of an increment or decrement operator cannot be a constant. + x--; + ~ +!!! error TS2449: The operand of an increment or decrement operator cannot be a constant. + ++x; + ~ +!!! error TS2449: The operand of an increment or decrement operator cannot be a constant. + --x; + ~ +!!! error TS2449: The operand of an increment or decrement operator cannot be a constant. + + ++((x)); + ~~~~~ +!!! error TS2449: The operand of an increment or decrement operator cannot be a constant. + + // OK + var a = x + 1; + + function f(v: number) { } + f(x); + + if (x) { } + + x; + (x); + + -x; + +x; + + x.toString(); + \ No newline at end of file diff --git a/tests/baselines/reference/constDeclarations-access3.errors.txt b/tests/baselines/reference/constDeclarations-access3.errors.txt new file mode 100644 index 0000000000000..577b087dff09a --- /dev/null +++ b/tests/baselines/reference/constDeclarations-access3.errors.txt @@ -0,0 +1,102 @@ +tests/cases/compiler/constDeclarations-access3.ts(8,1): error TS2450: Left-hand side of assignment expression cannot be a constant. +tests/cases/compiler/constDeclarations-access3.ts(9,1): error TS2450: Left-hand side of assignment expression cannot be a constant. +tests/cases/compiler/constDeclarations-access3.ts(10,1): error TS2450: Left-hand side of assignment expression cannot be a constant. +tests/cases/compiler/constDeclarations-access3.ts(11,1): error TS2450: Left-hand side of assignment expression cannot be a constant. +tests/cases/compiler/constDeclarations-access3.ts(12,1): error TS2450: Left-hand side of assignment expression cannot be a constant. +tests/cases/compiler/constDeclarations-access3.ts(13,1): error TS2450: Left-hand side of assignment expression cannot be a constant. +tests/cases/compiler/constDeclarations-access3.ts(14,1): error TS2450: Left-hand side of assignment expression cannot be a constant. +tests/cases/compiler/constDeclarations-access3.ts(15,1): error TS2450: Left-hand side of assignment expression cannot be a constant. +tests/cases/compiler/constDeclarations-access3.ts(16,1): error TS2450: Left-hand side of assignment expression cannot be a constant. +tests/cases/compiler/constDeclarations-access3.ts(17,1): error TS2450: Left-hand side of assignment expression cannot be a constant. +tests/cases/compiler/constDeclarations-access3.ts(18,1): error TS2450: Left-hand side of assignment expression cannot be a constant. +tests/cases/compiler/constDeclarations-access3.ts(19,1): error TS2450: Left-hand side of assignment expression cannot be a constant. +tests/cases/compiler/constDeclarations-access3.ts(21,1): error TS2449: The operand of an increment or decrement operator cannot be a constant. +tests/cases/compiler/constDeclarations-access3.ts(22,1): error TS2449: The operand of an increment or decrement operator cannot be a constant. +tests/cases/compiler/constDeclarations-access3.ts(23,3): error TS2449: The operand of an increment or decrement operator cannot be a constant. +tests/cases/compiler/constDeclarations-access3.ts(24,3): error TS2449: The operand of an increment or decrement operator cannot be a constant. +tests/cases/compiler/constDeclarations-access3.ts(26,3): error TS2449: The operand of an increment or decrement operator cannot be a constant. +tests/cases/compiler/constDeclarations-access3.ts(28,1): error TS2450: Left-hand side of assignment expression cannot be a constant. + + +==== tests/cases/compiler/constDeclarations-access3.ts (18 errors) ==== + + + module M { + export const x = 0; + } + + // Errors + M.x = 1; + ~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant. + M.x += 2; + ~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant. + M.x -= 3; + ~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant. + M.x *= 4; + ~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant. + M.x /= 5; + ~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant. + M.x %= 6; + ~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant. + M.x <<= 7; + ~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant. + M.x >>= 8; + ~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant. + M.x >>>= 9; + ~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant. + M.x &= 10; + ~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant. + M.x |= 11; + ~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant. + M.x ^= 12; + ~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant. + + M.x++; + ~~~ +!!! error TS2449: The operand of an increment or decrement operator cannot be a constant. + M.x--; + ~~~ +!!! error TS2449: The operand of an increment or decrement operator cannot be a constant. + ++M.x; + ~~~ +!!! error TS2449: The operand of an increment or decrement operator cannot be a constant. + --M.x; + ~~~ +!!! error TS2449: The operand of an increment or decrement operator cannot be a constant. + + ++((M.x)); + ~~~~~~~ +!!! error TS2449: The operand of an increment or decrement operator cannot be a constant. + + M["x"] = 0; + ~~~~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant. + + // OK + var a = M.x + 1; + + function f(v: number) { } + f(M.x); + + if (M.x) { } + + M.x; + (M.x); + + -M.x; + +M.x; + + M.x.toString(); + \ No newline at end of file diff --git a/tests/baselines/reference/constDeclarations-access4.errors.txt b/tests/baselines/reference/constDeclarations-access4.errors.txt new file mode 100644 index 0000000000000..9745c0d262497 --- /dev/null +++ b/tests/baselines/reference/constDeclarations-access4.errors.txt @@ -0,0 +1,102 @@ +tests/cases/compiler/constDeclarations-access4.ts(8,1): error TS2450: Left-hand side of assignment expression cannot be a constant. +tests/cases/compiler/constDeclarations-access4.ts(9,1): error TS2450: Left-hand side of assignment expression cannot be a constant. +tests/cases/compiler/constDeclarations-access4.ts(10,1): error TS2450: Left-hand side of assignment expression cannot be a constant. +tests/cases/compiler/constDeclarations-access4.ts(11,1): error TS2450: Left-hand side of assignment expression cannot be a constant. +tests/cases/compiler/constDeclarations-access4.ts(12,1): error TS2450: Left-hand side of assignment expression cannot be a constant. +tests/cases/compiler/constDeclarations-access4.ts(13,1): error TS2450: Left-hand side of assignment expression cannot be a constant. +tests/cases/compiler/constDeclarations-access4.ts(14,1): error TS2450: Left-hand side of assignment expression cannot be a constant. +tests/cases/compiler/constDeclarations-access4.ts(15,1): error TS2450: Left-hand side of assignment expression cannot be a constant. +tests/cases/compiler/constDeclarations-access4.ts(16,1): error TS2450: Left-hand side of assignment expression cannot be a constant. +tests/cases/compiler/constDeclarations-access4.ts(17,1): error TS2450: Left-hand side of assignment expression cannot be a constant. +tests/cases/compiler/constDeclarations-access4.ts(18,1): error TS2450: Left-hand side of assignment expression cannot be a constant. +tests/cases/compiler/constDeclarations-access4.ts(19,1): error TS2450: Left-hand side of assignment expression cannot be a constant. +tests/cases/compiler/constDeclarations-access4.ts(21,1): error TS2449: The operand of an increment or decrement operator cannot be a constant. +tests/cases/compiler/constDeclarations-access4.ts(22,1): error TS2449: The operand of an increment or decrement operator cannot be a constant. +tests/cases/compiler/constDeclarations-access4.ts(23,3): error TS2449: The operand of an increment or decrement operator cannot be a constant. +tests/cases/compiler/constDeclarations-access4.ts(24,3): error TS2449: The operand of an increment or decrement operator cannot be a constant. +tests/cases/compiler/constDeclarations-access4.ts(26,3): error TS2449: The operand of an increment or decrement operator cannot be a constant. +tests/cases/compiler/constDeclarations-access4.ts(28,1): error TS2450: Left-hand side of assignment expression cannot be a constant. + + +==== tests/cases/compiler/constDeclarations-access4.ts (18 errors) ==== + + + declare module M { + const x: number; + } + + // Errors + M.x = 1; + ~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant. + M.x += 2; + ~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant. + M.x -= 3; + ~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant. + M.x *= 4; + ~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant. + M.x /= 5; + ~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant. + M.x %= 6; + ~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant. + M.x <<= 7; + ~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant. + M.x >>= 8; + ~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant. + M.x >>>= 9; + ~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant. + M.x &= 10; + ~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant. + M.x |= 11; + ~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant. + M.x ^= 12; + ~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant. + + M.x++; + ~~~ +!!! error TS2449: The operand of an increment or decrement operator cannot be a constant. + M.x--; + ~~~ +!!! error TS2449: The operand of an increment or decrement operator cannot be a constant. + ++M.x; + ~~~ +!!! error TS2449: The operand of an increment or decrement operator cannot be a constant. + --M.x; + ~~~ +!!! error TS2449: The operand of an increment or decrement operator cannot be a constant. + + ++((M.x)); + ~~~~~~~ +!!! error TS2449: The operand of an increment or decrement operator cannot be a constant. + + M["x"] = 0; + ~~~~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant. + + // OK + var a = M.x + 1; + + function f(v: number) { } + f(M.x); + + if (M.x) { } + + M.x; + (M.x); + + -M.x; + +M.x; + + M.x.toString(); + \ No newline at end of file diff --git a/tests/baselines/reference/constDeclarations-access5.errors.txt b/tests/baselines/reference/constDeclarations-access5.errors.txt new file mode 100644 index 0000000000000..23200e50ee42b --- /dev/null +++ b/tests/baselines/reference/constDeclarations-access5.errors.txt @@ -0,0 +1,103 @@ +tests/cases/compiler/constDeclarations_access_2.ts(4,1): error TS2450: Left-hand side of assignment expression cannot be a constant. +tests/cases/compiler/constDeclarations_access_2.ts(5,1): error TS2450: Left-hand side of assignment expression cannot be a constant. +tests/cases/compiler/constDeclarations_access_2.ts(6,1): error TS2450: Left-hand side of assignment expression cannot be a constant. +tests/cases/compiler/constDeclarations_access_2.ts(7,1): error TS2450: Left-hand side of assignment expression cannot be a constant. +tests/cases/compiler/constDeclarations_access_2.ts(8,1): error TS2450: Left-hand side of assignment expression cannot be a constant. +tests/cases/compiler/constDeclarations_access_2.ts(9,1): error TS2450: Left-hand side of assignment expression cannot be a constant. +tests/cases/compiler/constDeclarations_access_2.ts(10,1): error TS2450: Left-hand side of assignment expression cannot be a constant. +tests/cases/compiler/constDeclarations_access_2.ts(11,1): error TS2450: Left-hand side of assignment expression cannot be a constant. +tests/cases/compiler/constDeclarations_access_2.ts(12,1): error TS2450: Left-hand side of assignment expression cannot be a constant. +tests/cases/compiler/constDeclarations_access_2.ts(13,1): error TS2450: Left-hand side of assignment expression cannot be a constant. +tests/cases/compiler/constDeclarations_access_2.ts(14,1): error TS2450: Left-hand side of assignment expression cannot be a constant. +tests/cases/compiler/constDeclarations_access_2.ts(15,1): error TS2450: Left-hand side of assignment expression cannot be a constant. +tests/cases/compiler/constDeclarations_access_2.ts(17,1): error TS2449: The operand of an increment or decrement operator cannot be a constant. +tests/cases/compiler/constDeclarations_access_2.ts(18,1): error TS2449: The operand of an increment or decrement operator cannot be a constant. +tests/cases/compiler/constDeclarations_access_2.ts(19,3): error TS2449: The operand of an increment or decrement operator cannot be a constant. +tests/cases/compiler/constDeclarations_access_2.ts(20,3): error TS2449: The operand of an increment or decrement operator cannot be a constant. +tests/cases/compiler/constDeclarations_access_2.ts(22,3): error TS2449: The operand of an increment or decrement operator cannot be a constant. +tests/cases/compiler/constDeclarations_access_2.ts(24,1): error TS2450: Left-hand side of assignment expression cannot be a constant. + + +==== tests/cases/compiler/constDeclarations_access_2.ts (18 errors) ==== + /// + import m = require('constDeclarations_access_1'); + // Errors + m.x = 1; + ~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant. + m.x += 2; + ~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant. + m.x -= 3; + ~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant. + m.x *= 4; + ~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant. + m.x /= 5; + ~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant. + m.x %= 6; + ~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant. + m.x <<= 7; + ~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant. + m.x >>= 8; + ~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant. + m.x >>>= 9; + ~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant. + m.x &= 10; + ~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant. + m.x |= 11; + ~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant. + m.x ^= 12; + ~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant. + m + m.x++; + ~~~ +!!! error TS2449: The operand of an increment or decrement operator cannot be a constant. + m.x--; + ~~~ +!!! error TS2449: The operand of an increment or decrement operator cannot be a constant. + ++m.x; + ~~~ +!!! error TS2449: The operand of an increment or decrement operator cannot be a constant. + --m.x; + ~~~ +!!! error TS2449: The operand of an increment or decrement operator cannot be a constant. + + ++((m.x)); + ~~~~~~~ +!!! error TS2449: The operand of an increment or decrement operator cannot be a constant. + + m["x"] = 0; + ~~~~~~ +!!! error TS2450: Left-hand side of assignment expression cannot be a constant. + + // OK + var a = m.x + 1; + + function f(v: number) { } + f(m.x); + + if (m.x) { } + + m.x; + (m.x); + + -m.x; + +m.x; + + m.x.toString(); + +==== tests/cases/compiler/constDeclarations_access_1.ts (0 errors) ==== + + + export const x = 0; + \ No newline at end of file diff --git a/tests/baselines/reference/constDeclarations-ambient-errors.errors.txt b/tests/baselines/reference/constDeclarations-ambient-errors.errors.txt new file mode 100644 index 0000000000000..6e2d00dc4c42c --- /dev/null +++ b/tests/baselines/reference/constDeclarations-ambient-errors.errors.txt @@ -0,0 +1,34 @@ +tests/cases/compiler/constDeclarations-ambient-errors.ts(3,27): error TS1039: Initializers are not allowed in ambient contexts. +tests/cases/compiler/constDeclarations-ambient-errors.ts(4,26): error TS1039: Initializers are not allowed in ambient contexts. +tests/cases/compiler/constDeclarations-ambient-errors.ts(5,18): error TS1039: Initializers are not allowed in ambient contexts. +tests/cases/compiler/constDeclarations-ambient-errors.ts(5,37): error TS1039: Initializers are not allowed in ambient contexts. +tests/cases/compiler/constDeclarations-ambient-errors.ts(5,51): error TS1039: Initializers are not allowed in ambient contexts. +tests/cases/compiler/constDeclarations-ambient-errors.ts(8,14): error TS1039: Initializers are not allowed in ambient contexts. +tests/cases/compiler/constDeclarations-ambient-errors.ts(9,22): error TS1039: Initializers are not allowed in ambient contexts. + + +==== tests/cases/compiler/constDeclarations-ambient-errors.ts (7 errors) ==== + + // error: no intialization expected in ambient declarations + declare const c1: boolean = true; + ~ +!!! error TS1039: Initializers are not allowed in ambient contexts. + declare const c2: number = 0; + ~ +!!! error TS1039: Initializers are not allowed in ambient contexts. + declare const c3 = null, c4 :string = "", c5: any = 0; + ~ +!!! error TS1039: Initializers are not allowed in ambient contexts. + ~ +!!! error TS1039: Initializers are not allowed in ambient contexts. + ~ +!!! error TS1039: Initializers are not allowed in ambient contexts. + + declare module M { + const c6 = 0; + ~ +!!! error TS1039: Initializers are not allowed in ambient contexts. + const c7: number = 7; + ~ +!!! error TS1039: Initializers are not allowed in ambient contexts. + } \ No newline at end of file diff --git a/tests/baselines/reference/constDeclarations-ambient.js b/tests/baselines/reference/constDeclarations-ambient.js new file mode 100644 index 0000000000000..dd78f73051aa4 --- /dev/null +++ b/tests/baselines/reference/constDeclarations-ambient.js @@ -0,0 +1,13 @@ +//// [constDeclarations-ambient.ts] + +// No error +declare const c1: boolean; +declare const c2: number; +declare const c3, c4 :string, c5: any; + +declare module M { + const c6; + const c7: number; +} + +//// [constDeclarations-ambient.js] diff --git a/tests/baselines/reference/constDeclarations-ambient.types b/tests/baselines/reference/constDeclarations-ambient.types new file mode 100644 index 0000000000000..0ab2d4b700a69 --- /dev/null +++ b/tests/baselines/reference/constDeclarations-ambient.types @@ -0,0 +1,23 @@ +=== tests/cases/compiler/constDeclarations-ambient.ts === + +// No error +declare const c1: boolean; +>c1 : boolean + +declare const c2: number; +>c2 : number + +declare const c3, c4 :string, c5: any; +>c3 : any +>c4 : string +>c5 : any + +declare module M { +>M : typeof M + + const c6; +>c6 : any + + const c7: number; +>c7 : number +} diff --git a/tests/baselines/reference/constDeclarations-errors.errors.txt b/tests/baselines/reference/constDeclarations-errors.errors.txt new file mode 100644 index 0000000000000..d87007474a1a4 --- /dev/null +++ b/tests/baselines/reference/constDeclarations-errors.errors.txt @@ -0,0 +1,50 @@ +tests/cases/compiler/constDeclarations-errors.ts(3,7): error TS1155: 'const' declarations must be initialized +tests/cases/compiler/constDeclarations-errors.ts(4,7): error TS1155: 'const' declarations must be initialized +tests/cases/compiler/constDeclarations-errors.ts(5,7): error TS1155: 'const' declarations must be initialized +tests/cases/compiler/constDeclarations-errors.ts(5,11): error TS1155: 'const' declarations must be initialized +tests/cases/compiler/constDeclarations-errors.ts(5,15): error TS1155: 'const' declarations must be initialized +tests/cases/compiler/constDeclarations-errors.ts(5,27): error TS1155: 'const' declarations must be initialized +tests/cases/compiler/constDeclarations-errors.ts(8,11): error TS1155: 'const' declarations must be initialized +tests/cases/compiler/constDeclarations-errors.ts(14,11): error TS1155: 'const' declarations must be initialized +tests/cases/compiler/constDeclarations-errors.ts(17,20): error TS1155: 'const' declarations must be initialized +tests/cases/compiler/constDeclarations-errors.ts(11,27): error TS2449: The operand of an increment or decrement operator cannot be a constant. + + +==== tests/cases/compiler/constDeclarations-errors.ts (10 errors) ==== + + // error, missing intialicer + const c1; + ~~ +!!! error TS1155: 'const' declarations must be initialized + const c2: number; + ~~ +!!! error TS1155: 'const' declarations must be initialized + const c3, c4, c5 :string, c6; // error, missing initialicer + ~~ +!!! error TS1155: 'const' declarations must be initialized + ~~ +!!! error TS1155: 'const' declarations must be initialized + ~~ +!!! error TS1155: 'const' declarations must be initialized + ~~ +!!! error TS1155: 'const' declarations must be initialized + + // error, can not be unintalized + for(const c in {}) { } + ~ +!!! error TS1155: 'const' declarations must be initialized + + // error, assigning to a const + for(const c8 = 0; c8 < 1; c8++) { } + ~~ +!!! error TS2449: The operand of an increment or decrement operator cannot be a constant. + + // error, can not be unintalized + for(const c9; c9 < 1;) { } + ~~ +!!! error TS1155: 'const' declarations must be initialized + + // error, can not be unintalized + for(const c10 = 0, c11; c10 < 1;) { } + ~~~ +!!! error TS1155: 'const' declarations must be initialized \ No newline at end of file diff --git a/tests/baselines/reference/constDeclarations-es5.errors.txt b/tests/baselines/reference/constDeclarations-es5.errors.txt new file mode 100644 index 0000000000000..0b830eab05a82 --- /dev/null +++ b/tests/baselines/reference/constDeclarations-es5.errors.txt @@ -0,0 +1,17 @@ +tests/cases/compiler/constDeclarations-es5.ts(2,1): error TS1154: 'const' declarations are only available when targeting ECMAScript 6 and higher. +tests/cases/compiler/constDeclarations-es5.ts(3,1): error TS1154: 'const' declarations are only available when targeting ECMAScript 6 and higher. +tests/cases/compiler/constDeclarations-es5.ts(4,1): error TS1154: 'const' declarations are only available when targeting ECMAScript 6 and higher. + + +==== tests/cases/compiler/constDeclarations-es5.ts (3 errors) ==== + + const z7 = false; + ~~~~~~~~~~~~~~~~~ +!!! error TS1154: 'const' declarations are only available when targeting ECMAScript 6 and higher. + const z8: number = 23; + ~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1154: 'const' declarations are only available when targeting ECMAScript 6 and higher. + const z9 = 0, z10 :string = "", z11 = null; + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1154: 'const' declarations are only available when targeting ECMAScript 6 and higher. + \ No newline at end of file diff --git a/tests/baselines/reference/constDeclarations-invalidContexts.errors.txt b/tests/baselines/reference/constDeclarations-invalidContexts.errors.txt new file mode 100644 index 0000000000000..745ef305ac6ba --- /dev/null +++ b/tests/baselines/reference/constDeclarations-invalidContexts.errors.txt @@ -0,0 +1,66 @@ +tests/cases/compiler/constDeclarations-invalidContexts.ts(4,5): error TS1156: 'const' declarations can only be declared inside a block. +tests/cases/compiler/constDeclarations-invalidContexts.ts(6,5): error TS1156: 'const' declarations can only be declared inside a block. +tests/cases/compiler/constDeclarations-invalidContexts.ts(9,5): error TS1156: 'const' declarations can only be declared inside a block. +tests/cases/compiler/constDeclarations-invalidContexts.ts(12,5): error TS1156: 'const' declarations can only be declared inside a block. +tests/cases/compiler/constDeclarations-invalidContexts.ts(17,5): error TS1156: 'const' declarations can only be declared inside a block. +tests/cases/compiler/constDeclarations-invalidContexts.ts(20,5): error TS1156: 'const' declarations can only be declared inside a block. +tests/cases/compiler/constDeclarations-invalidContexts.ts(23,5): error TS1156: 'const' declarations can only be declared inside a block. +tests/cases/compiler/constDeclarations-invalidContexts.ts(26,12): error TS1156: 'const' declarations can only be declared inside a block. +tests/cases/compiler/constDeclarations-invalidContexts.ts(29,29): error TS1156: 'const' declarations can only be declared inside a block. +tests/cases/compiler/constDeclarations-invalidContexts.ts(16,7): error TS2410: All symbols within a 'with' block will be resolved to 'any'. + + +==== tests/cases/compiler/constDeclarations-invalidContexts.ts (10 errors) ==== + + // Errors, const must be defined inside a block + if (true) + const c1 = 0; + ~~~~~~~~~~~~~ +!!! error TS1156: 'const' declarations can only be declared inside a block. + else + const c2 = 0; + ~~~~~~~~~~~~~ +!!! error TS1156: 'const' declarations can only be declared inside a block. + + while (true) + const c3 = 0; + ~~~~~~~~~~~~~ +!!! error TS1156: 'const' declarations can only be declared inside a block. + + do + const c4 = 0; + ~~~~~~~~~~~~~ +!!! error TS1156: 'const' declarations can only be declared inside a block. + while (true); + + var obj; + with (obj) + ~~~ +!!! error TS2410: All symbols within a 'with' block will be resolved to 'any'. + const c5 = 0; + ~~~~~~~~~~~~~ +!!! error TS1156: 'const' declarations can only be declared inside a block. + + for (var i = 0; i < 10; i++) + const c6 = 0; + ~~~~~~~~~~~~~ +!!! error TS1156: 'const' declarations can only be declared inside a block. + + for (var i2 in {}) + const c7 = 0; + ~~~~~~~~~~~~~ +!!! error TS1156: 'const' declarations can only be declared inside a block. + + if (true) + label: const c8 = 0; + ~~~~~~~~~~~~~ +!!! error TS1156: 'const' declarations can only be declared inside a block. + + while (false) + label2: label3: label4: const c9 = 0; + ~~~~~~~~~~~~~ +!!! error TS1156: 'const' declarations can only be declared inside a block. + + + + \ No newline at end of file diff --git a/tests/baselines/reference/constDeclarations-scopes.errors.txt b/tests/baselines/reference/constDeclarations-scopes.errors.txt new file mode 100644 index 0000000000000..138acd9b16d1c --- /dev/null +++ b/tests/baselines/reference/constDeclarations-scopes.errors.txt @@ -0,0 +1,153 @@ +tests/cases/compiler/constDeclarations-scopes.ts(28,7): error TS2410: All symbols within a 'with' block will be resolved to 'any'. + + +==== tests/cases/compiler/constDeclarations-scopes.ts (1 errors) ==== + + // global + const c = "string"; + + var n: number; + + // Control flow statements with blocks + if (true) { + const c = 0; + n = c; + } + else { + const c = 0; + n = c; + } + + while (true) { + const c = 0; + n = c; + } + + do { + const c = 0; + n = c; + } while (true); + + var obj; + with (obj) { + ~~~ +!!! error TS2410: All symbols within a 'with' block will be resolved to 'any'. + const c = 0; + n = c; + } + + for (var i = 0; i < 10; i++) { + const c = 0; + n = c; + } + + for (var i2 in {}) { + const c = 0; + n = c; + } + + if (true) { + label: const c = 0; + n = c; + } + + while (false) { + label2: label3: label4: const c = 0; + n = c; + } + + // Try/catch/finally + try { + const c = 0; + n = c; + } + catch (e) { + const c = 0; + n = c; + } + finally { + const c = 0; + n = c; + } + + // Switch + switch (0) { + case 0: + const c = 0; + n = c; + break; + } + + // blocks + { + const c = 0; + n = c; + { + const c = false; + var b: boolean = c; + } + } + + // functions + + function F() { + const c = 0; + n = c; + } + + var F2 = () => { + const c = 0; + n = c; + }; + + var F3 = function () { + const c = 0; + n = c; + }; + + // modules + module m { + const c = 0; + n = c; + + { + const c = false; + var b2: boolean = c; + } + } + + // methods + class C { + constructor() { + const c = 0; + n = c; + } + + method() { + const c = 0; + n = c; + } + + get v() { + const c = 0; + n = c; + return n; + } + + set v(value) { + const c = 0; + n = c; + } + } + + // object literals + var o = { + f() { + const c = 0; + n = c; + }, + f2: () => { + const c = 0; + n = c; + } + } \ No newline at end of file diff --git a/tests/baselines/reference/constDeclarations-scopes.js b/tests/baselines/reference/constDeclarations-scopes.js new file mode 100644 index 0000000000000..800dd856422ea --- /dev/null +++ b/tests/baselines/reference/constDeclarations-scopes.js @@ -0,0 +1,276 @@ +//// [constDeclarations-scopes.ts] + +// global +const c = "string"; + +var n: number; + +// Control flow statements with blocks +if (true) { + const c = 0; + n = c; +} +else { + const c = 0; + n = c; +} + +while (true) { + const c = 0; + n = c; +} + +do { + const c = 0; + n = c; +} while (true); + +var obj; +with (obj) { + const c = 0; + n = c; +} + +for (var i = 0; i < 10; i++) { + const c = 0; + n = c; +} + +for (var i2 in {}) { + const c = 0; + n = c; +} + +if (true) { + label: const c = 0; + n = c; +} + +while (false) { + label2: label3: label4: const c = 0; + n = c; +} + +// Try/catch/finally +try { + const c = 0; + n = c; +} +catch (e) { + const c = 0; + n = c; +} +finally { + const c = 0; + n = c; +} + +// Switch +switch (0) { + case 0: + const c = 0; + n = c; + break; +} + +// blocks +{ + const c = 0; + n = c; + { + const c = false; + var b: boolean = c; + } +} + +// functions + +function F() { + const c = 0; + n = c; +} + +var F2 = () => { + const c = 0; + n = c; +}; + +var F3 = function () { + const c = 0; + n = c; +}; + +// modules +module m { + const c = 0; + n = c; + + { + const c = false; + var b2: boolean = c; + } +} + +// methods +class C { + constructor() { + const c = 0; + n = c; + } + + method() { + const c = 0; + n = c; + } + + get v() { + const c = 0; + n = c; + return n; + } + + set v(value) { + const c = 0; + n = c; + } +} + +// object literals +var o = { + f() { + const c = 0; + n = c; + }, + f2: () => { + const c = 0; + n = c; + } +} + +//// [constDeclarations-scopes.js] +// global +const c = "string"; +var n; +// Control flow statements with blocks +if (true) { + const c = 0; + n = c; +} +else { + const c = 0; + n = c; +} +while (true) { + const c = 0; + n = c; +} +do { + const c = 0; + n = c; +} while (true); +var obj; +with (obj) { + const c = 0; + n = c; +} +for (var i = 0; i < 10; i++) { + const c = 0; + n = c; +} +for (var i2 in {}) { + const c = 0; + n = c; +} +if (true) { + label: const c = 0; + n = c; +} +while (false) { + label2: label3: label4: const c = 0; + n = c; +} +try { + const c = 0; + n = c; +} +catch (e) { + const c = 0; + n = c; +} +finally { + const c = 0; + n = c; +} +switch (0) { + case 0: + const c = 0; + n = c; + break; +} +{ + const c = 0; + n = c; + { + const c = false; + var b = c; + } +} +// functions +function F() { + const c = 0; + n = c; +} +var F2 = function () { + const c = 0; + n = c; +}; +var F3 = function () { + const c = 0; + n = c; +}; +// modules +var m; +(function (m) { + const c = 0; + n = c; + { + const c = false; + var b2 = c; + } +})(m || (m = {})); +// methods +var C = (function () { + function C() { + const c = 0; + n = c; + } + C.prototype.method = function () { + const c = 0; + n = c; + }; + Object.defineProperty(C.prototype, "v", { + get: function () { + const c = 0; + n = c; + return n; + }, + set: function (value) { + const c = 0; + n = c; + }, + enumerable: true, + configurable: true + }); + return C; +})(); +// object literals +var o = { + f: function () { + const c = 0; + n = c; + }, + f2: function () { + const c = 0; + n = c; + } +}; diff --git a/tests/baselines/reference/constDeclarations-scopes2.js b/tests/baselines/reference/constDeclarations-scopes2.js new file mode 100644 index 0000000000000..1d0f252ab4f2d --- /dev/null +++ b/tests/baselines/reference/constDeclarations-scopes2.js @@ -0,0 +1,27 @@ +//// [constDeclarations-scopes2.ts] + +// global +const c = "string"; + +var n: number; +var b: boolean; + +// for scope +for (const c = 0; c < 10; n = c ) { + // for block + const c = false; + b = c; +} + + + +//// [constDeclarations-scopes2.js] +// global +const c = "string"; +var n; +var b; +for (const c = 0; c < 10; n = c) { + // for block + const c = false; + b = c; +} diff --git a/tests/baselines/reference/constDeclarations-scopes2.types b/tests/baselines/reference/constDeclarations-scopes2.types new file mode 100644 index 0000000000000..9609ef8f44b1e --- /dev/null +++ b/tests/baselines/reference/constDeclarations-scopes2.types @@ -0,0 +1,32 @@ +=== tests/cases/compiler/constDeclarations-scopes2.ts === + +// global +const c = "string"; +>c : string + +var n: number; +>n : number + +var b: boolean; +>b : boolean + +// for scope +for (const c = 0; c < 10; n = c ) { +>c : number +>c < 10 : boolean +>c : number +>n = c : number +>n : number +>c : number + + // for block + const c = false; +>c : boolean + + b = c; +>b = c : boolean +>b : boolean +>c : boolean +} + + diff --git a/tests/baselines/reference/constDeclarations-useBeforeDefinition.errors.txt b/tests/baselines/reference/constDeclarations-useBeforeDefinition.errors.txt new file mode 100644 index 0000000000000..97cf58c6e9d23 --- /dev/null +++ b/tests/baselines/reference/constDeclarations-useBeforeDefinition.errors.txt @@ -0,0 +1,21 @@ +tests/cases/compiler/constDeclarations-useBeforeDefinition.ts(3,5): error TS2448: Block-scoped variable 'c1' used before its declaration. +tests/cases/compiler/constDeclarations-useBeforeDefinition.ts(9,5): error TS2448: Block-scoped variable 'v1' used before its declaration. + + +==== tests/cases/compiler/constDeclarations-useBeforeDefinition.ts (2 errors) ==== + + { + c1; + ~~ +!!! error TS2448: Block-scoped variable 'c1' used before its declaration. + const c1 = 0; + } + + var v1; + { + v1; + ~~ +!!! error TS2448: Block-scoped variable 'v1' used before its declaration. + const v1 = 0; + } + \ No newline at end of file diff --git a/tests/baselines/reference/constDeclarations-useBeforeDefinition2.errors.txt b/tests/baselines/reference/constDeclarations-useBeforeDefinition2.errors.txt new file mode 100644 index 0000000000000..a4d28f5187857 --- /dev/null +++ b/tests/baselines/reference/constDeclarations-useBeforeDefinition2.errors.txt @@ -0,0 +1,11 @@ +tests/cases/compiler/file1.ts(2,1): error TS2448: Block-scoped variable 'c' used before its declaration. + + +==== tests/cases/compiler/file1.ts (1 errors) ==== + + c; + ~ +!!! error TS2448: Block-scoped variable 'c' used before its declaration. + +==== tests/cases/compiler/file2.ts (0 errors) ==== + const c = 0; \ No newline at end of file diff --git a/tests/baselines/reference/constDeclarations-validContexts.errors.txt b/tests/baselines/reference/constDeclarations-validContexts.errors.txt new file mode 100644 index 0000000000000..7af16a53cbe7e --- /dev/null +++ b/tests/baselines/reference/constDeclarations-validContexts.errors.txt @@ -0,0 +1,129 @@ +tests/cases/compiler/constDeclarations-validContexts.ts(20,7): error TS2410: All symbols within a 'with' block will be resolved to 'any'. + + +==== tests/cases/compiler/constDeclarations-validContexts.ts (1 errors) ==== + + + // Control flow statements with blocks + if (true) { + const c1 = 0; + } + else { + const c2 = 0; + } + + while (true) { + const c3 = 0; + } + + do { + const c4 = 0; + } while (true); + + var obj; + with (obj) { + ~~~ +!!! error TS2410: All symbols within a 'with' block will be resolved to 'any'. + const c5 = 0; + } + + for (var i = 0; i < 10; i++) { + const c6 = 0; + } + + for (var i2 in {}) { + const c7 = 0; + } + + if (true) { + label: const c8 = 0; + } + + while (false) { + label2: label3: label4: const c9 = 0; + } + + // Try/catch/finally + try { + const c10 = 0; + } + catch (e) { + const c11 = 0; + } + finally { + const c12 = 0; + } + + // Switch + switch (0) { + case 0: + const c13 = 0; + break; + default: + const c14 = 0; + break; + } + + // blocks + { + const c15 = 0; + { + const c16 = 0 + label17: const c17 = 0; + } + } + + // global + const c18 = 0; + + // functions + function F() { + const c19 = 0; + } + + var F2 = () => { + const c20 = 0; + }; + + var F3 = function () { + const c21 = 0; + }; + + // modules + module m { + const c22 = 0; + + { + const c23 = 0; + } + } + + // methods + class C { + constructor() { + const c24 = 0; + } + + method() { + const c25 = 0; + } + + get v() { + const c26 = 0; + return c26; + } + + set v(value) { + const c27 = value; + } + } + + // object literals + var o = { + f() { + const c28 = 0; + }, + f2: () => { + const c29 = 0; + } + } \ No newline at end of file diff --git a/tests/baselines/reference/constDeclarations-validContexts.js b/tests/baselines/reference/constDeclarations-validContexts.js new file mode 100644 index 0000000000000..355f39af2f2f9 --- /dev/null +++ b/tests/baselines/reference/constDeclarations-validContexts.js @@ -0,0 +1,229 @@ +//// [constDeclarations-validContexts.ts] + + +// Control flow statements with blocks +if (true) { + const c1 = 0; +} +else { + const c2 = 0; +} + +while (true) { + const c3 = 0; +} + +do { + const c4 = 0; +} while (true); + +var obj; +with (obj) { + const c5 = 0; +} + +for (var i = 0; i < 10; i++) { + const c6 = 0; +} + +for (var i2 in {}) { + const c7 = 0; +} + +if (true) { + label: const c8 = 0; +} + +while (false) { + label2: label3: label4: const c9 = 0; +} + +// Try/catch/finally +try { + const c10 = 0; +} +catch (e) { + const c11 = 0; +} +finally { + const c12 = 0; +} + +// Switch +switch (0) { + case 0: + const c13 = 0; + break; + default: + const c14 = 0; + break; +} + +// blocks +{ + const c15 = 0; + { + const c16 = 0 + label17: const c17 = 0; + } +} + +// global +const c18 = 0; + +// functions +function F() { + const c19 = 0; +} + +var F2 = () => { + const c20 = 0; +}; + +var F3 = function () { + const c21 = 0; +}; + +// modules +module m { + const c22 = 0; + + { + const c23 = 0; + } +} + +// methods +class C { + constructor() { + const c24 = 0; + } + + method() { + const c25 = 0; + } + + get v() { + const c26 = 0; + return c26; + } + + set v(value) { + const c27 = value; + } +} + +// object literals +var o = { + f() { + const c28 = 0; + }, + f2: () => { + const c29 = 0; + } +} + +//// [constDeclarations-validContexts.js] +// Control flow statements with blocks +if (true) { + const c1 = 0; +} +else { + const c2 = 0; +} +while (true) { + const c3 = 0; +} +do { + const c4 = 0; +} while (true); +var obj; +with (obj) { + const c5 = 0; +} +for (var i = 0; i < 10; i++) { + const c6 = 0; +} +for (var i2 in {}) { + const c7 = 0; +} +if (true) { + label: const c8 = 0; +} +while (false) { + label2: label3: label4: const c9 = 0; +} +try { + const c10 = 0; +} +catch (e) { + const c11 = 0; +} +finally { + const c12 = 0; +} +switch (0) { + case 0: + const c13 = 0; + break; + default: + const c14 = 0; + break; +} +{ + const c15 = 0; + { + const c16 = 0; + label17: const c17 = 0; + } +} +// global +const c18 = 0; +// functions +function F() { + const c19 = 0; +} +var F2 = function () { + const c20 = 0; +}; +var F3 = function () { + const c21 = 0; +}; +// modules +var m; +(function (m) { + const c22 = 0; + { + const c23 = 0; + } +})(m || (m = {})); +// methods +var C = (function () { + function C() { + const c24 = 0; + } + C.prototype.method = function () { + const c25 = 0; + }; + Object.defineProperty(C.prototype, "v", { + get: function () { + const c26 = 0; + return c26; + }, + set: function (value) { + const c27 = value; + }, + enumerable: true, + configurable: true + }); + return C; +})(); +// object literals +var o = { + f: function () { + const c28 = 0; + }, + f2: function () { + const c29 = 0; + } +}; diff --git a/tests/baselines/reference/constDeclarations.js b/tests/baselines/reference/constDeclarations.js new file mode 100644 index 0000000000000..060c0aba61cd6 --- /dev/null +++ b/tests/baselines/reference/constDeclarations.js @@ -0,0 +1,30 @@ +//// [constDeclarations.ts] + +// No error +const c1 = false; +const c2: number = 23; +const c3 = 0, c4 :string = "", c5 = null; + + +for(const c4 = 0; c4 < 9; ) { break; } + + +for(const c5 = 0, c6 = 0; c5 < c6; ) { break; } + +//// [constDeclarations.js] +// No error +const c1 = false; +const c2 = 23; +const c3 = 0, c4 = "", c5 = null; +for (const c4 = 0; c4 < 9;) { + break; +} +for (const c5 = 0, c6 = 0; c5 < c6;) { + break; +} + + +//// [constDeclarations.d.ts] +declare const c1: boolean; +declare const c2: number; +declare const c3: number, c4: string, c5: any; diff --git a/tests/baselines/reference/constDeclarations.types b/tests/baselines/reference/constDeclarations.types new file mode 100644 index 0000000000000..e82a2f0035f50 --- /dev/null +++ b/tests/baselines/reference/constDeclarations.types @@ -0,0 +1,28 @@ +=== tests/cases/compiler/constDeclarations.ts === + +// No error +const c1 = false; +>c1 : boolean + +const c2: number = 23; +>c2 : number + +const c3 = 0, c4 :string = "", c5 = null; +>c3 : number +>c4 : string +>c5 : any + + +for(const c4 = 0; c4 < 9; ) { break; } +>c4 : number +>c4 < 9 : boolean +>c4 : number + + +for(const c5 = 0, c6 = 0; c5 < c6; ) { break; } +>c5 : number +>c6 : number +>c5 < c6 : boolean +>c5 : number +>c6 : number + diff --git a/tests/baselines/reference/constDeclarations2.js b/tests/baselines/reference/constDeclarations2.js new file mode 100644 index 0000000000000..e4ee67ebdcdd0 --- /dev/null +++ b/tests/baselines/reference/constDeclarations2.js @@ -0,0 +1,26 @@ +//// [constDeclarations2.ts] + +// No error +module M { + export const c1 = false; + export const c2: number = 23; + export const c3 = 0, c4 :string = "", c5 = null; +} + + +//// [constDeclarations2.js] +// No error +var M; +(function (M) { + M.c1 = false; + M.c2 = 23; + M.c3 = 0, M.c4 = "", M.c5 = null; +})(M || (M = {})); + + +//// [constDeclarations2.d.ts] +declare module M { + const c1: boolean; + const c2: number; + const c3: number, c4: string, c5: any; +} diff --git a/tests/baselines/reference/constDeclarations2.types b/tests/baselines/reference/constDeclarations2.types new file mode 100644 index 0000000000000..c81eca96b0dd0 --- /dev/null +++ b/tests/baselines/reference/constDeclarations2.types @@ -0,0 +1,18 @@ +=== tests/cases/compiler/constDeclarations2.ts === + +// No error +module M { +>M : typeof M + + export const c1 = false; +>c1 : boolean + + export const c2: number = 23; +>c2 : number + + export const c3 = 0, c4 :string = "", c5 = null; +>c3 : number +>c4 : string +>c5 : any +} + diff --git a/tests/baselines/reference/enumIdentifierLiterals.errors.txt b/tests/baselines/reference/enumIdentifierLiterals.errors.txt index 60d8ed81f84e4..dbf8734ea73bd 100644 --- a/tests/baselines/reference/enumIdentifierLiterals.errors.txt +++ b/tests/baselines/reference/enumIdentifierLiterals.errors.txt @@ -1,22 +1,22 @@ -tests/cases/compiler/enumIdentifierLiterals.ts(2,5): error TS1151: An enum member cannot have a numeric name. -tests/cases/compiler/enumIdentifierLiterals.ts(3,5): error TS1151: An enum member cannot have a numeric name. -tests/cases/compiler/enumIdentifierLiterals.ts(4,5): error TS1151: An enum member cannot have a numeric name. -tests/cases/compiler/enumIdentifierLiterals.ts(6,5): error TS1151: An enum member cannot have a numeric name. +tests/cases/compiler/enumIdentifierLiterals.ts(2,5): error TS2452: An enum member cannot have a numeric name. +tests/cases/compiler/enumIdentifierLiterals.ts(3,5): error TS2452: An enum member cannot have a numeric name. +tests/cases/compiler/enumIdentifierLiterals.ts(4,5): error TS2452: An enum member cannot have a numeric name. +tests/cases/compiler/enumIdentifierLiterals.ts(6,5): error TS2452: An enum member cannot have a numeric name. ==== tests/cases/compiler/enumIdentifierLiterals.ts (4 errors) ==== enum Nums { 1.0, ~~~ -!!! error TS1151: An enum member cannot have a numeric name. +!!! error TS2452: An enum member cannot have a numeric name. 11e-1, ~~~~~ -!!! error TS1151: An enum member cannot have a numeric name. +!!! error TS2452: An enum member cannot have a numeric name. 0.12e1, ~~~~~~ -!!! error TS1151: An enum member cannot have a numeric name. +!!! error TS2452: An enum member cannot have a numeric name. "13e-1", 0xF00D ~~~~~~ -!!! error TS1151: An enum member cannot have a numeric name. +!!! error TS2452: An enum member cannot have a numeric name. } \ No newline at end of file diff --git a/tests/baselines/reference/es6-amd.js b/tests/baselines/reference/es6-amd.js new file mode 100644 index 0000000000000..0cce3af04463a --- /dev/null +++ b/tests/baselines/reference/es6-amd.js @@ -0,0 +1,31 @@ +//// [es6-amd.ts] + +class A +{ + constructor () + { + + } + + public B() + { + return 42; + } +} + +//// [es6-amd.js] +var A = (function () { + function A() { + } + A.prototype.B = function () { + return 42; + }; + return A; +})(); +//# sourceMappingURL=es6-amd.js.map + +//// [es6-amd.d.ts] +declare class A { + constructor(); + B(): number; +} diff --git a/tests/baselines/reference/es6-amd.js.map b/tests/baselines/reference/es6-amd.js.map new file mode 100644 index 0000000000000..7371ba578bd1d --- /dev/null +++ b/tests/baselines/reference/es6-amd.js.map @@ -0,0 +1,2 @@ +//// [es6-amd.js.map] +{"version":3,"file":"es6-amd.js","sourceRoot":"","sources":["es6-amd.ts"],"names":["A","A.constructor","A.B"],"mappings":"AACA,IAAM,CAAC;IAEHA,SAFEA,CAACA;IAKHC,CAACA;IAEMD,aAACA,GAARA;QAEIE,MAAMA,CAACA,EAAEA,CAACA;IACdA,CAACA;IACLF,QAACA;AAADA,CAACA,AAXD,IAWC"} \ No newline at end of file diff --git a/tests/baselines/reference/es6-amd.sourcemap.txt b/tests/baselines/reference/es6-amd.sourcemap.txt new file mode 100644 index 0000000000000..070a35703e173 --- /dev/null +++ b/tests/baselines/reference/es6-amd.sourcemap.txt @@ -0,0 +1,128 @@ +=================================================================== +JsFile: es6-amd.js +mapUrl: es6-amd.js.map +sourceRoot: +sources: es6-amd.ts +=================================================================== +------------------------------------------------------------------- +emittedFile:tests/cases/compiler/es6-amd.js +sourceFile:es6-amd.ts +------------------------------------------------------------------- +>>>var A = (function () { +1 > +2 >^^^^ +3 > ^ +4 > ^^^^^^^^^^^^^^-> +1 > + > +2 >class +3 > A +1 >Emitted(1, 1) Source(2, 1) + SourceIndex(0) +2 >Emitted(1, 5) Source(2, 7) + SourceIndex(0) +3 >Emitted(1, 6) Source(2, 8) + SourceIndex(0) +--- +>>> function A() { +1->^^^^ +2 > ^^^^^^^^^ +3 > ^ +1-> + >{ + > +2 > +3 > A +1->Emitted(2, 5) Source(4, 5) + SourceIndex(0) name (A) +2 >Emitted(2, 14) Source(2, 7) + SourceIndex(0) name (A) +3 >Emitted(2, 15) Source(2, 8) + SourceIndex(0) name (A) +--- +>>> } +1 >^^^^ +2 > ^ +3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> +1 > + >{ + > constructor () + > { + > + > +2 > } +1 >Emitted(3, 5) Source(7, 5) + SourceIndex(0) name (A.constructor) +2 >Emitted(3, 6) Source(7, 6) + SourceIndex(0) name (A.constructor) +--- +>>> A.prototype.B = function () { +1->^^^^ +2 > ^^^^^^^^^^^^^ +3 > ^^^ +1-> + > + > public +2 > B +3 > +1->Emitted(4, 5) Source(9, 12) + SourceIndex(0) name (A) +2 >Emitted(4, 18) Source(9, 13) + SourceIndex(0) name (A) +3 >Emitted(4, 21) Source(9, 5) + SourceIndex(0) name (A) +--- +>>> return 42; +1 >^^^^^^^^ +2 > ^^^^^^ +3 > ^ +4 > ^^ +5 > ^ +1 >public B() + > { + > +2 > return +3 > +4 > 42 +5 > ; +1 >Emitted(5, 9) Source(11, 9) + SourceIndex(0) name (A.B) +2 >Emitted(5, 15) Source(11, 15) + SourceIndex(0) name (A.B) +3 >Emitted(5, 16) Source(11, 16) + SourceIndex(0) name (A.B) +4 >Emitted(5, 18) Source(11, 18) + SourceIndex(0) name (A.B) +5 >Emitted(5, 19) Source(11, 19) + SourceIndex(0) name (A.B) +--- +>>> }; +1 >^^^^ +2 > ^ +3 > ^^^^^^^^^-> +1 > + > +2 > } +1 >Emitted(6, 5) Source(12, 5) + SourceIndex(0) name (A.B) +2 >Emitted(6, 6) Source(12, 6) + SourceIndex(0) name (A.B) +--- +>>> return A; +1->^^^^ +2 > ^^^^^^^^ +1-> + > +2 > } +1->Emitted(7, 5) Source(13, 1) + SourceIndex(0) name (A) +2 >Emitted(7, 13) Source(13, 2) + SourceIndex(0) name (A) +--- +>>>})(); +1 > +2 >^ +3 > +4 > ^^^^ +5 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> +1 > +2 >} +3 > +4 > class A + > { + > constructor () + > { + > + > } + > + > public B() + > { + > return 42; + > } + > } +1 >Emitted(8, 1) Source(13, 1) + SourceIndex(0) name (A) +2 >Emitted(8, 2) Source(13, 2) + SourceIndex(0) name (A) +3 >Emitted(8, 2) Source(2, 1) + SourceIndex(0) +4 >Emitted(8, 6) Source(13, 2) + SourceIndex(0) +--- +>>>//# sourceMappingURL=es6-amd.js.map \ No newline at end of file diff --git a/tests/baselines/reference/es6-amd.types b/tests/baselines/reference/es6-amd.types new file mode 100644 index 0000000000000..62815911f7f97 --- /dev/null +++ b/tests/baselines/reference/es6-amd.types @@ -0,0 +1,16 @@ +=== tests/cases/compiler/es6-amd.ts === + +class A +>A : A +{ + constructor () + { + + } + + public B() +>B : () => number + { + return 42; + } +} diff --git a/tests/baselines/reference/es6-declaration-amd.js b/tests/baselines/reference/es6-declaration-amd.js new file mode 100644 index 0000000000000..471f96b223d1a --- /dev/null +++ b/tests/baselines/reference/es6-declaration-amd.js @@ -0,0 +1,31 @@ +//// [es6-declaration-amd.ts] + +class A +{ + constructor () + { + + } + + public B() + { + return 42; + } +} + +//// [es6-declaration-amd.js] +var A = (function () { + function A() { + } + A.prototype.B = function () { + return 42; + }; + return A; +})(); +//# sourceMappingURL=es6-declaration-amd.js.map + +//// [es6-declaration-amd.d.ts] +declare class A { + constructor(); + B(): number; +} diff --git a/tests/baselines/reference/es6-declaration-amd.js.map b/tests/baselines/reference/es6-declaration-amd.js.map new file mode 100644 index 0000000000000..0987f9478e99e --- /dev/null +++ b/tests/baselines/reference/es6-declaration-amd.js.map @@ -0,0 +1,2 @@ +//// [es6-declaration-amd.js.map] +{"version":3,"file":"es6-declaration-amd.js","sourceRoot":"","sources":["es6-declaration-amd.ts"],"names":["A","A.constructor","A.B"],"mappings":"AACA,IAAM,CAAC;IAEHA,SAFEA,CAACA;IAKHC,CAACA;IAEMD,aAACA,GAARA;QAEIE,MAAMA,CAACA,EAAEA,CAACA;IACdA,CAACA;IACLF,QAACA;AAADA,CAACA,AAXD,IAWC"} \ No newline at end of file diff --git a/tests/baselines/reference/es6-declaration-amd.sourcemap.txt b/tests/baselines/reference/es6-declaration-amd.sourcemap.txt new file mode 100644 index 0000000000000..1fc0b5f05fead --- /dev/null +++ b/tests/baselines/reference/es6-declaration-amd.sourcemap.txt @@ -0,0 +1,128 @@ +=================================================================== +JsFile: es6-declaration-amd.js +mapUrl: es6-declaration-amd.js.map +sourceRoot: +sources: es6-declaration-amd.ts +=================================================================== +------------------------------------------------------------------- +emittedFile:tests/cases/compiler/es6-declaration-amd.js +sourceFile:es6-declaration-amd.ts +------------------------------------------------------------------- +>>>var A = (function () { +1 > +2 >^^^^ +3 > ^ +4 > ^^^^^^^^^^^^^^-> +1 > + > +2 >class +3 > A +1 >Emitted(1, 1) Source(2, 1) + SourceIndex(0) +2 >Emitted(1, 5) Source(2, 7) + SourceIndex(0) +3 >Emitted(1, 6) Source(2, 8) + SourceIndex(0) +--- +>>> function A() { +1->^^^^ +2 > ^^^^^^^^^ +3 > ^ +1-> + >{ + > +2 > +3 > A +1->Emitted(2, 5) Source(4, 5) + SourceIndex(0) name (A) +2 >Emitted(2, 14) Source(2, 7) + SourceIndex(0) name (A) +3 >Emitted(2, 15) Source(2, 8) + SourceIndex(0) name (A) +--- +>>> } +1 >^^^^ +2 > ^ +3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> +1 > + >{ + > constructor () + > { + > + > +2 > } +1 >Emitted(3, 5) Source(7, 5) + SourceIndex(0) name (A.constructor) +2 >Emitted(3, 6) Source(7, 6) + SourceIndex(0) name (A.constructor) +--- +>>> A.prototype.B = function () { +1->^^^^ +2 > ^^^^^^^^^^^^^ +3 > ^^^ +1-> + > + > public +2 > B +3 > +1->Emitted(4, 5) Source(9, 12) + SourceIndex(0) name (A) +2 >Emitted(4, 18) Source(9, 13) + SourceIndex(0) name (A) +3 >Emitted(4, 21) Source(9, 5) + SourceIndex(0) name (A) +--- +>>> return 42; +1 >^^^^^^^^ +2 > ^^^^^^ +3 > ^ +4 > ^^ +5 > ^ +1 >public B() + > { + > +2 > return +3 > +4 > 42 +5 > ; +1 >Emitted(5, 9) Source(11, 9) + SourceIndex(0) name (A.B) +2 >Emitted(5, 15) Source(11, 15) + SourceIndex(0) name (A.B) +3 >Emitted(5, 16) Source(11, 16) + SourceIndex(0) name (A.B) +4 >Emitted(5, 18) Source(11, 18) + SourceIndex(0) name (A.B) +5 >Emitted(5, 19) Source(11, 19) + SourceIndex(0) name (A.B) +--- +>>> }; +1 >^^^^ +2 > ^ +3 > ^^^^^^^^^-> +1 > + > +2 > } +1 >Emitted(6, 5) Source(12, 5) + SourceIndex(0) name (A.B) +2 >Emitted(6, 6) Source(12, 6) + SourceIndex(0) name (A.B) +--- +>>> return A; +1->^^^^ +2 > ^^^^^^^^ +1-> + > +2 > } +1->Emitted(7, 5) Source(13, 1) + SourceIndex(0) name (A) +2 >Emitted(7, 13) Source(13, 2) + SourceIndex(0) name (A) +--- +>>>})(); +1 > +2 >^ +3 > +4 > ^^^^ +5 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> +1 > +2 >} +3 > +4 > class A + > { + > constructor () + > { + > + > } + > + > public B() + > { + > return 42; + > } + > } +1 >Emitted(8, 1) Source(13, 1) + SourceIndex(0) name (A) +2 >Emitted(8, 2) Source(13, 2) + SourceIndex(0) name (A) +3 >Emitted(8, 2) Source(2, 1) + SourceIndex(0) +4 >Emitted(8, 6) Source(13, 2) + SourceIndex(0) +--- +>>>//# sourceMappingURL=es6-declaration-amd.js.map \ No newline at end of file diff --git a/tests/baselines/reference/es6-declaration-amd.types b/tests/baselines/reference/es6-declaration-amd.types new file mode 100644 index 0000000000000..e275fc5243961 --- /dev/null +++ b/tests/baselines/reference/es6-declaration-amd.types @@ -0,0 +1,16 @@ +=== tests/cases/compiler/es6-declaration-amd.ts === + +class A +>A : A +{ + constructor () + { + + } + + public B() +>B : () => number + { + return 42; + } +} diff --git a/tests/baselines/reference/es6-sourcemap-amd.js b/tests/baselines/reference/es6-sourcemap-amd.js new file mode 100644 index 0000000000000..805e56cf830d0 --- /dev/null +++ b/tests/baselines/reference/es6-sourcemap-amd.js @@ -0,0 +1,25 @@ +//// [es6-sourcemap-amd.ts] + +class A +{ + constructor () + { + + } + + public B() + { + return 42; + } +} + +//// [es6-sourcemap-amd.js] +var A = (function () { + function A() { + } + A.prototype.B = function () { + return 42; + }; + return A; +})(); +//# sourceMappingURL=es6-sourcemap-amd.js.map \ No newline at end of file diff --git a/tests/baselines/reference/es6-sourcemap-amd.js.map b/tests/baselines/reference/es6-sourcemap-amd.js.map new file mode 100644 index 0000000000000..689f0447fa8db --- /dev/null +++ b/tests/baselines/reference/es6-sourcemap-amd.js.map @@ -0,0 +1,2 @@ +//// [es6-sourcemap-amd.js.map] +{"version":3,"file":"es6-sourcemap-amd.js","sourceRoot":"","sources":["es6-sourcemap-amd.ts"],"names":["A","A.constructor","A.B"],"mappings":"AACA,IAAM,CAAC;IAEHA,SAFEA,CAACA;IAKHC,CAACA;IAEMD,aAACA,GAARA;QAEIE,MAAMA,CAACA,EAAEA,CAACA;IACdA,CAACA;IACLF,QAACA;AAADA,CAACA,AAXD,IAWC"} \ No newline at end of file diff --git a/tests/baselines/reference/es6-sourcemap-amd.sourcemap.txt b/tests/baselines/reference/es6-sourcemap-amd.sourcemap.txt new file mode 100644 index 0000000000000..09abb195987c1 --- /dev/null +++ b/tests/baselines/reference/es6-sourcemap-amd.sourcemap.txt @@ -0,0 +1,128 @@ +=================================================================== +JsFile: es6-sourcemap-amd.js +mapUrl: es6-sourcemap-amd.js.map +sourceRoot: +sources: es6-sourcemap-amd.ts +=================================================================== +------------------------------------------------------------------- +emittedFile:tests/cases/compiler/es6-sourcemap-amd.js +sourceFile:es6-sourcemap-amd.ts +------------------------------------------------------------------- +>>>var A = (function () { +1 > +2 >^^^^ +3 > ^ +4 > ^^^^^^^^^^^^^^-> +1 > + > +2 >class +3 > A +1 >Emitted(1, 1) Source(2, 1) + SourceIndex(0) +2 >Emitted(1, 5) Source(2, 7) + SourceIndex(0) +3 >Emitted(1, 6) Source(2, 8) + SourceIndex(0) +--- +>>> function A() { +1->^^^^ +2 > ^^^^^^^^^ +3 > ^ +1-> + >{ + > +2 > +3 > A +1->Emitted(2, 5) Source(4, 5) + SourceIndex(0) name (A) +2 >Emitted(2, 14) Source(2, 7) + SourceIndex(0) name (A) +3 >Emitted(2, 15) Source(2, 8) + SourceIndex(0) name (A) +--- +>>> } +1 >^^^^ +2 > ^ +3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> +1 > + >{ + > constructor () + > { + > + > +2 > } +1 >Emitted(3, 5) Source(7, 5) + SourceIndex(0) name (A.constructor) +2 >Emitted(3, 6) Source(7, 6) + SourceIndex(0) name (A.constructor) +--- +>>> A.prototype.B = function () { +1->^^^^ +2 > ^^^^^^^^^^^^^ +3 > ^^^ +1-> + > + > public +2 > B +3 > +1->Emitted(4, 5) Source(9, 12) + SourceIndex(0) name (A) +2 >Emitted(4, 18) Source(9, 13) + SourceIndex(0) name (A) +3 >Emitted(4, 21) Source(9, 5) + SourceIndex(0) name (A) +--- +>>> return 42; +1 >^^^^^^^^ +2 > ^^^^^^ +3 > ^ +4 > ^^ +5 > ^ +1 >public B() + > { + > +2 > return +3 > +4 > 42 +5 > ; +1 >Emitted(5, 9) Source(11, 9) + SourceIndex(0) name (A.B) +2 >Emitted(5, 15) Source(11, 15) + SourceIndex(0) name (A.B) +3 >Emitted(5, 16) Source(11, 16) + SourceIndex(0) name (A.B) +4 >Emitted(5, 18) Source(11, 18) + SourceIndex(0) name (A.B) +5 >Emitted(5, 19) Source(11, 19) + SourceIndex(0) name (A.B) +--- +>>> }; +1 >^^^^ +2 > ^ +3 > ^^^^^^^^^-> +1 > + > +2 > } +1 >Emitted(6, 5) Source(12, 5) + SourceIndex(0) name (A.B) +2 >Emitted(6, 6) Source(12, 6) + SourceIndex(0) name (A.B) +--- +>>> return A; +1->^^^^ +2 > ^^^^^^^^ +1-> + > +2 > } +1->Emitted(7, 5) Source(13, 1) + SourceIndex(0) name (A) +2 >Emitted(7, 13) Source(13, 2) + SourceIndex(0) name (A) +--- +>>>})(); +1 > +2 >^ +3 > +4 > ^^^^ +5 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> +1 > +2 >} +3 > +4 > class A + > { + > constructor () + > { + > + > } + > + > public B() + > { + > return 42; + > } + > } +1 >Emitted(8, 1) Source(13, 1) + SourceIndex(0) name (A) +2 >Emitted(8, 2) Source(13, 2) + SourceIndex(0) name (A) +3 >Emitted(8, 2) Source(2, 1) + SourceIndex(0) +4 >Emitted(8, 6) Source(13, 2) + SourceIndex(0) +--- +>>>//# sourceMappingURL=es6-sourcemap-amd.js.map \ No newline at end of file diff --git a/tests/baselines/reference/es6-sourcemap-amd.types b/tests/baselines/reference/es6-sourcemap-amd.types new file mode 100644 index 0000000000000..661ab2e7cddfc --- /dev/null +++ b/tests/baselines/reference/es6-sourcemap-amd.types @@ -0,0 +1,16 @@ +=== tests/cases/compiler/es6-sourcemap-amd.ts === + +class A +>A : A +{ + constructor () + { + + } + + public B() +>B : () => number + { + return 42; + } +} diff --git a/tests/baselines/reference/functionTypeArgumentArrayAssignment.errors.txt b/tests/baselines/reference/functionTypeArgumentArrayAssignment.errors.txt deleted file mode 100644 index 9897286a62438..0000000000000 --- a/tests/baselines/reference/functionTypeArgumentArrayAssignment.errors.txt +++ /dev/null @@ -1,15 +0,0 @@ -tests/cases/compiler/functionTypeArgumentArrayAssignment.ts(3,2): error TS2300: Duplicate identifier 'length'. - - -==== tests/cases/compiler/functionTypeArgumentArrayAssignment.ts (1 errors) ==== - interface Array { - foo: T; - length: number; - ~~~~~~ -!!! error TS2300: Duplicate identifier 'length'. - } - - function map() { - var ys: U[] = []; - } - \ No newline at end of file diff --git a/tests/baselines/reference/functionTypeArgumentArrayAssignment.js b/tests/baselines/reference/functionTypeArgumentArrayAssignment.js index 9569c4566d818..38188c3505a83 100644 --- a/tests/baselines/reference/functionTypeArgumentArrayAssignment.js +++ b/tests/baselines/reference/functionTypeArgumentArrayAssignment.js @@ -1,15 +1,20 @@ //// [functionTypeArgumentArrayAssignment.ts] -interface Array { - foo: T; - length: number; -} +module test { + interface Array { + foo: T; + length: number; + } -function map() { -var ys: U[] = []; + function map() { + var ys: U[] = []; + } } //// [functionTypeArgumentArrayAssignment.js] -function map() { - var ys = []; -} +var test; +(function (test) { + function map() { + var ys = []; + } +})(test || (test = {})); diff --git a/tests/baselines/reference/functionTypeArgumentArrayAssignment.types b/tests/baselines/reference/functionTypeArgumentArrayAssignment.types new file mode 100644 index 0000000000000..588dfd506ef9e --- /dev/null +++ b/tests/baselines/reference/functionTypeArgumentArrayAssignment.types @@ -0,0 +1,27 @@ +=== tests/cases/compiler/functionTypeArgumentArrayAssignment.ts === +module test { +>test : typeof test + + interface Array { +>Array : Array +>T : T + + foo: T; +>foo : T +>T : T + + length: number; +>length : number + } + + function map() { +>map : () => void +>U : U + + var ys: U[] = []; +>ys : U[] +>U : U +>[] : undefined[] + } +} + diff --git a/tests/baselines/reference/instanceofOperator.errors.txt b/tests/baselines/reference/instanceofOperator.errors.txt index 15d5518874141..2fa517c53be8b 100644 --- a/tests/baselines/reference/instanceofOperator.errors.txt +++ b/tests/baselines/reference/instanceofOperator.errors.txt @@ -1,43 +1,42 @@ -tests/cases/compiler/instanceofOperator.ts(6,7): error TS2300: Duplicate identifier 'Object'. -tests/cases/compiler/instanceofOperator.ts(11,1): error TS2358: The left-hand side of an 'instanceof' expression must be of type 'any', an object type or a type parameter. -tests/cases/compiler/instanceofOperator.ts(14,16): error TS2359: The right-hand side of an 'instanceof' expression must be of type 'any' or of a type assignable to the 'Function' interface type. -tests/cases/compiler/instanceofOperator.ts(15,19): error TS2359: The right-hand side of an 'instanceof' expression must be of type 'any' or of a type assignable to the 'Function' interface type. -tests/cases/compiler/instanceofOperator.ts(18,1): error TS2358: The left-hand side of an 'instanceof' expression must be of type 'any', an object type or a type parameter. -tests/cases/compiler/instanceofOperator.ts(20,1): error TS2358: The left-hand side of an 'instanceof' expression must be of type 'any', an object type or a type parameter. +tests/cases/compiler/instanceofOperator.ts(12,5): error TS2358: The left-hand side of an 'instanceof' expression must be of type 'any', an object type or a type parameter. +tests/cases/compiler/instanceofOperator.ts(15,20): error TS2359: The right-hand side of an 'instanceof' expression must be of type 'any' or of a type assignable to the 'Function' interface type. +tests/cases/compiler/instanceofOperator.ts(16,23): error TS2359: The right-hand side of an 'instanceof' expression must be of type 'any' or of a type assignable to the 'Function' interface type. +tests/cases/compiler/instanceofOperator.ts(19,5): error TS2358: The left-hand side of an 'instanceof' expression must be of type 'any', an object type or a type parameter. +tests/cases/compiler/instanceofOperator.ts(21,5): error TS2358: The left-hand side of an 'instanceof' expression must be of type 'any', an object type or a type parameter. -==== tests/cases/compiler/instanceofOperator.ts (6 errors) ==== +==== tests/cases/compiler/instanceofOperator.ts (5 errors) ==== // Spec: // The instanceof operator requires the left operand to be of type Any or an object type, and the right // operand to be of type Any or a subtype of the ‘Function’ interface type. The result is always of the // Boolean primitive type. - class Object { } - ~~~~~~ -!!! error TS2300: Duplicate identifier 'Object'. - var obj: Object; + module test { + class Object { } + var obj: Object; - 4 instanceof null; - ~ + 4 instanceof null; + ~ !!! error TS2358: The left-hand side of an 'instanceof' expression must be of type 'any', an object type or a type parameter. - // Error and should be error - obj instanceof 4; - ~ + // Error and should be error + obj instanceof 4; + ~ !!! error TS2359: The right-hand side of an 'instanceof' expression must be of type 'any' or of a type assignable to the 'Function' interface type. - Object instanceof obj; - ~~~ + Object instanceof obj; + ~~~ !!! error TS2359: The right-hand side of an 'instanceof' expression must be of type 'any' or of a type assignable to the 'Function' interface type. - // Error on left hand side - null instanceof null; - ~~~~ + // Error on left hand side + null instanceof null; + ~~~~ !!! error TS2358: The left-hand side of an 'instanceof' expression must be of type 'any', an object type or a type parameter. - obj instanceof Object; - undefined instanceof undefined; - ~~~~~~~~~ + obj instanceof Object; + undefined instanceof undefined; + ~~~~~~~~~ !!! error TS2358: The left-hand side of an 'instanceof' expression must be of type 'any', an object type or a type parameter. + } \ No newline at end of file diff --git a/tests/baselines/reference/instanceofOperator.js b/tests/baselines/reference/instanceofOperator.js index 7620c3e83f4fc..3c6970b66a4f1 100644 --- a/tests/baselines/reference/instanceofOperator.js +++ b/tests/baselines/reference/instanceofOperator.js @@ -4,21 +4,23 @@ // operand to be of type Any or a subtype of the ‘Function’ interface type. The result is always of the // Boolean primitive type. -class Object { } -var obj: Object; +module test { + class Object { } + var obj: Object; -4 instanceof null; + 4 instanceof null; -// Error and should be error -obj instanceof 4; -Object instanceof obj; + // Error and should be error + obj instanceof 4; + Object instanceof obj; -// Error on left hand side -null instanceof null; -obj instanceof Object; -undefined instanceof undefined; + // Error on left hand side + null instanceof null; + obj instanceof Object; + undefined instanceof undefined; +} @@ -27,17 +29,20 @@ undefined instanceof undefined; // The instanceof operator requires the left operand to be of type Any or an object type, and the right // operand to be of type Any or a subtype of the ‘Function’ interface type. The result is always of the // Boolean primitive type. -var Object = (function () { - function Object() { - } - return Object; -})(); -var obj; -4 instanceof null; -// Error and should be error -obj instanceof 4; -Object instanceof obj; -// Error on left hand side -null instanceof null; -obj instanceof Object; -undefined instanceof undefined; +var test; +(function (test) { + var Object = (function () { + function Object() { + } + return Object; + })(); + var obj; + 4 instanceof null; + // Error and should be error + obj instanceof 4; + Object instanceof obj; + // Error on left hand side + null instanceof null; + obj instanceof Object; + undefined instanceof undefined; +})(test || (test = {})); diff --git a/tests/baselines/reference/letDeclarations-access.js b/tests/baselines/reference/letDeclarations-access.js new file mode 100644 index 0000000000000..404c287631079 --- /dev/null +++ b/tests/baselines/reference/letDeclarations-access.js @@ -0,0 +1,70 @@ +//// [letDeclarations-access.ts] + +let x = 0 + +// No errors + +x = 1; +x += 2; +x -= 3; +x *= 4; +x /= 5; +x %= 6; +x <<= 7; +x >>= 8; +x >>>= 9; +x &= 10; +x |= 11; +x ^= 12; + +x++; +x--; +++x; +--x; + +var a = x + 1; + +function f(v: number) { } +f(x); + +if (x) { } + +x; +(x); + +-x; ++x; + +x.toString(); + + +//// [letDeclarations-access.js] +let x = 0; +// No errors +x = 1; +x += 2; +x -= 3; +x *= 4; +x /= 5; +x %= 6; +x <<= 7; +x >>= 8; +x >>>= 9; +x &= 10; +x |= 11; +x ^= 12; +x++; +x--; +++x; +--x; +var a = x + 1; +function f(v) { +} +f(x); +if (x) { +} +x; +(x); +-x; ++x; +x.toString(); diff --git a/tests/baselines/reference/letDeclarations-access.types b/tests/baselines/reference/letDeclarations-access.types new file mode 100644 index 0000000000000..f26d07ca5f8e8 --- /dev/null +++ b/tests/baselines/reference/letDeclarations-access.types @@ -0,0 +1,109 @@ +=== tests/cases/compiler/letDeclarations-access.ts === + +let x = 0 +>x : number + +// No errors + +x = 1; +>x = 1 : number +>x : number + +x += 2; +>x += 2 : number +>x : number + +x -= 3; +>x -= 3 : number +>x : number + +x *= 4; +>x *= 4 : number +>x : number + +x /= 5; +>x /= 5 : number +>x : number + +x %= 6; +>x %= 6 : number +>x : number + +x <<= 7; +>x <<= 7 : number +>x : number + +x >>= 8; +>x >>= 8 : number +>x : number + +x >>>= 9; +>x >>>= 9 : number +>x : number + +x &= 10; +>x &= 10 : number +>x : number + +x |= 11; +>x |= 11 : number +>x : number + +x ^= 12; +>x ^= 12 : number +>x : number + +x++; +>x++ : number +>x : number + +x--; +>x-- : number +>x : number + +++x; +>++x : number +>x : number + +--x; +>--x : number +>x : number + +var a = x + 1; +>a : number +>x + 1 : number +>x : number + +function f(v: number) { } +>f : (v: number) => void +>v : number + +f(x); +>f(x) : void +>f : (v: number) => void +>x : number + +if (x) { } +>x : number + +x; +>x : number + +(x); +>(x) : number +>x : number + +-x; +>-x : number +>x : number + ++x; +>+x : number +>x : number + +x.toString(); +>x.toString() : string +>x.toString : (radix?: number) => string +>x : number +>toString : (radix?: number) => string + diff --git a/tests/baselines/reference/letDeclarations-es5.errors.txt b/tests/baselines/reference/letDeclarations-es5.errors.txt new file mode 100644 index 0000000000000..be1a56a8b7fa5 --- /dev/null +++ b/tests/baselines/reference/letDeclarations-es5.errors.txt @@ -0,0 +1,40 @@ +tests/cases/compiler/letDeclarations-es5.ts(2,1): error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. +tests/cases/compiler/letDeclarations-es5.ts(3,1): error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. +tests/cases/compiler/letDeclarations-es5.ts(4,1): error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. +tests/cases/compiler/letDeclarations-es5.ts(6,1): error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. +tests/cases/compiler/letDeclarations-es5.ts(7,1): error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. +tests/cases/compiler/letDeclarations-es5.ts(8,1): error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. +tests/cases/compiler/letDeclarations-es5.ts(10,8): error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. +tests/cases/compiler/letDeclarations-es5.ts(12,8): error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. + + +==== tests/cases/compiler/letDeclarations-es5.ts (8 errors) ==== + + let l1; + ~~~~~~~ +!!! error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. + let l2: number; + ~~~~~~~~~~~~~~~ +!!! error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. + let l3, l4, l5 :string, l6; + ~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. + + let l7 = false; + ~~~~~~~~~~~~~~~ +!!! error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. + let l8: number = 23; + ~~~~~~~~~~~~~~~~~~~~ +!!! error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. + let l9 = 0, l10 :string = "", l11 = null; + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. + + for(let l11 in {}) { } + ~~~~ +!!! error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. + + for(let l12 = 0; l12 < 9; l12++) { } + ~~~~~~~~ +!!! error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. + \ No newline at end of file diff --git a/tests/baselines/reference/letDeclarations-invalidContexts.errors.txt b/tests/baselines/reference/letDeclarations-invalidContexts.errors.txt new file mode 100644 index 0000000000000..ad0c0f741b5ce --- /dev/null +++ b/tests/baselines/reference/letDeclarations-invalidContexts.errors.txt @@ -0,0 +1,66 @@ +tests/cases/compiler/letDeclarations-invalidContexts.ts(4,5): error TS1157: 'let' declarations can only be declared inside a block. +tests/cases/compiler/letDeclarations-invalidContexts.ts(6,5): error TS1157: 'let' declarations can only be declared inside a block. +tests/cases/compiler/letDeclarations-invalidContexts.ts(9,5): error TS1157: 'let' declarations can only be declared inside a block. +tests/cases/compiler/letDeclarations-invalidContexts.ts(12,5): error TS1157: 'let' declarations can only be declared inside a block. +tests/cases/compiler/letDeclarations-invalidContexts.ts(17,5): error TS1157: 'let' declarations can only be declared inside a block. +tests/cases/compiler/letDeclarations-invalidContexts.ts(20,5): error TS1157: 'let' declarations can only be declared inside a block. +tests/cases/compiler/letDeclarations-invalidContexts.ts(23,5): error TS1157: 'let' declarations can only be declared inside a block. +tests/cases/compiler/letDeclarations-invalidContexts.ts(26,12): error TS1157: 'let' declarations can only be declared inside a block. +tests/cases/compiler/letDeclarations-invalidContexts.ts(29,29): error TS1157: 'let' declarations can only be declared inside a block. +tests/cases/compiler/letDeclarations-invalidContexts.ts(16,7): error TS2410: All symbols within a 'with' block will be resolved to 'any'. + + +==== tests/cases/compiler/letDeclarations-invalidContexts.ts (10 errors) ==== + + // Errors, let must be defined inside a block + if (true) + let l1 = 0; + ~~~~~~~~~~~ +!!! error TS1157: 'let' declarations can only be declared inside a block. + else + let l2 = 0; + ~~~~~~~~~~~ +!!! error TS1157: 'let' declarations can only be declared inside a block. + + while (true) + let l3 = 0; + ~~~~~~~~~~~ +!!! error TS1157: 'let' declarations can only be declared inside a block. + + do + let l4 = 0; + ~~~~~~~~~~~ +!!! error TS1157: 'let' declarations can only be declared inside a block. + while (true); + + var obj; + with (obj) + ~~~ +!!! error TS2410: All symbols within a 'with' block will be resolved to 'any'. + let l5 = 0; + ~~~~~~~~~~~ +!!! error TS1157: 'let' declarations can only be declared inside a block. + + for (var i = 0; i < 10; i++) + let l6 = 0; + ~~~~~~~~~~~ +!!! error TS1157: 'let' declarations can only be declared inside a block. + + for (var i2 in {}) + let l7 = 0; + ~~~~~~~~~~~ +!!! error TS1157: 'let' declarations can only be declared inside a block. + + if (true) + label: let l8 = 0; + ~~~~~~~~~~~ +!!! error TS1157: 'let' declarations can only be declared inside a block. + + while (false) + label2: label3: label4: let l9 = 0; + ~~~~~~~~~~~ +!!! error TS1157: 'let' declarations can only be declared inside a block. + + + + \ No newline at end of file diff --git a/tests/baselines/reference/letDeclarations-scopes-duplicates.errors.txt b/tests/baselines/reference/letDeclarations-scopes-duplicates.errors.txt new file mode 100644 index 0000000000000..b3b620a4c9ee8 --- /dev/null +++ b/tests/baselines/reference/letDeclarations-scopes-duplicates.errors.txt @@ -0,0 +1,152 @@ +tests/cases/compiler/letDeclarations-scopes-duplicates.ts(3,5): error TS2451: Cannot redeclare block-scoped variable 'var1'. +tests/cases/compiler/letDeclarations-scopes-duplicates.ts(4,5): error TS2451: Cannot redeclare block-scoped variable 'var1'. +tests/cases/compiler/letDeclarations-scopes-duplicates.ts(6,5): error TS2451: Cannot redeclare block-scoped variable 'var2'. +tests/cases/compiler/letDeclarations-scopes-duplicates.ts(7,7): error TS2451: Cannot redeclare block-scoped variable 'var2'. +tests/cases/compiler/letDeclarations-scopes-duplicates.ts(9,7): error TS2451: Cannot redeclare block-scoped variable 'var3'. +tests/cases/compiler/letDeclarations-scopes-duplicates.ts(10,5): error TS2451: Cannot redeclare block-scoped variable 'var3'. +tests/cases/compiler/letDeclarations-scopes-duplicates.ts(12,7): error TS2451: Cannot redeclare block-scoped variable 'var4'. +tests/cases/compiler/letDeclarations-scopes-duplicates.ts(13,7): error TS2451: Cannot redeclare block-scoped variable 'var4'. +tests/cases/compiler/letDeclarations-scopes-duplicates.ts(15,5): error TS2300: Duplicate identifier 'var5'. +tests/cases/compiler/letDeclarations-scopes-duplicates.ts(16,5): error TS2300: Duplicate identifier 'var5'. +tests/cases/compiler/letDeclarations-scopes-duplicates.ts(18,5): error TS2451: Cannot redeclare block-scoped variable 'var6'. +tests/cases/compiler/letDeclarations-scopes-duplicates.ts(19,5): error TS2451: Cannot redeclare block-scoped variable 'var6'. +tests/cases/compiler/letDeclarations-scopes-duplicates.ts(22,9): error TS2451: Cannot redeclare block-scoped variable 'var7'. +tests/cases/compiler/letDeclarations-scopes-duplicates.ts(23,9): error TS2451: Cannot redeclare block-scoped variable 'var7'. +tests/cases/compiler/letDeclarations-scopes-duplicates.ts(25,13): error TS2451: Cannot redeclare block-scoped variable 'var8'. +tests/cases/compiler/letDeclarations-scopes-duplicates.ts(26,15): error TS2451: Cannot redeclare block-scoped variable 'var8'. +tests/cases/compiler/letDeclarations-scopes-duplicates.ts(32,13): error TS2451: Cannot redeclare block-scoped variable 'var9'. +tests/cases/compiler/letDeclarations-scopes-duplicates.ts(33,13): error TS2451: Cannot redeclare block-scoped variable 'var9'. +tests/cases/compiler/letDeclarations-scopes-duplicates.ts(37,11): error TS2451: Cannot redeclare block-scoped variable 'var10'. +tests/cases/compiler/letDeclarations-scopes-duplicates.ts(38,11): error TS2451: Cannot redeclare block-scoped variable 'var10'. +tests/cases/compiler/letDeclarations-scopes-duplicates.ts(41,9): error TS2451: Cannot redeclare block-scoped variable 'var11'. +tests/cases/compiler/letDeclarations-scopes-duplicates.ts(42,9): error TS2451: Cannot redeclare block-scoped variable 'var11'. +tests/cases/compiler/letDeclarations-scopes-duplicates.ts(46,9): error TS2451: Cannot redeclare block-scoped variable 'var12'. +tests/cases/compiler/letDeclarations-scopes-duplicates.ts(47,9): error TS2451: Cannot redeclare block-scoped variable 'var12'. + + +==== tests/cases/compiler/letDeclarations-scopes-duplicates.ts (24 errors) ==== + + // Errors: redeclaration + let var1 = 0; + ~~~~ +!!! error TS2451: Cannot redeclare block-scoped variable 'var1'. + let var1 = 0; // error + ~~~~ +!!! error TS2451: Cannot redeclare block-scoped variable 'var1'. + + let var2 = 0; + ~~~~ +!!! error TS2451: Cannot redeclare block-scoped variable 'var2'. + const var2 = 0; + ~~~~ +!!! error TS2451: Cannot redeclare block-scoped variable 'var2'. + + const var3 = 0; + ~~~~ +!!! error TS2451: Cannot redeclare block-scoped variable 'var3'. + let var3 = 0; + ~~~~ +!!! error TS2451: Cannot redeclare block-scoped variable 'var3'. + + const var4 = 0; + ~~~~ +!!! error TS2451: Cannot redeclare block-scoped variable 'var4'. + const var4 = 0; + ~~~~ +!!! error TS2451: Cannot redeclare block-scoped variable 'var4'. + + var var5 = 0; + ~~~~ +!!! error TS2300: Duplicate identifier 'var5'. + let var5 = 0; + ~~~~ +!!! error TS2300: Duplicate identifier 'var5'. + + let var6 = 0; + ~~~~ +!!! error TS2451: Cannot redeclare block-scoped variable 'var6'. + var var6 = 0; + ~~~~ +!!! error TS2451: Cannot redeclare block-scoped variable 'var6'. + + { + let var7 = 0; + ~~~~ +!!! error TS2451: Cannot redeclare block-scoped variable 'var7'. + let var7 = 0; + ~~~~ +!!! error TS2451: Cannot redeclare block-scoped variable 'var7'. + { + let var8 = 0; + ~~~~ +!!! error TS2451: Cannot redeclare block-scoped variable 'var8'. + const var8 = 0; + ~~~~ +!!! error TS2451: Cannot redeclare block-scoped variable 'var8'. + } + } + + switch (0) { + default: + let var9 = 0; + ~~~~ +!!! error TS2451: Cannot redeclare block-scoped variable 'var9'. + let var9 = 0; + ~~~~ +!!! error TS2451: Cannot redeclare block-scoped variable 'var9'. + } + + try { + const var10 = 0; + ~~~~~ +!!! error TS2451: Cannot redeclare block-scoped variable 'var10'. + const var10 = 0; + ~~~~~ +!!! error TS2451: Cannot redeclare block-scoped variable 'var10'. + } + catch (e) { + let var11 = 0; + ~~~~~ +!!! error TS2451: Cannot redeclare block-scoped variable 'var11'. + let var11 = 0; + ~~~~~ +!!! error TS2451: Cannot redeclare block-scoped variable 'var11'. + } + + function F1() { + let var12; + ~~~~~ +!!! error TS2451: Cannot redeclare block-scoped variable 'var12'. + let var12; + ~~~~~ +!!! error TS2451: Cannot redeclare block-scoped variable 'var12'. + } + + // OK + var var20 = 0; + + var var20 = 0 + { + let var20 = 0; + { + let var20 = 0; + } + } + + switch (0) { + default: + let var20 = 0; + } + + try { + let var20 = 0; + } + catch (e) { + let var20 = 0; + } + + function F() { + let var20; + } + + \ No newline at end of file diff --git a/tests/baselines/reference/letDeclarations-scopes-duplicates2.errors.txt b/tests/baselines/reference/letDeclarations-scopes-duplicates2.errors.txt new file mode 100644 index 0000000000000..72b8b5609b695 --- /dev/null +++ b/tests/baselines/reference/letDeclarations-scopes-duplicates2.errors.txt @@ -0,0 +1,14 @@ +tests/cases/compiler/file1.ts(2,5): error TS2451: Cannot redeclare block-scoped variable 'var1'. +tests/cases/compiler/file2.ts(1,5): error TS2451: Cannot redeclare block-scoped variable 'var1'. + + +==== tests/cases/compiler/file1.ts (1 errors) ==== + + let var1 = 0; + ~~~~ +!!! error TS2451: Cannot redeclare block-scoped variable 'var1'. + +==== tests/cases/compiler/file2.ts (1 errors) ==== + let var1 = 0; + ~~~~ +!!! error TS2451: Cannot redeclare block-scoped variable 'var1'. \ No newline at end of file diff --git a/tests/baselines/reference/letDeclarations-scopes-duplicates3.errors.txt b/tests/baselines/reference/letDeclarations-scopes-duplicates3.errors.txt new file mode 100644 index 0000000000000..6ed2fb66195ba --- /dev/null +++ b/tests/baselines/reference/letDeclarations-scopes-duplicates3.errors.txt @@ -0,0 +1,14 @@ +tests/cases/compiler/file1.ts(2,5): error TS2451: Cannot redeclare block-scoped variable 'var1'. +tests/cases/compiler/file2.ts(1,7): error TS2451: Cannot redeclare block-scoped variable 'var1'. + + +==== tests/cases/compiler/file1.ts (1 errors) ==== + + let var1 = 0; + ~~~~ +!!! error TS2451: Cannot redeclare block-scoped variable 'var1'. + +==== tests/cases/compiler/file2.ts (1 errors) ==== + const var1 = 0; + ~~~~ +!!! error TS2451: Cannot redeclare block-scoped variable 'var1'. \ No newline at end of file diff --git a/tests/baselines/reference/letDeclarations-scopes-duplicates4.errors.txt b/tests/baselines/reference/letDeclarations-scopes-duplicates4.errors.txt new file mode 100644 index 0000000000000..ec87809b0cda5 --- /dev/null +++ b/tests/baselines/reference/letDeclarations-scopes-duplicates4.errors.txt @@ -0,0 +1,14 @@ +tests/cases/compiler/file1.ts(2,7): error TS2451: Cannot redeclare block-scoped variable 'var1'. +tests/cases/compiler/file2.ts(1,5): error TS2451: Cannot redeclare block-scoped variable 'var1'. + + +==== tests/cases/compiler/file1.ts (1 errors) ==== + + const var1 = 0; + ~~~~ +!!! error TS2451: Cannot redeclare block-scoped variable 'var1'. + +==== tests/cases/compiler/file2.ts (1 errors) ==== + let var1 = 0; + ~~~~ +!!! error TS2451: Cannot redeclare block-scoped variable 'var1'. \ No newline at end of file diff --git a/tests/baselines/reference/letDeclarations-scopes-duplicates5.errors.txt b/tests/baselines/reference/letDeclarations-scopes-duplicates5.errors.txt new file mode 100644 index 0000000000000..ce3a9da598a4a --- /dev/null +++ b/tests/baselines/reference/letDeclarations-scopes-duplicates5.errors.txt @@ -0,0 +1,14 @@ +tests/cases/compiler/file1.ts(2,7): error TS2451: Cannot redeclare block-scoped variable 'var1'. +tests/cases/compiler/file2.ts(1,7): error TS2451: Cannot redeclare block-scoped variable 'var1'. + + +==== tests/cases/compiler/file1.ts (1 errors) ==== + + const var1 = 0; + ~~~~ +!!! error TS2451: Cannot redeclare block-scoped variable 'var1'. + +==== tests/cases/compiler/file2.ts (1 errors) ==== + const var1 = 0; + ~~~~ +!!! error TS2451: Cannot redeclare block-scoped variable 'var1'. \ No newline at end of file diff --git a/tests/baselines/reference/letDeclarations-scopes-duplicates6.errors.txt b/tests/baselines/reference/letDeclarations-scopes-duplicates6.errors.txt new file mode 100644 index 0000000000000..d09eda28075d8 --- /dev/null +++ b/tests/baselines/reference/letDeclarations-scopes-duplicates6.errors.txt @@ -0,0 +1,14 @@ +tests/cases/compiler/file1.ts(2,5): error TS2451: Cannot redeclare block-scoped variable 'var1'. +tests/cases/compiler/file2.ts(1,5): error TS2451: Cannot redeclare block-scoped variable 'var1'. + + +==== tests/cases/compiler/file1.ts (1 errors) ==== + + var var1 = 0; + ~~~~ +!!! error TS2451: Cannot redeclare block-scoped variable 'var1'. + +==== tests/cases/compiler/file2.ts (1 errors) ==== + let var1 = 0; + ~~~~ +!!! error TS2451: Cannot redeclare block-scoped variable 'var1'. \ No newline at end of file diff --git a/tests/baselines/reference/letDeclarations-scopes-duplicates7.errors.txt b/tests/baselines/reference/letDeclarations-scopes-duplicates7.errors.txt new file mode 100644 index 0000000000000..dad85f9f81946 --- /dev/null +++ b/tests/baselines/reference/letDeclarations-scopes-duplicates7.errors.txt @@ -0,0 +1,14 @@ +tests/cases/compiler/file1.ts(2,5): error TS2451: Cannot redeclare block-scoped variable 'var1'. +tests/cases/compiler/file2.ts(1,5): error TS2451: Cannot redeclare block-scoped variable 'var1'. + + +==== tests/cases/compiler/file1.ts (1 errors) ==== + + let var1 = 0; + ~~~~ +!!! error TS2451: Cannot redeclare block-scoped variable 'var1'. + +==== tests/cases/compiler/file2.ts (1 errors) ==== + var var1 = 0; + ~~~~ +!!! error TS2451: Cannot redeclare block-scoped variable 'var1'. \ No newline at end of file diff --git a/tests/baselines/reference/letDeclarations-scopes.errors.txt b/tests/baselines/reference/letDeclarations-scopes.errors.txt new file mode 100644 index 0000000000000..5c89ea98049a6 --- /dev/null +++ b/tests/baselines/reference/letDeclarations-scopes.errors.txt @@ -0,0 +1,163 @@ +tests/cases/compiler/letDeclarations-scopes.ts(28,7): error TS2410: All symbols within a 'with' block will be resolved to 'any'. + + +==== tests/cases/compiler/letDeclarations-scopes.ts (1 errors) ==== + + // global + let l = "string"; + + var n: number; + + // Control flow statements with blocks + if (true) { + let l = 0; + n = l; + } + else { + let l = 0; + n = l; + } + + while (true) { + let l = 0; + n = l; + } + + do { + let l = 0; + n = l; + } while (true); + + var obj; + with (obj) { + ~~~ +!!! error TS2410: All symbols within a 'with' block will be resolved to 'any'. + let l = 0; + n = l; + } + + for (var i = 0; i < 10; i++) { + let l = 0; + n = l; + } + + for (var i2 in {}) { + let l = 0; + n = l; + } + + if (true) { + label: let l = 0; + n = l; + } + + while (false) { + label2: label3: label4: let l = 0; + n = l; + } + + for (let l = 0; n = l; l++) { + let l = true; + var b3: boolean = l; + } + + for (let l in {}) { + + } + + // Try/catch/finally + try { + let l = 0; + n = l; + } + catch (e) { + let l = 0; + n = l; + } + finally { + let l = 0; + n = l; + } + + // Switch + switch (0) { + case 0: + let l = 0; + n = l; + break; + } + + // blocks + { + let l = 0; + n = l; + { + let l = false; + var b: boolean = l; + } + } + + // functions + function F() { + let l = 0; + n = l; + } + + var F2 = () => { + let l = 0; + n = l; + }; + + var F3 = function () { + let l = 0; + n = l; + }; + + // modules + module m { + let l = 0; + n = l; + + { + let l = false; + var b2: boolean = l; + } + + lable: let l2 = 0; + } + + // methods + class C { + constructor() { + let l = 0; + n = l; + } + + method() { + let l = 0; + n = l; + } + + get v() { + let l = 0; + n = l; + return n; + } + + set v(value) { + let l = 0; + n = l; + } + } + + // object literals + var o = { + f() { + let l = 0; + n = l; + }, + f2: () => { + let l = 0; + n = l; + } + } \ No newline at end of file diff --git a/tests/baselines/reference/letDeclarations-scopes.js b/tests/baselines/reference/letDeclarations-scopes.js new file mode 100644 index 0000000000000..fb16a03f569f8 --- /dev/null +++ b/tests/baselines/reference/letDeclarations-scopes.js @@ -0,0 +1,293 @@ +//// [letDeclarations-scopes.ts] + +// global +let l = "string"; + +var n: number; + +// Control flow statements with blocks +if (true) { + let l = 0; + n = l; +} +else { + let l = 0; + n = l; +} + +while (true) { + let l = 0; + n = l; +} + +do { + let l = 0; + n = l; +} while (true); + +var obj; +with (obj) { + let l = 0; + n = l; +} + +for (var i = 0; i < 10; i++) { + let l = 0; + n = l; +} + +for (var i2 in {}) { + let l = 0; + n = l; +} + +if (true) { + label: let l = 0; + n = l; +} + +while (false) { + label2: label3: label4: let l = 0; + n = l; +} + +for (let l = 0; n = l; l++) { + let l = true; + var b3: boolean = l; +} + +for (let l in {}) { + +} + +// Try/catch/finally +try { + let l = 0; + n = l; +} +catch (e) { + let l = 0; + n = l; +} +finally { + let l = 0; + n = l; +} + +// Switch +switch (0) { + case 0: + let l = 0; + n = l; + break; +} + +// blocks +{ + let l = 0; + n = l; + { + let l = false; + var b: boolean = l; + } +} + +// functions +function F() { + let l = 0; + n = l; +} + +var F2 = () => { + let l = 0; + n = l; +}; + +var F3 = function () { + let l = 0; + n = l; +}; + +// modules +module m { + let l = 0; + n = l; + + { + let l = false; + var b2: boolean = l; + } + + lable: let l2 = 0; +} + +// methods +class C { + constructor() { + let l = 0; + n = l; + } + + method() { + let l = 0; + n = l; + } + + get v() { + let l = 0; + n = l; + return n; + } + + set v(value) { + let l = 0; + n = l; + } +} + +// object literals +var o = { + f() { + let l = 0; + n = l; + }, + f2: () => { + let l = 0; + n = l; + } +} + +//// [letDeclarations-scopes.js] +// global +let l = "string"; +var n; +// Control flow statements with blocks +if (true) { + let l = 0; + n = l; +} +else { + let l = 0; + n = l; +} +while (true) { + let l = 0; + n = l; +} +do { + let l = 0; + n = l; +} while (true); +var obj; +with (obj) { + let l = 0; + n = l; +} +for (var i = 0; i < 10; i++) { + let l = 0; + n = l; +} +for (var i2 in {}) { + let l = 0; + n = l; +} +if (true) { + label: let l = 0; + n = l; +} +while (false) { + label2: label3: label4: let l = 0; + n = l; +} +for (let l = 0; n = l; l++) { + let l = true; + var b3 = l; +} +for (let l in {}) { +} +try { + let l = 0; + n = l; +} +catch (e) { + let l = 0; + n = l; +} +finally { + let l = 0; + n = l; +} +switch (0) { + case 0: + let l = 0; + n = l; + break; +} +{ + let l = 0; + n = l; + { + let l = false; + var b = l; + } +} +// functions +function F() { + let l = 0; + n = l; +} +var F2 = function () { + let l = 0; + n = l; +}; +var F3 = function () { + let l = 0; + n = l; +}; +// modules +var m; +(function (m) { + let l = 0; + n = l; + { + let l = false; + var b2 = l; + } + lable: let l2 = 0; +})(m || (m = {})); +// methods +var C = (function () { + function C() { + let l = 0; + n = l; + } + C.prototype.method = function () { + let l = 0; + n = l; + }; + Object.defineProperty(C.prototype, "v", { + get: function () { + let l = 0; + n = l; + return n; + }, + set: function (value) { + let l = 0; + n = l; + }, + enumerable: true, + configurable: true + }); + return C; +})(); +// object literals +var o = { + f: function () { + let l = 0; + n = l; + }, + f2: function () { + let l = 0; + n = l; + } +}; diff --git a/tests/baselines/reference/letDeclarations-scopes2.errors.txt b/tests/baselines/reference/letDeclarations-scopes2.errors.txt new file mode 100644 index 0000000000000..a786db1104b79 --- /dev/null +++ b/tests/baselines/reference/letDeclarations-scopes2.errors.txt @@ -0,0 +1,42 @@ +tests/cases/compiler/letDeclarations-scopes2.ts(9,5): error TS2304: Cannot find name 'local2'. +tests/cases/compiler/letDeclarations-scopes2.ts(21,5): error TS2304: Cannot find name 'local2'. +tests/cases/compiler/letDeclarations-scopes2.ts(24,1): error TS2304: Cannot find name 'local'. +tests/cases/compiler/letDeclarations-scopes2.ts(26,1): error TS2304: Cannot find name 'local2'. + + +==== tests/cases/compiler/letDeclarations-scopes2.ts (4 errors) ==== + + let global = 0; + + { + let local = 0; + + local; // OK + global; // OK + local2; // Error + ~~~~~~ +!!! error TS2304: Cannot find name 'local2'. + + { + let local2 = 0; + + local; // OK + global; // OK + local2; // OK + } + + local; // OK + global; // OK + local2; // Error + ~~~~~~ +!!! error TS2304: Cannot find name 'local2'. + } + + local; // Error + ~~~~~ +!!! error TS2304: Cannot find name 'local'. + global; // OK + local2; // Error + ~~~~~~ +!!! error TS2304: Cannot find name 'local2'. + \ No newline at end of file diff --git a/tests/baselines/reference/letDeclarations-scopes2.js b/tests/baselines/reference/letDeclarations-scopes2.js new file mode 100644 index 0000000000000..98d0e791832e0 --- /dev/null +++ b/tests/baselines/reference/letDeclarations-scopes2.js @@ -0,0 +1,49 @@ +//// [letDeclarations-scopes2.ts] + +let global = 0; + +{ + let local = 0; + + local; // OK + global; // OK + local2; // Error + + { + let local2 = 0; + + local; // OK + global; // OK + local2; // OK + } + + local; // OK + global; // OK + local2; // Error +} + +local; // Error +global; // OK +local2; // Error + + +//// [letDeclarations-scopes2.js] +let global = 0; +{ + let local = 0; + local; // OK + global; // OK + local2; // Error + { + let local2 = 0; + local; // OK + global; // OK + local2; // OK + } + local; // OK + global; // OK + local2; // Error +} +local; // Error +global; // OK +local2; // Error diff --git a/tests/baselines/reference/letDeclarations-useBeforeDefinition.errors.txt b/tests/baselines/reference/letDeclarations-useBeforeDefinition.errors.txt new file mode 100644 index 0000000000000..74c354f4ff26f --- /dev/null +++ b/tests/baselines/reference/letDeclarations-useBeforeDefinition.errors.txt @@ -0,0 +1,21 @@ +tests/cases/compiler/letDeclarations-useBeforeDefinition.ts(3,5): error TS2448: Block-scoped variable 'l1' used before its declaration. +tests/cases/compiler/letDeclarations-useBeforeDefinition.ts(9,5): error TS2448: Block-scoped variable 'v1' used before its declaration. + + +==== tests/cases/compiler/letDeclarations-useBeforeDefinition.ts (2 errors) ==== + + { + l1; + ~~ +!!! error TS2448: Block-scoped variable 'l1' used before its declaration. + let l1; + } + + var v1; + { + v1; + ~~ +!!! error TS2448: Block-scoped variable 'v1' used before its declaration. + let v1 = 0; + } + \ No newline at end of file diff --git a/tests/baselines/reference/letDeclarations-useBeforeDefinition2.errors.txt b/tests/baselines/reference/letDeclarations-useBeforeDefinition2.errors.txt new file mode 100644 index 0000000000000..5b8633312d9a9 --- /dev/null +++ b/tests/baselines/reference/letDeclarations-useBeforeDefinition2.errors.txt @@ -0,0 +1,11 @@ +tests/cases/compiler/file1.ts(2,1): error TS2448: Block-scoped variable 'l' used before its declaration. + + +==== tests/cases/compiler/file1.ts (1 errors) ==== + + l; + ~ +!!! error TS2448: Block-scoped variable 'l' used before its declaration. + +==== tests/cases/compiler/file2.ts (0 errors) ==== + const l = 0; \ No newline at end of file diff --git a/tests/baselines/reference/letDeclarations-validContexts.errors.txt b/tests/baselines/reference/letDeclarations-validContexts.errors.txt new file mode 100644 index 0000000000000..3f3b7a2634f09 --- /dev/null +++ b/tests/baselines/reference/letDeclarations-validContexts.errors.txt @@ -0,0 +1,149 @@ +tests/cases/compiler/letDeclarations-validContexts.ts(20,7): error TS2410: All symbols within a 'with' block will be resolved to 'any'. + + +==== tests/cases/compiler/letDeclarations-validContexts.ts (1 errors) ==== + + + // Control flow statements with blocks + if (true) { + let l1 = 0; + } + else { + let l2 = 0; + } + + while (true) { + let l3 = 0; + } + + do { + let l4 = 0; + } while (true); + + var obj; + with (obj) { + ~~~ +!!! error TS2410: All symbols within a 'with' block will be resolved to 'any'. + let l5 = 0; + } + + for (var i = 0; i < 10; i++) { + let l6 = 0; + } + + for (var i2 in {}) { + let l7 = 0; + } + + if (true) { + label: let l8 = 0; + } + + while (false) { + label2: label3: label4: let l9 = 0; + } + + // Try/catch/finally + try { + let l10 = 0; + } + catch (e) { + let l11 = 0; + } + finally { + let l12 = 0; + } + + // Switch + switch (0) { + case 0: + let l13 = 0; + break; + default: + let l14 = 0; + break; + } + + // blocks + { + let l15 = 0; + { + let l16 = 0 + label17: let l17 = 0; + } + } + + // global + let l18 = 0; + + // functions + function F() { + let l19 = 0; + } + + var F2 = () => { + let l20 = 0; + }; + + var F3 = function () { + let l21 = 0; + }; + + // modules + module m { + let l22 = 0; + + { + let l23 = 0; + } + } + + // methods + class C { + constructor() { + let l24 = 0; + } + + method() { + let l25 = 0; + } + + get v() { + let l26 = 0; + return l26; + } + + set v(value) { + let l27 = value; + } + } + + // object literals + var o = { + f() { + let l28 = 0; + }, + f2: () => { + let l29 = 0; + } + } + + // labels + label: let l30 = 0; + { + label2: let l31 = 0; + } + + function f3() { + label: let l32 = 0; + { + label2: let l33 = 0; + } + } + + module m3 { + label: let l34 = 0; + { + label2: let l35 = 0; + } + } \ No newline at end of file diff --git a/tests/baselines/reference/letDeclarations-validContexts.js b/tests/baselines/reference/letDeclarations-validContexts.js new file mode 100644 index 0000000000000..13eaafb07120d --- /dev/null +++ b/tests/baselines/reference/letDeclarations-validContexts.js @@ -0,0 +1,266 @@ +//// [letDeclarations-validContexts.ts] + + +// Control flow statements with blocks +if (true) { + let l1 = 0; +} +else { + let l2 = 0; +} + +while (true) { + let l3 = 0; +} + +do { + let l4 = 0; +} while (true); + +var obj; +with (obj) { + let l5 = 0; +} + +for (var i = 0; i < 10; i++) { + let l6 = 0; +} + +for (var i2 in {}) { + let l7 = 0; +} + +if (true) { + label: let l8 = 0; +} + +while (false) { + label2: label3: label4: let l9 = 0; +} + +// Try/catch/finally +try { + let l10 = 0; +} +catch (e) { + let l11 = 0; +} +finally { + let l12 = 0; +} + +// Switch +switch (0) { + case 0: + let l13 = 0; + break; + default: + let l14 = 0; + break; +} + +// blocks +{ + let l15 = 0; + { + let l16 = 0 + label17: let l17 = 0; + } +} + +// global +let l18 = 0; + +// functions +function F() { + let l19 = 0; +} + +var F2 = () => { + let l20 = 0; +}; + +var F3 = function () { + let l21 = 0; +}; + +// modules +module m { + let l22 = 0; + + { + let l23 = 0; + } +} + +// methods +class C { + constructor() { + let l24 = 0; + } + + method() { + let l25 = 0; + } + + get v() { + let l26 = 0; + return l26; + } + + set v(value) { + let l27 = value; + } +} + +// object literals +var o = { + f() { + let l28 = 0; + }, + f2: () => { + let l29 = 0; + } +} + +// labels +label: let l30 = 0; +{ + label2: let l31 = 0; +} + +function f3() { + label: let l32 = 0; + { + label2: let l33 = 0; + } +} + +module m3 { + label: let l34 = 0; + { + label2: let l35 = 0; + } +} + +//// [letDeclarations-validContexts.js] +// Control flow statements with blocks +if (true) { + let l1 = 0; +} +else { + let l2 = 0; +} +while (true) { + let l3 = 0; +} +do { + let l4 = 0; +} while (true); +var obj; +with (obj) { + let l5 = 0; +} +for (var i = 0; i < 10; i++) { + let l6 = 0; +} +for (var i2 in {}) { + let l7 = 0; +} +if (true) { + label: let l8 = 0; +} +while (false) { + label2: label3: label4: let l9 = 0; +} +try { + let l10 = 0; +} +catch (e) { + let l11 = 0; +} +finally { + let l12 = 0; +} +switch (0) { + case 0: + let l13 = 0; + break; + default: + let l14 = 0; + break; +} +{ + let l15 = 0; + { + let l16 = 0; + label17: let l17 = 0; + } +} +// global +let l18 = 0; +// functions +function F() { + let l19 = 0; +} +var F2 = function () { + let l20 = 0; +}; +var F3 = function () { + let l21 = 0; +}; +// modules +var m; +(function (m) { + let l22 = 0; + { + let l23 = 0; + } +})(m || (m = {})); +// methods +var C = (function () { + function C() { + let l24 = 0; + } + C.prototype.method = function () { + let l25 = 0; + }; + Object.defineProperty(C.prototype, "v", { + get: function () { + let l26 = 0; + return l26; + }, + set: function (value) { + let l27 = value; + }, + enumerable: true, + configurable: true + }); + return C; +})(); +// object literals +var o = { + f: function () { + let l28 = 0; + }, + f2: function () { + let l29 = 0; + } +}; +label: let l30 = 0; +{ + label2: let l31 = 0; +} +function f3() { + label: let l32 = 0; + { + label2: let l33 = 0; + } +} +var m3; +(function (m3) { + label: let l34 = 0; + { + label2: let l35 = 0; + } +})(m3 || (m3 = {})); diff --git a/tests/baselines/reference/letDeclarations.js b/tests/baselines/reference/letDeclarations.js new file mode 100644 index 0000000000000..bc186b732f559 --- /dev/null +++ b/tests/baselines/reference/letDeclarations.js @@ -0,0 +1,35 @@ +//// [letDeclarations.ts] + +let l1; +let l2: number; +let l3, l4, l5 :string, l6; + +let l7 = false; +let l8: number = 23; +let l9 = 0, l10 :string = "", l11 = null; + +for(let l11 in {}) { } + +for(let l12 = 0; l12 < 9; l12++) { } + + +//// [letDeclarations.js] +let l1; +let l2; +let l3, l4, l5, l6; +let l7 = false; +let l8 = 23; +let l9 = 0, l10 = "", l11 = null; +for (let l11 in {}) { +} +for (let l12 = 0; l12 < 9; l12++) { +} + + +//// [letDeclarations.d.ts] +declare let l1: any; +declare let l2: number; +declare let l3: any, l4: any, l5: string, l6: any; +declare let l7: boolean; +declare let l8: number; +declare let l9: number, l10: string, l11: any; diff --git a/tests/baselines/reference/letDeclarations.types b/tests/baselines/reference/letDeclarations.types new file mode 100644 index 0000000000000..aa47a7f000645 --- /dev/null +++ b/tests/baselines/reference/letDeclarations.types @@ -0,0 +1,36 @@ +=== tests/cases/compiler/letDeclarations.ts === + +let l1; +>l1 : any + +let l2: number; +>l2 : number + +let l3, l4, l5 :string, l6; +>l3 : any +>l4 : any +>l5 : string +>l6 : any + +let l7 = false; +>l7 : boolean + +let l8: number = 23; +>l8 : number + +let l9 = 0, l10 :string = "", l11 = null; +>l9 : number +>l10 : string +>l11 : any + +for(let l11 in {}) { } +>l11 : any +>{} : {} + +for(let l12 = 0; l12 < 9; l12++) { } +>l12 : number +>l12 < 9 : boolean +>l12 : number +>l12++ : number +>l12 : number + diff --git a/tests/baselines/reference/letDeclarations2.js b/tests/baselines/reference/letDeclarations2.js new file mode 100644 index 0000000000000..8a6f039f2ca93 --- /dev/null +++ b/tests/baselines/reference/letDeclarations2.js @@ -0,0 +1,19 @@ +//// [letDeclarations2.ts] + +module M { + let l1 = "s"; + export let l2 = 0; +} + +//// [letDeclarations2.js] +var M; +(function (M) { + let l1 = "s"; + M.l2 = 0; +})(M || (M = {})); + + +//// [letDeclarations2.d.ts] +declare module M { + let l2: number; +} diff --git a/tests/baselines/reference/letDeclarations2.types b/tests/baselines/reference/letDeclarations2.types new file mode 100644 index 0000000000000..2fa08b6d9400b --- /dev/null +++ b/tests/baselines/reference/letDeclarations2.types @@ -0,0 +1,11 @@ +=== tests/cases/compiler/letDeclarations2.ts === + +module M { +>M : typeof M + + let l1 = "s"; +>l1 : string + + export let l2 = 0; +>l2 : number +} diff --git a/tests/baselines/reference/parserEnum5.errors.txt b/tests/baselines/reference/parserEnum5.errors.txt index 40c2c933955a6..b98fdfbfba503 100644 --- a/tests/baselines/reference/parserEnum5.errors.txt +++ b/tests/baselines/reference/parserEnum5.errors.txt @@ -1,9 +1,9 @@ tests/cases/conformance/parser/ecmascript5/EnumDeclarations/parserEnum5.ts(2,12): error TS1005: ',' expected. tests/cases/conformance/parser/ecmascript5/EnumDeclarations/parserEnum5.ts(3,15): error TS1005: ',' expected. tests/cases/conformance/parser/ecmascript5/EnumDeclarations/parserEnum5.ts(3,24): error TS1005: ',' expected. -tests/cases/conformance/parser/ecmascript5/EnumDeclarations/parserEnum5.ts(2,14): error TS1151: An enum member cannot have a numeric name. -tests/cases/conformance/parser/ecmascript5/EnumDeclarations/parserEnum5.ts(3,17): error TS1151: An enum member cannot have a numeric name. -tests/cases/conformance/parser/ecmascript5/EnumDeclarations/parserEnum5.ts(3,26): error TS1151: An enum member cannot have a numeric name. +tests/cases/conformance/parser/ecmascript5/EnumDeclarations/parserEnum5.ts(2,14): error TS2452: An enum member cannot have a numeric name. +tests/cases/conformance/parser/ecmascript5/EnumDeclarations/parserEnum5.ts(3,17): error TS2452: An enum member cannot have a numeric name. +tests/cases/conformance/parser/ecmascript5/EnumDeclarations/parserEnum5.ts(3,26): error TS2452: An enum member cannot have a numeric name. ==== tests/cases/conformance/parser/ecmascript5/EnumDeclarations/parserEnum5.ts (6 errors) ==== @@ -12,13 +12,13 @@ tests/cases/conformance/parser/ecmascript5/EnumDeclarations/parserEnum5.ts(3,26) ~ !!! error TS1005: ',' expected. ~ -!!! error TS1151: An enum member cannot have a numeric name. +!!! error TS2452: An enum member cannot have a numeric name. enum E1 { a, b: 1, c, d: 2 = 3 } ~ !!! error TS1005: ',' expected. ~ !!! error TS1005: ',' expected. ~ -!!! error TS1151: An enum member cannot have a numeric name. +!!! error TS2452: An enum member cannot have a numeric name. ~ -!!! error TS1151: An enum member cannot have a numeric name. \ No newline at end of file +!!! error TS2452: An enum member cannot have a numeric name. \ No newline at end of file diff --git a/tests/baselines/reference/parserEnum7.errors.txt b/tests/baselines/reference/parserEnum7.errors.txt index a4a2326546a05..1a7f26df8db9c 100644 --- a/tests/baselines/reference/parserEnum7.errors.txt +++ b/tests/baselines/reference/parserEnum7.errors.txt @@ -1,15 +1,15 @@ -tests/cases/conformance/parser/ecmascript5/EnumDeclarations/parserEnum7.ts(2,3): error TS1151: An enum member cannot have a numeric name. -tests/cases/conformance/parser/ecmascript5/EnumDeclarations/parserEnum7.ts(2,6): error TS1151: An enum member cannot have a numeric name. -tests/cases/conformance/parser/ecmascript5/EnumDeclarations/parserEnum7.ts(2,9): error TS1151: An enum member cannot have a numeric name. +tests/cases/conformance/parser/ecmascript5/EnumDeclarations/parserEnum7.ts(2,3): error TS2452: An enum member cannot have a numeric name. +tests/cases/conformance/parser/ecmascript5/EnumDeclarations/parserEnum7.ts(2,6): error TS2452: An enum member cannot have a numeric name. +tests/cases/conformance/parser/ecmascript5/EnumDeclarations/parserEnum7.ts(2,9): error TS2452: An enum member cannot have a numeric name. ==== tests/cases/conformance/parser/ecmascript5/EnumDeclarations/parserEnum7.ts (3 errors) ==== enum E { 1, 2, 3 ~ -!!! error TS1151: An enum member cannot have a numeric name. +!!! error TS2452: An enum member cannot have a numeric name. ~ -!!! error TS1151: An enum member cannot have a numeric name. +!!! error TS2452: An enum member cannot have a numeric name. ~ -!!! error TS1151: An enum member cannot have a numeric name. +!!! error TS2452: An enum member cannot have a numeric name. } \ No newline at end of file diff --git a/tests/baselines/reference/parserOptionalTypeMembers1.errors.txt b/tests/baselines/reference/parserOptionalTypeMembers1.errors.txt deleted file mode 100644 index 0279ad37777ef..0000000000000 --- a/tests/baselines/reference/parserOptionalTypeMembers1.errors.txt +++ /dev/null @@ -1,23 +0,0 @@ -tests/cases/conformance/parser/ecmascript5/parserOptionalTypeMembers1.ts(2,5): error TS2300: Duplicate identifier 'configurable'. -tests/cases/conformance/parser/ecmascript5/parserOptionalTypeMembers1.ts(3,5): error TS2300: Duplicate identifier 'enumerable'. -tests/cases/conformance/parser/ecmascript5/parserOptionalTypeMembers1.ts(4,5): error TS2300: Duplicate identifier 'value'. -tests/cases/conformance/parser/ecmascript5/parserOptionalTypeMembers1.ts(5,5): error TS2300: Duplicate identifier 'writable'. - - -==== tests/cases/conformance/parser/ecmascript5/parserOptionalTypeMembers1.ts (4 errors) ==== - interface PropertyDescriptor { - configurable?: boolean; - ~~~~~~~~~~~~ -!!! error TS2300: Duplicate identifier 'configurable'. - enumerable?: boolean; - ~~~~~~~~~~ -!!! error TS2300: Duplicate identifier 'enumerable'. - value?: any; - ~~~~~ -!!! error TS2300: Duplicate identifier 'value'. - writable?: boolean; - ~~~~~~~~ -!!! error TS2300: Duplicate identifier 'writable'. - get?(): any; - set?(v: any): void; - } \ No newline at end of file diff --git a/tests/baselines/reference/parserOptionalTypeMembers1.js b/tests/baselines/reference/parserOptionalTypeMembers1.js index 5dfb0adfe8260..757887e540966 100644 --- a/tests/baselines/reference/parserOptionalTypeMembers1.js +++ b/tests/baselines/reference/parserOptionalTypeMembers1.js @@ -1,5 +1,5 @@ //// [parserOptionalTypeMembers1.ts] -interface PropertyDescriptor { +interface PropertyDescriptor2 { configurable?: boolean; enumerable?: boolean; value?: any; diff --git a/tests/baselines/reference/parserOptionalTypeMembers1.types b/tests/baselines/reference/parserOptionalTypeMembers1.types new file mode 100644 index 0000000000000..7ede18a1d9246 --- /dev/null +++ b/tests/baselines/reference/parserOptionalTypeMembers1.types @@ -0,0 +1,23 @@ +=== tests/cases/conformance/parser/ecmascript5/parserOptionalTypeMembers1.ts === +interface PropertyDescriptor2 { +>PropertyDescriptor2 : PropertyDescriptor2 + + configurable?: boolean; +>configurable : boolean + + enumerable?: boolean; +>enumerable : boolean + + value?: any; +>value : any + + writable?: boolean; +>writable : boolean + + get?(): any; +>get : () => any + + set?(v: any): void; +>set : (v: any) => void +>v : any +} diff --git a/tests/baselines/reference/project/declareVariableCollision/amd/declareVariableCollision.errors.txt b/tests/baselines/reference/project/declareVariableCollision/amd/declareVariableCollision.errors.txt index 5dc0a63d7eb11..64ec399fabf71 100644 --- a/tests/baselines/reference/project/declareVariableCollision/amd/declareVariableCollision.errors.txt +++ b/tests/baselines/reference/project/declareVariableCollision/amd/declareVariableCollision.errors.txt @@ -1,3 +1,4 @@ +in1.d.ts(1,8): error TS2300: Duplicate identifier 'a'. in2.d.ts(1,8): error TS2300: Duplicate identifier 'a'. @@ -14,8 +15,10 @@ in2.d.ts(1,8): error TS2300: Duplicate identifier 'a'. class MyClass{ } } } -==== in1.d.ts (0 errors) ==== +==== in1.d.ts (1 errors) ==== import a = A; + ~ +!!! error TS2300: Duplicate identifier 'a'. ==== in2.d.ts (1 errors) ==== import a = A; ~ diff --git a/tests/baselines/reference/project/declareVariableCollision/node/declareVariableCollision.errors.txt b/tests/baselines/reference/project/declareVariableCollision/node/declareVariableCollision.errors.txt index 5dc0a63d7eb11..64ec399fabf71 100644 --- a/tests/baselines/reference/project/declareVariableCollision/node/declareVariableCollision.errors.txt +++ b/tests/baselines/reference/project/declareVariableCollision/node/declareVariableCollision.errors.txt @@ -1,3 +1,4 @@ +in1.d.ts(1,8): error TS2300: Duplicate identifier 'a'. in2.d.ts(1,8): error TS2300: Duplicate identifier 'a'. @@ -14,8 +15,10 @@ in2.d.ts(1,8): error TS2300: Duplicate identifier 'a'. class MyClass{ } } } -==== in1.d.ts (0 errors) ==== +==== in1.d.ts (1 errors) ==== import a = A; + ~ +!!! error TS2300: Duplicate identifier 'a'. ==== in2.d.ts (1 errors) ==== import a = A; ~ diff --git a/tests/cases/compiler/constDeclarationShadowedByVarDeclaration.ts b/tests/cases/compiler/constDeclarationShadowedByVarDeclaration.ts new file mode 100644 index 0000000000000..a4d392338477a --- /dev/null +++ b/tests/cases/compiler/constDeclarationShadowedByVarDeclaration.ts @@ -0,0 +1,24 @@ +// @target: ES6 + +// Error as declaration of var would cause a write to the const value +var x = 0; +{ + const x = 0; + + var x = 0; +} + + +var y = 0; +{ + const y = 0; + { + var y = 0; + } +} + + +{ + const z = 0; + var z = 0 +} \ No newline at end of file diff --git a/tests/cases/compiler/constDeclarationShadowedByVarDeclaration2.ts b/tests/cases/compiler/constDeclarationShadowedByVarDeclaration2.ts new file mode 100644 index 0000000000000..98930953996bb --- /dev/null +++ b/tests/cases/compiler/constDeclarationShadowedByVarDeclaration2.ts @@ -0,0 +1,9 @@ +// @target: ES6 + +// No errors, const declaration is not shadowed +function outer() { + const x = 0; + function inner() { + var x = "inner"; + } +} \ No newline at end of file diff --git a/tests/cases/compiler/constDeclarationShadowedByVarDeclaration3.ts b/tests/cases/compiler/constDeclarationShadowedByVarDeclaration3.ts new file mode 100644 index 0000000000000..5b4229a8e5469 --- /dev/null +++ b/tests/cases/compiler/constDeclarationShadowedByVarDeclaration3.ts @@ -0,0 +1,9 @@ +// Ensure only checking for const declarations shadowed by vars +class Rule { + public regex: RegExp = new RegExp(''); + public name: string = ''; + + constructor(name: string) { + this.name = name; + } +} \ No newline at end of file diff --git a/tests/cases/compiler/constDeclarations-access.ts b/tests/cases/compiler/constDeclarations-access.ts new file mode 100644 index 0000000000000..665d6753a6df6 --- /dev/null +++ b/tests/cases/compiler/constDeclarations-access.ts @@ -0,0 +1,7 @@ +// @target: ES6 + +// @Filename: file1.ts +const x = 0 + +// @Filename: file2.ts +x++; \ No newline at end of file diff --git a/tests/cases/compiler/constDeclarations-access2.ts b/tests/cases/compiler/constDeclarations-access2.ts new file mode 100644 index 0000000000000..e3f83940d1de0 --- /dev/null +++ b/tests/cases/compiler/constDeclarations-access2.ts @@ -0,0 +1,40 @@ +// @target: ES6 + +const x = 0 + +// Errors +x = 1; +x += 2; +x -= 3; +x *= 4; +x /= 5; +x %= 6; +x <<= 7; +x >>= 8; +x >>>= 9; +x &= 10; +x |= 11; +x ^= 12; + +x++; +x--; +++x; +--x; + +++((x)); + +// OK +var a = x + 1; + +function f(v: number) { } +f(x); + +if (x) { } + +x; +(x); + +-x; ++x; + +x.toString(); diff --git a/tests/cases/compiler/constDeclarations-access3.ts b/tests/cases/compiler/constDeclarations-access3.ts new file mode 100644 index 0000000000000..370288dab9734 --- /dev/null +++ b/tests/cases/compiler/constDeclarations-access3.ts @@ -0,0 +1,45 @@ +// @target: ES6 + + +module M { + export const x = 0; +} + +// Errors +M.x = 1; +M.x += 2; +M.x -= 3; +M.x *= 4; +M.x /= 5; +M.x %= 6; +M.x <<= 7; +M.x >>= 8; +M.x >>>= 9; +M.x &= 10; +M.x |= 11; +M.x ^= 12; + +M.x++; +M.x--; +++M.x; +--M.x; + +++((M.x)); + +M["x"] = 0; + +// OK +var a = M.x + 1; + +function f(v: number) { } +f(M.x); + +if (M.x) { } + +M.x; +(M.x); + +-M.x; ++M.x; + +M.x.toString(); diff --git a/tests/cases/compiler/constDeclarations-access4.ts b/tests/cases/compiler/constDeclarations-access4.ts new file mode 100644 index 0000000000000..492f6a31d6df7 --- /dev/null +++ b/tests/cases/compiler/constDeclarations-access4.ts @@ -0,0 +1,45 @@ +// @target: ES6 + + +declare module M { + const x: number; +} + +// Errors +M.x = 1; +M.x += 2; +M.x -= 3; +M.x *= 4; +M.x /= 5; +M.x %= 6; +M.x <<= 7; +M.x >>= 8; +M.x >>>= 9; +M.x &= 10; +M.x |= 11; +M.x ^= 12; + +M.x++; +M.x--; +++M.x; +--M.x; + +++((M.x)); + +M["x"] = 0; + +// OK +var a = M.x + 1; + +function f(v: number) { } +f(M.x); + +if (M.x) { } + +M.x; +(M.x); + +-M.x; ++M.x; + +M.x.toString(); diff --git a/tests/cases/compiler/constDeclarations-access5.ts b/tests/cases/compiler/constDeclarations-access5.ts new file mode 100644 index 0000000000000..1590d9289ef71 --- /dev/null +++ b/tests/cases/compiler/constDeclarations-access5.ts @@ -0,0 +1,48 @@ +// @target: ES6 +// @module: amd + + +// @Filename: constDeclarations_access_1.ts +export const x = 0; + +// @Filename: constDeclarations_access_2.ts +/// +import m = require('constDeclarations_access_1'); +// Errors +m.x = 1; +m.x += 2; +m.x -= 3; +m.x *= 4; +m.x /= 5; +m.x %= 6; +m.x <<= 7; +m.x >>= 8; +m.x >>>= 9; +m.x &= 10; +m.x |= 11; +m.x ^= 12; +m +m.x++; +m.x--; +++m.x; +--m.x; + +++((m.x)); + +m["x"] = 0; + +// OK +var a = m.x + 1; + +function f(v: number) { } +f(m.x); + +if (m.x) { } + +m.x; +(m.x); + +-m.x; ++m.x; + +m.x.toString(); diff --git a/tests/cases/compiler/constDeclarations-ambient-errors.ts b/tests/cases/compiler/constDeclarations-ambient-errors.ts new file mode 100644 index 0000000000000..c07bfb01810a5 --- /dev/null +++ b/tests/cases/compiler/constDeclarations-ambient-errors.ts @@ -0,0 +1,11 @@ +// @target: ES6 + +// error: no intialization expected in ambient declarations +declare const c1: boolean = true; +declare const c2: number = 0; +declare const c3 = null, c4 :string = "", c5: any = 0; + +declare module M { + const c6 = 0; + const c7: number = 7; +} \ No newline at end of file diff --git a/tests/cases/compiler/constDeclarations-ambient.ts b/tests/cases/compiler/constDeclarations-ambient.ts new file mode 100644 index 0000000000000..dcd4cb9fc726d --- /dev/null +++ b/tests/cases/compiler/constDeclarations-ambient.ts @@ -0,0 +1,11 @@ +// @target: ES6 + +// No error +declare const c1: boolean; +declare const c2: number; +declare const c3, c4 :string, c5: any; + +declare module M { + const c6; + const c7: number; +} \ No newline at end of file diff --git a/tests/cases/compiler/constDeclarations-errors.ts b/tests/cases/compiler/constDeclarations-errors.ts new file mode 100644 index 0000000000000..09dc0e9679068 --- /dev/null +++ b/tests/cases/compiler/constDeclarations-errors.ts @@ -0,0 +1,18 @@ +// @target: ES6 + +// error, missing intialicer +const c1; +const c2: number; +const c3, c4, c5 :string, c6; // error, missing initialicer + +// error, can not be unintalized +for(const c in {}) { } + +// error, assigning to a const +for(const c8 = 0; c8 < 1; c8++) { } + +// error, can not be unintalized +for(const c9; c9 < 1;) { } + +// error, can not be unintalized +for(const c10 = 0, c11; c10 < 1;) { } \ No newline at end of file diff --git a/tests/cases/compiler/constDeclarations-es5.ts b/tests/cases/compiler/constDeclarations-es5.ts new file mode 100644 index 0000000000000..0da824a7396d8 --- /dev/null +++ b/tests/cases/compiler/constDeclarations-es5.ts @@ -0,0 +1,5 @@ +// @target: ES5 + +const z7 = false; +const z8: number = 23; +const z9 = 0, z10 :string = "", z11 = null; diff --git a/tests/cases/compiler/constDeclarations-invalidContexts.ts b/tests/cases/compiler/constDeclarations-invalidContexts.ts new file mode 100644 index 0000000000000..3da91a7d1d75c --- /dev/null +++ b/tests/cases/compiler/constDeclarations-invalidContexts.ts @@ -0,0 +1,33 @@ +// @target: ES6 + +// Errors, const must be defined inside a block +if (true) + const c1 = 0; +else + const c2 = 0; + +while (true) + const c3 = 0; + +do + const c4 = 0; +while (true); + +var obj; +with (obj) + const c5 = 0; + +for (var i = 0; i < 10; i++) + const c6 = 0; + +for (var i2 in {}) + const c7 = 0; + +if (true) + label: const c8 = 0; + +while (false) + label2: label3: label4: const c9 = 0; + + + diff --git a/tests/cases/compiler/constDeclarations-scopes.ts b/tests/cases/compiler/constDeclarations-scopes.ts new file mode 100644 index 0000000000000..d0c1df425b618 --- /dev/null +++ b/tests/cases/compiler/constDeclarations-scopes.ts @@ -0,0 +1,148 @@ +// @target: ES6 + +// global +const c = "string"; + +var n: number; + +// Control flow statements with blocks +if (true) { + const c = 0; + n = c; +} +else { + const c = 0; + n = c; +} + +while (true) { + const c = 0; + n = c; +} + +do { + const c = 0; + n = c; +} while (true); + +var obj; +with (obj) { + const c = 0; + n = c; +} + +for (var i = 0; i < 10; i++) { + const c = 0; + n = c; +} + +for (var i2 in {}) { + const c = 0; + n = c; +} + +if (true) { + label: const c = 0; + n = c; +} + +while (false) { + label2: label3: label4: const c = 0; + n = c; +} + +// Try/catch/finally +try { + const c = 0; + n = c; +} +catch (e) { + const c = 0; + n = c; +} +finally { + const c = 0; + n = c; +} + +// Switch +switch (0) { + case 0: + const c = 0; + n = c; + break; +} + +// blocks +{ + const c = 0; + n = c; + { + const c = false; + var b: boolean = c; + } +} + +// functions + +function F() { + const c = 0; + n = c; +} + +var F2 = () => { + const c = 0; + n = c; +}; + +var F3 = function () { + const c = 0; + n = c; +}; + +// modules +module m { + const c = 0; + n = c; + + { + const c = false; + var b2: boolean = c; + } +} + +// methods +class C { + constructor() { + const c = 0; + n = c; + } + + method() { + const c = 0; + n = c; + } + + get v() { + const c = 0; + n = c; + return n; + } + + set v(value) { + const c = 0; + n = c; + } +} + +// object literals +var o = { + f() { + const c = 0; + n = c; + }, + f2: () => { + const c = 0; + n = c; + } +} \ No newline at end of file diff --git a/tests/cases/compiler/constDeclarations-scopes2.ts b/tests/cases/compiler/constDeclarations-scopes2.ts new file mode 100644 index 0000000000000..fe0ab16409a98 --- /dev/null +++ b/tests/cases/compiler/constDeclarations-scopes2.ts @@ -0,0 +1,15 @@ +// @target: ES6 + +// global +const c = "string"; + +var n: number; +var b: boolean; + +// for scope +for (const c = 0; c < 10; n = c ) { + // for block + const c = false; + b = c; +} + diff --git a/tests/cases/compiler/constDeclarations-useBeforeDefinition.ts b/tests/cases/compiler/constDeclarations-useBeforeDefinition.ts new file mode 100644 index 0000000000000..ec793fda4846f --- /dev/null +++ b/tests/cases/compiler/constDeclarations-useBeforeDefinition.ts @@ -0,0 +1,12 @@ +// @target: ES6 + +{ + c1; + const c1 = 0; +} + +var v1; +{ + v1; + const v1 = 0; +} diff --git a/tests/cases/compiler/constDeclarations-useBeforeDefinition2.ts b/tests/cases/compiler/constDeclarations-useBeforeDefinition2.ts new file mode 100644 index 0000000000000..c34bb4012bfc2 --- /dev/null +++ b/tests/cases/compiler/constDeclarations-useBeforeDefinition2.ts @@ -0,0 +1,8 @@ +// @target: ES6 +// @out: out.js + +// @Filename: file1.ts +c; + +// @Filename: file2.ts +const c = 0; \ No newline at end of file diff --git a/tests/cases/compiler/constDeclarations-validContexts.ts b/tests/cases/compiler/constDeclarations-validContexts.ts new file mode 100644 index 0000000000000..ffde8e45d6fa1 --- /dev/null +++ b/tests/cases/compiler/constDeclarations-validContexts.ts @@ -0,0 +1,124 @@ +// @target: ES6 + + +// Control flow statements with blocks +if (true) { + const c1 = 0; +} +else { + const c2 = 0; +} + +while (true) { + const c3 = 0; +} + +do { + const c4 = 0; +} while (true); + +var obj; +with (obj) { + const c5 = 0; +} + +for (var i = 0; i < 10; i++) { + const c6 = 0; +} + +for (var i2 in {}) { + const c7 = 0; +} + +if (true) { + label: const c8 = 0; +} + +while (false) { + label2: label3: label4: const c9 = 0; +} + +// Try/catch/finally +try { + const c10 = 0; +} +catch (e) { + const c11 = 0; +} +finally { + const c12 = 0; +} + +// Switch +switch (0) { + case 0: + const c13 = 0; + break; + default: + const c14 = 0; + break; +} + +// blocks +{ + const c15 = 0; + { + const c16 = 0 + label17: const c17 = 0; + } +} + +// global +const c18 = 0; + +// functions +function F() { + const c19 = 0; +} + +var F2 = () => { + const c20 = 0; +}; + +var F3 = function () { + const c21 = 0; +}; + +// modules +module m { + const c22 = 0; + + { + const c23 = 0; + } +} + +// methods +class C { + constructor() { + const c24 = 0; + } + + method() { + const c25 = 0; + } + + get v() { + const c26 = 0; + return c26; + } + + set v(value) { + const c27 = value; + } +} + +// object literals +var o = { + f() { + const c28 = 0; + }, + f2: () => { + const c29 = 0; + } +} \ No newline at end of file diff --git a/tests/cases/compiler/constDeclarations.ts b/tests/cases/compiler/constDeclarations.ts new file mode 100644 index 0000000000000..2b8563b340a21 --- /dev/null +++ b/tests/cases/compiler/constDeclarations.ts @@ -0,0 +1,13 @@ +// @target: ES6 +// @declaration: true + +// No error +const c1 = false; +const c2: number = 23; +const c3 = 0, c4 :string = "", c5 = null; + + +for(const c4 = 0; c4 < 9; ) { break; } + + +for(const c5 = 0, c6 = 0; c5 < c6; ) { break; } \ No newline at end of file diff --git a/tests/cases/compiler/constDeclarations2.ts b/tests/cases/compiler/constDeclarations2.ts new file mode 100644 index 0000000000000..a221c3563bae0 --- /dev/null +++ b/tests/cases/compiler/constDeclarations2.ts @@ -0,0 +1,9 @@ +// @target: ES6 +// @declaration: true + +// No error +module M { + export const c1 = false; + export const c2: number = 23; + export const c3 = 0, c4 :string = "", c5 = null; +} diff --git a/tests/cases/compiler/es6-amd.ts b/tests/cases/compiler/es6-amd.ts new file mode 100644 index 0000000000000..a5fb99a86051d --- /dev/null +++ b/tests/cases/compiler/es6-amd.ts @@ -0,0 +1,17 @@ +// @target: ES6 +// @sourcemap: false +// @declaration: false +// @module: amd + +class A +{ + constructor () + { + + } + + public B() + { + return 42; + } +} \ No newline at end of file diff --git a/tests/cases/compiler/es6-declaration-amd.ts b/tests/cases/compiler/es6-declaration-amd.ts new file mode 100644 index 0000000000000..1dcfeca84979e --- /dev/null +++ b/tests/cases/compiler/es6-declaration-amd.ts @@ -0,0 +1,17 @@ +// @target: ES6 +// @sourcemap: false +// @declaration: true +// @module: amd + +class A +{ + constructor () + { + + } + + public B() + { + return 42; + } +} \ No newline at end of file diff --git a/tests/cases/compiler/es6-sourcemap-amd.ts b/tests/cases/compiler/es6-sourcemap-amd.ts new file mode 100644 index 0000000000000..c00a697de940b --- /dev/null +++ b/tests/cases/compiler/es6-sourcemap-amd.ts @@ -0,0 +1,16 @@ +// @target: ES6 +// @sourcemap: true +// @module: amd + +class A +{ + constructor () + { + + } + + public B() + { + return 42; + } +} \ No newline at end of file diff --git a/tests/cases/compiler/functionTypeArgumentArrayAssignment.ts b/tests/cases/compiler/functionTypeArgumentArrayAssignment.ts index 77fbb74d7ad3e..91cf2d551b9d4 100644 --- a/tests/cases/compiler/functionTypeArgumentArrayAssignment.ts +++ b/tests/cases/compiler/functionTypeArgumentArrayAssignment.ts @@ -1,8 +1,10 @@ -interface Array { - foo: T; - length: number; -} +module test { + interface Array { + foo: T; + length: number; + } -function map() { -var ys: U[] = []; + function map() { + var ys: U[] = []; + } } diff --git a/tests/cases/compiler/instanceofOperator.ts b/tests/cases/compiler/instanceofOperator.ts index 60b724149ce5d..f9b304de11367 100644 Binary files a/tests/cases/compiler/instanceofOperator.ts and b/tests/cases/compiler/instanceofOperator.ts differ diff --git a/tests/cases/compiler/letDeclarations-access.ts b/tests/cases/compiler/letDeclarations-access.ts new file mode 100644 index 0000000000000..6ed655f1cb25c --- /dev/null +++ b/tests/cases/compiler/letDeclarations-access.ts @@ -0,0 +1,38 @@ +// @target: ES6 + +let x = 0 + +// No errors + +x = 1; +x += 2; +x -= 3; +x *= 4; +x /= 5; +x %= 6; +x <<= 7; +x >>= 8; +x >>>= 9; +x &= 10; +x |= 11; +x ^= 12; + +x++; +x--; +++x; +--x; + +var a = x + 1; + +function f(v: number) { } +f(x); + +if (x) { } + +x; +(x); + +-x; ++x; + +x.toString(); diff --git a/tests/cases/compiler/letDeclarations-es5.ts b/tests/cases/compiler/letDeclarations-es5.ts new file mode 100644 index 0000000000000..b115c260a915c --- /dev/null +++ b/tests/cases/compiler/letDeclarations-es5.ts @@ -0,0 +1,13 @@ +// @target: ES5 + +let l1; +let l2: number; +let l3, l4, l5 :string, l6; + +let l7 = false; +let l8: number = 23; +let l9 = 0, l10 :string = "", l11 = null; + +for(let l11 in {}) { } + +for(let l12 = 0; l12 < 9; l12++) { } diff --git a/tests/cases/compiler/letDeclarations-invalidContexts.ts b/tests/cases/compiler/letDeclarations-invalidContexts.ts new file mode 100644 index 0000000000000..4d165ba2cda0e --- /dev/null +++ b/tests/cases/compiler/letDeclarations-invalidContexts.ts @@ -0,0 +1,33 @@ +// @target: ES6 + +// Errors, let must be defined inside a block +if (true) + let l1 = 0; +else + let l2 = 0; + +while (true) + let l3 = 0; + +do + let l4 = 0; +while (true); + +var obj; +with (obj) + let l5 = 0; + +for (var i = 0; i < 10; i++) + let l6 = 0; + +for (var i2 in {}) + let l7 = 0; + +if (true) + label: let l8 = 0; + +while (false) + label2: label3: label4: let l9 = 0; + + + diff --git a/tests/cases/compiler/letDeclarations-scopes-duplicates.ts b/tests/cases/compiler/letDeclarations-scopes-duplicates.ts new file mode 100644 index 0000000000000..841b55af1685b --- /dev/null +++ b/tests/cases/compiler/letDeclarations-scopes-duplicates.ts @@ -0,0 +1,77 @@ +// @target: ES6 + +// Errors: redeclaration +let var1 = 0; +let var1 = 0; // error + +let var2 = 0; +const var2 = 0; + +const var3 = 0; +let var3 = 0; + +const var4 = 0; +const var4 = 0; + +var var5 = 0; +let var5 = 0; + +let var6 = 0; +var var6 = 0; + +{ + let var7 = 0; + let var7 = 0; + { + let var8 = 0; + const var8 = 0; + } +} + +switch (0) { + default: + let var9 = 0; + let var9 = 0; +} + +try { + const var10 = 0; + const var10 = 0; +} +catch (e) { + let var11 = 0; + let var11 = 0; +} + +function F1() { + let var12; + let var12; +} + +// OK +var var20 = 0; + +var var20 = 0 +{ + let var20 = 0; + { + let var20 = 0; + } +} + +switch (0) { + default: + let var20 = 0; +} + +try { + let var20 = 0; +} +catch (e) { + let var20 = 0; +} + +function F() { + let var20; +} + diff --git a/tests/cases/compiler/letDeclarations-scopes-duplicates2.ts b/tests/cases/compiler/letDeclarations-scopes-duplicates2.ts new file mode 100644 index 0000000000000..40ddc14fc3f1a --- /dev/null +++ b/tests/cases/compiler/letDeclarations-scopes-duplicates2.ts @@ -0,0 +1,7 @@ +// @target: ES6 + +// @Filename: file1.ts +let var1 = 0; + +// @Filename: file2.ts +let var1 = 0; \ No newline at end of file diff --git a/tests/cases/compiler/letDeclarations-scopes-duplicates3.ts b/tests/cases/compiler/letDeclarations-scopes-duplicates3.ts new file mode 100644 index 0000000000000..1f10efa53850c --- /dev/null +++ b/tests/cases/compiler/letDeclarations-scopes-duplicates3.ts @@ -0,0 +1,7 @@ +// @target: ES6 + +// @Filename: file1.ts +let var1 = 0; + +// @Filename: file2.ts +const var1 = 0; \ No newline at end of file diff --git a/tests/cases/compiler/letDeclarations-scopes-duplicates4.ts b/tests/cases/compiler/letDeclarations-scopes-duplicates4.ts new file mode 100644 index 0000000000000..150d434a2bc14 --- /dev/null +++ b/tests/cases/compiler/letDeclarations-scopes-duplicates4.ts @@ -0,0 +1,7 @@ +// @target: ES6 + +// @Filename: file1.ts +const var1 = 0; + +// @Filename: file2.ts +let var1 = 0; \ No newline at end of file diff --git a/tests/cases/compiler/letDeclarations-scopes-duplicates5.ts b/tests/cases/compiler/letDeclarations-scopes-duplicates5.ts new file mode 100644 index 0000000000000..da24985349910 --- /dev/null +++ b/tests/cases/compiler/letDeclarations-scopes-duplicates5.ts @@ -0,0 +1,7 @@ +// @target: ES6 + +// @Filename: file1.ts +const var1 = 0; + +// @Filename: file2.ts +const var1 = 0; \ No newline at end of file diff --git a/tests/cases/compiler/letDeclarations-scopes-duplicates6.ts b/tests/cases/compiler/letDeclarations-scopes-duplicates6.ts new file mode 100644 index 0000000000000..f71b7623790cc --- /dev/null +++ b/tests/cases/compiler/letDeclarations-scopes-duplicates6.ts @@ -0,0 +1,7 @@ +// @target: ES6 + +// @Filename: file1.ts +var var1 = 0; + +// @Filename: file2.ts +let var1 = 0; \ No newline at end of file diff --git a/tests/cases/compiler/letDeclarations-scopes-duplicates7.ts b/tests/cases/compiler/letDeclarations-scopes-duplicates7.ts new file mode 100644 index 0000000000000..829fda0c927bc --- /dev/null +++ b/tests/cases/compiler/letDeclarations-scopes-duplicates7.ts @@ -0,0 +1,7 @@ +// @target: ES6 + +// @Filename: file1.ts +let var1 = 0; + +// @Filename: file2.ts +var var1 = 0; \ No newline at end of file diff --git a/tests/cases/compiler/letDeclarations-scopes.ts b/tests/cases/compiler/letDeclarations-scopes.ts new file mode 100644 index 0000000000000..93f4ce5b4ed0f --- /dev/null +++ b/tests/cases/compiler/letDeclarations-scopes.ts @@ -0,0 +1,158 @@ +// @target: ES6 + +// global +let l = "string"; + +var n: number; + +// Control flow statements with blocks +if (true) { + let l = 0; + n = l; +} +else { + let l = 0; + n = l; +} + +while (true) { + let l = 0; + n = l; +} + +do { + let l = 0; + n = l; +} while (true); + +var obj; +with (obj) { + let l = 0; + n = l; +} + +for (var i = 0; i < 10; i++) { + let l = 0; + n = l; +} + +for (var i2 in {}) { + let l = 0; + n = l; +} + +if (true) { + label: let l = 0; + n = l; +} + +while (false) { + label2: label3: label4: let l = 0; + n = l; +} + +for (let l = 0; n = l; l++) { + let l = true; + var b3: boolean = l; +} + +for (let l in {}) { + +} + +// Try/catch/finally +try { + let l = 0; + n = l; +} +catch (e) { + let l = 0; + n = l; +} +finally { + let l = 0; + n = l; +} + +// Switch +switch (0) { + case 0: + let l = 0; + n = l; + break; +} + +// blocks +{ + let l = 0; + n = l; + { + let l = false; + var b: boolean = l; + } +} + +// functions +function F() { + let l = 0; + n = l; +} + +var F2 = () => { + let l = 0; + n = l; +}; + +var F3 = function () { + let l = 0; + n = l; +}; + +// modules +module m { + let l = 0; + n = l; + + { + let l = false; + var b2: boolean = l; + } + + lable: let l2 = 0; +} + +// methods +class C { + constructor() { + let l = 0; + n = l; + } + + method() { + let l = 0; + n = l; + } + + get v() { + let l = 0; + n = l; + return n; + } + + set v(value) { + let l = 0; + n = l; + } +} + +// object literals +var o = { + f() { + let l = 0; + n = l; + }, + f2: () => { + let l = 0; + n = l; + } +} \ No newline at end of file diff --git a/tests/cases/compiler/letDeclarations-scopes2.ts b/tests/cases/compiler/letDeclarations-scopes2.ts new file mode 100644 index 0000000000000..6f1200a0cb237 --- /dev/null +++ b/tests/cases/compiler/letDeclarations-scopes2.ts @@ -0,0 +1,27 @@ +// @target: ES6 + +let global = 0; + +{ + let local = 0; + + local; // OK + global; // OK + local2; // Error + + { + let local2 = 0; + + local; // OK + global; // OK + local2; // OK + } + + local; // OK + global; // OK + local2; // Error +} + +local; // Error +global; // OK +local2; // Error diff --git a/tests/cases/compiler/letDeclarations-useBeforeDefinition.ts b/tests/cases/compiler/letDeclarations-useBeforeDefinition.ts new file mode 100644 index 0000000000000..671762d4a45ea --- /dev/null +++ b/tests/cases/compiler/letDeclarations-useBeforeDefinition.ts @@ -0,0 +1,12 @@ +// @target: ES6 + +{ + l1; + let l1; +} + +var v1; +{ + v1; + let v1 = 0; +} diff --git a/tests/cases/compiler/letDeclarations-useBeforeDefinition2.ts b/tests/cases/compiler/letDeclarations-useBeforeDefinition2.ts new file mode 100644 index 0000000000000..a6cbc729b94c4 --- /dev/null +++ b/tests/cases/compiler/letDeclarations-useBeforeDefinition2.ts @@ -0,0 +1,8 @@ +// @target: ES6 +// @out: out.js + +// @Filename: file1.ts +l; + +// @Filename: file2.ts +const l = 0; \ No newline at end of file diff --git a/tests/cases/compiler/letDeclarations-validContexts.ts b/tests/cases/compiler/letDeclarations-validContexts.ts new file mode 100644 index 0000000000000..baedfa2644cb0 --- /dev/null +++ b/tests/cases/compiler/letDeclarations-validContexts.ts @@ -0,0 +1,144 @@ +// @target: ES6 + + +// Control flow statements with blocks +if (true) { + let l1 = 0; +} +else { + let l2 = 0; +} + +while (true) { + let l3 = 0; +} + +do { + let l4 = 0; +} while (true); + +var obj; +with (obj) { + let l5 = 0; +} + +for (var i = 0; i < 10; i++) { + let l6 = 0; +} + +for (var i2 in {}) { + let l7 = 0; +} + +if (true) { + label: let l8 = 0; +} + +while (false) { + label2: label3: label4: let l9 = 0; +} + +// Try/catch/finally +try { + let l10 = 0; +} +catch (e) { + let l11 = 0; +} +finally { + let l12 = 0; +} + +// Switch +switch (0) { + case 0: + let l13 = 0; + break; + default: + let l14 = 0; + break; +} + +// blocks +{ + let l15 = 0; + { + let l16 = 0 + label17: let l17 = 0; + } +} + +// global +let l18 = 0; + +// functions +function F() { + let l19 = 0; +} + +var F2 = () => { + let l20 = 0; +}; + +var F3 = function () { + let l21 = 0; +}; + +// modules +module m { + let l22 = 0; + + { + let l23 = 0; + } +} + +// methods +class C { + constructor() { + let l24 = 0; + } + + method() { + let l25 = 0; + } + + get v() { + let l26 = 0; + return l26; + } + + set v(value) { + let l27 = value; + } +} + +// object literals +var o = { + f() { + let l28 = 0; + }, + f2: () => { + let l29 = 0; + } +} + +// labels +label: let l30 = 0; +{ + label2: let l31 = 0; +} + +function f3() { + label: let l32 = 0; + { + label2: let l33 = 0; + } +} + +module m3 { + label: let l34 = 0; + { + label2: let l35 = 0; + } +} \ No newline at end of file diff --git a/tests/cases/compiler/letDeclarations.ts b/tests/cases/compiler/letDeclarations.ts new file mode 100644 index 0000000000000..e90e355ba68ac --- /dev/null +++ b/tests/cases/compiler/letDeclarations.ts @@ -0,0 +1,14 @@ +// @target: ES6 +// @declaration: true + +let l1; +let l2: number; +let l3, l4, l5 :string, l6; + +let l7 = false; +let l8: number = 23; +let l9 = 0, l10 :string = "", l11 = null; + +for(let l11 in {}) { } + +for(let l12 = 0; l12 < 9; l12++) { } diff --git a/tests/cases/compiler/letDeclarations2.ts b/tests/cases/compiler/letDeclarations2.ts new file mode 100644 index 0000000000000..e7e09f0849a3a --- /dev/null +++ b/tests/cases/compiler/letDeclarations2.ts @@ -0,0 +1,7 @@ +// @target: ES6 +// @declaration: true + +module M { + let l1 = "s"; + export let l2 = 0; +} \ No newline at end of file diff --git a/tests/cases/conformance/parser/ecmascript5/parserOptionalTypeMembers1.ts b/tests/cases/conformance/parser/ecmascript5/parserOptionalTypeMembers1.ts index fb3b96952feb3..331d0faed9e41 100644 --- a/tests/cases/conformance/parser/ecmascript5/parserOptionalTypeMembers1.ts +++ b/tests/cases/conformance/parser/ecmascript5/parserOptionalTypeMembers1.ts @@ -1,4 +1,4 @@ -interface PropertyDescriptor { +interface PropertyDescriptor2 { configurable?: boolean; enumerable?: boolean; value?: any; diff --git a/tests/cases/fourslash/completionEntryForConst.ts b/tests/cases/fourslash/completionEntryForConst.ts new file mode 100644 index 0000000000000..f6b7cc42d63d7 --- /dev/null +++ b/tests/cases/fourslash/completionEntryForConst.ts @@ -0,0 +1,7 @@ +/// + +////const c = "s"; +/////**/ + +goTo.marker(); +verify.completionListContains("c", /*text*/ undefined, /*documentation*/ undefined, "constant"); \ No newline at end of file diff --git a/tests/cases/fourslash/navbar_const.ts b/tests/cases/fourslash/navbar_const.ts new file mode 100644 index 0000000000000..ede2a9cd1d8b6 --- /dev/null +++ b/tests/cases/fourslash/navbar_const.ts @@ -0,0 +1,13 @@ +/// + +//// {| "itemName": "c", "kind": "constant", "parentName": "" |}const c = 0; + +test.markers().forEach(marker => { + verify.getScriptLexicalStructureListContains( + marker.data.itemName, + marker.data.kind, + marker.fileName, + marker.data.parentName, + marker.data.isAdditionalRange, + marker.position); +}); \ No newline at end of file diff --git a/tests/cases/fourslash/quickInfoForConstDeclaration.ts b/tests/cases/fourslash/quickInfoForConstDeclaration.ts new file mode 100644 index 0000000000000..dc234b040509f --- /dev/null +++ b/tests/cases/fourslash/quickInfoForConstDeclaration.ts @@ -0,0 +1,6 @@ +/// + +////const /**/c = 0 ; + +goTo.marker(); +verify.quickInfoIs("(constant) c: number"); \ No newline at end of file