mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Merge pull request #904 from Microsoft/letAndConst
Let and const support
This commit is contained in:
@@ -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}';
|
||||
|
||||
+81
-36
@@ -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(<SourceFile>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(<Declaration>node, SymbolFlags.TypeParameter, SymbolFlags.TypeParameterExcludes);
|
||||
bindDeclaration(<Declaration>node, SymbolFlags.TypeParameter, SymbolFlags.TypeParameterExcludes, /*isBlockScopeContainer*/ false);
|
||||
break;
|
||||
case SyntaxKind.Parameter:
|
||||
bindDeclaration(<Declaration>node, SymbolFlags.Variable, SymbolFlags.ParameterExcludes);
|
||||
bindDeclaration(<Declaration>node, SymbolFlags.FunctionScopedVariable, SymbolFlags.ParameterExcludes, /*isBlockScopeContainer*/ false);
|
||||
break;
|
||||
case SyntaxKind.VariableDeclaration:
|
||||
bindDeclaration(<Declaration>node, SymbolFlags.Variable, SymbolFlags.VariableExcludes);
|
||||
if (node.flags & NodeFlags.BlockScoped) {
|
||||
bindBlockScopedVariableDeclaration(<Declaration>node);
|
||||
}
|
||||
else {
|
||||
bindDeclaration(<Declaration>node, SymbolFlags.FunctionScopedVariable, SymbolFlags.FunctionScopedVariableExcludes, /*isBlockScopeContainer*/ false);
|
||||
}
|
||||
break;
|
||||
case SyntaxKind.Property:
|
||||
case SyntaxKind.PropertyAssignment:
|
||||
bindDeclaration(<Declaration>node, SymbolFlags.Property, SymbolFlags.PropertyExcludes);
|
||||
bindDeclaration(<Declaration>node, SymbolFlags.Property, SymbolFlags.PropertyExcludes, /*isBlockScopeContainer*/ false);
|
||||
break;
|
||||
case SyntaxKind.EnumMember:
|
||||
bindDeclaration(<Declaration>node, SymbolFlags.EnumMember, SymbolFlags.EnumMemberExcludes);
|
||||
bindDeclaration(<Declaration>node, SymbolFlags.EnumMember, SymbolFlags.EnumMemberExcludes, /*isBlockScopeContainer*/ false);
|
||||
break;
|
||||
case SyntaxKind.CallSignature:
|
||||
bindDeclaration(<Declaration>node, SymbolFlags.CallSignature, 0);
|
||||
bindDeclaration(<Declaration>node, SymbolFlags.CallSignature, 0, /*isBlockScopeContainer*/ false);
|
||||
break;
|
||||
case SyntaxKind.Method:
|
||||
bindDeclaration(<Declaration>node, SymbolFlags.Method, SymbolFlags.MethodExcludes);
|
||||
bindDeclaration(<Declaration>node, SymbolFlags.Method, SymbolFlags.MethodExcludes, /*isBlockScopeContainer*/ true);
|
||||
break;
|
||||
case SyntaxKind.ConstructSignature:
|
||||
bindDeclaration(<Declaration>node, SymbolFlags.ConstructSignature, 0);
|
||||
bindDeclaration(<Declaration>node, SymbolFlags.ConstructSignature, 0, /*isBlockScopeContainer*/ true);
|
||||
break;
|
||||
case SyntaxKind.IndexSignature:
|
||||
bindDeclaration(<Declaration>node, SymbolFlags.IndexSignature, 0);
|
||||
bindDeclaration(<Declaration>node, SymbolFlags.IndexSignature, 0, /*isBlockScopeContainer*/ false);
|
||||
break;
|
||||
case SyntaxKind.FunctionDeclaration:
|
||||
bindDeclaration(<Declaration>node, SymbolFlags.Function, SymbolFlags.FunctionExcludes);
|
||||
bindDeclaration(<Declaration>node, SymbolFlags.Function, SymbolFlags.FunctionExcludes, /*isBlockScopeContainer*/ true);
|
||||
break;
|
||||
case SyntaxKind.Constructor:
|
||||
bindConstructorDeclaration(<ConstructorDeclaration>node);
|
||||
break;
|
||||
case SyntaxKind.GetAccessor:
|
||||
bindDeclaration(<Declaration>node, SymbolFlags.GetAccessor, SymbolFlags.GetAccessorExcludes);
|
||||
bindDeclaration(<Declaration>node, SymbolFlags.GetAccessor, SymbolFlags.GetAccessorExcludes, /*isBlockScopeContainer*/ true);
|
||||
break;
|
||||
case SyntaxKind.SetAccessor:
|
||||
bindDeclaration(<Declaration>node, SymbolFlags.SetAccessor, SymbolFlags.SetAccessorExcludes);
|
||||
bindDeclaration(<Declaration>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(<CatchBlock>node);
|
||||
break;
|
||||
case SyntaxKind.ClassDeclaration:
|
||||
bindDeclaration(<Declaration>node, SymbolFlags.Class, SymbolFlags.ClassExcludes);
|
||||
bindDeclaration(<Declaration>node, SymbolFlags.Class, SymbolFlags.ClassExcludes, /*isBlockScopeContainer*/ false);
|
||||
break;
|
||||
case SyntaxKind.InterfaceDeclaration:
|
||||
bindDeclaration(<Declaration>node, SymbolFlags.Interface, SymbolFlags.InterfaceExcludes);
|
||||
bindDeclaration(<Declaration>node, SymbolFlags.Interface, SymbolFlags.InterfaceExcludes, /*isBlockScopeContainer*/ false);
|
||||
break;
|
||||
case SyntaxKind.EnumDeclaration:
|
||||
bindDeclaration(<Declaration>node, SymbolFlags.Enum, SymbolFlags.EnumExcludes);
|
||||
bindDeclaration(<Declaration>node, SymbolFlags.Enum, SymbolFlags.EnumExcludes, /*isBlockScopeContainer*/ false);
|
||||
break;
|
||||
case SyntaxKind.ModuleDeclaration:
|
||||
bindModuleDeclaration(<ModuleDeclaration>node);
|
||||
break;
|
||||
case SyntaxKind.ImportDeclaration:
|
||||
bindDeclaration(<Declaration>node, SymbolFlags.Import, SymbolFlags.ImportExcludes);
|
||||
bindDeclaration(<Declaration>node, SymbolFlags.Import, SymbolFlags.ImportExcludes, /*isBlockScopeContainer*/ false);
|
||||
break;
|
||||
case SyntaxKind.SourceFile:
|
||||
if (isExternalModule(<SourceFile>node)) {
|
||||
bindAnonymousDeclaration(node, SymbolFlags.ValueModule, '"' + removeFileExtension((<SourceFile>node).filename) + '"');
|
||||
bindAnonymousDeclaration(node, SymbolFlags.ValueModule, '"' + removeFileExtension((<SourceFile>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;
|
||||
|
||||
+103
-9
@@ -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 = (<IndexedAccess>n).index;
|
||||
var symbol = findSymbol((<IndexedAccess>n).object);
|
||||
if (symbol && index.kind === SyntaxKind.StringLiteral) {
|
||||
var name = (<LiteralExpression>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((<ParenExpression>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,
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -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<T>()' 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 <language> or <language>-<territory>. 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}'." },
|
||||
|
||||
@@ -447,9 +447,29 @@
|
||||
"category": "Error",
|
||||
"code": 1150
|
||||
},
|
||||
"An enum member cannot have a numeric name.": {
|
||||
"'var', 'let' or 'const' expected.": {
|
||||
"category": "Error",
|
||||
"code": 1151
|
||||
"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": 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
|
||||
},
|
||||
|
||||
+44
-8
@@ -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;
|
||||
|
||||
+79
-26
@@ -2696,11 +2696,14 @@ module ts {
|
||||
}
|
||||
|
||||
// STATEMENTS
|
||||
function parseStatementAllowingLetDeclaration() {
|
||||
return parseStatement(/*allowLetAndConstDeclarations*/ true);
|
||||
}
|
||||
|
||||
function parseBlock(ignoreMissingOpenBrace: boolean, checkForStrictMode: boolean): Block {
|
||||
var node = <Block>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,11 +2797,29 @@ 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 = <CaseOrDefaultClause>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 = <LabeledStatement>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 = <VariableStatement>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);
|
||||
|
||||
+12
-7
@@ -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);
|
||||
|
||||
+52
-32
@@ -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 {
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
@@ -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 */
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -233,7 +233,12 @@ module ts.NavigationBar {
|
||||
return createItem(node, getTextOfNode((<FunctionDeclaration>node).name), ts.ScriptElementKind.functionElement);
|
||||
|
||||
case SyntaxKind.VariableDeclaration:
|
||||
return createItem(node, getTextOfNode((<VariableDeclaration>node).name), ts.ScriptElementKind.variableElement);
|
||||
if (node.flags & NodeFlags.Const) {
|
||||
return createItem(node, getTextOfNode((<VariableDeclaration>node).name), ts.ScriptElementKind.constantElement);
|
||||
}
|
||||
else {
|
||||
return createItem(node, getTextOfNode((<VariableDeclaration>node).name), ts.ScriptElementKind.variableElement);
|
||||
}
|
||||
|
||||
case SyntaxKind.Constructor:
|
||||
return createItem(node, "constructor", ts.ScriptElementKind.constructorImplementationElement);
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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'.
|
||||
}
|
||||
@@ -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";
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
})();
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
@@ -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.
|
||||
@@ -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();
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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) ====
|
||||
///<reference path='constDeclarations_access_1.ts'/>
|
||||
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;
|
||||
|
||||
@@ -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.
|
||||
}
|
||||
@@ -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]
|
||||
@@ -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
|
||||
}
|
||||
@@ -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
|
||||
@@ -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.
|
||||
|
||||
@@ -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.
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
};
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
};
|
||||
@@ -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;
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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"}
|
||||
@@ -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
|
||||
@@ -0,0 +1,16 @@
|
||||
=== tests/cases/compiler/es6-amd.ts ===
|
||||
|
||||
class A
|
||||
>A : A
|
||||
{
|
||||
constructor ()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public B()
|
||||
>B : () => number
|
||||
{
|
||||
return 42;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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"}
|
||||
@@ -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
|
||||
@@ -0,0 +1,16 @@
|
||||
=== tests/cases/compiler/es6-declaration-amd.ts ===
|
||||
|
||||
class A
|
||||
>A : A
|
||||
{
|
||||
constructor ()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public B()
|
||||
>B : () => number
|
||||
{
|
||||
return 42;
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
@@ -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"}
|
||||
@@ -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
|
||||
@@ -0,0 +1,16 @@
|
||||
=== tests/cases/compiler/es6-sourcemap-amd.ts ===
|
||||
|
||||
class A
|
||||
>A : A
|
||||
{
|
||||
constructor ()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public B()
|
||||
>B : () => number
|
||||
{
|
||||
return 42;
|
||||
}
|
||||
}
|
||||
@@ -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<T> {
|
||||
foo: T;
|
||||
length: number;
|
||||
~~~~~~
|
||||
!!! error TS2300: Duplicate identifier 'length'.
|
||||
}
|
||||
|
||||
function map<U>() {
|
||||
var ys: U[] = [];
|
||||
}
|
||||
|
||||
@@ -1,15 +1,20 @@
|
||||
//// [functionTypeArgumentArrayAssignment.ts]
|
||||
interface Array<T> {
|
||||
foo: T;
|
||||
length: number;
|
||||
}
|
||||
module test {
|
||||
interface Array<T> {
|
||||
foo: T;
|
||||
length: number;
|
||||
}
|
||||
|
||||
function map<U>() {
|
||||
var ys: U[] = [];
|
||||
function map<U>() {
|
||||
var ys: U[] = [];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//// [functionTypeArgumentArrayAssignment.js]
|
||||
function map() {
|
||||
var ys = [];
|
||||
}
|
||||
var test;
|
||||
(function (test) {
|
||||
function map() {
|
||||
var ys = [];
|
||||
}
|
||||
})(test || (test = {}));
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
=== tests/cases/compiler/functionTypeArgumentArrayAssignment.ts ===
|
||||
module test {
|
||||
>test : typeof test
|
||||
|
||||
interface Array<T> {
|
||||
>Array : Array<T>
|
||||
>T : T
|
||||
|
||||
foo: T;
|
||||
>foo : T
|
||||
>T : T
|
||||
|
||||
length: number;
|
||||
>length : number
|
||||
}
|
||||
|
||||
function map<U>() {
|
||||
>map : <U>() => void
|
||||
>U : U
|
||||
|
||||
var ys: U[] = [];
|
||||
>ys : U[]
|
||||
>U : U
|
||||
>[] : undefined[]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
}
|
||||
|
||||
|
||||
@@ -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 = {}));
|
||||
|
||||
@@ -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();
|
||||
@@ -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
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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.
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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'.
|
||||
@@ -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'.
|
||||
@@ -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'.
|
||||
@@ -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'.
|
||||
@@ -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'.
|
||||
@@ -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'.
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
};
|
||||
@@ -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'.
|
||||
|
||||
@@ -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
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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 = {}));
|
||||
@@ -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;
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
@@ -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.
|
||||
!!! error TS2452: An enum member cannot have a numeric name.
|
||||
@@ -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.
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
//// [parserOptionalTypeMembers1.ts]
|
||||
interface PropertyDescriptor {
|
||||
interface PropertyDescriptor2 {
|
||||
configurable?: boolean;
|
||||
enumerable?: boolean;
|
||||
value?: any;
|
||||
|
||||
@@ -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
|
||||
}
|
||||
+4
-1
@@ -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;
|
||||
~
|
||||
|
||||
+4
-1
@@ -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;
|
||||
~
|
||||
|
||||
@@ -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
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
// @target: ES6
|
||||
|
||||
// No errors, const declaration is not shadowed
|
||||
function outer() {
|
||||
const x = 0;
|
||||
function inner() {
|
||||
var x = "inner";
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
// @target: ES6
|
||||
|
||||
// @Filename: file1.ts
|
||||
const x = 0
|
||||
|
||||
// @Filename: file2.ts
|
||||
x++;
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user