diff --git a/Jakefile.js b/Jakefile.js index 07a2ade06a6..a0ec0d880fe 100644 --- a/Jakefile.js +++ b/Jakefile.js @@ -103,7 +103,7 @@ var serverSources = [ "server.ts" ].map(function (f) { return path.join(serverDirectory, f); -}); +}).concat(servicesSources); var languageServiceLibrarySources = [ "editorServices.ts", diff --git a/bin/lib.core.es6.d.ts b/bin/lib.core.es6.d.ts index 1ee111caa9b..50c7fcc9017 100644 --- a/bin/lib.core.es6.d.ts +++ b/bin/lib.core.es6.d.ts @@ -1880,6 +1880,7 @@ interface Map { } interface MapConstructor { + new (): Map; new (): Map; new (iterable: Iterable<[K, V]>): Map; prototype: Map; @@ -1896,6 +1897,7 @@ interface WeakMap { } interface WeakMapConstructor { + new (): WeakMap; new (): WeakMap; new (iterable: Iterable<[K, V]>): WeakMap; prototype: WeakMap; @@ -1917,6 +1919,7 @@ interface Set { } interface SetConstructor { + new (): Set; new (): Set; new (iterable: Iterable): Set; prototype: Set; @@ -1932,6 +1935,7 @@ interface WeakSet { } interface WeakSetConstructor { + new (): WeakSet; new (): WeakSet; new (iterable: Iterable): WeakSet; prototype: WeakSet; diff --git a/bin/lib.es6.d.ts b/bin/lib.es6.d.ts index e17cb3f35cf..931d60ec47a 100644 --- a/bin/lib.es6.d.ts +++ b/bin/lib.es6.d.ts @@ -1880,6 +1880,7 @@ interface Map { } interface MapConstructor { + new (): Map; new (): Map; new (iterable: Iterable<[K, V]>): Map; prototype: Map; @@ -1896,6 +1897,7 @@ interface WeakMap { } interface WeakMapConstructor { + new (): WeakMap; new (): WeakMap; new (iterable: Iterable<[K, V]>): WeakMap; prototype: WeakMap; @@ -1917,6 +1919,7 @@ interface Set { } interface SetConstructor { + new (): Set; new (): Set; new (iterable: Iterable): Set; prototype: Set; @@ -1932,6 +1935,7 @@ interface WeakSet { } interface WeakSetConstructor { + new (): WeakSet; new (): WeakSet; new (iterable: Iterable): WeakSet; prototype: WeakSet; diff --git a/bin/tsc.js b/bin/tsc.js index e5f449c4101..9e1d681e218 100644 --- a/bin/tsc.js +++ b/bin/tsc.js @@ -1166,6 +1166,12 @@ var ts; An_export_declaration_can_only_be_used_in_a_module: { code: 1233, category: ts.DiagnosticCategory.Error, key: "An export declaration can only be used in a module." }, An_ambient_module_declaration_is_only_allowed_at_the_top_level_in_a_file: { code: 1234, category: ts.DiagnosticCategory.Error, key: "An ambient module declaration is only allowed at the top level in a file." }, A_namespace_declaration_is_only_allowed_in_a_namespace_or_module: { code: 1235, category: ts.DiagnosticCategory.Error, key: "A namespace declaration is only allowed in a namespace or module." }, + The_return_type_of_a_property_decorator_function_must_be_either_void_or_any: { code: 1236, category: ts.DiagnosticCategory.Error, key: "The return type of a property decorator function must be either 'void' or 'any'." }, + The_return_type_of_a_parameter_decorator_function_must_be_either_void_or_any: { code: 1237, category: ts.DiagnosticCategory.Error, key: "The return type of a parameter decorator function must be either 'void' or 'any'." }, + Unable_to_resolve_signature_of_class_decorator_when_called_as_an_expression: { code: 1238, category: ts.DiagnosticCategory.Error, key: "Unable to resolve signature of class decorator when called as an expression." }, + Unable_to_resolve_signature_of_parameter_decorator_when_called_as_an_expression: { code: 1239, category: ts.DiagnosticCategory.Error, key: "Unable to resolve signature of parameter decorator when called as an expression." }, + Unable_to_resolve_signature_of_property_decorator_when_called_as_an_expression: { code: 1240, category: ts.DiagnosticCategory.Error, key: "Unable to resolve signature of property decorator when called as an expression." }, + Unable_to_resolve_signature_of_method_decorator_when_called_as_an_expression: { code: 1241, category: ts.DiagnosticCategory.Error, key: "Unable to resolve signature of method decorator when called as an expression." }, Duplicate_identifier_0: { code: 2300, category: ts.DiagnosticCategory.Error, key: "Duplicate identifier '{0}'." }, Initializer_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor: { code: 2301, category: ts.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: ts.DiagnosticCategory.Error, key: "Static members cannot reference class type parameters." }, @@ -1541,9 +1547,7 @@ var ts; property_declarations_can_only_be_used_in_a_ts_file: { code: 8014, category: ts.DiagnosticCategory.Error, key: "'property declarations' can only be used in a .ts file." }, enum_declarations_can_only_be_used_in_a_ts_file: { code: 8015, category: ts.DiagnosticCategory.Error, key: "'enum declarations' can only be used in a .ts file." }, type_assertion_expressions_can_only_be_used_in_a_ts_file: { code: 8016, category: ts.DiagnosticCategory.Error, key: "'type assertion expressions' can only be used in a .ts file." }, - decorators_can_only_be_used_in_a_ts_file: { code: 8017, category: ts.DiagnosticCategory.Error, key: "'decorators' can only be used in a .ts file." }, - Only_identifiers_Slashqualified_names_with_optional_type_arguments_are_currently_supported_in_a_class_extends_clauses: { code: 9002, category: ts.DiagnosticCategory.Error, key: "Only identifiers/qualified-names with optional type arguments are currently supported in a class 'extends' clauses." }, - class_expressions_are_not_currently_supported: { code: 9003, category: ts.DiagnosticCategory.Error, key: "'class' expressions are not currently supported." } + decorators_can_only_be_used_in_a_ts_file: { code: 8017, category: ts.DiagnosticCategory.Error, key: "'decorators' can only be used in a .ts file." } }; })(ts || (ts = {})); /// @@ -3214,7 +3218,7 @@ var ts; } } function getStrictModeIdentifierMessage(node) { - if (ts.getAncestor(node, 204) || ts.getAncestor(node, 177)) { + if (ts.getContainingClass(node)) { return ts.Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode_Class_definitions_are_automatically_in_strict_mode; } if (file.externalModuleIndicator) { @@ -3252,7 +3256,7 @@ var ts; } } function getStrictModeEvalOrArgumentsMessage(node) { - if (ts.getAncestor(node, 204) || ts.getAncestor(node, 177)) { + if (ts.getContainingClass(node)) { return ts.Diagnostics.Invalid_use_of_0_Class_definitions_are_automatically_in_strict_mode; } if (file.externalModuleIndicator) { @@ -3504,7 +3508,7 @@ var ts; } if (node.flags & 112 && node.parent.kind === 137 && - (node.parent.parent.kind === 204 || node.parent.parent.kind === 177)) { + ts.isClassLike(node.parent.parent)) { var classDeclaration = node.parent.parent; declareSymbol(classDeclaration.symbol.members, classDeclaration.symbol, node, 4, 107455); } @@ -3928,6 +3932,7 @@ var ts; case 208: case 206: case 204: + case 177: return; default: if (isFunctionLike(node)) { @@ -3962,20 +3967,11 @@ var ts; } ts.isVariableLike = isVariableLike; function isAccessor(node) { - if (node) { - switch (node.kind) { - case 138: - case 139: - return true; - } - } - return false; + return node && (node.kind === 138 || node.kind === 139); } ts.isAccessor = isAccessor; function isClassLike(node) { - if (node) { - return node.kind === 204 || node.kind === 177; - } + return node && (node.kind === 204 || node.kind === 177); } ts.isClassLike = isClassLike; function isFunctionLike(node) { @@ -4017,6 +4013,15 @@ var ts; } } ts.getContainingFunction = getContainingFunction; + function getContainingClass(node) { + while (true) { + node = node.parent; + if (!node || isClassLike(node)) { + return node; + } + } + } + ts.getContainingClass = getContainingClass; function getThisContainer(node, includeArrowFunctions) { while (true) { node = node.parent; @@ -4025,7 +4030,7 @@ var ts; } switch (node.kind) { case 129: - if (node.parent.parent.kind === 204) { + if (isClassLike(node.parent.parent)) { return node; } node = node.parent; @@ -4066,7 +4071,7 @@ var ts; return node; switch (node.kind) { case 129: - if (node.parent.parent.kind === 204) { + if (isClassLike(node.parent.parent)) { return node; } node = node.parent; @@ -4406,6 +4411,7 @@ var ts; case 166: case 155: case 204: + case 177: case 137: case 207: case 229: @@ -5107,7 +5113,7 @@ var ts; function isExpressionWithTypeArgumentsInClassExtendsClause(node) { return node.kind === 179 && node.parent.token === 79 && - node.parent.parent.kind === 204; + isClassLike(node.parent.parent); } ts.isExpressionWithTypeArgumentsInClassExtendsClause = isExpressionWithTypeArgumentsInClassExtendsClause; function isSupportedExpressionWithTypeArguments(node) { @@ -9709,10 +9715,7 @@ var ts; var globalIteratorType; var globalIterableIteratorType; var anyArrayType; - var getGlobalClassDecoratorType; - var getGlobalParameterDecoratorType; - var getGlobalPropertyDecoratorType; - var getGlobalMethodDecoratorType; + var getGlobalTypedPropertyDescriptorType; var tupleTypes = {}; var unionTypes = {}; var stringLiteralTypes = {}; @@ -9969,7 +9972,7 @@ var ts; break; case 134: case 133: - if (location.parent.kind === 204 && !(location.flags & 128)) { + if (ts.isClassLike(location.parent) && !(location.flags & 128)) { var ctor = findConstructorDeclaration(location.parent); if (ctor && ctor.locals) { if (getSymbol(ctor.locals, name, meaning & 107455)) { @@ -9979,6 +9982,7 @@ var ts; } break; case 204: + case 177: case 205: if (result = getSymbol(getSymbolOfNode(location).members, name, meaning & 793056)) { if (lastLocation && lastLocation.flags & 128) { @@ -9987,10 +9991,17 @@ var ts; } break loop; } + if (location.kind === 177 && meaning & 32) { + var className = location.name; + if (className && name === className.text) { + result = location.symbol; + break loop; + } + } break; case 129: grandparent = location.parent.parent; - if (grandparent.kind === 204 || grandparent.kind === 205) { + if (ts.isClassLike(grandparent) || grandparent.kind === 205) { if (result = getSymbol(getSymbolOfNode(grandparent).members, name, meaning & 793056)) { error(errorLocation, ts.Diagnostics.A_computed_property_name_cannot_reference_a_type_parameter_from_its_containing_type); return undefined; @@ -10022,15 +10033,6 @@ var ts; } } break; - case 177: - if (meaning & 32) { - var className = location.name; - if (className && name === className.text) { - result = location.symbol; - break loop; - } - } - break; case 132: if (location.parent && location.parent.kind === 131) { location = location.parent; @@ -10731,15 +10733,24 @@ var ts; } var _displayBuilder; function getSymbolDisplayBuilder() { - function appendSymbolNameOnly(symbol, writer) { - if (symbol.declarations && symbol.declarations.length > 0) { + function getNameOfSymbol(symbol) { + if (symbol.declarations && symbol.declarations.length) { var declaration = symbol.declarations[0]; if (declaration.name) { - writer.writeSymbol(ts.declarationNameToString(declaration.name), symbol); - return; + return ts.declarationNameToString(declaration.name); + } + switch (declaration.kind) { + case 177: + return "(Anonymous class)"; + case 165: + case 166: + return "(Anonymous function)"; } } - writer.writeSymbol(symbol.name, symbol); + return symbol.name; + } + function appendSymbolNameOnly(symbol, writer) { + writer.writeSymbol(getNameOfSymbol(symbol), symbol); } function buildSymbolDisplay(symbol, writer, enclosingDeclaration, meaning, flags, typeFlags) { var parentSymbol; @@ -11655,9 +11666,9 @@ var ts; if (!node) { return typeParameters; } - if (node.kind === 204 || node.kind === 203 || - node.kind === 165 || node.kind === 136 || - node.kind === 166) { + if (node.kind === 204 || node.kind === 177 || + node.kind === 203 || node.kind === 165 || + node.kind === 136 || node.kind === 166) { var declarations = node.typeParameters; if (declarations) { return appendTypeParameters(appendOuterTypeParameters(typeParameters, node), declarations); @@ -11666,14 +11677,15 @@ var ts; } } function getOuterTypeParametersOfClassOrInterface(symbol) { - var kind = symbol.flags & 32 ? 204 : 205; - return appendOuterTypeParameters(undefined, ts.getDeclarationOfKind(symbol, kind)); + var declaration = symbol.flags & 32 ? symbol.valueDeclaration : ts.getDeclarationOfKind(symbol, 205); + return appendOuterTypeParameters(undefined, declaration); } function getLocalTypeParametersOfClassOrInterfaceOrTypeAlias(symbol) { var result; for (var _i = 0, _a = symbol.declarations; _i < _a.length; _i++) { var node = _a[_i]; - if (node.kind === 205 || node.kind === 204 || node.kind === 206) { + if (node.kind === 205 || node.kind === 204 || + node.kind === 177 || node.kind === 206) { var declaration = node; if (declaration.typeParameters) { result = appendTypeParameters(result, declaration.typeParameters); @@ -12686,6 +12698,12 @@ var ts; function getGlobalESSymbolConstructorSymbol() { return globalESSymbolConstructorSymbol || (globalESSymbolConstructorSymbol = getGlobalValueSymbol("Symbol")); } + function createTypedPropertyDescriptorType(propertyType) { + var globalTypedPropertyDescriptorType = getGlobalTypedPropertyDescriptorType(); + return globalTypedPropertyDescriptorType !== emptyObjectType + ? createTypeReference(globalTypedPropertyDescriptorType, [propertyType]) + : emptyObjectType; + } function createTypeFromGenericGlobalType(genericGlobalType, elementType) { return genericGlobalType !== emptyGenericType ? createTypeReference(genericGlobalType, [elementType]) : emptyObjectType; } @@ -13101,8 +13119,8 @@ var ts; function checkTypeSubtypeOf(source, target, errorNode, headMessage, containingMessageChain) { return checkTypeRelatedTo(source, target, subtypeRelation, errorNode, headMessage, containingMessageChain); } - function checkTypeAssignableTo(source, target, errorNode, headMessage) { - return checkTypeRelatedTo(source, target, assignableRelation, errorNode, headMessage); + function checkTypeAssignableTo(source, target, errorNode, headMessage, containingMessageChain) { + return checkTypeRelatedTo(source, target, assignableRelation, errorNode, headMessage, containingMessageChain); } function isSignatureAssignableTo(source, target) { var sourceType = getOrCreateTypeFromSignature(source); @@ -14487,9 +14505,9 @@ var ts; } } function captureLexicalThis(node, container) { - var classNode = container.parent && container.parent.kind === 204 ? container.parent : undefined; getNodeLinks(node).flags |= 2; if (container.kind === 134 || container.kind === 137) { + var classNode = container.parent; getNodeLinks(classNode).flags |= 4; } else { @@ -14528,9 +14546,8 @@ var ts; if (needToCaptureLexicalThis) { captureLexicalThis(node, container); } - var classNode = container.parent && container.parent.kind === 204 ? container.parent : undefined; - if (classNode) { - var symbol = getSymbolOfNode(classNode); + if (ts.isClassLike(container.parent)) { + var symbol = getSymbolOfNode(container.parent); return container.flags & 128 ? getTypeOfSymbol(symbol) : getDeclaredTypeOfSymbol(symbol); } return anyType; @@ -14545,7 +14562,7 @@ var ts; } function checkSuperExpression(node) { var isCallExpression = node.parent.kind === 160 && node.parent.expression === node; - var classDeclaration = ts.getAncestor(node, 204); + var classDeclaration = ts.getContainingClass(node); var classType = classDeclaration && getDeclaredTypeOfSymbol(getSymbolOfNode(classDeclaration)); var baseClassType = classType && getBaseTypes(classType)[0]; if (!baseClassType) { @@ -14567,7 +14584,7 @@ var ts; container = ts.getSuperContainer(container, true); needToCaptureLexicalThis = languageVersion < 2; } - if (container && container.parent && container.parent.kind === 204) { + if (container && ts.isClassLike(container.parent)) { if (container.flags & 128) { canUseSuperExpression = container.kind === 136 || @@ -15050,7 +15067,7 @@ var ts; if (!(flags & (32 | 64))) { return; } - var enclosingClassDeclaration = ts.getAncestor(node, 204); + var enclosingClassDeclaration = ts.getContainingClass(node); var enclosingClass = enclosingClassDeclaration ? getDeclaredTypeOfSymbol(getSymbolOfNode(enclosingClassDeclaration)) : undefined; var declaringClass = getDeclaredTypeOfSymbol(prop.parent); if (flags & 32) { @@ -15228,7 +15245,7 @@ var ts; if (node.kind === 162) { checkExpression(node.template); } - else { + else if (node.kind !== 132) { ts.forEach(node.arguments, function (argument) { checkExpression(argument); }); @@ -15278,7 +15295,8 @@ var ts; } function getSpreadArgumentIndex(args) { for (var i = 0; i < args.length; i++) { - if (args[i].kind === 176) { + var arg = args[i]; + if (arg && arg.kind === 176) { return i; } } @@ -15288,6 +15306,8 @@ var ts; var adjustedArgCount; var typeArguments; var callIsIncomplete; + var isDecorator; + var spreadArgIndex = -1; if (node.kind === 162) { var tagExpression = node; adjustedArgCount = args.length; @@ -15304,6 +15324,11 @@ var ts; callIsIncomplete = !!templateLiteral.isUnterminated; } } + else if (node.kind === 132) { + isDecorator = true; + typeArguments = undefined; + adjustedArgCount = getEffectiveArgumentCount(node, undefined, signature); + } else { var callExpression = node; if (!callExpression.arguments) { @@ -15313,13 +15338,13 @@ var ts; adjustedArgCount = callExpression.arguments.hasTrailingComma ? args.length + 1 : args.length; callIsIncomplete = callExpression.arguments.end === callExpression.end; typeArguments = callExpression.typeArguments; + spreadArgIndex = getSpreadArgumentIndex(args); } var hasRightNumberOfTypeArgs = !typeArguments || (signature.typeParameters && typeArguments.length === signature.typeParameters.length); if (!hasRightNumberOfTypeArgs) { return false; } - var spreadArgIndex = getSpreadArgumentIndex(args); if (spreadArgIndex >= 0) { return signature.hasRestParameter && spreadArgIndex >= signature.parameters.length - 1; } @@ -15346,7 +15371,7 @@ var ts; }); return getSignatureInstantiation(signature, getInferredTypes(context)); } - function inferTypeArguments(signature, args, excludeArgument, context) { + function inferTypeArguments(node, signature, args, excludeArgument, context) { var typeParameters = signature.typeParameters; var inferenceMapper = createInferenceMapper(context); for (var i = 0; i < typeParameters.length; i++) { @@ -15357,15 +15382,13 @@ var ts; if (context.failedTypeParameterIndex !== undefined && !context.inferences[context.failedTypeParameterIndex].isFixed) { context.failedTypeParameterIndex = undefined; } - for (var i = 0; i < args.length; i++) { - var arg = args[i]; - if (arg.kind !== 178) { + var argCount = getEffectiveArgumentCount(node, args, signature); + for (var i = 0; i < argCount; i++) { + var arg = getEffectiveArgument(node, args, i); + if (arg === undefined || arg.kind !== 178) { var paramType = getTypeAtPosition(signature, i); - var argType = void 0; - if (i === 0 && args[i].parent.kind === 162) { - argType = globalTemplateStringsArrayType; - } - else { + var argType = getEffectiveArgumentType(node, i, arg); + if (argType === undefined) { var mapper = excludeArgument && excludeArgument[i] !== undefined ? identityMapper : inferenceMapper; argType = checkExpressionWithContextualType(arg, paramType, mapper); } @@ -15373,7 +15396,7 @@ var ts; } } if (excludeArgument) { - for (var i = 0; i < args.length; i++) { + for (var i = 0; i < argCount; i++) { if (excludeArgument[i] === false) { var arg = args[i]; var paramType = getTypeAtPosition(signature, i); @@ -15383,7 +15406,7 @@ var ts; } getInferredTypes(context); } - function checkTypeArguments(signature, typeArguments, typeArgumentResultTypes, reportErrors) { + function checkTypeArguments(signature, typeArguments, typeArgumentResultTypes, reportErrors, headMessage) { var typeParameters = signature.typeParameters; var typeArgumentsAreAssignable = true; for (var i = 0; i < typeParameters.length; i++) { @@ -15393,23 +15416,33 @@ var ts; if (typeArgumentsAreAssignable) { var constraint = getConstraintOfTypeParameter(typeParameters[i]); if (constraint) { - typeArgumentsAreAssignable = checkTypeAssignableTo(typeArgument, constraint, reportErrors ? typeArgNode : undefined, ts.Diagnostics.Type_0_does_not_satisfy_the_constraint_1); + var errorInfo = void 0; + var typeArgumentHeadMessage = ts.Diagnostics.Type_0_does_not_satisfy_the_constraint_1; + if (reportErrors && headMessage) { + errorInfo = ts.chainDiagnosticMessages(errorInfo, typeArgumentHeadMessage); + typeArgumentHeadMessage = headMessage; + } + typeArgumentsAreAssignable = checkTypeAssignableTo(typeArgument, constraint, reportErrors ? typeArgNode : undefined, typeArgumentHeadMessage, errorInfo); } } } return typeArgumentsAreAssignable; } function checkApplicableSignature(node, args, signature, relation, excludeArgument, reportErrors) { - for (var i = 0; i < args.length; i++) { - var arg = args[i]; - if (arg.kind !== 178) { + var argCount = getEffectiveArgumentCount(node, args, signature); + for (var i = 0; i < argCount; i++) { + var arg = getEffectiveArgument(node, args, i); + if (arg === undefined || arg.kind !== 178) { var paramType = getTypeAtPosition(signature, i); - var argType = i === 0 && node.kind === 162 - ? globalTemplateStringsArrayType - : arg.kind === 8 && !reportErrors + var argType = getEffectiveArgumentType(node, i, arg); + if (argType === undefined) { + argType = arg.kind === 8 && !reportErrors ? getStringLiteralType(arg) : checkExpressionWithContextualType(arg, paramType, excludeArgument && excludeArgument[i] ? identityMapper : undefined); - if (!checkTypeRelatedTo(argType, paramType, relation, reportErrors ? arg : undefined, ts.Diagnostics.Argument_of_type_0_is_not_assignable_to_parameter_of_type_1)) { + } + var errorNode = reportErrors ? getEffectiveArgumentErrorNode(node, i, arg) : undefined; + var headMessage = ts.Diagnostics.Argument_of_type_0_is_not_assignable_to_parameter_of_type_1; + if (!checkTypeRelatedTo(argType, paramType, relation, errorNode, headMessage)) { return false; } } @@ -15420,22 +15453,165 @@ var ts; var args; if (node.kind === 162) { var template = node.template; - args = [template]; + args = [undefined]; if (template.kind === 174) { ts.forEach(template.templateSpans, function (span) { args.push(span.expression); }); } } + else if (node.kind === 132) { + return undefined; + } else { args = node.arguments || emptyArray; } return args; } - function resolveCall(node, signatures, candidatesOutArray) { + function getEffectiveArgumentCount(node, args, signature) { + if (node.kind === 132) { + switch (node.parent.kind) { + case 204: + case 177: + return 1; + case 134: + return 2; + case 136: + case 138: + case 139: + return signature.parameters.length >= 3 ? 3 : 2; + case 131: + return 3; + } + } + else { + return args.length; + } + } + function getEffectiveDecoratorFirstArgumentType(node) { + switch (node.kind) { + case 204: + case 177: + var classSymbol = getSymbolOfNode(node); + return getTypeOfSymbol(classSymbol); + case 131: + node = node.parent; + if (node.kind === 137) { + var classSymbol_1 = getSymbolOfNode(node); + return getTypeOfSymbol(classSymbol_1); + } + case 134: + case 136: + case 138: + case 139: + return getParentTypeOfClassElement(node); + default: + ts.Debug.fail("Unsupported decorator target."); + return unknownType; + } + } + function getEffectiveDecoratorSecondArgumentType(node) { + switch (node.kind) { + case 204: + ts.Debug.fail("Class decorators should not have a second synthetic argument."); + return unknownType; + case 131: + node = node.parent; + if (node.kind === 137) { + return anyType; + } + case 134: + case 136: + case 138: + case 139: + var element = node; + switch (element.name.kind) { + case 65: + case 7: + case 8: + return getStringLiteralType(element.name); + case 129: + var nameType = checkComputedPropertyName(element.name); + if (allConstituentTypesHaveKind(nameType, 2097152)) { + return nameType; + } + else { + return stringType; + } + default: + ts.Debug.fail("Unsupported property name."); + return unknownType; + } + default: + ts.Debug.fail("Unsupported decorator target."); + return unknownType; + } + } + function getEffectiveDecoratorThirdArgumentType(node) { + switch (node.kind) { + case 204: + ts.Debug.fail("Class decorators should not have a third synthetic argument."); + return unknownType; + case 131: + return numberType; + case 134: + ts.Debug.fail("Property decorators should not have a third synthetic argument."); + return unknownType; + case 136: + case 138: + case 139: + var propertyType = getTypeOfNode(node); + return createTypedPropertyDescriptorType(propertyType); + default: + ts.Debug.fail("Unsupported decorator target."); + return unknownType; + } + } + function getEffectiveDecoratorArgumentType(node, argIndex) { + if (argIndex === 0) { + return getEffectiveDecoratorFirstArgumentType(node.parent); + } + else if (argIndex === 1) { + return getEffectiveDecoratorSecondArgumentType(node.parent); + } + else if (argIndex === 2) { + return getEffectiveDecoratorThirdArgumentType(node.parent); + } + ts.Debug.fail("Decorators should not have a fourth synthetic argument."); + return unknownType; + } + function getEffectiveArgumentType(node, argIndex, arg) { + if (node.kind === 132) { + return getEffectiveDecoratorArgumentType(node, argIndex); + } + else if (argIndex === 0 && node.kind === 162) { + return globalTemplateStringsArrayType; + } + return undefined; + } + function getEffectiveArgument(node, args, argIndex) { + if (node.kind === 132 || + (argIndex === 0 && node.kind === 162)) { + return undefined; + } + return args[argIndex]; + } + function getEffectiveArgumentErrorNode(node, argIndex, arg) { + if (node.kind === 132) { + return node.expression; + } + else if (argIndex === 0 && node.kind === 162) { + return node.template; + } + else { + return arg; + } + } + function resolveCall(node, signatures, candidatesOutArray, headMessage) { var isTaggedTemplate = node.kind === 162; + var isDecorator = node.kind === 132; var typeArguments; - if (!isTaggedTemplate) { + if (!isTaggedTemplate && !isDecorator) { typeArguments = node.typeArguments; if (node.expression.kind !== 91) { ts.forEach(typeArguments, checkSourceElement); @@ -15444,17 +15620,19 @@ var ts; var candidates = candidatesOutArray || []; reorderCandidates(signatures, candidates); if (!candidates.length) { - error(node, ts.Diagnostics.Supplied_parameters_do_not_match_any_signature_of_call_target); + reportError(ts.Diagnostics.Supplied_parameters_do_not_match_any_signature_of_call_target); return resolveErrorCall(node); } var args = getEffectiveCallArguments(node); var excludeArgument; - for (var i = isTaggedTemplate ? 1 : 0; i < args.length; i++) { - if (isContextSensitive(args[i])) { - if (!excludeArgument) { - excludeArgument = new Array(args.length); + if (!isDecorator) { + for (var i = isTaggedTemplate ? 1 : 0; i < args.length; i++) { + if (isContextSensitive(args[i])) { + if (!excludeArgument) { + excludeArgument = new Array(args.length); + } + excludeArgument[i] = true; } - excludeArgument[i] = true; } } var candidateForArgumentError; @@ -15477,19 +15655,22 @@ var ts; checkApplicableSignature(node, args, candidateForArgumentError, assignableRelation, undefined, true); } else if (candidateForTypeArgumentError) { - if (!isTaggedTemplate && typeArguments) { - checkTypeArguments(candidateForTypeArgumentError, typeArguments, [], true); + if (!isTaggedTemplate && !isDecorator && typeArguments) { + checkTypeArguments(candidateForTypeArgumentError, node.typeArguments, [], true, headMessage); } else { ts.Debug.assert(resultOfFailedInference.failedTypeParameterIndex >= 0); var failedTypeParameter = candidateForTypeArgumentError.typeParameters[resultOfFailedInference.failedTypeParameterIndex]; var inferenceCandidates = getInferenceCandidates(resultOfFailedInference, resultOfFailedInference.failedTypeParameterIndex); var diagnosticChainHead = ts.chainDiagnosticMessages(undefined, ts.Diagnostics.The_type_argument_for_type_parameter_0_cannot_be_inferred_from_the_usage_Consider_specifying_the_type_arguments_explicitly, typeToString(failedTypeParameter)); + if (headMessage) { + diagnosticChainHead = ts.chainDiagnosticMessages(diagnosticChainHead, headMessage); + } reportNoCommonSupertypeError(inferenceCandidates, node.expression || node.tag, diagnosticChainHead); } } else { - error(node, ts.Diagnostics.Supplied_parameters_do_not_match_any_signature_of_call_target); + reportError(ts.Diagnostics.Supplied_parameters_do_not_match_any_signature_of_call_target); } if (!produceDiagnostics) { for (var _i = 0; _i < candidates.length; _i++) { @@ -15500,6 +15681,14 @@ var ts; } } return resolveErrorCall(node); + function reportError(message, arg0, arg1, arg2) { + var errorInfo; + errorInfo = ts.chainDiagnosticMessages(errorInfo, message, arg0, arg1, arg2); + if (headMessage) { + errorInfo = ts.chainDiagnosticMessages(errorInfo, headMessage); + } + diagnostics.add(ts.createDiagnosticForNodeFromMessageChain(node, errorInfo)); + } function chooseOverload(candidates, relation) { for (var _i = 0; _i < candidates.length; _i++) { var originalCandidate = candidates[_i]; @@ -15520,7 +15709,7 @@ var ts; typeArgumentsAreValid = checkTypeArguments(candidate, typeArguments, typeArgumentTypes, false); } else { - inferTypeArguments(candidate, args, excludeArgument, inferenceContext); + inferTypeArguments(node, candidate, args, excludeArgument, inferenceContext); typeArgumentsAreValid = inferenceContext.failedTypeParameterIndex === undefined; typeArgumentTypes = inferenceContext.inferredTypes; } @@ -15562,7 +15751,7 @@ var ts; if (node.expression.kind === 91) { var superType = checkSuperExpression(node.expression); if (superType !== unknownType) { - var baseTypeNode = ts.getClassExtendsHeritageClauseElement(ts.getAncestor(node, 204)); + var baseTypeNode = ts.getClassExtendsHeritageClauseElement(ts.getContainingClass(node)); var baseConstructors = getInstantiatedConstructorsForTypeArguments(superType, baseTypeNode.typeArguments); return resolveCall(node, baseConstructors, candidatesOutArray); } @@ -15641,6 +15830,41 @@ var ts; } return resolveCall(node, callSignatures, candidatesOutArray); } + function getDiagnosticHeadMessageForDecoratorResolution(node) { + switch (node.parent.kind) { + case 204: + case 177: + return ts.Diagnostics.Unable_to_resolve_signature_of_class_decorator_when_called_as_an_expression; + case 131: + return ts.Diagnostics.Unable_to_resolve_signature_of_parameter_decorator_when_called_as_an_expression; + case 134: + return ts.Diagnostics.Unable_to_resolve_signature_of_property_decorator_when_called_as_an_expression; + case 136: + case 138: + case 139: + return ts.Diagnostics.Unable_to_resolve_signature_of_method_decorator_when_called_as_an_expression; + } + } + function resolveDecorator(node, candidatesOutArray) { + var funcType = checkExpression(node.expression); + var apparentType = getApparentType(funcType); + if (apparentType === unknownType) { + return resolveErrorCall(node); + } + var callSignatures = getSignaturesOfType(apparentType, 0); + if (funcType === anyType || (!callSignatures.length && !(funcType.flags & 16384) && isTypeAssignableTo(funcType, globalFunctionType))) { + return resolveUntypedCall(node); + } + var headMessage = getDiagnosticHeadMessageForDecoratorResolution(node); + if (!callSignatures.length) { + var errorInfo; + errorInfo = ts.chainDiagnosticMessages(errorInfo, ts.Diagnostics.Cannot_invoke_an_expression_whose_type_lacks_a_call_signature); + errorInfo = ts.chainDiagnosticMessages(errorInfo, headMessage); + diagnostics.add(ts.createDiagnosticForNodeFromMessageChain(node, errorInfo)); + return resolveErrorCall(node); + } + return resolveCall(node, callSignatures, candidatesOutArray, headMessage); + } function getResolvedSignature(node, candidatesOutArray) { var links = getNodeLinks(node); if (!links.resolvedSignature || candidatesOutArray) { @@ -15654,6 +15878,9 @@ var ts; else if (node.kind === 162) { links.resolvedSignature = resolveTaggedTemplateExpression(node, candidatesOutArray); } + else if (node.kind === 132) { + links.resolvedSignature = resolveDecorator(node, candidatesOutArray); + } else { ts.Debug.fail("Branch in 'getResolvedSignature' should be unreachable."); } @@ -15869,7 +16096,7 @@ var ts; if (node.type) { checkTypeAssignableTo(exprType, getTypeFromTypeNode(node.type), node.body, undefined); } - checkFunctionExpressionBodies(node.body); + checkFunctionAndClassExpressionBodies(node.body); } } } @@ -16269,7 +16496,7 @@ var ts; if (ts.isFunctionLike(parent) && current === parent.body) { return false; } - else if (current.kind === 204 || current.kind === 177) { + else if (ts.isClassLike(current)) { return true; } current = parent; @@ -17045,29 +17272,37 @@ var ts; } } function checkDecorator(node) { - var expression = node.expression; - var exprType = checkExpression(expression); + var signature = getResolvedSignature(node); + var returnType = getReturnTypeOfSignature(signature); + if (returnType.flags & 1) { + return; + } + var expectedReturnType; + var headMessage = getDiagnosticHeadMessageForDecoratorResolution(node); + var errorInfo; switch (node.parent.kind) { case 204: var classSymbol = getSymbolOfNode(node.parent); var classConstructorType = getTypeOfSymbol(classSymbol); - var classDecoratorType = instantiateSingleCallFunctionType(getGlobalClassDecoratorType(), [classConstructorType]); - checkTypeAssignableTo(exprType, classDecoratorType, node); + expectedReturnType = getUnionType([classConstructorType, voidType]); + break; + case 131: + expectedReturnType = voidType; + errorInfo = ts.chainDiagnosticMessages(errorInfo, ts.Diagnostics.The_return_type_of_a_parameter_decorator_function_must_be_either_void_or_any); break; case 134: - checkTypeAssignableTo(exprType, getGlobalPropertyDecoratorType(), node); + expectedReturnType = voidType; + errorInfo = ts.chainDiagnosticMessages(errorInfo, ts.Diagnostics.The_return_type_of_a_property_decorator_function_must_be_either_void_or_any); break; case 136: case 138: case 139: var methodType = getTypeOfNode(node.parent); - var methodDecoratorType = instantiateSingleCallFunctionType(getGlobalMethodDecoratorType(), [methodType]); - checkTypeAssignableTo(exprType, methodDecoratorType, node); - break; - case 131: - checkTypeAssignableTo(exprType, getGlobalParameterDecoratorType(), node); + var descriptorType = createTypedPropertyDescriptorType(methodType); + expectedReturnType = getUnionType([descriptorType, voidType]); break; } + checkTypeAssignableTo(returnType, expectedReturnType, node, headMessage, errorInfo); } function checkTypeNodeAsExpression(node) { if (node && node.kind === 144) { @@ -17186,7 +17421,7 @@ var ts; } ts.forEach(node.statements, checkSourceElement); if (ts.isFunctionBlock(node) || node.kind === 209) { - checkFunctionExpressionBodies(node); + checkFunctionAndClassExpressionBodies(node); } } function checkCollisionWithArgumentsInGeneratedCode(node) { @@ -17245,7 +17480,7 @@ var ts; if (!needCollisionCheckForIdentifier(node, name, "_super")) { return; } - var enclosingClass = ts.getAncestor(node, 204); + var enclosingClass = ts.getContainingClass(node); if (!enclosingClass || ts.isInAmbientContext(enclosingClass)) { return; } @@ -17779,7 +18014,7 @@ var ts; checkIndexConstraintForProperty(prop, propType, type, declaredStringIndexer, stringIndexType, 0); checkIndexConstraintForProperty(prop, propType, type, declaredNumberIndexer, numberIndexType, 1); }); - if (type.flags & 1024 && type.symbol.valueDeclaration.kind === 204) { + if (type.flags & 1024 && ts.isClassLike(type.symbol.valueDeclaration)) { var classDeclaration = type.symbol.valueDeclaration; for (var _i = 0, _a = classDeclaration.members; _i < _a.length; _i++) { var member = _a[_i]; @@ -17855,14 +18090,17 @@ var ts; } } function checkClassExpression(node) { - grammarErrorOnNode(node, ts.Diagnostics.class_expressions_are_not_currently_supported); - ts.forEach(node.members, checkSourceElement); - return unknownType; + checkClassLikeDeclaration(node); + return getTypeOfSymbol(getSymbolOfNode(node)); } function checkClassDeclaration(node) { if (!node.name && !(node.flags & 256)) { grammarErrorOnFirstToken(node, ts.Diagnostics.A_class_declaration_without_the_default_modifier_must_have_a_name); } + checkClassLikeDeclaration(node); + ts.forEach(node.members, checkSourceElement); + } + function checkClassLikeDeclaration(node) { checkGrammarClassDeclarationHeritageClauses(node); checkDecorators(node); if (node.name) { @@ -17923,7 +18161,6 @@ var ts; } }); } - ts.forEach(node.members, checkSourceElement); if (produceDiagnostics) { checkIndexConstraints(type); checkTypeForDuplicateIndexSignatures(node); @@ -18665,17 +18902,20 @@ var ts; return checkMissingDeclaration(node); } } - function checkFunctionExpressionBodies(node) { + function checkFunctionAndClassExpressionBodies(node) { switch (node.kind) { case 165: case 166: - ts.forEach(node.parameters, checkFunctionExpressionBodies); + ts.forEach(node.parameters, checkFunctionAndClassExpressionBodies); checkFunctionExpressionOrObjectLiteralMethodBody(node); break; + case 177: + ts.forEach(node.members, checkSourceElement); + break; case 136: case 135: - ts.forEach(node.decorators, checkFunctionExpressionBodies); - ts.forEach(node.parameters, checkFunctionExpressionBodies); + ts.forEach(node.decorators, checkFunctionAndClassExpressionBodies); + ts.forEach(node.parameters, checkFunctionAndClassExpressionBodies); if (ts.isObjectLiteralMethod(node)) { checkFunctionExpressionOrObjectLiteralMethodBody(node); } @@ -18684,10 +18924,10 @@ var ts; case 138: case 139: case 203: - ts.forEach(node.parameters, checkFunctionExpressionBodies); + ts.forEach(node.parameters, checkFunctionAndClassExpressionBodies); break; case 195: - checkFunctionExpressionBodies(node.expression); + checkFunctionAndClassExpressionBodies(node.expression); break; case 132: case 131: @@ -18744,7 +18984,7 @@ var ts; case 229: case 217: case 230: - ts.forEachChild(node, checkFunctionExpressionBodies); + ts.forEachChild(node, checkFunctionAndClassExpressionBodies); break; } } @@ -18765,7 +19005,7 @@ var ts; emitParam = false; potentialThisCollisions.length = 0; ts.forEach(node.statements, checkSourceElement); - checkFunctionExpressionBodies(node); + checkFunctionAndClassExpressionBodies(node); if (ts.isExternalModule(node)) { checkExternalModuleExports(node); } @@ -18838,6 +19078,10 @@ var ts; case 207: copySymbols(getSymbolOfNode(location).exports, meaning & 8); break; + case 177: + if (location.name) { + copySymbol(location.symbol, meaning); + } case 204: case 205: if (!(memberFlags & 128)) { @@ -18872,40 +19116,6 @@ var ts; } } } - if (isInsideWithStatementBody(location)) { - return []; - } - while (location) { - if (location.locals && !isGlobalSourceFile(location)) { - copySymbols(location.locals, meaning); - } - switch (location.kind) { - case 230: - if (!ts.isExternalModule(location)) - break; - case 208: - copySymbols(getSymbolOfNode(location).exports, meaning & 8914931); - break; - case 207: - copySymbols(getSymbolOfNode(location).exports, meaning & 8); - break; - case 204: - case 205: - if (!(memberFlags & 128)) { - copySymbols(getSymbolOfNode(location).members, meaning & 793056); - } - break; - case 165: - if (location.name) { - copySymbol(location.symbol, meaning); - } - break; - } - memberFlags = location.flags; - location = location.parent; - } - copySymbols(globals, meaning); - return symbolsToArray(symbols); } function isTypeDeclarationName(name) { return name.kind === 65 && @@ -18999,6 +19209,9 @@ var ts; meaning |= 8388608; return resolveEntityName(entityName, meaning); } + if (entityName.parent.kind === 143) { + return resolveEntityName(entityName, 1); + } return undefined; } function getSymbolInfo(node) { @@ -19098,6 +19311,12 @@ var ts; } return checkExpression(expr); } + function getParentTypeOfClassElement(node) { + var classSymbol = getSymbolOfNode(node.parent); + return node.flags & 128 + ? getTypeOfSymbol(classSymbol) + : getDeclaredTypeOfSymbol(classSymbol); + } function getAugmentedPropertiesOfType(type) { type = getApparentType(type); var propsByName = createSymbolTable(getPropertiesOfType(type)); @@ -19500,10 +19719,7 @@ var ts; globalNumberType = getGlobalType("Number"); globalBooleanType = getGlobalType("Boolean"); globalRegExpType = getGlobalType("RegExp"); - getGlobalClassDecoratorType = ts.memoize(function () { return getGlobalType("ClassDecorator"); }); - getGlobalPropertyDecoratorType = ts.memoize(function () { return getGlobalType("PropertyDecorator"); }); - getGlobalMethodDecoratorType = ts.memoize(function () { return getGlobalType("MethodDecorator"); }); - getGlobalParameterDecoratorType = ts.memoize(function () { return getGlobalType("ParameterDecorator"); }); + getGlobalTypedPropertyDescriptorType = ts.memoize(function () { return getGlobalType("TypedPropertyDescriptor", 1); }); if (languageVersion >= 2) { globalTemplateStringsArrayType = getGlobalType("TemplateStringsArray"); globalESSymbolType = getGlobalType("Symbol"); @@ -20045,7 +20261,7 @@ var ts; return grammarErrorAtPos(getSourceFile(node), node.end - 1, ";".length, ts.Diagnostics._0_expected, "{"); } } - if (node.parent.kind === 204) { + if (ts.isClassLike(node.parent)) { if (checkGrammarForInvalidQuestionMark(node, node.questionToken, ts.Diagnostics.A_class_member_cannot_be_declared_optional)) { return true; } @@ -20276,7 +20492,7 @@ var ts; } } function checkGrammarProperty(node) { - if (node.parent.kind === 204) { + if (ts.isClassLike(node.parent)) { if (checkGrammarForInvalidQuestionMark(node, node.questionToken, ts.Diagnostics.A_class_member_cannot_be_declared_optional) || checkGrammarForNonSymbolComputedProperty(node.name, ts.Diagnostics.A_computed_property_name_in_a_class_property_declaration_must_directly_refer_to_a_built_in_symbol)) { return true; @@ -21826,6 +22042,9 @@ var ts; function generateNameForExportDefault() { return makeUniqueName("default"); } + function generateNameForClassExpression() { + return makeUniqueName("class"); + } function generateNameForNode(node) { switch (node.kind) { case 65: @@ -21838,9 +22057,10 @@ var ts; return generateNameForImportOrExportDeclaration(node); case 203: case 204: - case 177: case 217: return generateNameForExportDefault(); + case 177: + return generateNameForClassExpression(); } } function getGeneratedNameForNode(node) { diff --git a/bin/tsserver.js b/bin/tsserver.js index 6f4c99b36a6..b9b8ecc2ad1 100644 --- a/bin/tsserver.js +++ b/bin/tsserver.js @@ -1166,6 +1166,12 @@ var ts; An_export_declaration_can_only_be_used_in_a_module: { code: 1233, category: ts.DiagnosticCategory.Error, key: "An export declaration can only be used in a module." }, An_ambient_module_declaration_is_only_allowed_at_the_top_level_in_a_file: { code: 1234, category: ts.DiagnosticCategory.Error, key: "An ambient module declaration is only allowed at the top level in a file." }, A_namespace_declaration_is_only_allowed_in_a_namespace_or_module: { code: 1235, category: ts.DiagnosticCategory.Error, key: "A namespace declaration is only allowed in a namespace or module." }, + The_return_type_of_a_property_decorator_function_must_be_either_void_or_any: { code: 1236, category: ts.DiagnosticCategory.Error, key: "The return type of a property decorator function must be either 'void' or 'any'." }, + The_return_type_of_a_parameter_decorator_function_must_be_either_void_or_any: { code: 1237, category: ts.DiagnosticCategory.Error, key: "The return type of a parameter decorator function must be either 'void' or 'any'." }, + Unable_to_resolve_signature_of_class_decorator_when_called_as_an_expression: { code: 1238, category: ts.DiagnosticCategory.Error, key: "Unable to resolve signature of class decorator when called as an expression." }, + Unable_to_resolve_signature_of_parameter_decorator_when_called_as_an_expression: { code: 1239, category: ts.DiagnosticCategory.Error, key: "Unable to resolve signature of parameter decorator when called as an expression." }, + Unable_to_resolve_signature_of_property_decorator_when_called_as_an_expression: { code: 1240, category: ts.DiagnosticCategory.Error, key: "Unable to resolve signature of property decorator when called as an expression." }, + Unable_to_resolve_signature_of_method_decorator_when_called_as_an_expression: { code: 1241, category: ts.DiagnosticCategory.Error, key: "Unable to resolve signature of method decorator when called as an expression." }, Duplicate_identifier_0: { code: 2300, category: ts.DiagnosticCategory.Error, key: "Duplicate identifier '{0}'." }, Initializer_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor: { code: 2301, category: ts.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: ts.DiagnosticCategory.Error, key: "Static members cannot reference class type parameters." }, @@ -1541,9 +1547,7 @@ var ts; property_declarations_can_only_be_used_in_a_ts_file: { code: 8014, category: ts.DiagnosticCategory.Error, key: "'property declarations' can only be used in a .ts file." }, enum_declarations_can_only_be_used_in_a_ts_file: { code: 8015, category: ts.DiagnosticCategory.Error, key: "'enum declarations' can only be used in a .ts file." }, type_assertion_expressions_can_only_be_used_in_a_ts_file: { code: 8016, category: ts.DiagnosticCategory.Error, key: "'type assertion expressions' can only be used in a .ts file." }, - decorators_can_only_be_used_in_a_ts_file: { code: 8017, category: ts.DiagnosticCategory.Error, key: "'decorators' can only be used in a .ts file." }, - Only_identifiers_Slashqualified_names_with_optional_type_arguments_are_currently_supported_in_a_class_extends_clauses: { code: 9002, category: ts.DiagnosticCategory.Error, key: "Only identifiers/qualified-names with optional type arguments are currently supported in a class 'extends' clauses." }, - class_expressions_are_not_currently_supported: { code: 9003, category: ts.DiagnosticCategory.Error, key: "'class' expressions are not currently supported." } + decorators_can_only_be_used_in_a_ts_file: { code: 8017, category: ts.DiagnosticCategory.Error, key: "'decorators' can only be used in a .ts file." } }; })(ts || (ts = {})); /// @@ -3620,6 +3624,7 @@ var ts; case 208: case 206: case 204: + case 177: return; default: if (isFunctionLike(node)) { @@ -3654,20 +3659,11 @@ var ts; } ts.isVariableLike = isVariableLike; function isAccessor(node) { - if (node) { - switch (node.kind) { - case 138: - case 139: - return true; - } - } - return false; + return node && (node.kind === 138 || node.kind === 139); } ts.isAccessor = isAccessor; function isClassLike(node) { - if (node) { - return node.kind === 204 || node.kind === 177; - } + return node && (node.kind === 204 || node.kind === 177); } ts.isClassLike = isClassLike; function isFunctionLike(node) { @@ -3709,6 +3705,15 @@ var ts; } } ts.getContainingFunction = getContainingFunction; + function getContainingClass(node) { + while (true) { + node = node.parent; + if (!node || isClassLike(node)) { + return node; + } + } + } + ts.getContainingClass = getContainingClass; function getThisContainer(node, includeArrowFunctions) { while (true) { node = node.parent; @@ -3717,7 +3722,7 @@ var ts; } switch (node.kind) { case 129: - if (node.parent.parent.kind === 204) { + if (isClassLike(node.parent.parent)) { return node; } node = node.parent; @@ -3758,7 +3763,7 @@ var ts; return node; switch (node.kind) { case 129: - if (node.parent.parent.kind === 204) { + if (isClassLike(node.parent.parent)) { return node; } node = node.parent; @@ -4098,6 +4103,7 @@ var ts; case 166: case 155: case 204: + case 177: case 137: case 207: case 229: @@ -4799,7 +4805,7 @@ var ts; function isExpressionWithTypeArgumentsInClassExtendsClause(node) { return node.kind === 179 && node.parent.token === 79 && - node.parent.parent.kind === 204; + isClassLike(node.parent.parent); } ts.isExpressionWithTypeArgumentsInClassExtendsClause = isExpressionWithTypeArgumentsInClassExtendsClause; function isSupportedExpressionWithTypeArguments(node) { @@ -9701,7 +9707,7 @@ var ts; } } function getStrictModeIdentifierMessage(node) { - if (ts.getAncestor(node, 204) || ts.getAncestor(node, 177)) { + if (ts.getContainingClass(node)) { return ts.Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode_Class_definitions_are_automatically_in_strict_mode; } if (file.externalModuleIndicator) { @@ -9739,7 +9745,7 @@ var ts; } } function getStrictModeEvalOrArgumentsMessage(node) { - if (ts.getAncestor(node, 204) || ts.getAncestor(node, 177)) { + if (ts.getContainingClass(node)) { return ts.Diagnostics.Invalid_use_of_0_Class_definitions_are_automatically_in_strict_mode; } if (file.externalModuleIndicator) { @@ -9991,7 +9997,7 @@ var ts; } if (node.flags & 112 && node.parent.kind === 137 && - (node.parent.parent.kind === 204 || node.parent.parent.kind === 177)) { + ts.isClassLike(node.parent.parent)) { var classDeclaration = node.parent.parent; declareSymbol(classDeclaration.symbol.members, classDeclaration.symbol, node, 4, 107455); } @@ -10105,10 +10111,7 @@ var ts; var globalIteratorType; var globalIterableIteratorType; var anyArrayType; - var getGlobalClassDecoratorType; - var getGlobalParameterDecoratorType; - var getGlobalPropertyDecoratorType; - var getGlobalMethodDecoratorType; + var getGlobalTypedPropertyDescriptorType; var tupleTypes = {}; var unionTypes = {}; var stringLiteralTypes = {}; @@ -10365,7 +10368,7 @@ var ts; break; case 134: case 133: - if (location.parent.kind === 204 && !(location.flags & 128)) { + if (ts.isClassLike(location.parent) && !(location.flags & 128)) { var ctor = findConstructorDeclaration(location.parent); if (ctor && ctor.locals) { if (getSymbol(ctor.locals, name, meaning & 107455)) { @@ -10375,6 +10378,7 @@ var ts; } break; case 204: + case 177: case 205: if (result = getSymbol(getSymbolOfNode(location).members, name, meaning & 793056)) { if (lastLocation && lastLocation.flags & 128) { @@ -10383,10 +10387,17 @@ var ts; } break loop; } + if (location.kind === 177 && meaning & 32) { + var className = location.name; + if (className && name === className.text) { + result = location.symbol; + break loop; + } + } break; case 129: grandparent = location.parent.parent; - if (grandparent.kind === 204 || grandparent.kind === 205) { + if (ts.isClassLike(grandparent) || grandparent.kind === 205) { if (result = getSymbol(getSymbolOfNode(grandparent).members, name, meaning & 793056)) { error(errorLocation, ts.Diagnostics.A_computed_property_name_cannot_reference_a_type_parameter_from_its_containing_type); return undefined; @@ -10418,15 +10429,6 @@ var ts; } } break; - case 177: - if (meaning & 32) { - var className = location.name; - if (className && name === className.text) { - result = location.symbol; - break loop; - } - } - break; case 132: if (location.parent && location.parent.kind === 131) { location = location.parent; @@ -11127,15 +11129,24 @@ var ts; } var _displayBuilder; function getSymbolDisplayBuilder() { - function appendSymbolNameOnly(symbol, writer) { - if (symbol.declarations && symbol.declarations.length > 0) { + function getNameOfSymbol(symbol) { + if (symbol.declarations && symbol.declarations.length) { var declaration = symbol.declarations[0]; if (declaration.name) { - writer.writeSymbol(ts.declarationNameToString(declaration.name), symbol); - return; + return ts.declarationNameToString(declaration.name); + } + switch (declaration.kind) { + case 177: + return "(Anonymous class)"; + case 165: + case 166: + return "(Anonymous function)"; } } - writer.writeSymbol(symbol.name, symbol); + return symbol.name; + } + function appendSymbolNameOnly(symbol, writer) { + writer.writeSymbol(getNameOfSymbol(symbol), symbol); } function buildSymbolDisplay(symbol, writer, enclosingDeclaration, meaning, flags, typeFlags) { var parentSymbol; @@ -12051,9 +12062,9 @@ var ts; if (!node) { return typeParameters; } - if (node.kind === 204 || node.kind === 203 || - node.kind === 165 || node.kind === 136 || - node.kind === 166) { + if (node.kind === 204 || node.kind === 177 || + node.kind === 203 || node.kind === 165 || + node.kind === 136 || node.kind === 166) { var declarations = node.typeParameters; if (declarations) { return appendTypeParameters(appendOuterTypeParameters(typeParameters, node), declarations); @@ -12062,14 +12073,15 @@ var ts; } } function getOuterTypeParametersOfClassOrInterface(symbol) { - var kind = symbol.flags & 32 ? 204 : 205; - return appendOuterTypeParameters(undefined, ts.getDeclarationOfKind(symbol, kind)); + var declaration = symbol.flags & 32 ? symbol.valueDeclaration : ts.getDeclarationOfKind(symbol, 205); + return appendOuterTypeParameters(undefined, declaration); } function getLocalTypeParametersOfClassOrInterfaceOrTypeAlias(symbol) { var result; for (var _i = 0, _a = symbol.declarations; _i < _a.length; _i++) { var node = _a[_i]; - if (node.kind === 205 || node.kind === 204 || node.kind === 206) { + if (node.kind === 205 || node.kind === 204 || + node.kind === 177 || node.kind === 206) { var declaration = node; if (declaration.typeParameters) { result = appendTypeParameters(result, declaration.typeParameters); @@ -13082,6 +13094,12 @@ var ts; function getGlobalESSymbolConstructorSymbol() { return globalESSymbolConstructorSymbol || (globalESSymbolConstructorSymbol = getGlobalValueSymbol("Symbol")); } + function createTypedPropertyDescriptorType(propertyType) { + var globalTypedPropertyDescriptorType = getGlobalTypedPropertyDescriptorType(); + return globalTypedPropertyDescriptorType !== emptyObjectType + ? createTypeReference(globalTypedPropertyDescriptorType, [propertyType]) + : emptyObjectType; + } function createTypeFromGenericGlobalType(genericGlobalType, elementType) { return genericGlobalType !== emptyGenericType ? createTypeReference(genericGlobalType, [elementType]) : emptyObjectType; } @@ -13497,8 +13515,8 @@ var ts; function checkTypeSubtypeOf(source, target, errorNode, headMessage, containingMessageChain) { return checkTypeRelatedTo(source, target, subtypeRelation, errorNode, headMessage, containingMessageChain); } - function checkTypeAssignableTo(source, target, errorNode, headMessage) { - return checkTypeRelatedTo(source, target, assignableRelation, errorNode, headMessage); + function checkTypeAssignableTo(source, target, errorNode, headMessage, containingMessageChain) { + return checkTypeRelatedTo(source, target, assignableRelation, errorNode, headMessage, containingMessageChain); } function isSignatureAssignableTo(source, target) { var sourceType = getOrCreateTypeFromSignature(source); @@ -14883,9 +14901,9 @@ var ts; } } function captureLexicalThis(node, container) { - var classNode = container.parent && container.parent.kind === 204 ? container.parent : undefined; getNodeLinks(node).flags |= 2; if (container.kind === 134 || container.kind === 137) { + var classNode = container.parent; getNodeLinks(classNode).flags |= 4; } else { @@ -14924,9 +14942,8 @@ var ts; if (needToCaptureLexicalThis) { captureLexicalThis(node, container); } - var classNode = container.parent && container.parent.kind === 204 ? container.parent : undefined; - if (classNode) { - var symbol = getSymbolOfNode(classNode); + if (ts.isClassLike(container.parent)) { + var symbol = getSymbolOfNode(container.parent); return container.flags & 128 ? getTypeOfSymbol(symbol) : getDeclaredTypeOfSymbol(symbol); } return anyType; @@ -14941,7 +14958,7 @@ var ts; } function checkSuperExpression(node) { var isCallExpression = node.parent.kind === 160 && node.parent.expression === node; - var classDeclaration = ts.getAncestor(node, 204); + var classDeclaration = ts.getContainingClass(node); var classType = classDeclaration && getDeclaredTypeOfSymbol(getSymbolOfNode(classDeclaration)); var baseClassType = classType && getBaseTypes(classType)[0]; if (!baseClassType) { @@ -14963,7 +14980,7 @@ var ts; container = ts.getSuperContainer(container, true); needToCaptureLexicalThis = languageVersion < 2; } - if (container && container.parent && container.parent.kind === 204) { + if (container && ts.isClassLike(container.parent)) { if (container.flags & 128) { canUseSuperExpression = container.kind === 136 || @@ -15446,7 +15463,7 @@ var ts; if (!(flags & (32 | 64))) { return; } - var enclosingClassDeclaration = ts.getAncestor(node, 204); + var enclosingClassDeclaration = ts.getContainingClass(node); var enclosingClass = enclosingClassDeclaration ? getDeclaredTypeOfSymbol(getSymbolOfNode(enclosingClassDeclaration)) : undefined; var declaringClass = getDeclaredTypeOfSymbol(prop.parent); if (flags & 32) { @@ -15624,7 +15641,7 @@ var ts; if (node.kind === 162) { checkExpression(node.template); } - else { + else if (node.kind !== 132) { ts.forEach(node.arguments, function (argument) { checkExpression(argument); }); @@ -15674,7 +15691,8 @@ var ts; } function getSpreadArgumentIndex(args) { for (var i = 0; i < args.length; i++) { - if (args[i].kind === 176) { + var arg = args[i]; + if (arg && arg.kind === 176) { return i; } } @@ -15684,6 +15702,8 @@ var ts; var adjustedArgCount; var typeArguments; var callIsIncomplete; + var isDecorator; + var spreadArgIndex = -1; if (node.kind === 162) { var tagExpression = node; adjustedArgCount = args.length; @@ -15700,6 +15720,11 @@ var ts; callIsIncomplete = !!templateLiteral.isUnterminated; } } + else if (node.kind === 132) { + isDecorator = true; + typeArguments = undefined; + adjustedArgCount = getEffectiveArgumentCount(node, undefined, signature); + } else { var callExpression = node; if (!callExpression.arguments) { @@ -15709,13 +15734,13 @@ var ts; adjustedArgCount = callExpression.arguments.hasTrailingComma ? args.length + 1 : args.length; callIsIncomplete = callExpression.arguments.end === callExpression.end; typeArguments = callExpression.typeArguments; + spreadArgIndex = getSpreadArgumentIndex(args); } var hasRightNumberOfTypeArgs = !typeArguments || (signature.typeParameters && typeArguments.length === signature.typeParameters.length); if (!hasRightNumberOfTypeArgs) { return false; } - var spreadArgIndex = getSpreadArgumentIndex(args); if (spreadArgIndex >= 0) { return signature.hasRestParameter && spreadArgIndex >= signature.parameters.length - 1; } @@ -15742,7 +15767,7 @@ var ts; }); return getSignatureInstantiation(signature, getInferredTypes(context)); } - function inferTypeArguments(signature, args, excludeArgument, context) { + function inferTypeArguments(node, signature, args, excludeArgument, context) { var typeParameters = signature.typeParameters; var inferenceMapper = createInferenceMapper(context); for (var i = 0; i < typeParameters.length; i++) { @@ -15753,15 +15778,13 @@ var ts; if (context.failedTypeParameterIndex !== undefined && !context.inferences[context.failedTypeParameterIndex].isFixed) { context.failedTypeParameterIndex = undefined; } - for (var i = 0; i < args.length; i++) { - var arg = args[i]; - if (arg.kind !== 178) { + var argCount = getEffectiveArgumentCount(node, args, signature); + for (var i = 0; i < argCount; i++) { + var arg = getEffectiveArgument(node, args, i); + if (arg === undefined || arg.kind !== 178) { var paramType = getTypeAtPosition(signature, i); - var argType = void 0; - if (i === 0 && args[i].parent.kind === 162) { - argType = globalTemplateStringsArrayType; - } - else { + var argType = getEffectiveArgumentType(node, i, arg); + if (argType === undefined) { var mapper = excludeArgument && excludeArgument[i] !== undefined ? identityMapper : inferenceMapper; argType = checkExpressionWithContextualType(arg, paramType, mapper); } @@ -15769,7 +15792,7 @@ var ts; } } if (excludeArgument) { - for (var i = 0; i < args.length; i++) { + for (var i = 0; i < argCount; i++) { if (excludeArgument[i] === false) { var arg = args[i]; var paramType = getTypeAtPosition(signature, i); @@ -15779,7 +15802,7 @@ var ts; } getInferredTypes(context); } - function checkTypeArguments(signature, typeArguments, typeArgumentResultTypes, reportErrors) { + function checkTypeArguments(signature, typeArguments, typeArgumentResultTypes, reportErrors, headMessage) { var typeParameters = signature.typeParameters; var typeArgumentsAreAssignable = true; for (var i = 0; i < typeParameters.length; i++) { @@ -15789,23 +15812,33 @@ var ts; if (typeArgumentsAreAssignable) { var constraint = getConstraintOfTypeParameter(typeParameters[i]); if (constraint) { - typeArgumentsAreAssignable = checkTypeAssignableTo(typeArgument, constraint, reportErrors ? typeArgNode : undefined, ts.Diagnostics.Type_0_does_not_satisfy_the_constraint_1); + var errorInfo = void 0; + var typeArgumentHeadMessage = ts.Diagnostics.Type_0_does_not_satisfy_the_constraint_1; + if (reportErrors && headMessage) { + errorInfo = ts.chainDiagnosticMessages(errorInfo, typeArgumentHeadMessage); + typeArgumentHeadMessage = headMessage; + } + typeArgumentsAreAssignable = checkTypeAssignableTo(typeArgument, constraint, reportErrors ? typeArgNode : undefined, typeArgumentHeadMessage, errorInfo); } } } return typeArgumentsAreAssignable; } function checkApplicableSignature(node, args, signature, relation, excludeArgument, reportErrors) { - for (var i = 0; i < args.length; i++) { - var arg = args[i]; - if (arg.kind !== 178) { + var argCount = getEffectiveArgumentCount(node, args, signature); + for (var i = 0; i < argCount; i++) { + var arg = getEffectiveArgument(node, args, i); + if (arg === undefined || arg.kind !== 178) { var paramType = getTypeAtPosition(signature, i); - var argType = i === 0 && node.kind === 162 - ? globalTemplateStringsArrayType - : arg.kind === 8 && !reportErrors + var argType = getEffectiveArgumentType(node, i, arg); + if (argType === undefined) { + argType = arg.kind === 8 && !reportErrors ? getStringLiteralType(arg) : checkExpressionWithContextualType(arg, paramType, excludeArgument && excludeArgument[i] ? identityMapper : undefined); - if (!checkTypeRelatedTo(argType, paramType, relation, reportErrors ? arg : undefined, ts.Diagnostics.Argument_of_type_0_is_not_assignable_to_parameter_of_type_1)) { + } + var errorNode = reportErrors ? getEffectiveArgumentErrorNode(node, i, arg) : undefined; + var headMessage = ts.Diagnostics.Argument_of_type_0_is_not_assignable_to_parameter_of_type_1; + if (!checkTypeRelatedTo(argType, paramType, relation, errorNode, headMessage)) { return false; } } @@ -15816,22 +15849,165 @@ var ts; var args; if (node.kind === 162) { var template = node.template; - args = [template]; + args = [undefined]; if (template.kind === 174) { ts.forEach(template.templateSpans, function (span) { args.push(span.expression); }); } } + else if (node.kind === 132) { + return undefined; + } else { args = node.arguments || emptyArray; } return args; } - function resolveCall(node, signatures, candidatesOutArray) { + function getEffectiveArgumentCount(node, args, signature) { + if (node.kind === 132) { + switch (node.parent.kind) { + case 204: + case 177: + return 1; + case 134: + return 2; + case 136: + case 138: + case 139: + return signature.parameters.length >= 3 ? 3 : 2; + case 131: + return 3; + } + } + else { + return args.length; + } + } + function getEffectiveDecoratorFirstArgumentType(node) { + switch (node.kind) { + case 204: + case 177: + var classSymbol = getSymbolOfNode(node); + return getTypeOfSymbol(classSymbol); + case 131: + node = node.parent; + if (node.kind === 137) { + var classSymbol_1 = getSymbolOfNode(node); + return getTypeOfSymbol(classSymbol_1); + } + case 134: + case 136: + case 138: + case 139: + return getParentTypeOfClassElement(node); + default: + ts.Debug.fail("Unsupported decorator target."); + return unknownType; + } + } + function getEffectiveDecoratorSecondArgumentType(node) { + switch (node.kind) { + case 204: + ts.Debug.fail("Class decorators should not have a second synthetic argument."); + return unknownType; + case 131: + node = node.parent; + if (node.kind === 137) { + return anyType; + } + case 134: + case 136: + case 138: + case 139: + var element = node; + switch (element.name.kind) { + case 65: + case 7: + case 8: + return getStringLiteralType(element.name); + case 129: + var nameType = checkComputedPropertyName(element.name); + if (allConstituentTypesHaveKind(nameType, 2097152)) { + return nameType; + } + else { + return stringType; + } + default: + ts.Debug.fail("Unsupported property name."); + return unknownType; + } + default: + ts.Debug.fail("Unsupported decorator target."); + return unknownType; + } + } + function getEffectiveDecoratorThirdArgumentType(node) { + switch (node.kind) { + case 204: + ts.Debug.fail("Class decorators should not have a third synthetic argument."); + return unknownType; + case 131: + return numberType; + case 134: + ts.Debug.fail("Property decorators should not have a third synthetic argument."); + return unknownType; + case 136: + case 138: + case 139: + var propertyType = getTypeOfNode(node); + return createTypedPropertyDescriptorType(propertyType); + default: + ts.Debug.fail("Unsupported decorator target."); + return unknownType; + } + } + function getEffectiveDecoratorArgumentType(node, argIndex) { + if (argIndex === 0) { + return getEffectiveDecoratorFirstArgumentType(node.parent); + } + else if (argIndex === 1) { + return getEffectiveDecoratorSecondArgumentType(node.parent); + } + else if (argIndex === 2) { + return getEffectiveDecoratorThirdArgumentType(node.parent); + } + ts.Debug.fail("Decorators should not have a fourth synthetic argument."); + return unknownType; + } + function getEffectiveArgumentType(node, argIndex, arg) { + if (node.kind === 132) { + return getEffectiveDecoratorArgumentType(node, argIndex); + } + else if (argIndex === 0 && node.kind === 162) { + return globalTemplateStringsArrayType; + } + return undefined; + } + function getEffectiveArgument(node, args, argIndex) { + if (node.kind === 132 || + (argIndex === 0 && node.kind === 162)) { + return undefined; + } + return args[argIndex]; + } + function getEffectiveArgumentErrorNode(node, argIndex, arg) { + if (node.kind === 132) { + return node.expression; + } + else if (argIndex === 0 && node.kind === 162) { + return node.template; + } + else { + return arg; + } + } + function resolveCall(node, signatures, candidatesOutArray, headMessage) { var isTaggedTemplate = node.kind === 162; + var isDecorator = node.kind === 132; var typeArguments; - if (!isTaggedTemplate) { + if (!isTaggedTemplate && !isDecorator) { typeArguments = node.typeArguments; if (node.expression.kind !== 91) { ts.forEach(typeArguments, checkSourceElement); @@ -15840,17 +16016,19 @@ var ts; var candidates = candidatesOutArray || []; reorderCandidates(signatures, candidates); if (!candidates.length) { - error(node, ts.Diagnostics.Supplied_parameters_do_not_match_any_signature_of_call_target); + reportError(ts.Diagnostics.Supplied_parameters_do_not_match_any_signature_of_call_target); return resolveErrorCall(node); } var args = getEffectiveCallArguments(node); var excludeArgument; - for (var i = isTaggedTemplate ? 1 : 0; i < args.length; i++) { - if (isContextSensitive(args[i])) { - if (!excludeArgument) { - excludeArgument = new Array(args.length); + if (!isDecorator) { + for (var i = isTaggedTemplate ? 1 : 0; i < args.length; i++) { + if (isContextSensitive(args[i])) { + if (!excludeArgument) { + excludeArgument = new Array(args.length); + } + excludeArgument[i] = true; } - excludeArgument[i] = true; } } var candidateForArgumentError; @@ -15873,19 +16051,22 @@ var ts; checkApplicableSignature(node, args, candidateForArgumentError, assignableRelation, undefined, true); } else if (candidateForTypeArgumentError) { - if (!isTaggedTemplate && typeArguments) { - checkTypeArguments(candidateForTypeArgumentError, typeArguments, [], true); + if (!isTaggedTemplate && !isDecorator && typeArguments) { + checkTypeArguments(candidateForTypeArgumentError, node.typeArguments, [], true, headMessage); } else { ts.Debug.assert(resultOfFailedInference.failedTypeParameterIndex >= 0); var failedTypeParameter = candidateForTypeArgumentError.typeParameters[resultOfFailedInference.failedTypeParameterIndex]; var inferenceCandidates = getInferenceCandidates(resultOfFailedInference, resultOfFailedInference.failedTypeParameterIndex); var diagnosticChainHead = ts.chainDiagnosticMessages(undefined, ts.Diagnostics.The_type_argument_for_type_parameter_0_cannot_be_inferred_from_the_usage_Consider_specifying_the_type_arguments_explicitly, typeToString(failedTypeParameter)); + if (headMessage) { + diagnosticChainHead = ts.chainDiagnosticMessages(diagnosticChainHead, headMessage); + } reportNoCommonSupertypeError(inferenceCandidates, node.expression || node.tag, diagnosticChainHead); } } else { - error(node, ts.Diagnostics.Supplied_parameters_do_not_match_any_signature_of_call_target); + reportError(ts.Diagnostics.Supplied_parameters_do_not_match_any_signature_of_call_target); } if (!produceDiagnostics) { for (var _i = 0; _i < candidates.length; _i++) { @@ -15896,6 +16077,14 @@ var ts; } } return resolveErrorCall(node); + function reportError(message, arg0, arg1, arg2) { + var errorInfo; + errorInfo = ts.chainDiagnosticMessages(errorInfo, message, arg0, arg1, arg2); + if (headMessage) { + errorInfo = ts.chainDiagnosticMessages(errorInfo, headMessage); + } + diagnostics.add(ts.createDiagnosticForNodeFromMessageChain(node, errorInfo)); + } function chooseOverload(candidates, relation) { for (var _i = 0; _i < candidates.length; _i++) { var originalCandidate = candidates[_i]; @@ -15916,7 +16105,7 @@ var ts; typeArgumentsAreValid = checkTypeArguments(candidate, typeArguments, typeArgumentTypes, false); } else { - inferTypeArguments(candidate, args, excludeArgument, inferenceContext); + inferTypeArguments(node, candidate, args, excludeArgument, inferenceContext); typeArgumentsAreValid = inferenceContext.failedTypeParameterIndex === undefined; typeArgumentTypes = inferenceContext.inferredTypes; } @@ -15958,7 +16147,7 @@ var ts; if (node.expression.kind === 91) { var superType = checkSuperExpression(node.expression); if (superType !== unknownType) { - var baseTypeNode = ts.getClassExtendsHeritageClauseElement(ts.getAncestor(node, 204)); + var baseTypeNode = ts.getClassExtendsHeritageClauseElement(ts.getContainingClass(node)); var baseConstructors = getInstantiatedConstructorsForTypeArguments(superType, baseTypeNode.typeArguments); return resolveCall(node, baseConstructors, candidatesOutArray); } @@ -16037,6 +16226,41 @@ var ts; } return resolveCall(node, callSignatures, candidatesOutArray); } + function getDiagnosticHeadMessageForDecoratorResolution(node) { + switch (node.parent.kind) { + case 204: + case 177: + return ts.Diagnostics.Unable_to_resolve_signature_of_class_decorator_when_called_as_an_expression; + case 131: + return ts.Diagnostics.Unable_to_resolve_signature_of_parameter_decorator_when_called_as_an_expression; + case 134: + return ts.Diagnostics.Unable_to_resolve_signature_of_property_decorator_when_called_as_an_expression; + case 136: + case 138: + case 139: + return ts.Diagnostics.Unable_to_resolve_signature_of_method_decorator_when_called_as_an_expression; + } + } + function resolveDecorator(node, candidatesOutArray) { + var funcType = checkExpression(node.expression); + var apparentType = getApparentType(funcType); + if (apparentType === unknownType) { + return resolveErrorCall(node); + } + var callSignatures = getSignaturesOfType(apparentType, 0); + if (funcType === anyType || (!callSignatures.length && !(funcType.flags & 16384) && isTypeAssignableTo(funcType, globalFunctionType))) { + return resolveUntypedCall(node); + } + var headMessage = getDiagnosticHeadMessageForDecoratorResolution(node); + if (!callSignatures.length) { + var errorInfo; + errorInfo = ts.chainDiagnosticMessages(errorInfo, ts.Diagnostics.Cannot_invoke_an_expression_whose_type_lacks_a_call_signature); + errorInfo = ts.chainDiagnosticMessages(errorInfo, headMessage); + diagnostics.add(ts.createDiagnosticForNodeFromMessageChain(node, errorInfo)); + return resolveErrorCall(node); + } + return resolveCall(node, callSignatures, candidatesOutArray, headMessage); + } function getResolvedSignature(node, candidatesOutArray) { var links = getNodeLinks(node); if (!links.resolvedSignature || candidatesOutArray) { @@ -16050,6 +16274,9 @@ var ts; else if (node.kind === 162) { links.resolvedSignature = resolveTaggedTemplateExpression(node, candidatesOutArray); } + else if (node.kind === 132) { + links.resolvedSignature = resolveDecorator(node, candidatesOutArray); + } else { ts.Debug.fail("Branch in 'getResolvedSignature' should be unreachable."); } @@ -16265,7 +16492,7 @@ var ts; if (node.type) { checkTypeAssignableTo(exprType, getTypeFromTypeNode(node.type), node.body, undefined); } - checkFunctionExpressionBodies(node.body); + checkFunctionAndClassExpressionBodies(node.body); } } } @@ -16665,7 +16892,7 @@ var ts; if (ts.isFunctionLike(parent) && current === parent.body) { return false; } - else if (current.kind === 204 || current.kind === 177) { + else if (ts.isClassLike(current)) { return true; } current = parent; @@ -17441,29 +17668,37 @@ var ts; } } function checkDecorator(node) { - var expression = node.expression; - var exprType = checkExpression(expression); + var signature = getResolvedSignature(node); + var returnType = getReturnTypeOfSignature(signature); + if (returnType.flags & 1) { + return; + } + var expectedReturnType; + var headMessage = getDiagnosticHeadMessageForDecoratorResolution(node); + var errorInfo; switch (node.parent.kind) { case 204: var classSymbol = getSymbolOfNode(node.parent); var classConstructorType = getTypeOfSymbol(classSymbol); - var classDecoratorType = instantiateSingleCallFunctionType(getGlobalClassDecoratorType(), [classConstructorType]); - checkTypeAssignableTo(exprType, classDecoratorType, node); + expectedReturnType = getUnionType([classConstructorType, voidType]); + break; + case 131: + expectedReturnType = voidType; + errorInfo = ts.chainDiagnosticMessages(errorInfo, ts.Diagnostics.The_return_type_of_a_parameter_decorator_function_must_be_either_void_or_any); break; case 134: - checkTypeAssignableTo(exprType, getGlobalPropertyDecoratorType(), node); + expectedReturnType = voidType; + errorInfo = ts.chainDiagnosticMessages(errorInfo, ts.Diagnostics.The_return_type_of_a_property_decorator_function_must_be_either_void_or_any); break; case 136: case 138: case 139: var methodType = getTypeOfNode(node.parent); - var methodDecoratorType = instantiateSingleCallFunctionType(getGlobalMethodDecoratorType(), [methodType]); - checkTypeAssignableTo(exprType, methodDecoratorType, node); - break; - case 131: - checkTypeAssignableTo(exprType, getGlobalParameterDecoratorType(), node); + var descriptorType = createTypedPropertyDescriptorType(methodType); + expectedReturnType = getUnionType([descriptorType, voidType]); break; } + checkTypeAssignableTo(returnType, expectedReturnType, node, headMessage, errorInfo); } function checkTypeNodeAsExpression(node) { if (node && node.kind === 144) { @@ -17582,7 +17817,7 @@ var ts; } ts.forEach(node.statements, checkSourceElement); if (ts.isFunctionBlock(node) || node.kind === 209) { - checkFunctionExpressionBodies(node); + checkFunctionAndClassExpressionBodies(node); } } function checkCollisionWithArgumentsInGeneratedCode(node) { @@ -17641,7 +17876,7 @@ var ts; if (!needCollisionCheckForIdentifier(node, name, "_super")) { return; } - var enclosingClass = ts.getAncestor(node, 204); + var enclosingClass = ts.getContainingClass(node); if (!enclosingClass || ts.isInAmbientContext(enclosingClass)) { return; } @@ -18175,7 +18410,7 @@ var ts; checkIndexConstraintForProperty(prop, propType, type, declaredStringIndexer, stringIndexType, 0); checkIndexConstraintForProperty(prop, propType, type, declaredNumberIndexer, numberIndexType, 1); }); - if (type.flags & 1024 && type.symbol.valueDeclaration.kind === 204) { + if (type.flags & 1024 && ts.isClassLike(type.symbol.valueDeclaration)) { var classDeclaration = type.symbol.valueDeclaration; for (var _i = 0, _a = classDeclaration.members; _i < _a.length; _i++) { var member = _a[_i]; @@ -18251,14 +18486,17 @@ var ts; } } function checkClassExpression(node) { - grammarErrorOnNode(node, ts.Diagnostics.class_expressions_are_not_currently_supported); - ts.forEach(node.members, checkSourceElement); - return unknownType; + checkClassLikeDeclaration(node); + return getTypeOfSymbol(getSymbolOfNode(node)); } function checkClassDeclaration(node) { if (!node.name && !(node.flags & 256)) { grammarErrorOnFirstToken(node, ts.Diagnostics.A_class_declaration_without_the_default_modifier_must_have_a_name); } + checkClassLikeDeclaration(node); + ts.forEach(node.members, checkSourceElement); + } + function checkClassLikeDeclaration(node) { checkGrammarClassDeclarationHeritageClauses(node); checkDecorators(node); if (node.name) { @@ -18319,7 +18557,6 @@ var ts; } }); } - ts.forEach(node.members, checkSourceElement); if (produceDiagnostics) { checkIndexConstraints(type); checkTypeForDuplicateIndexSignatures(node); @@ -19061,17 +19298,20 @@ var ts; return checkMissingDeclaration(node); } } - function checkFunctionExpressionBodies(node) { + function checkFunctionAndClassExpressionBodies(node) { switch (node.kind) { case 165: case 166: - ts.forEach(node.parameters, checkFunctionExpressionBodies); + ts.forEach(node.parameters, checkFunctionAndClassExpressionBodies); checkFunctionExpressionOrObjectLiteralMethodBody(node); break; + case 177: + ts.forEach(node.members, checkSourceElement); + break; case 136: case 135: - ts.forEach(node.decorators, checkFunctionExpressionBodies); - ts.forEach(node.parameters, checkFunctionExpressionBodies); + ts.forEach(node.decorators, checkFunctionAndClassExpressionBodies); + ts.forEach(node.parameters, checkFunctionAndClassExpressionBodies); if (ts.isObjectLiteralMethod(node)) { checkFunctionExpressionOrObjectLiteralMethodBody(node); } @@ -19080,10 +19320,10 @@ var ts; case 138: case 139: case 203: - ts.forEach(node.parameters, checkFunctionExpressionBodies); + ts.forEach(node.parameters, checkFunctionAndClassExpressionBodies); break; case 195: - checkFunctionExpressionBodies(node.expression); + checkFunctionAndClassExpressionBodies(node.expression); break; case 132: case 131: @@ -19140,7 +19380,7 @@ var ts; case 229: case 217: case 230: - ts.forEachChild(node, checkFunctionExpressionBodies); + ts.forEachChild(node, checkFunctionAndClassExpressionBodies); break; } } @@ -19161,7 +19401,7 @@ var ts; emitParam = false; potentialThisCollisions.length = 0; ts.forEach(node.statements, checkSourceElement); - checkFunctionExpressionBodies(node); + checkFunctionAndClassExpressionBodies(node); if (ts.isExternalModule(node)) { checkExternalModuleExports(node); } @@ -19234,6 +19474,10 @@ var ts; case 207: copySymbols(getSymbolOfNode(location).exports, meaning & 8); break; + case 177: + if (location.name) { + copySymbol(location.symbol, meaning); + } case 204: case 205: if (!(memberFlags & 128)) { @@ -19268,40 +19512,6 @@ var ts; } } } - if (isInsideWithStatementBody(location)) { - return []; - } - while (location) { - if (location.locals && !isGlobalSourceFile(location)) { - copySymbols(location.locals, meaning); - } - switch (location.kind) { - case 230: - if (!ts.isExternalModule(location)) - break; - case 208: - copySymbols(getSymbolOfNode(location).exports, meaning & 8914931); - break; - case 207: - copySymbols(getSymbolOfNode(location).exports, meaning & 8); - break; - case 204: - case 205: - if (!(memberFlags & 128)) { - copySymbols(getSymbolOfNode(location).members, meaning & 793056); - } - break; - case 165: - if (location.name) { - copySymbol(location.symbol, meaning); - } - break; - } - memberFlags = location.flags; - location = location.parent; - } - copySymbols(globals, meaning); - return symbolsToArray(symbols); } function isTypeDeclarationName(name) { return name.kind === 65 && @@ -19395,6 +19605,9 @@ var ts; meaning |= 8388608; return resolveEntityName(entityName, meaning); } + if (entityName.parent.kind === 143) { + return resolveEntityName(entityName, 1); + } return undefined; } function getSymbolInfo(node) { @@ -19494,6 +19707,12 @@ var ts; } return checkExpression(expr); } + function getParentTypeOfClassElement(node) { + var classSymbol = getSymbolOfNode(node.parent); + return node.flags & 128 + ? getTypeOfSymbol(classSymbol) + : getDeclaredTypeOfSymbol(classSymbol); + } function getAugmentedPropertiesOfType(type) { type = getApparentType(type); var propsByName = createSymbolTable(getPropertiesOfType(type)); @@ -19896,10 +20115,7 @@ var ts; globalNumberType = getGlobalType("Number"); globalBooleanType = getGlobalType("Boolean"); globalRegExpType = getGlobalType("RegExp"); - getGlobalClassDecoratorType = ts.memoize(function () { return getGlobalType("ClassDecorator"); }); - getGlobalPropertyDecoratorType = ts.memoize(function () { return getGlobalType("PropertyDecorator"); }); - getGlobalMethodDecoratorType = ts.memoize(function () { return getGlobalType("MethodDecorator"); }); - getGlobalParameterDecoratorType = ts.memoize(function () { return getGlobalType("ParameterDecorator"); }); + getGlobalTypedPropertyDescriptorType = ts.memoize(function () { return getGlobalType("TypedPropertyDescriptor", 1); }); if (languageVersion >= 2) { globalTemplateStringsArrayType = getGlobalType("TemplateStringsArray"); globalESSymbolType = getGlobalType("Symbol"); @@ -20441,7 +20657,7 @@ var ts; return grammarErrorAtPos(getSourceFile(node), node.end - 1, ";".length, ts.Diagnostics._0_expected, "{"); } } - if (node.parent.kind === 204) { + if (ts.isClassLike(node.parent)) { if (checkGrammarForInvalidQuestionMark(node, node.questionToken, ts.Diagnostics.A_class_member_cannot_be_declared_optional)) { return true; } @@ -20672,7 +20888,7 @@ var ts; } } function checkGrammarProperty(node) { - if (node.parent.kind === 204) { + if (ts.isClassLike(node.parent)) { if (checkGrammarForInvalidQuestionMark(node, node.questionToken, ts.Diagnostics.A_class_member_cannot_be_declared_optional) || checkGrammarForNonSymbolComputedProperty(node.name, ts.Diagnostics.A_computed_property_name_in_a_class_property_declaration_must_directly_refer_to_a_built_in_symbol)) { return true; @@ -22222,6 +22438,9 @@ var ts; function generateNameForExportDefault() { return makeUniqueName("default"); } + function generateNameForClassExpression() { + return makeUniqueName("class"); + } function generateNameForNode(node) { switch (node.kind) { case 65: @@ -22234,9 +22453,10 @@ var ts; return generateNameForImportOrExportDeclaration(node); case 203: case 204: - case 177: case 217: return generateNameForExportDefault(); + case 177: + return generateNameForClassExpression(); } } function getGeneratedNameForNode(node) { @@ -31651,6 +31871,10 @@ var ts; if (actualIndentation !== -1) { return actualIndentation; } + actualIndentation = getLineIndentationWhenExpressionIsInMultiLine(current, sourceFile, options); + if (actualIndentation !== -1) { + return actualIndentation + options.IndentSize; + } previous = current; current = current.parent; } @@ -31688,6 +31912,10 @@ var ts; if (actualIndentation !== -1) { return actualIndentation + indentationDelta; } + actualIndentation = getLineIndentationWhenExpressionIsInMultiLine(current, sourceFile, options); + if (actualIndentation !== -1) { + return actualIndentation + indentationDelta; + } } if (shouldIndentChildNode(parent.kind, current.kind) && !parentAndChildShareLine) { indentationDelta += options.IndentSize; @@ -31804,6 +32032,42 @@ var ts; return index !== -1 ? deriveActualIndentationFromList(list, index, sourceFile, options) : -1; } } + function getLineIndentationWhenExpressionIsInMultiLine(node, sourceFile, options) { + if (node.kind === 17) { + return -1; + } + if (node.parent && (node.parent.kind === 160 || + node.parent.kind === 161) && + node.parent.expression !== node) { + var fullCallOrNewExpression = node.parent.expression; + var startingExpression = getStartingExpression(fullCallOrNewExpression); + if (fullCallOrNewExpression === startingExpression) { + return -1; + } + var fullCallOrNewExpressionEnd = sourceFile.getLineAndCharacterOfPosition(fullCallOrNewExpression.end); + var startingExpressionEnd = sourceFile.getLineAndCharacterOfPosition(startingExpression.end); + if (fullCallOrNewExpressionEnd.line === startingExpressionEnd.line) { + return -1; + } + return findColumnForFirstNonWhitespaceCharacterInLine(fullCallOrNewExpressionEnd, sourceFile, options); + } + return -1; + function getStartingExpression(node) { + while (true) { + switch (node.kind) { + case 160: + case 161: + case 158: + case 159: + node = node.expression; + break; + default: + return node; + } + } + return node; + } + } function deriveActualIndentationFromList(list, index, sourceFile, options) { ts.Debug.assert(index >= 0 && index < list.length); var node = list[index]; @@ -36217,6 +36481,9 @@ var ts; } } function classifyToken(token) { + if (ts.nodeIsMissing(token)) { + return; + } var tokenStart = classifyLeadingTriviaAndGetTokenStart(token); var tokenWidth = token.end - tokenStart; ts.Debug.assert(tokenWidth >= 0); diff --git a/bin/typescript.d.ts b/bin/typescript.d.ts index 2fd4bb2c2f3..e7637e0bc19 100644 --- a/bin/typescript.d.ts +++ b/bin/typescript.d.ts @@ -600,7 +600,7 @@ declare module "typescript" { tag: LeftHandSideExpression; template: LiteralExpression | TemplateExpression; } - type CallLikeExpression = CallExpression | NewExpression | TaggedTemplateExpression; + type CallLikeExpression = CallExpression | NewExpression | TaggedTemplateExpression | Decorator; interface TypeAssertion extends UnaryExpression { type: TypeNode; expression: UnaryExpression; diff --git a/bin/typescript.js b/bin/typescript.js index 2e3a784b298..6373e3f9c58 100644 --- a/bin/typescript.js +++ b/bin/typescript.js @@ -1950,6 +1950,12 @@ var ts; An_export_declaration_can_only_be_used_in_a_module: { code: 1233, category: ts.DiagnosticCategory.Error, key: "An export declaration can only be used in a module." }, An_ambient_module_declaration_is_only_allowed_at_the_top_level_in_a_file: { code: 1234, category: ts.DiagnosticCategory.Error, key: "An ambient module declaration is only allowed at the top level in a file." }, A_namespace_declaration_is_only_allowed_in_a_namespace_or_module: { code: 1235, category: ts.DiagnosticCategory.Error, key: "A namespace declaration is only allowed in a namespace or module." }, + The_return_type_of_a_property_decorator_function_must_be_either_void_or_any: { code: 1236, category: ts.DiagnosticCategory.Error, key: "The return type of a property decorator function must be either 'void' or 'any'." }, + The_return_type_of_a_parameter_decorator_function_must_be_either_void_or_any: { code: 1237, category: ts.DiagnosticCategory.Error, key: "The return type of a parameter decorator function must be either 'void' or 'any'." }, + Unable_to_resolve_signature_of_class_decorator_when_called_as_an_expression: { code: 1238, category: ts.DiagnosticCategory.Error, key: "Unable to resolve signature of class decorator when called as an expression." }, + Unable_to_resolve_signature_of_parameter_decorator_when_called_as_an_expression: { code: 1239, category: ts.DiagnosticCategory.Error, key: "Unable to resolve signature of parameter decorator when called as an expression." }, + Unable_to_resolve_signature_of_property_decorator_when_called_as_an_expression: { code: 1240, category: ts.DiagnosticCategory.Error, key: "Unable to resolve signature of property decorator when called as an expression." }, + Unable_to_resolve_signature_of_method_decorator_when_called_as_an_expression: { code: 1241, category: ts.DiagnosticCategory.Error, key: "Unable to resolve signature of method decorator when called as an expression." }, Duplicate_identifier_0: { code: 2300, category: ts.DiagnosticCategory.Error, key: "Duplicate identifier '{0}'." }, Initializer_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor: { code: 2301, category: ts.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: ts.DiagnosticCategory.Error, key: "Static members cannot reference class type parameters." }, @@ -2325,9 +2331,7 @@ var ts; property_declarations_can_only_be_used_in_a_ts_file: { code: 8014, category: ts.DiagnosticCategory.Error, key: "'property declarations' can only be used in a .ts file." }, enum_declarations_can_only_be_used_in_a_ts_file: { code: 8015, category: ts.DiagnosticCategory.Error, key: "'enum declarations' can only be used in a .ts file." }, type_assertion_expressions_can_only_be_used_in_a_ts_file: { code: 8016, category: ts.DiagnosticCategory.Error, key: "'type assertion expressions' can only be used in a .ts file." }, - decorators_can_only_be_used_in_a_ts_file: { code: 8017, category: ts.DiagnosticCategory.Error, key: "'decorators' can only be used in a .ts file." }, - Only_identifiers_Slashqualified_names_with_optional_type_arguments_are_currently_supported_in_a_class_extends_clauses: { code: 9002, category: ts.DiagnosticCategory.Error, key: "Only identifiers/qualified-names with optional type arguments are currently supported in a class 'extends' clauses." }, - class_expressions_are_not_currently_supported: { code: 9003, category: ts.DiagnosticCategory.Error, key: "'class' expressions are not currently supported." } + decorators_can_only_be_used_in_a_ts_file: { code: 8017, category: ts.DiagnosticCategory.Error, key: "'decorators' can only be used in a .ts file." } }; })(ts || (ts = {})); /// @@ -4284,7 +4288,7 @@ var ts; function getStrictModeIdentifierMessage(node) { // Provide specialized messages to help the user understand why we think they're in // strict mode. - if (ts.getAncestor(node, 204 /* ClassDeclaration */) || ts.getAncestor(node, 177 /* ClassExpression */)) { + if (ts.getContainingClass(node)) { return ts.Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode_Class_definitions_are_automatically_in_strict_mode; } if (file.externalModuleIndicator) { @@ -4333,7 +4337,7 @@ var ts; function getStrictModeEvalOrArgumentsMessage(node) { // Provide specialized messages to help the user understand why we think they're in // strict mode. - if (ts.getAncestor(node, 204 /* ClassDeclaration */) || ts.getAncestor(node, 177 /* ClassExpression */)) { + if (ts.getContainingClass(node)) { return ts.Diagnostics.Invalid_use_of_0_Class_definitions_are_automatically_in_strict_mode; } if (file.externalModuleIndicator) { @@ -4641,7 +4645,7 @@ var ts; // containing class. if (node.flags & 112 /* AccessibilityModifier */ && node.parent.kind === 137 /* Constructor */ && - (node.parent.parent.kind === 204 /* ClassDeclaration */ || node.parent.parent.kind === 177 /* ClassExpression */)) { + ts.isClassLike(node.parent.parent)) { var classDeclaration = node.parent.parent; declareSymbol(classDeclaration.symbol.members, classDeclaration.symbol, node, 4 /* Property */, 107455 /* PropertyExcludes */); } @@ -5136,6 +5140,7 @@ var ts; case 208 /* ModuleDeclaration */: case 206 /* TypeAliasDeclaration */: case 204 /* ClassDeclaration */: + case 177 /* ClassExpression */: // These are not allowed inside a generator now, but eventually they may be allowed // as local types. Regardless, any yield statements contained within them should be // skipped in this traversal. @@ -5177,20 +5182,11 @@ var ts; } ts.isVariableLike = isVariableLike; function isAccessor(node) { - if (node) { - switch (node.kind) { - case 138 /* GetAccessor */: - case 139 /* SetAccessor */: - return true; - } - } - return false; + return node && (node.kind === 138 /* GetAccessor */ || node.kind === 139 /* SetAccessor */); } ts.isAccessor = isAccessor; function isClassLike(node) { - if (node) { - return node.kind === 204 /* ClassDeclaration */ || node.kind === 177 /* ClassExpression */; - } + return node && (node.kind === 204 /* ClassDeclaration */ || node.kind === 177 /* ClassExpression */); } ts.isClassLike = isClassLike; function isFunctionLike(node) { @@ -5232,6 +5228,15 @@ var ts; } } ts.getContainingFunction = getContainingFunction; + function getContainingClass(node) { + while (true) { + node = node.parent; + if (!node || isClassLike(node)) { + return node; + } + } + } + ts.getContainingClass = getContainingClass; function getThisContainer(node, includeArrowFunctions) { while (true) { node = node.parent; @@ -5244,7 +5249,7 @@ var ts; // then the computed property is not a 'this' container. // A computed property name in a class needs to be a this container // so that we can error on it. - if (node.parent.parent.kind === 204 /* ClassDeclaration */) { + if (isClassLike(node.parent.parent)) { return node; } // If this is a computed property, then the parent should not @@ -5300,7 +5305,7 @@ var ts; // then the computed property is not a 'super' container. // A computed property name in a class needs to be a super container // so that we can error on it. - if (node.parent.parent.kind === 204 /* ClassDeclaration */) { + if (isClassLike(node.parent.parent)) { return node; } // If this is a computed property, then the parent should not @@ -5345,7 +5350,7 @@ var ts; if (node.kind === 162 /* TaggedTemplateExpression */) { return node.tag; } - // Will either be a CallExpression or NewExpression. + // Will either be a CallExpression, NewExpression, or Decorator. return node.expression; } ts.getInvokedExpression = getInvokedExpression; @@ -5658,6 +5663,7 @@ var ts; case 166 /* ArrowFunction */: case 155 /* BindingElement */: case 204 /* ClassDeclaration */: + case 177 /* ClassExpression */: case 137 /* Constructor */: case 207 /* EnumDeclaration */: case 229 /* EnumMember */: @@ -6429,7 +6435,7 @@ var ts; function isExpressionWithTypeArgumentsInClassExtendsClause(node) { return node.kind === 179 /* ExpressionWithTypeArguments */ && node.parent.token === 79 /* ExtendsKeyword */ && - node.parent.parent.kind === 204 /* ClassDeclaration */; + isClassLike(node.parent.parent); } ts.isExpressionWithTypeArgumentsInClassExtendsClause = isExpressionWithTypeArgumentsInClassExtendsClause; // Returns false if this heritage clause element's expression contains something unsupported @@ -12210,10 +12216,7 @@ var ts; var globalIteratorType; var globalIterableIteratorType; var anyArrayType; - var getGlobalClassDecoratorType; - var getGlobalParameterDecoratorType; - var getGlobalPropertyDecoratorType; - var getGlobalMethodDecoratorType; + var getGlobalTypedPropertyDescriptorType; var tupleTypes = {}; var unionTypes = {}; var stringLiteralTypes = {}; @@ -12499,7 +12502,7 @@ var ts; // local variables of the constructor. This effectively means that entities from outer scopes // by the same name as a constructor parameter or local variable are inaccessible // in initializer expressions for instance member variables. - if (location.parent.kind === 204 /* ClassDeclaration */ && !(location.flags & 128 /* Static */)) { + if (ts.isClassLike(location.parent) && !(location.flags & 128 /* Static */)) { var ctor = findConstructorDeclaration(location.parent); if (ctor && ctor.locals) { if (getSymbol(ctor.locals, name, meaning & 107455 /* Value */)) { @@ -12510,6 +12513,7 @@ var ts; } break; case 204 /* ClassDeclaration */: + case 177 /* ClassExpression */: case 205 /* InterfaceDeclaration */: if (result = getSymbol(getSymbolOfNode(location).members, name, meaning & 793056 /* Type */)) { if (lastLocation && lastLocation.flags & 128 /* Static */) { @@ -12521,6 +12525,13 @@ var ts; } break loop; } + if (location.kind === 177 /* ClassExpression */ && meaning & 32 /* Class */) { + var className = location.name; + if (className && name === className.text) { + result = location.symbol; + break loop; + } + } break; // It is not legal to reference a class's own type parameters from a computed property name that // belongs to the class. For example: @@ -12532,7 +12543,7 @@ var ts; // case 129 /* ComputedPropertyName */: grandparent = location.parent.parent; - if (grandparent.kind === 204 /* ClassDeclaration */ || grandparent.kind === 205 /* InterfaceDeclaration */) { + if (ts.isClassLike(grandparent) || grandparent.kind === 205 /* InterfaceDeclaration */) { // A reference to this grandparent's type parameters would be an error if (result = getSymbol(getSymbolOfNode(grandparent).members, name, meaning & 793056 /* Type */)) { error(errorLocation, ts.Diagnostics.A_computed_property_name_cannot_reference_a_type_parameter_from_its_containing_type); @@ -12565,15 +12576,6 @@ var ts; } } break; - case 177 /* ClassExpression */: - if (meaning & 32 /* Class */) { - var className = location.name; - if (className && name === className.text) { - result = location.symbol; - break loop; - } - } - break; case 132 /* Decorator */: // Decorators are resolved at the class declaration. Resolving at the parameter // or member would result in looking up locals in the method. @@ -13407,19 +13409,28 @@ var ts; // This is for caching the result of getSymbolDisplayBuilder. Do not access directly. var _displayBuilder; function getSymbolDisplayBuilder() { + function getNameOfSymbol(symbol) { + if (symbol.declarations && symbol.declarations.length) { + var declaration = symbol.declarations[0]; + if (declaration.name) { + return ts.declarationNameToString(declaration.name); + } + switch (declaration.kind) { + case 177 /* ClassExpression */: + return "(Anonymous class)"; + case 165 /* FunctionExpression */: + case 166 /* ArrowFunction */: + return "(Anonymous function)"; + } + } + return symbol.name; + } /** * Writes only the name of the symbol out to the writer. Uses the original source text * for the name of the symbol if it is available to match how the user inputted the name. */ function appendSymbolNameOnly(symbol, writer) { - if (symbol.declarations && symbol.declarations.length > 0) { - var declaration = symbol.declarations[0]; - if (declaration.name) { - writer.writeSymbol(ts.declarationNameToString(declaration.name), symbol); - return; - } - } - writer.writeSymbol(symbol.name, symbol); + writer.writeSymbol(getNameOfSymbol(symbol), symbol); } /** * Enclosing declaration is optional when we don't want to get qualified name in the enclosing declaration scope @@ -14488,9 +14499,9 @@ var ts; if (!node) { return typeParameters; } - if (node.kind === 204 /* ClassDeclaration */ || node.kind === 203 /* FunctionDeclaration */ || - node.kind === 165 /* FunctionExpression */ || node.kind === 136 /* MethodDeclaration */ || - node.kind === 166 /* ArrowFunction */) { + if (node.kind === 204 /* ClassDeclaration */ || node.kind === 177 /* ClassExpression */ || + node.kind === 203 /* FunctionDeclaration */ || node.kind === 165 /* FunctionExpression */ || + node.kind === 136 /* MethodDeclaration */ || node.kind === 166 /* ArrowFunction */) { var declarations = node.typeParameters; if (declarations) { return appendTypeParameters(appendOuterTypeParameters(typeParameters, node), declarations); @@ -14500,8 +14511,8 @@ var ts; } // The outer type parameters are those defined by enclosing generic classes, methods, or functions. function getOuterTypeParametersOfClassOrInterface(symbol) { - var kind = symbol.flags & 32 /* Class */ ? 204 /* ClassDeclaration */ : 205 /* InterfaceDeclaration */; - return appendOuterTypeParameters(undefined, ts.getDeclarationOfKind(symbol, kind)); + var declaration = symbol.flags & 32 /* Class */ ? symbol.valueDeclaration : ts.getDeclarationOfKind(symbol, 205 /* InterfaceDeclaration */); + return appendOuterTypeParameters(undefined, declaration); } // The local type parameters are the combined set of type parameters from all declarations of the class, // interface, or type alias. @@ -14509,7 +14520,8 @@ var ts; var result; for (var _i = 0, _a = symbol.declarations; _i < _a.length; _i++) { var node = _a[_i]; - if (node.kind === 205 /* InterfaceDeclaration */ || node.kind === 204 /* ClassDeclaration */ || node.kind === 206 /* TypeAliasDeclaration */) { + if (node.kind === 205 /* InterfaceDeclaration */ || node.kind === 204 /* ClassDeclaration */ || + node.kind === 177 /* ClassExpression */ || node.kind === 206 /* TypeAliasDeclaration */) { var declaration = node; if (declaration.typeParameters) { result = appendTypeParameters(result, declaration.typeParameters); @@ -15604,6 +15616,15 @@ var ts; function getGlobalESSymbolConstructorSymbol() { return globalESSymbolConstructorSymbol || (globalESSymbolConstructorSymbol = getGlobalValueSymbol("Symbol")); } + /** + * Creates a TypeReference for a generic `TypedPropertyDescriptor`. + */ + function createTypedPropertyDescriptorType(propertyType) { + var globalTypedPropertyDescriptorType = getGlobalTypedPropertyDescriptorType(); + return globalTypedPropertyDescriptorType !== emptyObjectType + ? createTypeReference(globalTypedPropertyDescriptorType, [propertyType]) + : emptyObjectType; + } /** * Instantiates a global type that is generic with some element type, and returns that instantiation. */ @@ -16042,8 +16063,8 @@ var ts; function checkTypeSubtypeOf(source, target, errorNode, headMessage, containingMessageChain) { return checkTypeRelatedTo(source, target, subtypeRelation, errorNode, headMessage, containingMessageChain); } - function checkTypeAssignableTo(source, target, errorNode, headMessage) { - return checkTypeRelatedTo(source, target, assignableRelation, errorNode, headMessage); + function checkTypeAssignableTo(source, target, errorNode, headMessage, containingMessageChain) { + return checkTypeRelatedTo(source, target, assignableRelation, errorNode, headMessage, containingMessageChain); } function isSignatureAssignableTo(source, target) { var sourceType = getOrCreateTypeFromSignature(source); @@ -17582,9 +17603,9 @@ var ts; } } function captureLexicalThis(node, container) { - var classNode = container.parent && container.parent.kind === 204 /* ClassDeclaration */ ? container.parent : undefined; getNodeLinks(node).flags |= 2 /* LexicalThis */; if (container.kind === 134 /* PropertyDeclaration */ || container.kind === 137 /* Constructor */) { + var classNode = container.parent; getNodeLinks(classNode).flags |= 4 /* CaptureThis */; } else { @@ -17629,9 +17650,8 @@ var ts; if (needToCaptureLexicalThis) { captureLexicalThis(node, container); } - var classNode = container.parent && container.parent.kind === 204 /* ClassDeclaration */ ? container.parent : undefined; - if (classNode) { - var symbol = getSymbolOfNode(classNode); + if (ts.isClassLike(container.parent)) { + var symbol = getSymbolOfNode(container.parent); return container.flags & 128 /* Static */ ? getTypeOfSymbol(symbol) : getDeclaredTypeOfSymbol(symbol); } return anyType; @@ -17646,7 +17666,7 @@ var ts; } function checkSuperExpression(node) { var isCallExpression = node.parent.kind === 160 /* CallExpression */ && node.parent.expression === node; - var classDeclaration = ts.getAncestor(node, 204 /* ClassDeclaration */); + var classDeclaration = ts.getContainingClass(node); var classType = classDeclaration && getDeclaredTypeOfSymbol(getSymbolOfNode(classDeclaration)); var baseClassType = classType && getBaseTypes(classType)[0]; if (!baseClassType) { @@ -17676,7 +17696,7 @@ var ts; needToCaptureLexicalThis = languageVersion < 2 /* ES6 */; } // topmost container must be something that is directly nested in the class declaration - if (container && container.parent && container.parent.kind === 204 /* ClassDeclaration */) { + if (container && ts.isClassLike(container.parent)) { if (container.flags & 128 /* Static */) { canUseSuperExpression = container.kind === 136 /* MethodDeclaration */ || @@ -18276,7 +18296,7 @@ var ts; } // Property is known to be private or protected at this point // Get the declaring and enclosing class instance types - var enclosingClassDeclaration = ts.getAncestor(node, 204 /* ClassDeclaration */); + var enclosingClassDeclaration = ts.getContainingClass(node); var enclosingClass = enclosingClassDeclaration ? getDeclaredTypeOfSymbol(getSymbolOfNode(enclosingClassDeclaration)) : undefined; var declaringClass = getDeclaredTypeOfSymbol(prop.parent); // Private property is accessible if declaring and enclosing class are the same @@ -18502,7 +18522,7 @@ var ts; if (node.kind === 162 /* TaggedTemplateExpression */) { checkExpression(node.template); } - else { + else if (node.kind !== 132 /* Decorator */) { ts.forEach(node.arguments, function (argument) { checkExpression(argument); }); @@ -18567,7 +18587,8 @@ var ts; } function getSpreadArgumentIndex(args) { for (var i = 0; i < args.length; i++) { - if (args[i].kind === 176 /* SpreadElementExpression */) { + var arg = args[i]; + if (arg && arg.kind === 176 /* SpreadElementExpression */) { return i; } } @@ -18577,6 +18598,8 @@ var ts; var adjustedArgCount; // Apparent number of arguments we will have in this call var typeArguments; // Type arguments (undefined if none) var callIsIncomplete; // In incomplete call we want to be lenient when we have too few arguments + var isDecorator; + var spreadArgIndex = -1; if (node.kind === 162 /* TaggedTemplateExpression */) { var tagExpression = node; // Even if the call is incomplete, we'll have a missing expression as our last argument, @@ -18600,6 +18623,11 @@ var ts; callIsIncomplete = !!templateLiteral.isUnterminated; } } + else if (node.kind === 132 /* Decorator */) { + isDecorator = true; + typeArguments = undefined; + adjustedArgCount = getEffectiveArgumentCount(node, undefined, signature); + } else { var callExpression = node; if (!callExpression.arguments) { @@ -18612,6 +18640,7 @@ var ts; // If we are missing the close paren, the call is incomplete. callIsIncomplete = callExpression.arguments.end === callExpression.end; typeArguments = callExpression.typeArguments; + spreadArgIndex = getSpreadArgumentIndex(args); } // If the user supplied type arguments, but the number of type arguments does not match // the declared number of type parameters, the call has an incorrect arity. @@ -18622,7 +18651,6 @@ var ts; } // If spread arguments are present, check that they correspond to a rest parameter. If so, no // further checking is necessary. - var spreadArgIndex = getSpreadArgumentIndex(args); if (spreadArgIndex >= 0) { return signature.hasRestParameter && spreadArgIndex >= signature.parameters.length - 1; } @@ -18654,7 +18682,7 @@ var ts; }); return getSignatureInstantiation(signature, getInferredTypes(context)); } - function inferTypeArguments(signature, args, excludeArgument, context) { + function inferTypeArguments(node, signature, args, excludeArgument, context) { var typeParameters = signature.typeParameters; var inferenceMapper = createInferenceMapper(context); // Clear out all the inference results from the last time inferTypeArguments was called on this context @@ -18679,15 +18707,16 @@ var ts; } // We perform two passes over the arguments. In the first pass we infer from all arguments, but use // wildcards for all context sensitive function expressions. - for (var i = 0; i < args.length; i++) { - var arg = args[i]; - if (arg.kind !== 178 /* OmittedExpression */) { + var argCount = getEffectiveArgumentCount(node, args, signature); + for (var i = 0; i < argCount; i++) { + var arg = getEffectiveArgument(node, args, i); + // If the effective argument is 'undefined', then it is an argument that is present but is synthetic. + if (arg === undefined || arg.kind !== 178 /* OmittedExpression */) { var paramType = getTypeAtPosition(signature, i); - var argType = void 0; - if (i === 0 && args[i].parent.kind === 162 /* TaggedTemplateExpression */) { - argType = globalTemplateStringsArrayType; - } - else { + var argType = getEffectiveArgumentType(node, i, arg); + // If the effective argument type is 'undefined', there is no synthetic type + // for the argument. In that case, we should check the argument. + if (argType === undefined) { // For context sensitive arguments we pass the identityMapper, which is a signal to treat all // context sensitive function expressions as wildcards var mapper = excludeArgument && excludeArgument[i] !== undefined ? identityMapper : inferenceMapper; @@ -18699,8 +18728,10 @@ var ts; // In the second pass we visit only context sensitive arguments, and only those that aren't excluded, this // time treating function expressions normally (which may cause previously inferred type arguments to be fixed // as we construct types for contextually typed parameters) + // Decorators will not have `excludeArgument`, as their arguments cannot be contextually typed. + // Tagged template expressions will always have `undefined` for `excludeArgument[0]`. if (excludeArgument) { - for (var i = 0; i < args.length; i++) { + for (var i = 0; i < argCount; i++) { // No need to check for omitted args and template expressions, their exlusion value is always undefined if (excludeArgument[i] === false) { var arg = args[i]; @@ -18711,7 +18742,7 @@ var ts; } getInferredTypes(context); } - function checkTypeArguments(signature, typeArguments, typeArgumentResultTypes, reportErrors) { + function checkTypeArguments(signature, typeArguments, typeArgumentResultTypes, reportErrors, headMessage) { var typeParameters = signature.typeParameters; var typeArgumentsAreAssignable = true; for (var i = 0; i < typeParameters.length; i++) { @@ -18722,27 +18753,38 @@ var ts; if (typeArgumentsAreAssignable /* so far */) { var constraint = getConstraintOfTypeParameter(typeParameters[i]); if (constraint) { - typeArgumentsAreAssignable = checkTypeAssignableTo(typeArgument, constraint, reportErrors ? typeArgNode : undefined, ts.Diagnostics.Type_0_does_not_satisfy_the_constraint_1); + var errorInfo = void 0; + var typeArgumentHeadMessage = ts.Diagnostics.Type_0_does_not_satisfy_the_constraint_1; + if (reportErrors && headMessage) { + errorInfo = ts.chainDiagnosticMessages(errorInfo, typeArgumentHeadMessage); + typeArgumentHeadMessage = headMessage; + } + typeArgumentsAreAssignable = checkTypeAssignableTo(typeArgument, constraint, reportErrors ? typeArgNode : undefined, typeArgumentHeadMessage, errorInfo); } } } return typeArgumentsAreAssignable; } function checkApplicableSignature(node, args, signature, relation, excludeArgument, reportErrors) { - for (var i = 0; i < args.length; i++) { - var arg = args[i]; - if (arg.kind !== 178 /* OmittedExpression */) { + var argCount = getEffectiveArgumentCount(node, args, signature); + for (var i = 0; i < argCount; i++) { + var arg = getEffectiveArgument(node, args, i); + // If the effective argument is 'undefined', then it is an argument that is present but is synthetic. + if (arg === undefined || arg.kind !== 178 /* OmittedExpression */) { // Check spread elements against rest type (from arity check we know spread argument corresponds to a rest parameter) var paramType = getTypeAtPosition(signature, i); - // A tagged template expression provides a special first argument, and string literals get string literal types - // unless we're reporting errors - var argType = i === 0 && node.kind === 162 /* TaggedTemplateExpression */ - ? globalTemplateStringsArrayType - : arg.kind === 8 /* StringLiteral */ && !reportErrors + var argType = getEffectiveArgumentType(node, i, arg); + // If the effective argument type is 'undefined', there is no synthetic type + // for the argument. In that case, we should check the argument. + if (argType === undefined) { + argType = arg.kind === 8 /* StringLiteral */ && !reportErrors ? getStringLiteralType(arg) : checkExpressionWithContextualType(arg, paramType, excludeArgument && excludeArgument[i] ? identityMapper : undefined); + } // Use argument expression as error location when reporting errors - if (!checkTypeRelatedTo(argType, paramType, relation, reportErrors ? arg : undefined, ts.Diagnostics.Argument_of_type_0_is_not_assignable_to_parameter_of_type_1)) { + var errorNode = reportErrors ? getEffectiveArgumentErrorNode(node, i, arg) : undefined; + var headMessage = ts.Diagnostics.Argument_of_type_0_is_not_assignable_to_parameter_of_type_1; + if (!checkTypeRelatedTo(argType, paramType, relation, errorNode, headMessage)) { return false; } } @@ -18754,28 +18796,276 @@ var ts; * * If 'node' is a CallExpression or a NewExpression, then its argument list is returned. * If 'node' is a TaggedTemplateExpression, a new argument list is constructed from the substitution - * expressions, where the first element of the list is the template for error reporting purposes. + * expressions, where the first element of the list is `undefined`. + * If 'node' is a Decorator, the argument list will be `undefined`, and its arguments and types + * will be supplied from calls to `getEffectiveArgumentCount` and `getEffectiveArgumentType`. */ function getEffectiveCallArguments(node) { var args; if (node.kind === 162 /* TaggedTemplateExpression */) { var template = node.template; - args = [template]; + args = [undefined]; if (template.kind === 174 /* TemplateExpression */) { ts.forEach(template.templateSpans, function (span) { args.push(span.expression); }); } } + else if (node.kind === 132 /* Decorator */) { + // For a decorator, we return undefined as we will determine + // the number and types of arguments for a decorator using + // `getEffectiveArgumentCount` and `getEffectiveArgumentType` below. + return undefined; + } else { args = node.arguments || emptyArray; } return args; } - function resolveCall(node, signatures, candidatesOutArray) { + /** + * Returns the effective argument count for a node that works like a function invocation. + * If 'node' is a Decorator, the number of arguments is derived from the decoration + * target and the signature: + * If 'node.target' is a class declaration or class expression, the effective argument + * count is 1. + * If 'node.target' is a parameter declaration, the effective argument count is 3. + * If 'node.target' is a property declaration, the effective argument count is 2. + * If 'node.target' is a method or accessor declaration, the effective argument count + * is 3, although it can be 2 if the signature only accepts two arguments, allowing + * us to match a property decorator. + * Otherwise, the argument count is the length of the 'args' array. + */ + function getEffectiveArgumentCount(node, args, signature) { + if (node.kind === 132 /* Decorator */) { + switch (node.parent.kind) { + case 204 /* ClassDeclaration */: + case 177 /* ClassExpression */: + // A class decorator will have one argument (see `ClassDecorator` in core.d.ts) + return 1; + case 134 /* PropertyDeclaration */: + // A property declaration decorator will have two arguments (see + // `PropertyDecorator` in core.d.ts) + return 2; + case 136 /* MethodDeclaration */: + case 138 /* GetAccessor */: + case 139 /* SetAccessor */: + // A method or accessor declaration decorator will have two or three arguments (see + // `PropertyDecorator` and `MethodDecorator` in core.d.ts) + // If the method decorator signature only accepts a target and a key, we will only + // type check those arguments. + return signature.parameters.length >= 3 ? 3 : 2; + case 131 /* Parameter */: + // A parameter declaration decorator will have three arguments (see + // `ParameterDecorator` in core.d.ts) + return 3; + } + } + else { + return args.length; + } + } + /** + * Returns the effective type of the first argument to a decorator. + * If 'node' is a class declaration or class expression, the effective argument type + * is the type of the static side of the class. + * If 'node' is a parameter declaration, the effective argument type is either the type + * of the static or instance side of the class for the parameter's parent method, + * depending on whether the method is declared static. + * For a constructor, the type is always the type of the static side of the class. + * If 'node' is a property, method, or accessor declaration, the effective argument + * type is the type of the static or instance side of the parent class for class + * element, depending on whether the element is declared static. + */ + function getEffectiveDecoratorFirstArgumentType(node) { + // The first argument to a decorator is its `target`. + switch (node.kind) { + case 204 /* ClassDeclaration */: + case 177 /* ClassExpression */: + // For a class decorator, the `target` is the type of the class (e.g. the + // "static" or "constructor" side of the class) + var classSymbol = getSymbolOfNode(node); + return getTypeOfSymbol(classSymbol); + case 131 /* Parameter */: + // For a parameter decorator, the `target` is the parent type of the + // parameter's containing method. + node = node.parent; + if (node.kind === 137 /* Constructor */) { + var classSymbol_1 = getSymbolOfNode(node); + return getTypeOfSymbol(classSymbol_1); + } + // fall-through + case 134 /* PropertyDeclaration */: + case 136 /* MethodDeclaration */: + case 138 /* GetAccessor */: + case 139 /* SetAccessor */: + // For a property or method decorator, the `target` is the + // "static"-side type of the parent of the member if the member is + // declared "static"; otherwise, it is the "instance"-side type of the + // parent of the member. + return getParentTypeOfClassElement(node); + default: + ts.Debug.fail("Unsupported decorator target."); + return unknownType; + } + } + /** + * Returns the effective type for the second argument to a decorator. + * If 'node' is a parameter, its effective argument type is one of the following: + * If 'node.parent' is a constructor, the effective argument type is 'any', as we + * will emit `undefined`. + * If 'node.parent' is a member with an identifier, numeric, or string literal name, + * the effective argument type will be a string literal type for the member name. + * If 'node.parent' is a computed property name, the effective argument type will + * either be a symbol type or the string type. + * If 'node' is a member with an identifier, numeric, or string literal name, the + * effective argument type will be a string literal type for the member name. + * If 'node' is a computed property name, the effective argument type will either + * be a symbol type or the string type. + * A class decorator does not have a second argument type. + */ + function getEffectiveDecoratorSecondArgumentType(node) { + // The second argument to a decorator is its `propertyKey` + switch (node.kind) { + case 204 /* ClassDeclaration */: + ts.Debug.fail("Class decorators should not have a second synthetic argument."); + return unknownType; + case 131 /* Parameter */: + node = node.parent; + if (node.kind === 137 /* Constructor */) { + // For a constructor parameter decorator, the `propertyKey` will be `undefined`. + return anyType; + } + // For a non-constructor parameter decorator, the `propertyKey` will be either + // a string or a symbol, based on the name of the parameter's containing method. + // fall-through + case 134 /* PropertyDeclaration */: + case 136 /* MethodDeclaration */: + case 138 /* GetAccessor */: + case 139 /* SetAccessor */: + // The `propertyKey` for a property or method decorator will be a + // string literal type if the member name is an identifier, number, or string; + // otherwise, if the member name is a computed property name it will + // be either string or symbol. + var element = node; + switch (element.name.kind) { + case 65 /* Identifier */: + case 7 /* NumericLiteral */: + case 8 /* StringLiteral */: + return getStringLiteralType(element.name); + case 129 /* ComputedPropertyName */: + var nameType = checkComputedPropertyName(element.name); + if (allConstituentTypesHaveKind(nameType, 2097152 /* ESSymbol */)) { + return nameType; + } + else { + return stringType; + } + default: + ts.Debug.fail("Unsupported property name."); + return unknownType; + } + default: + ts.Debug.fail("Unsupported decorator target."); + return unknownType; + } + } + /** + * Returns the effective argument type for the third argument to a decorator. + * If 'node' is a parameter, the effective argument type is the number type. + * If 'node' is a method or accessor, the effective argument type is a + * `TypedPropertyDescriptor` instantiated with the type of the member. + * Class and property decorators do not have a third effective argument. + */ + function getEffectiveDecoratorThirdArgumentType(node) { + // The third argument to a decorator is either its `descriptor` for a method decorator + // or its `parameterIndex` for a paramter decorator + switch (node.kind) { + case 204 /* ClassDeclaration */: + ts.Debug.fail("Class decorators should not have a third synthetic argument."); + return unknownType; + case 131 /* Parameter */: + // The `parameterIndex` for a parameter decorator is always a number + return numberType; + case 134 /* PropertyDeclaration */: + ts.Debug.fail("Property decorators should not have a third synthetic argument."); + return unknownType; + case 136 /* MethodDeclaration */: + case 138 /* GetAccessor */: + case 139 /* SetAccessor */: + // The `descriptor` for a method decorator will be a `TypedPropertyDescriptor` + // for the type of the member. + var propertyType = getTypeOfNode(node); + return createTypedPropertyDescriptorType(propertyType); + default: + ts.Debug.fail("Unsupported decorator target."); + return unknownType; + } + } + /** + * Returns the effective argument type for the provided argument to a decorator. + */ + function getEffectiveDecoratorArgumentType(node, argIndex) { + if (argIndex === 0) { + return getEffectiveDecoratorFirstArgumentType(node.parent); + } + else if (argIndex === 1) { + return getEffectiveDecoratorSecondArgumentType(node.parent); + } + else if (argIndex === 2) { + return getEffectiveDecoratorThirdArgumentType(node.parent); + } + ts.Debug.fail("Decorators should not have a fourth synthetic argument."); + return unknownType; + } + /** + * Gets the effective argument type for an argument in a call expression. + */ + function getEffectiveArgumentType(node, argIndex, arg) { + // Decorators provide special arguments, a tagged template expression provides + // a special first argument, and string literals get string literal types + // unless we're reporting errors + if (node.kind === 132 /* Decorator */) { + return getEffectiveDecoratorArgumentType(node, argIndex); + } + else if (argIndex === 0 && node.kind === 162 /* TaggedTemplateExpression */) { + return globalTemplateStringsArrayType; + } + // This is not a synthetic argument, so we return 'undefined' + // to signal that the caller needs to check the argument. + return undefined; + } + /** + * Gets the effective argument expression for an argument in a call expression. + */ + function getEffectiveArgument(node, args, argIndex) { + // For a decorator or the first argument of a tagged template expression we return undefined. + if (node.kind === 132 /* Decorator */ || + (argIndex === 0 && node.kind === 162 /* TaggedTemplateExpression */)) { + return undefined; + } + return args[argIndex]; + } + /** + * Gets the error node to use when reporting errors for an effective argument. + */ + function getEffectiveArgumentErrorNode(node, argIndex, arg) { + if (node.kind === 132 /* Decorator */) { + // For a decorator, we use the expression of the decorator for error reporting. + return node.expression; + } + else if (argIndex === 0 && node.kind === 162 /* TaggedTemplateExpression */) { + // For a the first argument of a tagged template expression, we use the template of the tag for error reporting. + return node.template; + } + else { + return arg; + } + } + function resolveCall(node, signatures, candidatesOutArray, headMessage) { var isTaggedTemplate = node.kind === 162 /* TaggedTemplateExpression */; + var isDecorator = node.kind === 132 /* Decorator */; var typeArguments; - if (!isTaggedTemplate) { + if (!isTaggedTemplate && !isDecorator) { typeArguments = node.typeArguments; // We already perform checking on the type arguments on the class declaration itself. if (node.expression.kind !== 91 /* SuperKeyword */) { @@ -18786,7 +19076,7 @@ var ts; // reorderCandidates fills up the candidates array directly reorderCandidates(signatures, candidates); if (!candidates.length) { - error(node, ts.Diagnostics.Supplied_parameters_do_not_match_any_signature_of_call_target); + reportError(ts.Diagnostics.Supplied_parameters_do_not_match_any_signature_of_call_target); return resolveErrorCall(node); } var args = getEffectiveCallArguments(node); @@ -18801,13 +19091,20 @@ var ts; // // For a tagged template, then the first argument be 'undefined' if necessary // because it represents a TemplateStringsArray. + // + // For a decorator, no arguments are susceptible to contextual typing due to the fact + // decorators are applied to a declaration by the emitter, and not to an expression. var excludeArgument; - for (var i = isTaggedTemplate ? 1 : 0; i < args.length; i++) { - if (isContextSensitive(args[i])) { - if (!excludeArgument) { - excludeArgument = new Array(args.length); + if (!isDecorator) { + // We do not need to call `getEffectiveArgumentCount` here as it only + // applies when calculating the number of arguments for a decorator. + for (var i = isTaggedTemplate ? 1 : 0; i < args.length; i++) { + if (isContextSensitive(args[i])) { + if (!excludeArgument) { + excludeArgument = new Array(args.length); + } + excludeArgument[i] = true; } - excludeArgument[i] = true; } } // The following variables are captured and modified by calls to chooseOverload. @@ -18871,19 +19168,22 @@ var ts; checkApplicableSignature(node, args, candidateForArgumentError, assignableRelation, undefined, true); } else if (candidateForTypeArgumentError) { - if (!isTaggedTemplate && typeArguments) { - checkTypeArguments(candidateForTypeArgumentError, typeArguments, [], true); + if (!isTaggedTemplate && !isDecorator && typeArguments) { + checkTypeArguments(candidateForTypeArgumentError, node.typeArguments, [], true, headMessage); } else { ts.Debug.assert(resultOfFailedInference.failedTypeParameterIndex >= 0); var failedTypeParameter = candidateForTypeArgumentError.typeParameters[resultOfFailedInference.failedTypeParameterIndex]; var inferenceCandidates = getInferenceCandidates(resultOfFailedInference, resultOfFailedInference.failedTypeParameterIndex); var diagnosticChainHead = ts.chainDiagnosticMessages(undefined, ts.Diagnostics.The_type_argument_for_type_parameter_0_cannot_be_inferred_from_the_usage_Consider_specifying_the_type_arguments_explicitly, typeToString(failedTypeParameter)); + if (headMessage) { + diagnosticChainHead = ts.chainDiagnosticMessages(diagnosticChainHead, headMessage); + } reportNoCommonSupertypeError(inferenceCandidates, node.expression || node.tag, diagnosticChainHead); } } else { - error(node, ts.Diagnostics.Supplied_parameters_do_not_match_any_signature_of_call_target); + reportError(ts.Diagnostics.Supplied_parameters_do_not_match_any_signature_of_call_target); } // No signature was applicable. We have already reported the errors for the invalid signature. // If this is a type resolution session, e.g. Language Service, try to get better information that anySignature. @@ -18899,6 +19199,14 @@ var ts; } } return resolveErrorCall(node); + function reportError(message, arg0, arg1, arg2) { + var errorInfo; + errorInfo = ts.chainDiagnosticMessages(errorInfo, message, arg0, arg1, arg2); + if (headMessage) { + errorInfo = ts.chainDiagnosticMessages(errorInfo, headMessage); + } + diagnostics.add(ts.createDiagnosticForNodeFromMessageChain(node, errorInfo)); + } function chooseOverload(candidates, relation) { for (var _i = 0; _i < candidates.length; _i++) { var originalCandidate = candidates[_i]; @@ -18919,7 +19227,7 @@ var ts; typeArgumentsAreValid = checkTypeArguments(candidate, typeArguments, typeArgumentTypes, false); } else { - inferTypeArguments(candidate, args, excludeArgument, inferenceContext); + inferTypeArguments(node, candidate, args, excludeArgument, inferenceContext); typeArgumentsAreValid = inferenceContext.failedTypeParameterIndex === undefined; typeArgumentTypes = inferenceContext.inferredTypes; } @@ -18968,7 +19276,7 @@ var ts; if (superType !== unknownType) { // In super call, the candidate signatures are the matching arity signatures of the base constructor function instantiated // with the type arguments specified in the extends clause. - var baseTypeNode = ts.getClassExtendsHeritageClauseElement(ts.getAncestor(node, 204 /* ClassDeclaration */)); + var baseTypeNode = ts.getClassExtendsHeritageClauseElement(ts.getContainingClass(node)); var baseConstructors = getInstantiatedConstructorsForTypeArguments(superType, baseTypeNode.typeArguments); return resolveCall(node, baseConstructors, candidatesOutArray); } @@ -19082,6 +19390,47 @@ var ts; } return resolveCall(node, callSignatures, candidatesOutArray); } + /** + * Gets the localized diagnostic head message to use for errors when resolving a decorator as a call expression. + */ + function getDiagnosticHeadMessageForDecoratorResolution(node) { + switch (node.parent.kind) { + case 204 /* ClassDeclaration */: + case 177 /* ClassExpression */: + return ts.Diagnostics.Unable_to_resolve_signature_of_class_decorator_when_called_as_an_expression; + case 131 /* Parameter */: + return ts.Diagnostics.Unable_to_resolve_signature_of_parameter_decorator_when_called_as_an_expression; + case 134 /* PropertyDeclaration */: + return ts.Diagnostics.Unable_to_resolve_signature_of_property_decorator_when_called_as_an_expression; + case 136 /* MethodDeclaration */: + case 138 /* GetAccessor */: + case 139 /* SetAccessor */: + return ts.Diagnostics.Unable_to_resolve_signature_of_method_decorator_when_called_as_an_expression; + } + } + /** + * Resolves a decorator as if it were a call expression. + */ + function resolveDecorator(node, candidatesOutArray) { + var funcType = checkExpression(node.expression); + var apparentType = getApparentType(funcType); + if (apparentType === unknownType) { + return resolveErrorCall(node); + } + var callSignatures = getSignaturesOfType(apparentType, 0 /* Call */); + if (funcType === anyType || (!callSignatures.length && !(funcType.flags & 16384 /* Union */) && isTypeAssignableTo(funcType, globalFunctionType))) { + return resolveUntypedCall(node); + } + var headMessage = getDiagnosticHeadMessageForDecoratorResolution(node); + if (!callSignatures.length) { + var errorInfo; + errorInfo = ts.chainDiagnosticMessages(errorInfo, ts.Diagnostics.Cannot_invoke_an_expression_whose_type_lacks_a_call_signature); + errorInfo = ts.chainDiagnosticMessages(errorInfo, headMessage); + diagnostics.add(ts.createDiagnosticForNodeFromMessageChain(node, errorInfo)); + return resolveErrorCall(node); + } + return resolveCall(node, callSignatures, candidatesOutArray, headMessage); + } // candidatesOutArray is passed by signature help in the language service, and collectCandidates // must fill it up with the appropriate candidate signatures function getResolvedSignature(node, candidatesOutArray) { @@ -19101,6 +19450,9 @@ var ts; else if (node.kind === 162 /* TaggedTemplateExpression */) { links.resolvedSignature = resolveTaggedTemplateExpression(node, candidatesOutArray); } + else if (node.kind === 132 /* Decorator */) { + links.resolvedSignature = resolveDecorator(node, candidatesOutArray); + } else { ts.Debug.fail("Branch in 'getResolvedSignature' should be unreachable."); } @@ -19343,7 +19695,7 @@ var ts; if (node.type) { checkTypeAssignableTo(exprType, getTypeFromTypeNode(node.type), node.body, undefined); } - checkFunctionExpressionBodies(node.body); + checkFunctionAndClassExpressionBodies(node.body); } } } @@ -19807,7 +20159,7 @@ var ts; if (ts.isFunctionLike(parent) && current === parent.body) { return false; } - else if (current.kind === 204 /* ClassDeclaration */ || current.kind === 177 /* ClassExpression */) { + else if (ts.isClassLike(current)) { return true; } current = parent; @@ -20707,29 +21059,37 @@ var ts; } /** Check a decorator */ function checkDecorator(node) { - var expression = node.expression; - var exprType = checkExpression(expression); + var signature = getResolvedSignature(node); + var returnType = getReturnTypeOfSignature(signature); + if (returnType.flags & 1 /* Any */) { + return; + } + var expectedReturnType; + var headMessage = getDiagnosticHeadMessageForDecoratorResolution(node); + var errorInfo; switch (node.parent.kind) { case 204 /* ClassDeclaration */: var classSymbol = getSymbolOfNode(node.parent); var classConstructorType = getTypeOfSymbol(classSymbol); - var classDecoratorType = instantiateSingleCallFunctionType(getGlobalClassDecoratorType(), [classConstructorType]); - checkTypeAssignableTo(exprType, classDecoratorType, node); + expectedReturnType = getUnionType([classConstructorType, voidType]); + break; + case 131 /* Parameter */: + expectedReturnType = voidType; + errorInfo = ts.chainDiagnosticMessages(errorInfo, ts.Diagnostics.The_return_type_of_a_parameter_decorator_function_must_be_either_void_or_any); break; case 134 /* PropertyDeclaration */: - checkTypeAssignableTo(exprType, getGlobalPropertyDecoratorType(), node); + expectedReturnType = voidType; + errorInfo = ts.chainDiagnosticMessages(errorInfo, ts.Diagnostics.The_return_type_of_a_property_decorator_function_must_be_either_void_or_any); break; case 136 /* MethodDeclaration */: case 138 /* GetAccessor */: case 139 /* SetAccessor */: var methodType = getTypeOfNode(node.parent); - var methodDecoratorType = instantiateSingleCallFunctionType(getGlobalMethodDecoratorType(), [methodType]); - checkTypeAssignableTo(exprType, methodDecoratorType, node); - break; - case 131 /* Parameter */: - checkTypeAssignableTo(exprType, getGlobalParameterDecoratorType(), node); + var descriptorType = createTypedPropertyDescriptorType(methodType); + expectedReturnType = getUnionType([descriptorType, voidType]); break; } + checkTypeAssignableTo(returnType, expectedReturnType, node, headMessage, errorInfo); } /** Checks a type reference node as an expression. */ function checkTypeNodeAsExpression(node) { @@ -20880,7 +21240,7 @@ var ts; } ts.forEach(node.statements, checkSourceElement); if (ts.isFunctionBlock(node) || node.kind === 209 /* ModuleBlock */) { - checkFunctionExpressionBodies(node); + checkFunctionAndClassExpressionBodies(node); } } function checkCollisionWithArgumentsInGeneratedCode(node) { @@ -20945,7 +21305,7 @@ var ts; return; } // bubble up and find containing type - var enclosingClass = ts.getAncestor(node, 204 /* ClassDeclaration */); + var enclosingClass = ts.getContainingClass(node); // if containing type was not found or it is ambient - exit (no codegen) if (!enclosingClass || ts.isInAmbientContext(enclosingClass)) { return; @@ -21650,7 +22010,7 @@ var ts; checkIndexConstraintForProperty(prop, propType, type, declaredStringIndexer, stringIndexType, 0 /* String */); checkIndexConstraintForProperty(prop, propType, type, declaredNumberIndexer, numberIndexType, 1 /* Number */); }); - if (type.flags & 1024 /* Class */ && type.symbol.valueDeclaration.kind === 204 /* ClassDeclaration */) { + if (type.flags & 1024 /* Class */ && ts.isClassLike(type.symbol.valueDeclaration)) { var classDeclaration = type.symbol.valueDeclaration; for (var _i = 0, _a = classDeclaration.members; _i < _a.length; _i++) { var member = _a[_i]; @@ -21739,15 +22099,17 @@ var ts; } } function checkClassExpression(node) { - grammarErrorOnNode(node, ts.Diagnostics.class_expressions_are_not_currently_supported); - ts.forEach(node.members, checkSourceElement); - return unknownType; + checkClassLikeDeclaration(node); + return getTypeOfSymbol(getSymbolOfNode(node)); } function checkClassDeclaration(node) { - // Grammar checking if (!node.name && !(node.flags & 256 /* Default */)) { grammarErrorOnFirstToken(node, ts.Diagnostics.A_class_declaration_without_the_default_modifier_must_have_a_name); } + checkClassLikeDeclaration(node); + ts.forEach(node.members, checkSourceElement); + } + function checkClassLikeDeclaration(node) { checkGrammarClassDeclarationHeritageClauses(node); checkDecorators(node); if (node.name) { @@ -21812,7 +22174,6 @@ var ts; } }); } - ts.forEach(node.members, checkSourceElement); if (produceDiagnostics) { checkIndexConstraints(type); checkTypeForDuplicateIndexSignatures(node); @@ -22608,8 +22969,8 @@ var ts; return checkMissingDeclaration(node); } } - // Function expression bodies are checked after all statements in the enclosing body. This is to ensure - // constructs like the following are permitted: + // Function and class expression bodies are checked after all statements in the enclosing body. This is + // to ensure constructs like the following are permitted: // let foo = function () { // let s = foo(); // return "hello"; @@ -22617,17 +22978,20 @@ var ts; // Here, performing a full type check of the body of the function expression whilst in the process of // determining the type of foo would cause foo to be given type any because of the recursive reference. // Delaying the type check of the body ensures foo has been assigned a type. - function checkFunctionExpressionBodies(node) { + function checkFunctionAndClassExpressionBodies(node) { switch (node.kind) { case 165 /* FunctionExpression */: case 166 /* ArrowFunction */: - ts.forEach(node.parameters, checkFunctionExpressionBodies); + ts.forEach(node.parameters, checkFunctionAndClassExpressionBodies); checkFunctionExpressionOrObjectLiteralMethodBody(node); break; + case 177 /* ClassExpression */: + ts.forEach(node.members, checkSourceElement); + break; case 136 /* MethodDeclaration */: case 135 /* MethodSignature */: - ts.forEach(node.decorators, checkFunctionExpressionBodies); - ts.forEach(node.parameters, checkFunctionExpressionBodies); + ts.forEach(node.decorators, checkFunctionAndClassExpressionBodies); + ts.forEach(node.parameters, checkFunctionAndClassExpressionBodies); if (ts.isObjectLiteralMethod(node)) { checkFunctionExpressionOrObjectLiteralMethodBody(node); } @@ -22636,10 +23000,10 @@ var ts; case 138 /* GetAccessor */: case 139 /* SetAccessor */: case 203 /* FunctionDeclaration */: - ts.forEach(node.parameters, checkFunctionExpressionBodies); + ts.forEach(node.parameters, checkFunctionAndClassExpressionBodies); break; case 195 /* WithStatement */: - checkFunctionExpressionBodies(node.expression); + checkFunctionAndClassExpressionBodies(node.expression); break; case 132 /* Decorator */: case 131 /* Parameter */: @@ -22696,7 +23060,7 @@ var ts; case 229 /* EnumMember */: case 217 /* ExportAssignment */: case 230 /* SourceFile */: - ts.forEachChild(node, checkFunctionExpressionBodies); + ts.forEachChild(node, checkFunctionAndClassExpressionBodies); break; } } @@ -22721,7 +23085,7 @@ var ts; emitParam = false; potentialThisCollisions.length = 0; ts.forEach(node.statements, checkSourceElement); - checkFunctionExpressionBodies(node); + checkFunctionAndClassExpressionBodies(node); if (ts.isExternalModule(node)) { checkExternalModuleExports(node); } @@ -22796,6 +23160,11 @@ var ts; case 207 /* EnumDeclaration */: copySymbols(getSymbolOfNode(location).exports, meaning & 8 /* EnumMember */); break; + case 177 /* ClassExpression */: + if (location.name) { + copySymbol(location.symbol, meaning); + } + // Fall through case 204 /* ClassDeclaration */: case 205 /* InterfaceDeclaration */: if (!(memberFlags & 128 /* Static */)) { @@ -22831,41 +23200,6 @@ var ts; } } } - if (isInsideWithStatementBody(location)) { - // We cannot answer semantic questions within a with block, do not proceed any further - return []; - } - while (location) { - if (location.locals && !isGlobalSourceFile(location)) { - copySymbols(location.locals, meaning); - } - switch (location.kind) { - case 230 /* SourceFile */: - if (!ts.isExternalModule(location)) - break; - case 208 /* ModuleDeclaration */: - copySymbols(getSymbolOfNode(location).exports, meaning & 8914931 /* ModuleMember */); - break; - case 207 /* EnumDeclaration */: - copySymbols(getSymbolOfNode(location).exports, meaning & 8 /* EnumMember */); - break; - case 204 /* ClassDeclaration */: - case 205 /* InterfaceDeclaration */: - if (!(memberFlags & 128 /* Static */)) { - copySymbols(getSymbolOfNode(location).members, meaning & 793056 /* Type */); - } - break; - case 165 /* FunctionExpression */: - if (location.name) { - copySymbol(location.symbol, meaning); - } - break; - } - memberFlags = location.flags; - location = location.parent; - } - copySymbols(globals, meaning); - return symbolsToArray(symbols); } function isTypeDeclarationName(name) { return name.kind === 65 /* Identifier */ && @@ -22967,6 +23301,9 @@ var ts; meaning |= 8388608 /* Alias */; return resolveEntityName(entityName, meaning); } + if (entityName.parent.kind === 143 /* TypePredicate */) { + return resolveEntityName(entityName, 1 /* FunctionScopedVariable */); + } // Do we want to return undefined here? return undefined; } @@ -23081,6 +23418,16 @@ var ts; } return checkExpression(expr); } + /** + * Gets either the static or instance type of a class element, based on + * whether the element is declared as "static". + */ + function getParentTypeOfClassElement(node) { + var classSymbol = getSymbolOfNode(node.parent); + return node.flags & 128 /* Static */ + ? getTypeOfSymbol(classSymbol) + : getDeclaredTypeOfSymbol(classSymbol); + } // Return the list of properties of the given type, augmented with properties from Function // if the type has call or construct signatures function getAugmentedPropertiesOfType(type) { @@ -23566,10 +23913,7 @@ var ts; globalNumberType = getGlobalType("Number"); globalBooleanType = getGlobalType("Boolean"); globalRegExpType = getGlobalType("RegExp"); - getGlobalClassDecoratorType = ts.memoize(function () { return getGlobalType("ClassDecorator"); }); - getGlobalPropertyDecoratorType = ts.memoize(function () { return getGlobalType("PropertyDecorator"); }); - getGlobalMethodDecoratorType = ts.memoize(function () { return getGlobalType("MethodDecorator"); }); - getGlobalParameterDecoratorType = ts.memoize(function () { return getGlobalType("ParameterDecorator"); }); + getGlobalTypedPropertyDescriptorType = ts.memoize(function () { return getGlobalType("TypedPropertyDescriptor", 1); }); // If we're in ES6 mode, load the TemplateStringsArray. // Otherwise, default to 'unknown' for the purposes of type checking in LS scenarios. if (languageVersion >= 2 /* ES6 */) { @@ -24132,7 +24476,7 @@ var ts; return grammarErrorAtPos(getSourceFile(node), node.end - 1, ";".length, ts.Diagnostics._0_expected, "{"); } } - if (node.parent.kind === 204 /* ClassDeclaration */) { + if (ts.isClassLike(node.parent)) { if (checkGrammarForInvalidQuestionMark(node, node.questionToken, ts.Diagnostics.A_class_member_cannot_be_declared_optional)) { return true; } @@ -24390,7 +24734,7 @@ var ts; } } function checkGrammarProperty(node) { - if (node.parent.kind === 204 /* ClassDeclaration */) { + if (ts.isClassLike(node.parent)) { if (checkGrammarForInvalidQuestionMark(node, node.questionToken, ts.Diagnostics.A_class_member_cannot_be_declared_optional) || checkGrammarForNonSymbolComputedProperty(node.name, ts.Diagnostics.A_computed_property_name_in_a_class_property_declaration_must_directly_refer_to_a_built_in_symbol)) { return true; @@ -26121,6 +26465,9 @@ var ts; function generateNameForExportDefault() { return makeUniqueName("default"); } + function generateNameForClassExpression() { + return makeUniqueName("class"); + } function generateNameForNode(node) { switch (node.kind) { case 65 /* Identifier */: @@ -26133,9 +26480,10 @@ var ts; return generateNameForImportOrExportDeclaration(node); case 203 /* FunctionDeclaration */: case 204 /* ClassDeclaration */: - case 177 /* ClassExpression */: case 217 /* ExportAssignment */: return generateNameForExportDefault(); + case 177 /* ClassExpression */: + return generateNameForClassExpression(); } } function getGeneratedNameForNode(node) { @@ -37159,6 +37507,10 @@ var ts; if (actualIndentation !== -1 /* Unknown */) { return actualIndentation; } + actualIndentation = getLineIndentationWhenExpressionIsInMultiLine(current, sourceFile, options); + if (actualIndentation !== -1 /* Unknown */) { + return actualIndentation + options.IndentSize; + } previous = current; current = current.parent; } @@ -37201,6 +37553,10 @@ var ts; if (actualIndentation !== -1 /* Unknown */) { return actualIndentation + indentationDelta; } + actualIndentation = getLineIndentationWhenExpressionIsInMultiLine(current, sourceFile, options); + if (actualIndentation !== -1 /* Unknown */) { + return actualIndentation + indentationDelta; + } } // increase indentation if parent node wants its content to be indented and parent and child nodes don't start on the same line if (shouldIndentChildNode(parent.kind, current.kind) && !parentAndChildShareLine) { @@ -37338,6 +37694,44 @@ var ts; return index !== -1 ? deriveActualIndentationFromList(list, index, sourceFile, options) : -1 /* Unknown */; } } + function getLineIndentationWhenExpressionIsInMultiLine(node, sourceFile, options) { + // actual indentation should not be used when: + // - node is close parenthesis - this is the end of the expression + if (node.kind === 17 /* CloseParenToken */) { + return -1 /* Unknown */; + } + if (node.parent && (node.parent.kind === 160 /* CallExpression */ || + node.parent.kind === 161 /* NewExpression */) && + node.parent.expression !== node) { + var fullCallOrNewExpression = node.parent.expression; + var startingExpression = getStartingExpression(fullCallOrNewExpression); + if (fullCallOrNewExpression === startingExpression) { + return -1 /* Unknown */; + } + var fullCallOrNewExpressionEnd = sourceFile.getLineAndCharacterOfPosition(fullCallOrNewExpression.end); + var startingExpressionEnd = sourceFile.getLineAndCharacterOfPosition(startingExpression.end); + if (fullCallOrNewExpressionEnd.line === startingExpressionEnd.line) { + return -1 /* Unknown */; + } + return findColumnForFirstNonWhitespaceCharacterInLine(fullCallOrNewExpressionEnd, sourceFile, options); + } + return -1 /* Unknown */; + function getStartingExpression(node) { + while (true) { + switch (node.kind) { + case 160 /* CallExpression */: + case 161 /* NewExpression */: + case 158 /* PropertyAccessExpression */: + case 159 /* ElementAccessExpression */: + node = node.expression; + break; + default: + return node; + } + } + return node; + } + } function deriveActualIndentationFromList(list, index, sourceFile, options) { ts.Debug.assert(index >= 0 && index < list.length); var node = list[index]; @@ -42395,6 +42789,9 @@ var ts; } } function classifyToken(token) { + if (ts.nodeIsMissing(token)) { + return; + } var tokenStart = classifyLeadingTriviaAndGetTokenStart(token); var tokenWidth = token.end - tokenStart; ts.Debug.assert(tokenWidth >= 0); diff --git a/bin/typescriptServices.d.ts b/bin/typescriptServices.d.ts index da6d55bfd80..70e4f42e1ef 100644 --- a/bin/typescriptServices.d.ts +++ b/bin/typescriptServices.d.ts @@ -600,7 +600,7 @@ declare namespace ts { tag: LeftHandSideExpression; template: LiteralExpression | TemplateExpression; } - type CallLikeExpression = CallExpression | NewExpression | TaggedTemplateExpression; + type CallLikeExpression = CallExpression | NewExpression | TaggedTemplateExpression | Decorator; interface TypeAssertion extends UnaryExpression { type: TypeNode; expression: UnaryExpression; diff --git a/bin/typescriptServices.js b/bin/typescriptServices.js index 2e3a784b298..6373e3f9c58 100644 --- a/bin/typescriptServices.js +++ b/bin/typescriptServices.js @@ -1950,6 +1950,12 @@ var ts; An_export_declaration_can_only_be_used_in_a_module: { code: 1233, category: ts.DiagnosticCategory.Error, key: "An export declaration can only be used in a module." }, An_ambient_module_declaration_is_only_allowed_at_the_top_level_in_a_file: { code: 1234, category: ts.DiagnosticCategory.Error, key: "An ambient module declaration is only allowed at the top level in a file." }, A_namespace_declaration_is_only_allowed_in_a_namespace_or_module: { code: 1235, category: ts.DiagnosticCategory.Error, key: "A namespace declaration is only allowed in a namespace or module." }, + The_return_type_of_a_property_decorator_function_must_be_either_void_or_any: { code: 1236, category: ts.DiagnosticCategory.Error, key: "The return type of a property decorator function must be either 'void' or 'any'." }, + The_return_type_of_a_parameter_decorator_function_must_be_either_void_or_any: { code: 1237, category: ts.DiagnosticCategory.Error, key: "The return type of a parameter decorator function must be either 'void' or 'any'." }, + Unable_to_resolve_signature_of_class_decorator_when_called_as_an_expression: { code: 1238, category: ts.DiagnosticCategory.Error, key: "Unable to resolve signature of class decorator when called as an expression." }, + Unable_to_resolve_signature_of_parameter_decorator_when_called_as_an_expression: { code: 1239, category: ts.DiagnosticCategory.Error, key: "Unable to resolve signature of parameter decorator when called as an expression." }, + Unable_to_resolve_signature_of_property_decorator_when_called_as_an_expression: { code: 1240, category: ts.DiagnosticCategory.Error, key: "Unable to resolve signature of property decorator when called as an expression." }, + Unable_to_resolve_signature_of_method_decorator_when_called_as_an_expression: { code: 1241, category: ts.DiagnosticCategory.Error, key: "Unable to resolve signature of method decorator when called as an expression." }, Duplicate_identifier_0: { code: 2300, category: ts.DiagnosticCategory.Error, key: "Duplicate identifier '{0}'." }, Initializer_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor: { code: 2301, category: ts.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: ts.DiagnosticCategory.Error, key: "Static members cannot reference class type parameters." }, @@ -2325,9 +2331,7 @@ var ts; property_declarations_can_only_be_used_in_a_ts_file: { code: 8014, category: ts.DiagnosticCategory.Error, key: "'property declarations' can only be used in a .ts file." }, enum_declarations_can_only_be_used_in_a_ts_file: { code: 8015, category: ts.DiagnosticCategory.Error, key: "'enum declarations' can only be used in a .ts file." }, type_assertion_expressions_can_only_be_used_in_a_ts_file: { code: 8016, category: ts.DiagnosticCategory.Error, key: "'type assertion expressions' can only be used in a .ts file." }, - decorators_can_only_be_used_in_a_ts_file: { code: 8017, category: ts.DiagnosticCategory.Error, key: "'decorators' can only be used in a .ts file." }, - Only_identifiers_Slashqualified_names_with_optional_type_arguments_are_currently_supported_in_a_class_extends_clauses: { code: 9002, category: ts.DiagnosticCategory.Error, key: "Only identifiers/qualified-names with optional type arguments are currently supported in a class 'extends' clauses." }, - class_expressions_are_not_currently_supported: { code: 9003, category: ts.DiagnosticCategory.Error, key: "'class' expressions are not currently supported." } + decorators_can_only_be_used_in_a_ts_file: { code: 8017, category: ts.DiagnosticCategory.Error, key: "'decorators' can only be used in a .ts file." } }; })(ts || (ts = {})); /// @@ -4284,7 +4288,7 @@ var ts; function getStrictModeIdentifierMessage(node) { // Provide specialized messages to help the user understand why we think they're in // strict mode. - if (ts.getAncestor(node, 204 /* ClassDeclaration */) || ts.getAncestor(node, 177 /* ClassExpression */)) { + if (ts.getContainingClass(node)) { return ts.Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode_Class_definitions_are_automatically_in_strict_mode; } if (file.externalModuleIndicator) { @@ -4333,7 +4337,7 @@ var ts; function getStrictModeEvalOrArgumentsMessage(node) { // Provide specialized messages to help the user understand why we think they're in // strict mode. - if (ts.getAncestor(node, 204 /* ClassDeclaration */) || ts.getAncestor(node, 177 /* ClassExpression */)) { + if (ts.getContainingClass(node)) { return ts.Diagnostics.Invalid_use_of_0_Class_definitions_are_automatically_in_strict_mode; } if (file.externalModuleIndicator) { @@ -4641,7 +4645,7 @@ var ts; // containing class. if (node.flags & 112 /* AccessibilityModifier */ && node.parent.kind === 137 /* Constructor */ && - (node.parent.parent.kind === 204 /* ClassDeclaration */ || node.parent.parent.kind === 177 /* ClassExpression */)) { + ts.isClassLike(node.parent.parent)) { var classDeclaration = node.parent.parent; declareSymbol(classDeclaration.symbol.members, classDeclaration.symbol, node, 4 /* Property */, 107455 /* PropertyExcludes */); } @@ -5136,6 +5140,7 @@ var ts; case 208 /* ModuleDeclaration */: case 206 /* TypeAliasDeclaration */: case 204 /* ClassDeclaration */: + case 177 /* ClassExpression */: // These are not allowed inside a generator now, but eventually they may be allowed // as local types. Regardless, any yield statements contained within them should be // skipped in this traversal. @@ -5177,20 +5182,11 @@ var ts; } ts.isVariableLike = isVariableLike; function isAccessor(node) { - if (node) { - switch (node.kind) { - case 138 /* GetAccessor */: - case 139 /* SetAccessor */: - return true; - } - } - return false; + return node && (node.kind === 138 /* GetAccessor */ || node.kind === 139 /* SetAccessor */); } ts.isAccessor = isAccessor; function isClassLike(node) { - if (node) { - return node.kind === 204 /* ClassDeclaration */ || node.kind === 177 /* ClassExpression */; - } + return node && (node.kind === 204 /* ClassDeclaration */ || node.kind === 177 /* ClassExpression */); } ts.isClassLike = isClassLike; function isFunctionLike(node) { @@ -5232,6 +5228,15 @@ var ts; } } ts.getContainingFunction = getContainingFunction; + function getContainingClass(node) { + while (true) { + node = node.parent; + if (!node || isClassLike(node)) { + return node; + } + } + } + ts.getContainingClass = getContainingClass; function getThisContainer(node, includeArrowFunctions) { while (true) { node = node.parent; @@ -5244,7 +5249,7 @@ var ts; // then the computed property is not a 'this' container. // A computed property name in a class needs to be a this container // so that we can error on it. - if (node.parent.parent.kind === 204 /* ClassDeclaration */) { + if (isClassLike(node.parent.parent)) { return node; } // If this is a computed property, then the parent should not @@ -5300,7 +5305,7 @@ var ts; // then the computed property is not a 'super' container. // A computed property name in a class needs to be a super container // so that we can error on it. - if (node.parent.parent.kind === 204 /* ClassDeclaration */) { + if (isClassLike(node.parent.parent)) { return node; } // If this is a computed property, then the parent should not @@ -5345,7 +5350,7 @@ var ts; if (node.kind === 162 /* TaggedTemplateExpression */) { return node.tag; } - // Will either be a CallExpression or NewExpression. + // Will either be a CallExpression, NewExpression, or Decorator. return node.expression; } ts.getInvokedExpression = getInvokedExpression; @@ -5658,6 +5663,7 @@ var ts; case 166 /* ArrowFunction */: case 155 /* BindingElement */: case 204 /* ClassDeclaration */: + case 177 /* ClassExpression */: case 137 /* Constructor */: case 207 /* EnumDeclaration */: case 229 /* EnumMember */: @@ -6429,7 +6435,7 @@ var ts; function isExpressionWithTypeArgumentsInClassExtendsClause(node) { return node.kind === 179 /* ExpressionWithTypeArguments */ && node.parent.token === 79 /* ExtendsKeyword */ && - node.parent.parent.kind === 204 /* ClassDeclaration */; + isClassLike(node.parent.parent); } ts.isExpressionWithTypeArgumentsInClassExtendsClause = isExpressionWithTypeArgumentsInClassExtendsClause; // Returns false if this heritage clause element's expression contains something unsupported @@ -12210,10 +12216,7 @@ var ts; var globalIteratorType; var globalIterableIteratorType; var anyArrayType; - var getGlobalClassDecoratorType; - var getGlobalParameterDecoratorType; - var getGlobalPropertyDecoratorType; - var getGlobalMethodDecoratorType; + var getGlobalTypedPropertyDescriptorType; var tupleTypes = {}; var unionTypes = {}; var stringLiteralTypes = {}; @@ -12499,7 +12502,7 @@ var ts; // local variables of the constructor. This effectively means that entities from outer scopes // by the same name as a constructor parameter or local variable are inaccessible // in initializer expressions for instance member variables. - if (location.parent.kind === 204 /* ClassDeclaration */ && !(location.flags & 128 /* Static */)) { + if (ts.isClassLike(location.parent) && !(location.flags & 128 /* Static */)) { var ctor = findConstructorDeclaration(location.parent); if (ctor && ctor.locals) { if (getSymbol(ctor.locals, name, meaning & 107455 /* Value */)) { @@ -12510,6 +12513,7 @@ var ts; } break; case 204 /* ClassDeclaration */: + case 177 /* ClassExpression */: case 205 /* InterfaceDeclaration */: if (result = getSymbol(getSymbolOfNode(location).members, name, meaning & 793056 /* Type */)) { if (lastLocation && lastLocation.flags & 128 /* Static */) { @@ -12521,6 +12525,13 @@ var ts; } break loop; } + if (location.kind === 177 /* ClassExpression */ && meaning & 32 /* Class */) { + var className = location.name; + if (className && name === className.text) { + result = location.symbol; + break loop; + } + } break; // It is not legal to reference a class's own type parameters from a computed property name that // belongs to the class. For example: @@ -12532,7 +12543,7 @@ var ts; // case 129 /* ComputedPropertyName */: grandparent = location.parent.parent; - if (grandparent.kind === 204 /* ClassDeclaration */ || grandparent.kind === 205 /* InterfaceDeclaration */) { + if (ts.isClassLike(grandparent) || grandparent.kind === 205 /* InterfaceDeclaration */) { // A reference to this grandparent's type parameters would be an error if (result = getSymbol(getSymbolOfNode(grandparent).members, name, meaning & 793056 /* Type */)) { error(errorLocation, ts.Diagnostics.A_computed_property_name_cannot_reference_a_type_parameter_from_its_containing_type); @@ -12565,15 +12576,6 @@ var ts; } } break; - case 177 /* ClassExpression */: - if (meaning & 32 /* Class */) { - var className = location.name; - if (className && name === className.text) { - result = location.symbol; - break loop; - } - } - break; case 132 /* Decorator */: // Decorators are resolved at the class declaration. Resolving at the parameter // or member would result in looking up locals in the method. @@ -13407,19 +13409,28 @@ var ts; // This is for caching the result of getSymbolDisplayBuilder. Do not access directly. var _displayBuilder; function getSymbolDisplayBuilder() { + function getNameOfSymbol(symbol) { + if (symbol.declarations && symbol.declarations.length) { + var declaration = symbol.declarations[0]; + if (declaration.name) { + return ts.declarationNameToString(declaration.name); + } + switch (declaration.kind) { + case 177 /* ClassExpression */: + return "(Anonymous class)"; + case 165 /* FunctionExpression */: + case 166 /* ArrowFunction */: + return "(Anonymous function)"; + } + } + return symbol.name; + } /** * Writes only the name of the symbol out to the writer. Uses the original source text * for the name of the symbol if it is available to match how the user inputted the name. */ function appendSymbolNameOnly(symbol, writer) { - if (symbol.declarations && symbol.declarations.length > 0) { - var declaration = symbol.declarations[0]; - if (declaration.name) { - writer.writeSymbol(ts.declarationNameToString(declaration.name), symbol); - return; - } - } - writer.writeSymbol(symbol.name, symbol); + writer.writeSymbol(getNameOfSymbol(symbol), symbol); } /** * Enclosing declaration is optional when we don't want to get qualified name in the enclosing declaration scope @@ -14488,9 +14499,9 @@ var ts; if (!node) { return typeParameters; } - if (node.kind === 204 /* ClassDeclaration */ || node.kind === 203 /* FunctionDeclaration */ || - node.kind === 165 /* FunctionExpression */ || node.kind === 136 /* MethodDeclaration */ || - node.kind === 166 /* ArrowFunction */) { + if (node.kind === 204 /* ClassDeclaration */ || node.kind === 177 /* ClassExpression */ || + node.kind === 203 /* FunctionDeclaration */ || node.kind === 165 /* FunctionExpression */ || + node.kind === 136 /* MethodDeclaration */ || node.kind === 166 /* ArrowFunction */) { var declarations = node.typeParameters; if (declarations) { return appendTypeParameters(appendOuterTypeParameters(typeParameters, node), declarations); @@ -14500,8 +14511,8 @@ var ts; } // The outer type parameters are those defined by enclosing generic classes, methods, or functions. function getOuterTypeParametersOfClassOrInterface(symbol) { - var kind = symbol.flags & 32 /* Class */ ? 204 /* ClassDeclaration */ : 205 /* InterfaceDeclaration */; - return appendOuterTypeParameters(undefined, ts.getDeclarationOfKind(symbol, kind)); + var declaration = symbol.flags & 32 /* Class */ ? symbol.valueDeclaration : ts.getDeclarationOfKind(symbol, 205 /* InterfaceDeclaration */); + return appendOuterTypeParameters(undefined, declaration); } // The local type parameters are the combined set of type parameters from all declarations of the class, // interface, or type alias. @@ -14509,7 +14520,8 @@ var ts; var result; for (var _i = 0, _a = symbol.declarations; _i < _a.length; _i++) { var node = _a[_i]; - if (node.kind === 205 /* InterfaceDeclaration */ || node.kind === 204 /* ClassDeclaration */ || node.kind === 206 /* TypeAliasDeclaration */) { + if (node.kind === 205 /* InterfaceDeclaration */ || node.kind === 204 /* ClassDeclaration */ || + node.kind === 177 /* ClassExpression */ || node.kind === 206 /* TypeAliasDeclaration */) { var declaration = node; if (declaration.typeParameters) { result = appendTypeParameters(result, declaration.typeParameters); @@ -15604,6 +15616,15 @@ var ts; function getGlobalESSymbolConstructorSymbol() { return globalESSymbolConstructorSymbol || (globalESSymbolConstructorSymbol = getGlobalValueSymbol("Symbol")); } + /** + * Creates a TypeReference for a generic `TypedPropertyDescriptor`. + */ + function createTypedPropertyDescriptorType(propertyType) { + var globalTypedPropertyDescriptorType = getGlobalTypedPropertyDescriptorType(); + return globalTypedPropertyDescriptorType !== emptyObjectType + ? createTypeReference(globalTypedPropertyDescriptorType, [propertyType]) + : emptyObjectType; + } /** * Instantiates a global type that is generic with some element type, and returns that instantiation. */ @@ -16042,8 +16063,8 @@ var ts; function checkTypeSubtypeOf(source, target, errorNode, headMessage, containingMessageChain) { return checkTypeRelatedTo(source, target, subtypeRelation, errorNode, headMessage, containingMessageChain); } - function checkTypeAssignableTo(source, target, errorNode, headMessage) { - return checkTypeRelatedTo(source, target, assignableRelation, errorNode, headMessage); + function checkTypeAssignableTo(source, target, errorNode, headMessage, containingMessageChain) { + return checkTypeRelatedTo(source, target, assignableRelation, errorNode, headMessage, containingMessageChain); } function isSignatureAssignableTo(source, target) { var sourceType = getOrCreateTypeFromSignature(source); @@ -17582,9 +17603,9 @@ var ts; } } function captureLexicalThis(node, container) { - var classNode = container.parent && container.parent.kind === 204 /* ClassDeclaration */ ? container.parent : undefined; getNodeLinks(node).flags |= 2 /* LexicalThis */; if (container.kind === 134 /* PropertyDeclaration */ || container.kind === 137 /* Constructor */) { + var classNode = container.parent; getNodeLinks(classNode).flags |= 4 /* CaptureThis */; } else { @@ -17629,9 +17650,8 @@ var ts; if (needToCaptureLexicalThis) { captureLexicalThis(node, container); } - var classNode = container.parent && container.parent.kind === 204 /* ClassDeclaration */ ? container.parent : undefined; - if (classNode) { - var symbol = getSymbolOfNode(classNode); + if (ts.isClassLike(container.parent)) { + var symbol = getSymbolOfNode(container.parent); return container.flags & 128 /* Static */ ? getTypeOfSymbol(symbol) : getDeclaredTypeOfSymbol(symbol); } return anyType; @@ -17646,7 +17666,7 @@ var ts; } function checkSuperExpression(node) { var isCallExpression = node.parent.kind === 160 /* CallExpression */ && node.parent.expression === node; - var classDeclaration = ts.getAncestor(node, 204 /* ClassDeclaration */); + var classDeclaration = ts.getContainingClass(node); var classType = classDeclaration && getDeclaredTypeOfSymbol(getSymbolOfNode(classDeclaration)); var baseClassType = classType && getBaseTypes(classType)[0]; if (!baseClassType) { @@ -17676,7 +17696,7 @@ var ts; needToCaptureLexicalThis = languageVersion < 2 /* ES6 */; } // topmost container must be something that is directly nested in the class declaration - if (container && container.parent && container.parent.kind === 204 /* ClassDeclaration */) { + if (container && ts.isClassLike(container.parent)) { if (container.flags & 128 /* Static */) { canUseSuperExpression = container.kind === 136 /* MethodDeclaration */ || @@ -18276,7 +18296,7 @@ var ts; } // Property is known to be private or protected at this point // Get the declaring and enclosing class instance types - var enclosingClassDeclaration = ts.getAncestor(node, 204 /* ClassDeclaration */); + var enclosingClassDeclaration = ts.getContainingClass(node); var enclosingClass = enclosingClassDeclaration ? getDeclaredTypeOfSymbol(getSymbolOfNode(enclosingClassDeclaration)) : undefined; var declaringClass = getDeclaredTypeOfSymbol(prop.parent); // Private property is accessible if declaring and enclosing class are the same @@ -18502,7 +18522,7 @@ var ts; if (node.kind === 162 /* TaggedTemplateExpression */) { checkExpression(node.template); } - else { + else if (node.kind !== 132 /* Decorator */) { ts.forEach(node.arguments, function (argument) { checkExpression(argument); }); @@ -18567,7 +18587,8 @@ var ts; } function getSpreadArgumentIndex(args) { for (var i = 0; i < args.length; i++) { - if (args[i].kind === 176 /* SpreadElementExpression */) { + var arg = args[i]; + if (arg && arg.kind === 176 /* SpreadElementExpression */) { return i; } } @@ -18577,6 +18598,8 @@ var ts; var adjustedArgCount; // Apparent number of arguments we will have in this call var typeArguments; // Type arguments (undefined if none) var callIsIncomplete; // In incomplete call we want to be lenient when we have too few arguments + var isDecorator; + var spreadArgIndex = -1; if (node.kind === 162 /* TaggedTemplateExpression */) { var tagExpression = node; // Even if the call is incomplete, we'll have a missing expression as our last argument, @@ -18600,6 +18623,11 @@ var ts; callIsIncomplete = !!templateLiteral.isUnterminated; } } + else if (node.kind === 132 /* Decorator */) { + isDecorator = true; + typeArguments = undefined; + adjustedArgCount = getEffectiveArgumentCount(node, undefined, signature); + } else { var callExpression = node; if (!callExpression.arguments) { @@ -18612,6 +18640,7 @@ var ts; // If we are missing the close paren, the call is incomplete. callIsIncomplete = callExpression.arguments.end === callExpression.end; typeArguments = callExpression.typeArguments; + spreadArgIndex = getSpreadArgumentIndex(args); } // If the user supplied type arguments, but the number of type arguments does not match // the declared number of type parameters, the call has an incorrect arity. @@ -18622,7 +18651,6 @@ var ts; } // If spread arguments are present, check that they correspond to a rest parameter. If so, no // further checking is necessary. - var spreadArgIndex = getSpreadArgumentIndex(args); if (spreadArgIndex >= 0) { return signature.hasRestParameter && spreadArgIndex >= signature.parameters.length - 1; } @@ -18654,7 +18682,7 @@ var ts; }); return getSignatureInstantiation(signature, getInferredTypes(context)); } - function inferTypeArguments(signature, args, excludeArgument, context) { + function inferTypeArguments(node, signature, args, excludeArgument, context) { var typeParameters = signature.typeParameters; var inferenceMapper = createInferenceMapper(context); // Clear out all the inference results from the last time inferTypeArguments was called on this context @@ -18679,15 +18707,16 @@ var ts; } // We perform two passes over the arguments. In the first pass we infer from all arguments, but use // wildcards for all context sensitive function expressions. - for (var i = 0; i < args.length; i++) { - var arg = args[i]; - if (arg.kind !== 178 /* OmittedExpression */) { + var argCount = getEffectiveArgumentCount(node, args, signature); + for (var i = 0; i < argCount; i++) { + var arg = getEffectiveArgument(node, args, i); + // If the effective argument is 'undefined', then it is an argument that is present but is synthetic. + if (arg === undefined || arg.kind !== 178 /* OmittedExpression */) { var paramType = getTypeAtPosition(signature, i); - var argType = void 0; - if (i === 0 && args[i].parent.kind === 162 /* TaggedTemplateExpression */) { - argType = globalTemplateStringsArrayType; - } - else { + var argType = getEffectiveArgumentType(node, i, arg); + // If the effective argument type is 'undefined', there is no synthetic type + // for the argument. In that case, we should check the argument. + if (argType === undefined) { // For context sensitive arguments we pass the identityMapper, which is a signal to treat all // context sensitive function expressions as wildcards var mapper = excludeArgument && excludeArgument[i] !== undefined ? identityMapper : inferenceMapper; @@ -18699,8 +18728,10 @@ var ts; // In the second pass we visit only context sensitive arguments, and only those that aren't excluded, this // time treating function expressions normally (which may cause previously inferred type arguments to be fixed // as we construct types for contextually typed parameters) + // Decorators will not have `excludeArgument`, as their arguments cannot be contextually typed. + // Tagged template expressions will always have `undefined` for `excludeArgument[0]`. if (excludeArgument) { - for (var i = 0; i < args.length; i++) { + for (var i = 0; i < argCount; i++) { // No need to check for omitted args and template expressions, their exlusion value is always undefined if (excludeArgument[i] === false) { var arg = args[i]; @@ -18711,7 +18742,7 @@ var ts; } getInferredTypes(context); } - function checkTypeArguments(signature, typeArguments, typeArgumentResultTypes, reportErrors) { + function checkTypeArguments(signature, typeArguments, typeArgumentResultTypes, reportErrors, headMessage) { var typeParameters = signature.typeParameters; var typeArgumentsAreAssignable = true; for (var i = 0; i < typeParameters.length; i++) { @@ -18722,27 +18753,38 @@ var ts; if (typeArgumentsAreAssignable /* so far */) { var constraint = getConstraintOfTypeParameter(typeParameters[i]); if (constraint) { - typeArgumentsAreAssignable = checkTypeAssignableTo(typeArgument, constraint, reportErrors ? typeArgNode : undefined, ts.Diagnostics.Type_0_does_not_satisfy_the_constraint_1); + var errorInfo = void 0; + var typeArgumentHeadMessage = ts.Diagnostics.Type_0_does_not_satisfy_the_constraint_1; + if (reportErrors && headMessage) { + errorInfo = ts.chainDiagnosticMessages(errorInfo, typeArgumentHeadMessage); + typeArgumentHeadMessage = headMessage; + } + typeArgumentsAreAssignable = checkTypeAssignableTo(typeArgument, constraint, reportErrors ? typeArgNode : undefined, typeArgumentHeadMessage, errorInfo); } } } return typeArgumentsAreAssignable; } function checkApplicableSignature(node, args, signature, relation, excludeArgument, reportErrors) { - for (var i = 0; i < args.length; i++) { - var arg = args[i]; - if (arg.kind !== 178 /* OmittedExpression */) { + var argCount = getEffectiveArgumentCount(node, args, signature); + for (var i = 0; i < argCount; i++) { + var arg = getEffectiveArgument(node, args, i); + // If the effective argument is 'undefined', then it is an argument that is present but is synthetic. + if (arg === undefined || arg.kind !== 178 /* OmittedExpression */) { // Check spread elements against rest type (from arity check we know spread argument corresponds to a rest parameter) var paramType = getTypeAtPosition(signature, i); - // A tagged template expression provides a special first argument, and string literals get string literal types - // unless we're reporting errors - var argType = i === 0 && node.kind === 162 /* TaggedTemplateExpression */ - ? globalTemplateStringsArrayType - : arg.kind === 8 /* StringLiteral */ && !reportErrors + var argType = getEffectiveArgumentType(node, i, arg); + // If the effective argument type is 'undefined', there is no synthetic type + // for the argument. In that case, we should check the argument. + if (argType === undefined) { + argType = arg.kind === 8 /* StringLiteral */ && !reportErrors ? getStringLiteralType(arg) : checkExpressionWithContextualType(arg, paramType, excludeArgument && excludeArgument[i] ? identityMapper : undefined); + } // Use argument expression as error location when reporting errors - if (!checkTypeRelatedTo(argType, paramType, relation, reportErrors ? arg : undefined, ts.Diagnostics.Argument_of_type_0_is_not_assignable_to_parameter_of_type_1)) { + var errorNode = reportErrors ? getEffectiveArgumentErrorNode(node, i, arg) : undefined; + var headMessage = ts.Diagnostics.Argument_of_type_0_is_not_assignable_to_parameter_of_type_1; + if (!checkTypeRelatedTo(argType, paramType, relation, errorNode, headMessage)) { return false; } } @@ -18754,28 +18796,276 @@ var ts; * * If 'node' is a CallExpression or a NewExpression, then its argument list is returned. * If 'node' is a TaggedTemplateExpression, a new argument list is constructed from the substitution - * expressions, where the first element of the list is the template for error reporting purposes. + * expressions, where the first element of the list is `undefined`. + * If 'node' is a Decorator, the argument list will be `undefined`, and its arguments and types + * will be supplied from calls to `getEffectiveArgumentCount` and `getEffectiveArgumentType`. */ function getEffectiveCallArguments(node) { var args; if (node.kind === 162 /* TaggedTemplateExpression */) { var template = node.template; - args = [template]; + args = [undefined]; if (template.kind === 174 /* TemplateExpression */) { ts.forEach(template.templateSpans, function (span) { args.push(span.expression); }); } } + else if (node.kind === 132 /* Decorator */) { + // For a decorator, we return undefined as we will determine + // the number and types of arguments for a decorator using + // `getEffectiveArgumentCount` and `getEffectiveArgumentType` below. + return undefined; + } else { args = node.arguments || emptyArray; } return args; } - function resolveCall(node, signatures, candidatesOutArray) { + /** + * Returns the effective argument count for a node that works like a function invocation. + * If 'node' is a Decorator, the number of arguments is derived from the decoration + * target and the signature: + * If 'node.target' is a class declaration or class expression, the effective argument + * count is 1. + * If 'node.target' is a parameter declaration, the effective argument count is 3. + * If 'node.target' is a property declaration, the effective argument count is 2. + * If 'node.target' is a method or accessor declaration, the effective argument count + * is 3, although it can be 2 if the signature only accepts two arguments, allowing + * us to match a property decorator. + * Otherwise, the argument count is the length of the 'args' array. + */ + function getEffectiveArgumentCount(node, args, signature) { + if (node.kind === 132 /* Decorator */) { + switch (node.parent.kind) { + case 204 /* ClassDeclaration */: + case 177 /* ClassExpression */: + // A class decorator will have one argument (see `ClassDecorator` in core.d.ts) + return 1; + case 134 /* PropertyDeclaration */: + // A property declaration decorator will have two arguments (see + // `PropertyDecorator` in core.d.ts) + return 2; + case 136 /* MethodDeclaration */: + case 138 /* GetAccessor */: + case 139 /* SetAccessor */: + // A method or accessor declaration decorator will have two or three arguments (see + // `PropertyDecorator` and `MethodDecorator` in core.d.ts) + // If the method decorator signature only accepts a target and a key, we will only + // type check those arguments. + return signature.parameters.length >= 3 ? 3 : 2; + case 131 /* Parameter */: + // A parameter declaration decorator will have three arguments (see + // `ParameterDecorator` in core.d.ts) + return 3; + } + } + else { + return args.length; + } + } + /** + * Returns the effective type of the first argument to a decorator. + * If 'node' is a class declaration or class expression, the effective argument type + * is the type of the static side of the class. + * If 'node' is a parameter declaration, the effective argument type is either the type + * of the static or instance side of the class for the parameter's parent method, + * depending on whether the method is declared static. + * For a constructor, the type is always the type of the static side of the class. + * If 'node' is a property, method, or accessor declaration, the effective argument + * type is the type of the static or instance side of the parent class for class + * element, depending on whether the element is declared static. + */ + function getEffectiveDecoratorFirstArgumentType(node) { + // The first argument to a decorator is its `target`. + switch (node.kind) { + case 204 /* ClassDeclaration */: + case 177 /* ClassExpression */: + // For a class decorator, the `target` is the type of the class (e.g. the + // "static" or "constructor" side of the class) + var classSymbol = getSymbolOfNode(node); + return getTypeOfSymbol(classSymbol); + case 131 /* Parameter */: + // For a parameter decorator, the `target` is the parent type of the + // parameter's containing method. + node = node.parent; + if (node.kind === 137 /* Constructor */) { + var classSymbol_1 = getSymbolOfNode(node); + return getTypeOfSymbol(classSymbol_1); + } + // fall-through + case 134 /* PropertyDeclaration */: + case 136 /* MethodDeclaration */: + case 138 /* GetAccessor */: + case 139 /* SetAccessor */: + // For a property or method decorator, the `target` is the + // "static"-side type of the parent of the member if the member is + // declared "static"; otherwise, it is the "instance"-side type of the + // parent of the member. + return getParentTypeOfClassElement(node); + default: + ts.Debug.fail("Unsupported decorator target."); + return unknownType; + } + } + /** + * Returns the effective type for the second argument to a decorator. + * If 'node' is a parameter, its effective argument type is one of the following: + * If 'node.parent' is a constructor, the effective argument type is 'any', as we + * will emit `undefined`. + * If 'node.parent' is a member with an identifier, numeric, or string literal name, + * the effective argument type will be a string literal type for the member name. + * If 'node.parent' is a computed property name, the effective argument type will + * either be a symbol type or the string type. + * If 'node' is a member with an identifier, numeric, or string literal name, the + * effective argument type will be a string literal type for the member name. + * If 'node' is a computed property name, the effective argument type will either + * be a symbol type or the string type. + * A class decorator does not have a second argument type. + */ + function getEffectiveDecoratorSecondArgumentType(node) { + // The second argument to a decorator is its `propertyKey` + switch (node.kind) { + case 204 /* ClassDeclaration */: + ts.Debug.fail("Class decorators should not have a second synthetic argument."); + return unknownType; + case 131 /* Parameter */: + node = node.parent; + if (node.kind === 137 /* Constructor */) { + // For a constructor parameter decorator, the `propertyKey` will be `undefined`. + return anyType; + } + // For a non-constructor parameter decorator, the `propertyKey` will be either + // a string or a symbol, based on the name of the parameter's containing method. + // fall-through + case 134 /* PropertyDeclaration */: + case 136 /* MethodDeclaration */: + case 138 /* GetAccessor */: + case 139 /* SetAccessor */: + // The `propertyKey` for a property or method decorator will be a + // string literal type if the member name is an identifier, number, or string; + // otherwise, if the member name is a computed property name it will + // be either string or symbol. + var element = node; + switch (element.name.kind) { + case 65 /* Identifier */: + case 7 /* NumericLiteral */: + case 8 /* StringLiteral */: + return getStringLiteralType(element.name); + case 129 /* ComputedPropertyName */: + var nameType = checkComputedPropertyName(element.name); + if (allConstituentTypesHaveKind(nameType, 2097152 /* ESSymbol */)) { + return nameType; + } + else { + return stringType; + } + default: + ts.Debug.fail("Unsupported property name."); + return unknownType; + } + default: + ts.Debug.fail("Unsupported decorator target."); + return unknownType; + } + } + /** + * Returns the effective argument type for the third argument to a decorator. + * If 'node' is a parameter, the effective argument type is the number type. + * If 'node' is a method or accessor, the effective argument type is a + * `TypedPropertyDescriptor` instantiated with the type of the member. + * Class and property decorators do not have a third effective argument. + */ + function getEffectiveDecoratorThirdArgumentType(node) { + // The third argument to a decorator is either its `descriptor` for a method decorator + // or its `parameterIndex` for a paramter decorator + switch (node.kind) { + case 204 /* ClassDeclaration */: + ts.Debug.fail("Class decorators should not have a third synthetic argument."); + return unknownType; + case 131 /* Parameter */: + // The `parameterIndex` for a parameter decorator is always a number + return numberType; + case 134 /* PropertyDeclaration */: + ts.Debug.fail("Property decorators should not have a third synthetic argument."); + return unknownType; + case 136 /* MethodDeclaration */: + case 138 /* GetAccessor */: + case 139 /* SetAccessor */: + // The `descriptor` for a method decorator will be a `TypedPropertyDescriptor` + // for the type of the member. + var propertyType = getTypeOfNode(node); + return createTypedPropertyDescriptorType(propertyType); + default: + ts.Debug.fail("Unsupported decorator target."); + return unknownType; + } + } + /** + * Returns the effective argument type for the provided argument to a decorator. + */ + function getEffectiveDecoratorArgumentType(node, argIndex) { + if (argIndex === 0) { + return getEffectiveDecoratorFirstArgumentType(node.parent); + } + else if (argIndex === 1) { + return getEffectiveDecoratorSecondArgumentType(node.parent); + } + else if (argIndex === 2) { + return getEffectiveDecoratorThirdArgumentType(node.parent); + } + ts.Debug.fail("Decorators should not have a fourth synthetic argument."); + return unknownType; + } + /** + * Gets the effective argument type for an argument in a call expression. + */ + function getEffectiveArgumentType(node, argIndex, arg) { + // Decorators provide special arguments, a tagged template expression provides + // a special first argument, and string literals get string literal types + // unless we're reporting errors + if (node.kind === 132 /* Decorator */) { + return getEffectiveDecoratorArgumentType(node, argIndex); + } + else if (argIndex === 0 && node.kind === 162 /* TaggedTemplateExpression */) { + return globalTemplateStringsArrayType; + } + // This is not a synthetic argument, so we return 'undefined' + // to signal that the caller needs to check the argument. + return undefined; + } + /** + * Gets the effective argument expression for an argument in a call expression. + */ + function getEffectiveArgument(node, args, argIndex) { + // For a decorator or the first argument of a tagged template expression we return undefined. + if (node.kind === 132 /* Decorator */ || + (argIndex === 0 && node.kind === 162 /* TaggedTemplateExpression */)) { + return undefined; + } + return args[argIndex]; + } + /** + * Gets the error node to use when reporting errors for an effective argument. + */ + function getEffectiveArgumentErrorNode(node, argIndex, arg) { + if (node.kind === 132 /* Decorator */) { + // For a decorator, we use the expression of the decorator for error reporting. + return node.expression; + } + else if (argIndex === 0 && node.kind === 162 /* TaggedTemplateExpression */) { + // For a the first argument of a tagged template expression, we use the template of the tag for error reporting. + return node.template; + } + else { + return arg; + } + } + function resolveCall(node, signatures, candidatesOutArray, headMessage) { var isTaggedTemplate = node.kind === 162 /* TaggedTemplateExpression */; + var isDecorator = node.kind === 132 /* Decorator */; var typeArguments; - if (!isTaggedTemplate) { + if (!isTaggedTemplate && !isDecorator) { typeArguments = node.typeArguments; // We already perform checking on the type arguments on the class declaration itself. if (node.expression.kind !== 91 /* SuperKeyword */) { @@ -18786,7 +19076,7 @@ var ts; // reorderCandidates fills up the candidates array directly reorderCandidates(signatures, candidates); if (!candidates.length) { - error(node, ts.Diagnostics.Supplied_parameters_do_not_match_any_signature_of_call_target); + reportError(ts.Diagnostics.Supplied_parameters_do_not_match_any_signature_of_call_target); return resolveErrorCall(node); } var args = getEffectiveCallArguments(node); @@ -18801,13 +19091,20 @@ var ts; // // For a tagged template, then the first argument be 'undefined' if necessary // because it represents a TemplateStringsArray. + // + // For a decorator, no arguments are susceptible to contextual typing due to the fact + // decorators are applied to a declaration by the emitter, and not to an expression. var excludeArgument; - for (var i = isTaggedTemplate ? 1 : 0; i < args.length; i++) { - if (isContextSensitive(args[i])) { - if (!excludeArgument) { - excludeArgument = new Array(args.length); + if (!isDecorator) { + // We do not need to call `getEffectiveArgumentCount` here as it only + // applies when calculating the number of arguments for a decorator. + for (var i = isTaggedTemplate ? 1 : 0; i < args.length; i++) { + if (isContextSensitive(args[i])) { + if (!excludeArgument) { + excludeArgument = new Array(args.length); + } + excludeArgument[i] = true; } - excludeArgument[i] = true; } } // The following variables are captured and modified by calls to chooseOverload. @@ -18871,19 +19168,22 @@ var ts; checkApplicableSignature(node, args, candidateForArgumentError, assignableRelation, undefined, true); } else if (candidateForTypeArgumentError) { - if (!isTaggedTemplate && typeArguments) { - checkTypeArguments(candidateForTypeArgumentError, typeArguments, [], true); + if (!isTaggedTemplate && !isDecorator && typeArguments) { + checkTypeArguments(candidateForTypeArgumentError, node.typeArguments, [], true, headMessage); } else { ts.Debug.assert(resultOfFailedInference.failedTypeParameterIndex >= 0); var failedTypeParameter = candidateForTypeArgumentError.typeParameters[resultOfFailedInference.failedTypeParameterIndex]; var inferenceCandidates = getInferenceCandidates(resultOfFailedInference, resultOfFailedInference.failedTypeParameterIndex); var diagnosticChainHead = ts.chainDiagnosticMessages(undefined, ts.Diagnostics.The_type_argument_for_type_parameter_0_cannot_be_inferred_from_the_usage_Consider_specifying_the_type_arguments_explicitly, typeToString(failedTypeParameter)); + if (headMessage) { + diagnosticChainHead = ts.chainDiagnosticMessages(diagnosticChainHead, headMessage); + } reportNoCommonSupertypeError(inferenceCandidates, node.expression || node.tag, diagnosticChainHead); } } else { - error(node, ts.Diagnostics.Supplied_parameters_do_not_match_any_signature_of_call_target); + reportError(ts.Diagnostics.Supplied_parameters_do_not_match_any_signature_of_call_target); } // No signature was applicable. We have already reported the errors for the invalid signature. // If this is a type resolution session, e.g. Language Service, try to get better information that anySignature. @@ -18899,6 +19199,14 @@ var ts; } } return resolveErrorCall(node); + function reportError(message, arg0, arg1, arg2) { + var errorInfo; + errorInfo = ts.chainDiagnosticMessages(errorInfo, message, arg0, arg1, arg2); + if (headMessage) { + errorInfo = ts.chainDiagnosticMessages(errorInfo, headMessage); + } + diagnostics.add(ts.createDiagnosticForNodeFromMessageChain(node, errorInfo)); + } function chooseOverload(candidates, relation) { for (var _i = 0; _i < candidates.length; _i++) { var originalCandidate = candidates[_i]; @@ -18919,7 +19227,7 @@ var ts; typeArgumentsAreValid = checkTypeArguments(candidate, typeArguments, typeArgumentTypes, false); } else { - inferTypeArguments(candidate, args, excludeArgument, inferenceContext); + inferTypeArguments(node, candidate, args, excludeArgument, inferenceContext); typeArgumentsAreValid = inferenceContext.failedTypeParameterIndex === undefined; typeArgumentTypes = inferenceContext.inferredTypes; } @@ -18968,7 +19276,7 @@ var ts; if (superType !== unknownType) { // In super call, the candidate signatures are the matching arity signatures of the base constructor function instantiated // with the type arguments specified in the extends clause. - var baseTypeNode = ts.getClassExtendsHeritageClauseElement(ts.getAncestor(node, 204 /* ClassDeclaration */)); + var baseTypeNode = ts.getClassExtendsHeritageClauseElement(ts.getContainingClass(node)); var baseConstructors = getInstantiatedConstructorsForTypeArguments(superType, baseTypeNode.typeArguments); return resolveCall(node, baseConstructors, candidatesOutArray); } @@ -19082,6 +19390,47 @@ var ts; } return resolveCall(node, callSignatures, candidatesOutArray); } + /** + * Gets the localized diagnostic head message to use for errors when resolving a decorator as a call expression. + */ + function getDiagnosticHeadMessageForDecoratorResolution(node) { + switch (node.parent.kind) { + case 204 /* ClassDeclaration */: + case 177 /* ClassExpression */: + return ts.Diagnostics.Unable_to_resolve_signature_of_class_decorator_when_called_as_an_expression; + case 131 /* Parameter */: + return ts.Diagnostics.Unable_to_resolve_signature_of_parameter_decorator_when_called_as_an_expression; + case 134 /* PropertyDeclaration */: + return ts.Diagnostics.Unable_to_resolve_signature_of_property_decorator_when_called_as_an_expression; + case 136 /* MethodDeclaration */: + case 138 /* GetAccessor */: + case 139 /* SetAccessor */: + return ts.Diagnostics.Unable_to_resolve_signature_of_method_decorator_when_called_as_an_expression; + } + } + /** + * Resolves a decorator as if it were a call expression. + */ + function resolveDecorator(node, candidatesOutArray) { + var funcType = checkExpression(node.expression); + var apparentType = getApparentType(funcType); + if (apparentType === unknownType) { + return resolveErrorCall(node); + } + var callSignatures = getSignaturesOfType(apparentType, 0 /* Call */); + if (funcType === anyType || (!callSignatures.length && !(funcType.flags & 16384 /* Union */) && isTypeAssignableTo(funcType, globalFunctionType))) { + return resolveUntypedCall(node); + } + var headMessage = getDiagnosticHeadMessageForDecoratorResolution(node); + if (!callSignatures.length) { + var errorInfo; + errorInfo = ts.chainDiagnosticMessages(errorInfo, ts.Diagnostics.Cannot_invoke_an_expression_whose_type_lacks_a_call_signature); + errorInfo = ts.chainDiagnosticMessages(errorInfo, headMessage); + diagnostics.add(ts.createDiagnosticForNodeFromMessageChain(node, errorInfo)); + return resolveErrorCall(node); + } + return resolveCall(node, callSignatures, candidatesOutArray, headMessage); + } // candidatesOutArray is passed by signature help in the language service, and collectCandidates // must fill it up with the appropriate candidate signatures function getResolvedSignature(node, candidatesOutArray) { @@ -19101,6 +19450,9 @@ var ts; else if (node.kind === 162 /* TaggedTemplateExpression */) { links.resolvedSignature = resolveTaggedTemplateExpression(node, candidatesOutArray); } + else if (node.kind === 132 /* Decorator */) { + links.resolvedSignature = resolveDecorator(node, candidatesOutArray); + } else { ts.Debug.fail("Branch in 'getResolvedSignature' should be unreachable."); } @@ -19343,7 +19695,7 @@ var ts; if (node.type) { checkTypeAssignableTo(exprType, getTypeFromTypeNode(node.type), node.body, undefined); } - checkFunctionExpressionBodies(node.body); + checkFunctionAndClassExpressionBodies(node.body); } } } @@ -19807,7 +20159,7 @@ var ts; if (ts.isFunctionLike(parent) && current === parent.body) { return false; } - else if (current.kind === 204 /* ClassDeclaration */ || current.kind === 177 /* ClassExpression */) { + else if (ts.isClassLike(current)) { return true; } current = parent; @@ -20707,29 +21059,37 @@ var ts; } /** Check a decorator */ function checkDecorator(node) { - var expression = node.expression; - var exprType = checkExpression(expression); + var signature = getResolvedSignature(node); + var returnType = getReturnTypeOfSignature(signature); + if (returnType.flags & 1 /* Any */) { + return; + } + var expectedReturnType; + var headMessage = getDiagnosticHeadMessageForDecoratorResolution(node); + var errorInfo; switch (node.parent.kind) { case 204 /* ClassDeclaration */: var classSymbol = getSymbolOfNode(node.parent); var classConstructorType = getTypeOfSymbol(classSymbol); - var classDecoratorType = instantiateSingleCallFunctionType(getGlobalClassDecoratorType(), [classConstructorType]); - checkTypeAssignableTo(exprType, classDecoratorType, node); + expectedReturnType = getUnionType([classConstructorType, voidType]); + break; + case 131 /* Parameter */: + expectedReturnType = voidType; + errorInfo = ts.chainDiagnosticMessages(errorInfo, ts.Diagnostics.The_return_type_of_a_parameter_decorator_function_must_be_either_void_or_any); break; case 134 /* PropertyDeclaration */: - checkTypeAssignableTo(exprType, getGlobalPropertyDecoratorType(), node); + expectedReturnType = voidType; + errorInfo = ts.chainDiagnosticMessages(errorInfo, ts.Diagnostics.The_return_type_of_a_property_decorator_function_must_be_either_void_or_any); break; case 136 /* MethodDeclaration */: case 138 /* GetAccessor */: case 139 /* SetAccessor */: var methodType = getTypeOfNode(node.parent); - var methodDecoratorType = instantiateSingleCallFunctionType(getGlobalMethodDecoratorType(), [methodType]); - checkTypeAssignableTo(exprType, methodDecoratorType, node); - break; - case 131 /* Parameter */: - checkTypeAssignableTo(exprType, getGlobalParameterDecoratorType(), node); + var descriptorType = createTypedPropertyDescriptorType(methodType); + expectedReturnType = getUnionType([descriptorType, voidType]); break; } + checkTypeAssignableTo(returnType, expectedReturnType, node, headMessage, errorInfo); } /** Checks a type reference node as an expression. */ function checkTypeNodeAsExpression(node) { @@ -20880,7 +21240,7 @@ var ts; } ts.forEach(node.statements, checkSourceElement); if (ts.isFunctionBlock(node) || node.kind === 209 /* ModuleBlock */) { - checkFunctionExpressionBodies(node); + checkFunctionAndClassExpressionBodies(node); } } function checkCollisionWithArgumentsInGeneratedCode(node) { @@ -20945,7 +21305,7 @@ var ts; return; } // bubble up and find containing type - var enclosingClass = ts.getAncestor(node, 204 /* ClassDeclaration */); + var enclosingClass = ts.getContainingClass(node); // if containing type was not found or it is ambient - exit (no codegen) if (!enclosingClass || ts.isInAmbientContext(enclosingClass)) { return; @@ -21650,7 +22010,7 @@ var ts; checkIndexConstraintForProperty(prop, propType, type, declaredStringIndexer, stringIndexType, 0 /* String */); checkIndexConstraintForProperty(prop, propType, type, declaredNumberIndexer, numberIndexType, 1 /* Number */); }); - if (type.flags & 1024 /* Class */ && type.symbol.valueDeclaration.kind === 204 /* ClassDeclaration */) { + if (type.flags & 1024 /* Class */ && ts.isClassLike(type.symbol.valueDeclaration)) { var classDeclaration = type.symbol.valueDeclaration; for (var _i = 0, _a = classDeclaration.members; _i < _a.length; _i++) { var member = _a[_i]; @@ -21739,15 +22099,17 @@ var ts; } } function checkClassExpression(node) { - grammarErrorOnNode(node, ts.Diagnostics.class_expressions_are_not_currently_supported); - ts.forEach(node.members, checkSourceElement); - return unknownType; + checkClassLikeDeclaration(node); + return getTypeOfSymbol(getSymbolOfNode(node)); } function checkClassDeclaration(node) { - // Grammar checking if (!node.name && !(node.flags & 256 /* Default */)) { grammarErrorOnFirstToken(node, ts.Diagnostics.A_class_declaration_without_the_default_modifier_must_have_a_name); } + checkClassLikeDeclaration(node); + ts.forEach(node.members, checkSourceElement); + } + function checkClassLikeDeclaration(node) { checkGrammarClassDeclarationHeritageClauses(node); checkDecorators(node); if (node.name) { @@ -21812,7 +22174,6 @@ var ts; } }); } - ts.forEach(node.members, checkSourceElement); if (produceDiagnostics) { checkIndexConstraints(type); checkTypeForDuplicateIndexSignatures(node); @@ -22608,8 +22969,8 @@ var ts; return checkMissingDeclaration(node); } } - // Function expression bodies are checked after all statements in the enclosing body. This is to ensure - // constructs like the following are permitted: + // Function and class expression bodies are checked after all statements in the enclosing body. This is + // to ensure constructs like the following are permitted: // let foo = function () { // let s = foo(); // return "hello"; @@ -22617,17 +22978,20 @@ var ts; // Here, performing a full type check of the body of the function expression whilst in the process of // determining the type of foo would cause foo to be given type any because of the recursive reference. // Delaying the type check of the body ensures foo has been assigned a type. - function checkFunctionExpressionBodies(node) { + function checkFunctionAndClassExpressionBodies(node) { switch (node.kind) { case 165 /* FunctionExpression */: case 166 /* ArrowFunction */: - ts.forEach(node.parameters, checkFunctionExpressionBodies); + ts.forEach(node.parameters, checkFunctionAndClassExpressionBodies); checkFunctionExpressionOrObjectLiteralMethodBody(node); break; + case 177 /* ClassExpression */: + ts.forEach(node.members, checkSourceElement); + break; case 136 /* MethodDeclaration */: case 135 /* MethodSignature */: - ts.forEach(node.decorators, checkFunctionExpressionBodies); - ts.forEach(node.parameters, checkFunctionExpressionBodies); + ts.forEach(node.decorators, checkFunctionAndClassExpressionBodies); + ts.forEach(node.parameters, checkFunctionAndClassExpressionBodies); if (ts.isObjectLiteralMethod(node)) { checkFunctionExpressionOrObjectLiteralMethodBody(node); } @@ -22636,10 +23000,10 @@ var ts; case 138 /* GetAccessor */: case 139 /* SetAccessor */: case 203 /* FunctionDeclaration */: - ts.forEach(node.parameters, checkFunctionExpressionBodies); + ts.forEach(node.parameters, checkFunctionAndClassExpressionBodies); break; case 195 /* WithStatement */: - checkFunctionExpressionBodies(node.expression); + checkFunctionAndClassExpressionBodies(node.expression); break; case 132 /* Decorator */: case 131 /* Parameter */: @@ -22696,7 +23060,7 @@ var ts; case 229 /* EnumMember */: case 217 /* ExportAssignment */: case 230 /* SourceFile */: - ts.forEachChild(node, checkFunctionExpressionBodies); + ts.forEachChild(node, checkFunctionAndClassExpressionBodies); break; } } @@ -22721,7 +23085,7 @@ var ts; emitParam = false; potentialThisCollisions.length = 0; ts.forEach(node.statements, checkSourceElement); - checkFunctionExpressionBodies(node); + checkFunctionAndClassExpressionBodies(node); if (ts.isExternalModule(node)) { checkExternalModuleExports(node); } @@ -22796,6 +23160,11 @@ var ts; case 207 /* EnumDeclaration */: copySymbols(getSymbolOfNode(location).exports, meaning & 8 /* EnumMember */); break; + case 177 /* ClassExpression */: + if (location.name) { + copySymbol(location.symbol, meaning); + } + // Fall through case 204 /* ClassDeclaration */: case 205 /* InterfaceDeclaration */: if (!(memberFlags & 128 /* Static */)) { @@ -22831,41 +23200,6 @@ var ts; } } } - if (isInsideWithStatementBody(location)) { - // We cannot answer semantic questions within a with block, do not proceed any further - return []; - } - while (location) { - if (location.locals && !isGlobalSourceFile(location)) { - copySymbols(location.locals, meaning); - } - switch (location.kind) { - case 230 /* SourceFile */: - if (!ts.isExternalModule(location)) - break; - case 208 /* ModuleDeclaration */: - copySymbols(getSymbolOfNode(location).exports, meaning & 8914931 /* ModuleMember */); - break; - case 207 /* EnumDeclaration */: - copySymbols(getSymbolOfNode(location).exports, meaning & 8 /* EnumMember */); - break; - case 204 /* ClassDeclaration */: - case 205 /* InterfaceDeclaration */: - if (!(memberFlags & 128 /* Static */)) { - copySymbols(getSymbolOfNode(location).members, meaning & 793056 /* Type */); - } - break; - case 165 /* FunctionExpression */: - if (location.name) { - copySymbol(location.symbol, meaning); - } - break; - } - memberFlags = location.flags; - location = location.parent; - } - copySymbols(globals, meaning); - return symbolsToArray(symbols); } function isTypeDeclarationName(name) { return name.kind === 65 /* Identifier */ && @@ -22967,6 +23301,9 @@ var ts; meaning |= 8388608 /* Alias */; return resolveEntityName(entityName, meaning); } + if (entityName.parent.kind === 143 /* TypePredicate */) { + return resolveEntityName(entityName, 1 /* FunctionScopedVariable */); + } // Do we want to return undefined here? return undefined; } @@ -23081,6 +23418,16 @@ var ts; } return checkExpression(expr); } + /** + * Gets either the static or instance type of a class element, based on + * whether the element is declared as "static". + */ + function getParentTypeOfClassElement(node) { + var classSymbol = getSymbolOfNode(node.parent); + return node.flags & 128 /* Static */ + ? getTypeOfSymbol(classSymbol) + : getDeclaredTypeOfSymbol(classSymbol); + } // Return the list of properties of the given type, augmented with properties from Function // if the type has call or construct signatures function getAugmentedPropertiesOfType(type) { @@ -23566,10 +23913,7 @@ var ts; globalNumberType = getGlobalType("Number"); globalBooleanType = getGlobalType("Boolean"); globalRegExpType = getGlobalType("RegExp"); - getGlobalClassDecoratorType = ts.memoize(function () { return getGlobalType("ClassDecorator"); }); - getGlobalPropertyDecoratorType = ts.memoize(function () { return getGlobalType("PropertyDecorator"); }); - getGlobalMethodDecoratorType = ts.memoize(function () { return getGlobalType("MethodDecorator"); }); - getGlobalParameterDecoratorType = ts.memoize(function () { return getGlobalType("ParameterDecorator"); }); + getGlobalTypedPropertyDescriptorType = ts.memoize(function () { return getGlobalType("TypedPropertyDescriptor", 1); }); // If we're in ES6 mode, load the TemplateStringsArray. // Otherwise, default to 'unknown' for the purposes of type checking in LS scenarios. if (languageVersion >= 2 /* ES6 */) { @@ -24132,7 +24476,7 @@ var ts; return grammarErrorAtPos(getSourceFile(node), node.end - 1, ";".length, ts.Diagnostics._0_expected, "{"); } } - if (node.parent.kind === 204 /* ClassDeclaration */) { + if (ts.isClassLike(node.parent)) { if (checkGrammarForInvalidQuestionMark(node, node.questionToken, ts.Diagnostics.A_class_member_cannot_be_declared_optional)) { return true; } @@ -24390,7 +24734,7 @@ var ts; } } function checkGrammarProperty(node) { - if (node.parent.kind === 204 /* ClassDeclaration */) { + if (ts.isClassLike(node.parent)) { if (checkGrammarForInvalidQuestionMark(node, node.questionToken, ts.Diagnostics.A_class_member_cannot_be_declared_optional) || checkGrammarForNonSymbolComputedProperty(node.name, ts.Diagnostics.A_computed_property_name_in_a_class_property_declaration_must_directly_refer_to_a_built_in_symbol)) { return true; @@ -26121,6 +26465,9 @@ var ts; function generateNameForExportDefault() { return makeUniqueName("default"); } + function generateNameForClassExpression() { + return makeUniqueName("class"); + } function generateNameForNode(node) { switch (node.kind) { case 65 /* Identifier */: @@ -26133,9 +26480,10 @@ var ts; return generateNameForImportOrExportDeclaration(node); case 203 /* FunctionDeclaration */: case 204 /* ClassDeclaration */: - case 177 /* ClassExpression */: case 217 /* ExportAssignment */: return generateNameForExportDefault(); + case 177 /* ClassExpression */: + return generateNameForClassExpression(); } } function getGeneratedNameForNode(node) { @@ -37159,6 +37507,10 @@ var ts; if (actualIndentation !== -1 /* Unknown */) { return actualIndentation; } + actualIndentation = getLineIndentationWhenExpressionIsInMultiLine(current, sourceFile, options); + if (actualIndentation !== -1 /* Unknown */) { + return actualIndentation + options.IndentSize; + } previous = current; current = current.parent; } @@ -37201,6 +37553,10 @@ var ts; if (actualIndentation !== -1 /* Unknown */) { return actualIndentation + indentationDelta; } + actualIndentation = getLineIndentationWhenExpressionIsInMultiLine(current, sourceFile, options); + if (actualIndentation !== -1 /* Unknown */) { + return actualIndentation + indentationDelta; + } } // increase indentation if parent node wants its content to be indented and parent and child nodes don't start on the same line if (shouldIndentChildNode(parent.kind, current.kind) && !parentAndChildShareLine) { @@ -37338,6 +37694,44 @@ var ts; return index !== -1 ? deriveActualIndentationFromList(list, index, sourceFile, options) : -1 /* Unknown */; } } + function getLineIndentationWhenExpressionIsInMultiLine(node, sourceFile, options) { + // actual indentation should not be used when: + // - node is close parenthesis - this is the end of the expression + if (node.kind === 17 /* CloseParenToken */) { + return -1 /* Unknown */; + } + if (node.parent && (node.parent.kind === 160 /* CallExpression */ || + node.parent.kind === 161 /* NewExpression */) && + node.parent.expression !== node) { + var fullCallOrNewExpression = node.parent.expression; + var startingExpression = getStartingExpression(fullCallOrNewExpression); + if (fullCallOrNewExpression === startingExpression) { + return -1 /* Unknown */; + } + var fullCallOrNewExpressionEnd = sourceFile.getLineAndCharacterOfPosition(fullCallOrNewExpression.end); + var startingExpressionEnd = sourceFile.getLineAndCharacterOfPosition(startingExpression.end); + if (fullCallOrNewExpressionEnd.line === startingExpressionEnd.line) { + return -1 /* Unknown */; + } + return findColumnForFirstNonWhitespaceCharacterInLine(fullCallOrNewExpressionEnd, sourceFile, options); + } + return -1 /* Unknown */; + function getStartingExpression(node) { + while (true) { + switch (node.kind) { + case 160 /* CallExpression */: + case 161 /* NewExpression */: + case 158 /* PropertyAccessExpression */: + case 159 /* ElementAccessExpression */: + node = node.expression; + break; + default: + return node; + } + } + return node; + } + } function deriveActualIndentationFromList(list, index, sourceFile, options) { ts.Debug.assert(index >= 0 && index < list.length); var node = list[index]; @@ -42395,6 +42789,9 @@ var ts; } } function classifyToken(token) { + if (ts.nodeIsMissing(token)) { + return; + } var tokenStart = classifyLeadingTriviaAndGetTokenStart(token); var tokenWidth = token.end - tokenStart; ts.Debug.assert(tokenWidth >= 0); diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index eaad8593eee..e403ed994e5 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -630,7 +630,7 @@ namespace ts { function getStrictModeIdentifierMessage(node: Node) { // Provide specialized messages to help the user understand why we think they're in // strict mode. - if (getAncestor(node, SyntaxKind.ClassDeclaration) || getAncestor(node, SyntaxKind.ClassExpression)) { + if (getContainingClass(node)) { return Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode_Class_definitions_are_automatically_in_strict_mode; } @@ -688,7 +688,7 @@ namespace ts { function getStrictModeEvalOrArgumentsMessage(node: Node) { // Provide specialized messages to help the user understand why we think they're in // strict mode. - if (getAncestor(node, SyntaxKind.ClassDeclaration) || getAncestor(node, SyntaxKind.ClassExpression)) { + if (getContainingClass(node)) { return Diagnostics.Invalid_use_of_0_Class_definitions_are_automatically_in_strict_mode; } @@ -1031,7 +1031,7 @@ namespace ts { // containing class. if (node.flags & NodeFlags.AccessibilityModifier && node.parent.kind === SyntaxKind.Constructor && - (node.parent.parent.kind === SyntaxKind.ClassDeclaration || node.parent.parent.kind === SyntaxKind.ClassExpression)) { + isClassLike(node.parent.parent)) { let classDeclaration = node.parent.parent; declareSymbol(classDeclaration.symbol.members, classDeclaration.symbol, node, SymbolFlags.Property, SymbolFlags.PropertyExcludes); diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 019fd8faf36..7f65ed7d506 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -128,6 +128,7 @@ namespace ts { let getGlobalParameterDecoratorType: () => ObjectType; let getGlobalPropertyDecoratorType: () => ObjectType; let getGlobalMethodDecoratorType: () => ObjectType; + let getGlobalTypedPropertyDescriptorType: () => ObjectType; let tupleTypes: Map = {}; let unionTypes: Map = {}; @@ -425,8 +426,8 @@ namespace ts { // local variables of the constructor. This effectively means that entities from outer scopes // by the same name as a constructor parameter or local variable are inaccessible // in initializer expressions for instance member variables. - if (location.parent.kind === SyntaxKind.ClassDeclaration && !(location.flags & NodeFlags.Static)) { - let ctor = findConstructorDeclaration(location.parent); + if (isClassLike(location.parent) && !(location.flags & NodeFlags.Static)) { + let ctor = findConstructorDeclaration(location.parent); if (ctor && ctor.locals) { if (getSymbol(ctor.locals, name, meaning & SymbolFlags.Value)) { // Remember the property node, it will be used later to report appropriate error @@ -436,6 +437,7 @@ namespace ts { } break; case SyntaxKind.ClassDeclaration: + case SyntaxKind.ClassExpression: case SyntaxKind.InterfaceDeclaration: if (result = getSymbol(getSymbolOfNode(location).members, name, meaning & SymbolFlags.Type)) { if (lastLocation && lastLocation.flags & NodeFlags.Static) { @@ -447,6 +449,13 @@ namespace ts { } break loop; } + if (location.kind === SyntaxKind.ClassExpression && meaning & SymbolFlags.Class) { + let className = (location).name; + if (className && name === className.text) { + result = location.symbol; + break loop; + } + } break; // It is not legal to reference a class's own type parameters from a computed property name that @@ -459,7 +468,7 @@ namespace ts { // case SyntaxKind.ComputedPropertyName: grandparent = location.parent.parent; - if (grandparent.kind === SyntaxKind.ClassDeclaration || grandparent.kind === SyntaxKind.InterfaceDeclaration) { + if (isClassLike(grandparent) || grandparent.kind === SyntaxKind.InterfaceDeclaration) { // A reference to this grandparent's type parameters would be an error if (result = getSymbol(getSymbolOfNode(grandparent).members, name, meaning & SymbolFlags.Type)) { error(errorLocation, Diagnostics.A_computed_property_name_cannot_reference_a_type_parameter_from_its_containing_type); @@ -493,15 +502,6 @@ namespace ts { } } break; - case SyntaxKind.ClassExpression: - if (meaning & SymbolFlags.Class) { - let className = (location).name; - if (className && name === className.text) { - result = location.symbol; - break loop; - } - } - break; case SyntaxKind.Decorator: // Decorators are resolved at the class declaration. Resolving at the parameter // or member would result in looking up locals in the method. @@ -1048,7 +1048,7 @@ namespace ts { return false; } - function findConstructorDeclaration(node: ClassDeclaration): ConstructorDeclaration { + function findConstructorDeclaration(node: ClassLikeDeclaration): ConstructorDeclaration { let members = node.members; for (let member of members) { if (member.kind === SyntaxKind.Constructor && nodeIsPresent((member).body)) { @@ -1435,20 +1435,30 @@ namespace ts { // This is for caching the result of getSymbolDisplayBuilder. Do not access directly. let _displayBuilder: SymbolDisplayBuilder; function getSymbolDisplayBuilder(): SymbolDisplayBuilder { + + function getNameOfSymbol(symbol: Symbol): string { + if (symbol.declarations && symbol.declarations.length) { + let declaration = symbol.declarations[0]; + if (declaration.name) { + return declarationNameToString(declaration.name); + } + switch (declaration.kind) { + case SyntaxKind.ClassExpression: + return "(Anonymous class)"; + case SyntaxKind.FunctionExpression: + case SyntaxKind.ArrowFunction: + return "(Anonymous function)"; + } + } + return symbol.name; + } + /** * Writes only the name of the symbol out to the writer. Uses the original source text * for the name of the symbol if it is available to match how the user inputted the name. */ function appendSymbolNameOnly(symbol: Symbol, writer: SymbolWriter): void { - if (symbol.declarations && symbol.declarations.length > 0) { - let declaration = symbol.declarations[0]; - if (declaration.name) { - writer.writeSymbol(declarationNameToString(declaration.name), symbol); - return; - } - } - - writer.writeSymbol(symbol.name, symbol); + writer.writeSymbol(getNameOfSymbol(symbol), symbol); } /** @@ -2601,10 +2611,10 @@ namespace ts { if (!node) { return typeParameters; } - if (node.kind === SyntaxKind.ClassDeclaration || node.kind === SyntaxKind.FunctionDeclaration || - node.kind === SyntaxKind.FunctionExpression || node.kind === SyntaxKind.MethodDeclaration || - node.kind === SyntaxKind.ArrowFunction) { - let declarations = (node).typeParameters; + if (node.kind === SyntaxKind.ClassDeclaration || node.kind === SyntaxKind.ClassExpression || + node.kind === SyntaxKind.FunctionDeclaration || node.kind === SyntaxKind.FunctionExpression || + node.kind === SyntaxKind.MethodDeclaration || node.kind === SyntaxKind.ArrowFunction) { + let declarations = (node).typeParameters; if (declarations) { return appendTypeParameters(appendOuterTypeParameters(typeParameters, node), declarations); } @@ -2614,8 +2624,8 @@ namespace ts { // The outer type parameters are those defined by enclosing generic classes, methods, or functions. function getOuterTypeParametersOfClassOrInterface(symbol: Symbol): TypeParameter[] { - var kind = symbol.flags & SymbolFlags.Class ? SyntaxKind.ClassDeclaration : SyntaxKind.InterfaceDeclaration; - return appendOuterTypeParameters(undefined, getDeclarationOfKind(symbol, kind)); + var declaration = symbol.flags & SymbolFlags.Class ? symbol.valueDeclaration : getDeclarationOfKind(symbol, SyntaxKind.InterfaceDeclaration); + return appendOuterTypeParameters(undefined, declaration); } // The local type parameters are the combined set of type parameters from all declarations of the class, @@ -2623,7 +2633,8 @@ namespace ts { function getLocalTypeParametersOfClassOrInterfaceOrTypeAlias(symbol: Symbol): TypeParameter[] { let result: TypeParameter[]; for (let node of symbol.declarations) { - if (node.kind === SyntaxKind.InterfaceDeclaration || node.kind === SyntaxKind.ClassDeclaration || node.kind === SyntaxKind.TypeAliasDeclaration) { + if (node.kind === SyntaxKind.InterfaceDeclaration || node.kind === SyntaxKind.ClassDeclaration || + node.kind === SyntaxKind.ClassExpression || node.kind === SyntaxKind.TypeAliasDeclaration) { let declaration = node; if (declaration.typeParameters) { result = appendTypeParameters(result, declaration.typeParameters); @@ -3525,7 +3536,6 @@ namespace ts { let syntaxKind = kind === IndexKind.Number ? SyntaxKind.NumberKeyword : SyntaxKind.StringKeyword; let indexSymbol = getIndexSymbol(symbol); if (indexSymbol) { - let len = indexSymbol.declarations.length; for (let decl of indexSymbol.declarations) { let node = decl; if (node.parameters.length === 1) { @@ -3807,6 +3817,16 @@ namespace ts { return globalESSymbolConstructorSymbol || (globalESSymbolConstructorSymbol = getGlobalValueSymbol("Symbol")); } + /** + * Creates a TypeReference for a generic `TypedPropertyDescriptor`. + */ + function createTypedPropertyDescriptorType(propertyType: Type): Type { + let globalTypedPropertyDescriptorType = getGlobalTypedPropertyDescriptorType(); + return globalTypedPropertyDescriptorType !== emptyObjectType + ? createTypeReference(globalTypedPropertyDescriptorType, [propertyType]) + : emptyObjectType; + } + /** * Instantiates a global type that is generic with some element type, and returns that instantiation. */ @@ -5937,9 +5957,9 @@ namespace ts { } function captureLexicalThis(node: Node, container: Node): void { - let classNode = container.parent && container.parent.kind === SyntaxKind.ClassDeclaration ? container.parent : undefined; getNodeLinks(node).flags |= NodeCheckFlags.LexicalThis; if (container.kind === SyntaxKind.PropertyDeclaration || container.kind === SyntaxKind.Constructor) { + let classNode = container.parent; getNodeLinks(classNode).flags |= NodeCheckFlags.CaptureThis; } else { @@ -5992,9 +6012,8 @@ namespace ts { captureLexicalThis(node, container); } - let classNode = container.parent && container.parent.kind === SyntaxKind.ClassDeclaration ? container.parent : undefined; - if (classNode) { - let symbol = getSymbolOfNode(classNode); + if (isClassLike(container.parent)) { + let symbol = getSymbolOfNode(container.parent); return container.flags & NodeFlags.Static ? getTypeOfSymbol(symbol) : getDeclaredTypeOfSymbol(symbol); } return anyType; @@ -6011,7 +6030,7 @@ namespace ts { function checkSuperExpression(node: Node): Type { let isCallExpression = node.parent.kind === SyntaxKind.CallExpression && (node.parent).expression === node; - let classDeclaration = getAncestor(node, SyntaxKind.ClassDeclaration); + let classDeclaration = getContainingClass(node); let classType = classDeclaration && getDeclaredTypeOfSymbol(getSymbolOfNode(classDeclaration)); let baseClassType = classType && getBaseTypes(classType)[0]; @@ -6046,7 +6065,7 @@ namespace ts { } // topmost container must be something that is directly nested in the class declaration - if (container && container.parent && container.parent.kind === SyntaxKind.ClassDeclaration) { + if (container && isClassLike(container.parent)) { if (container.flags & NodeFlags.Static) { canUseSuperExpression = container.kind === SyntaxKind.MethodDeclaration || @@ -7157,7 +7176,7 @@ namespace ts { } // Property is known to be private or protected at this point // Get the declaring and enclosing class instance types - let enclosingClassDeclaration = getAncestor(node, SyntaxKind.ClassDeclaration); + let enclosingClassDeclaration = getContainingClass(node); let enclosingClass = enclosingClassDeclaration ? getDeclaredTypeOfSymbol(getSymbolOfNode(enclosingClassDeclaration)) : undefined; let declaringClass = getDeclaredTypeOfSymbol(prop.parent); // Private property is accessible if declaring and enclosing class are the same @@ -7412,7 +7431,7 @@ namespace ts { if (node.kind === SyntaxKind.TaggedTemplateExpression) { checkExpression((node).template); } - else { + else if (node.kind !== SyntaxKind.Decorator) { forEach((node).arguments, argument => { checkExpression(argument); }); @@ -7481,7 +7500,8 @@ namespace ts { function getSpreadArgumentIndex(args: Expression[]): number { for (let i = 0; i < args.length; i++) { - if (args[i].kind === SyntaxKind.SpreadElementExpression) { + let arg = args[i]; + if (arg && arg.kind === SyntaxKind.SpreadElementExpression) { return i; } } @@ -7492,7 +7512,9 @@ namespace ts { let adjustedArgCount: number; // Apparent number of arguments we will have in this call let typeArguments: NodeArray; // Type arguments (undefined if none) let callIsIncomplete: boolean; // In incomplete call we want to be lenient when we have too few arguments - + let isDecorator: boolean; + let spreadArgIndex = -1; + if (node.kind === SyntaxKind.TaggedTemplateExpression) { let tagExpression = node; @@ -7518,6 +7540,11 @@ namespace ts { callIsIncomplete = !!templateLiteral.isUnterminated; } } + else if (node.kind === SyntaxKind.Decorator) { + isDecorator = true; + typeArguments = undefined; + adjustedArgCount = getEffectiveArgumentCount(node, /*args*/ undefined, signature); + } else { let callExpression = node; if (!callExpression.arguments) { @@ -7534,6 +7561,7 @@ namespace ts { callIsIncomplete = (callExpression).arguments.end === callExpression.end; typeArguments = callExpression.typeArguments; + spreadArgIndex = getSpreadArgumentIndex(args); } // If the user supplied type arguments, but the number of type arguments does not match @@ -7546,7 +7574,6 @@ namespace ts { // If spread arguments are present, check that they correspond to a rest parameter. If so, no // further checking is necessary. - let spreadArgIndex = getSpreadArgumentIndex(args); if (spreadArgIndex >= 0) { return signature.hasRestParameter && spreadArgIndex >= signature.parameters.length - 1; } @@ -7583,7 +7610,7 @@ namespace ts { return getSignatureInstantiation(signature, getInferredTypes(context)); } - function inferTypeArguments(signature: Signature, args: Expression[], excludeArgument: boolean[], context: InferenceContext): void { + function inferTypeArguments(node: CallLikeExpression, signature: Signature, args: Expression[], excludeArgument: boolean[], context: InferenceContext): void { let typeParameters = signature.typeParameters; let inferenceMapper = createInferenceMapper(context); @@ -7611,20 +7638,23 @@ namespace ts { // We perform two passes over the arguments. In the first pass we infer from all arguments, but use // wildcards for all context sensitive function expressions. - for (let i = 0; i < args.length; i++) { - let arg = args[i]; - if (arg.kind !== SyntaxKind.OmittedExpression) { + let argCount = getEffectiveArgumentCount(node, args, signature); + for (let i = 0; i < argCount; i++) { + let arg = getEffectiveArgument(node, args, i); + // If the effective argument is 'undefined', then it is an argument that is present but is synthetic. + if (arg === undefined || arg.kind !== SyntaxKind.OmittedExpression) { let paramType = getTypeAtPosition(signature, i); - let argType: Type; - if (i === 0 && args[i].parent.kind === SyntaxKind.TaggedTemplateExpression) { - argType = globalTemplateStringsArrayType; - } - else { + let argType = getEffectiveArgumentType(node, i, arg); + + // If the effective argument type is 'undefined', there is no synthetic type + // for the argument. In that case, we should check the argument. + if (argType === undefined) { // For context sensitive arguments we pass the identityMapper, which is a signal to treat all // context sensitive function expressions as wildcards let mapper = excludeArgument && excludeArgument[i] !== undefined ? identityMapper : inferenceMapper; argType = checkExpressionWithContextualType(arg, paramType, mapper); } + inferTypes(context, argType, paramType); } } @@ -7632,8 +7662,10 @@ namespace ts { // In the second pass we visit only context sensitive arguments, and only those that aren't excluded, this // time treating function expressions normally (which may cause previously inferred type arguments to be fixed // as we construct types for contextually typed parameters) + // Decorators will not have `excludeArgument`, as their arguments cannot be contextually typed. + // Tagged template expressions will always have `undefined` for `excludeArgument[0]`. if (excludeArgument) { - for (let i = 0; i < args.length; i++) { + for (let i = 0; i < argCount; i++) { // No need to check for omitted args and template expressions, their exlusion value is always undefined if (excludeArgument[i] === false) { let arg = args[i]; @@ -7646,7 +7678,7 @@ namespace ts { getInferredTypes(context); } - function checkTypeArguments(signature: Signature, typeArguments: TypeNode[], typeArgumentResultTypes: Type[], reportErrors: boolean): boolean { + function checkTypeArguments(signature: Signature, typeArguments: TypeNode[], typeArgumentResultTypes: Type[], reportErrors: boolean, headMessage?: DiagnosticMessage): boolean { let typeParameters = signature.typeParameters; let typeArgumentsAreAssignable = true; for (let i = 0; i < typeParameters.length; i++) { @@ -7657,35 +7689,53 @@ namespace ts { if (typeArgumentsAreAssignable /* so far */) { let constraint = getConstraintOfTypeParameter(typeParameters[i]); if (constraint) { - typeArgumentsAreAssignable = checkTypeAssignableTo(typeArgument, constraint, reportErrors ? typeArgNode : undefined, - Diagnostics.Type_0_does_not_satisfy_the_constraint_1); + let errorInfo: DiagnosticMessageChain; + let typeArgumentHeadMessage = Diagnostics.Type_0_does_not_satisfy_the_constraint_1; + if (reportErrors && headMessage) { + errorInfo = chainDiagnosticMessages(errorInfo, typeArgumentHeadMessage); + typeArgumentHeadMessage = headMessage; + } + + typeArgumentsAreAssignable = checkTypeAssignableTo( + typeArgument, + constraint, + reportErrors ? typeArgNode : undefined, + typeArgumentHeadMessage, + errorInfo); } } } + return typeArgumentsAreAssignable; } function checkApplicableSignature(node: CallLikeExpression, args: Expression[], signature: Signature, relation: Map, excludeArgument: boolean[], reportErrors: boolean) { - for (let i = 0; i < args.length; i++) { - let arg = args[i]; - if (arg.kind !== SyntaxKind.OmittedExpression) { + let argCount = getEffectiveArgumentCount(node, args, signature); + for (let i = 0; i < argCount; i++) { + let arg = getEffectiveArgument(node, args, i); + // If the effective argument is 'undefined', then it is an argument that is present but is synthetic. + if (arg === undefined || arg.kind !== SyntaxKind.OmittedExpression) { // Check spread elements against rest type (from arity check we know spread argument corresponds to a rest parameter) let paramType = getTypeAtPosition(signature, i); - // A tagged template expression provides a special first argument, and string literals get string literal types - // unless we're reporting errors - let argType = i === 0 && node.kind === SyntaxKind.TaggedTemplateExpression - ? globalTemplateStringsArrayType - : arg.kind === SyntaxKind.StringLiteral && !reportErrors + let argType = getEffectiveArgumentType(node, i, arg); + + // If the effective argument type is 'undefined', there is no synthetic type + // for the argument. In that case, we should check the argument. + if (argType === undefined) { + argType = arg.kind === SyntaxKind.StringLiteral && !reportErrors ? getStringLiteralType(arg) : checkExpressionWithContextualType(arg, paramType, excludeArgument && excludeArgument[i] ? identityMapper : undefined); + } // Use argument expression as error location when reporting errors - if (!checkTypeRelatedTo(argType, paramType, relation, reportErrors ? arg : undefined, - Diagnostics.Argument_of_type_0_is_not_assignable_to_parameter_of_type_1)) { + let errorNode = reportErrors ? getEffectiveArgumentErrorNode(node, i, arg) : undefined; + let headMessage = Diagnostics.Argument_of_type_0_is_not_assignable_to_parameter_of_type_1; + if (!checkTypeRelatedTo(argType, paramType, relation, errorNode, headMessage)) { return false; } } } + return true; } @@ -7694,20 +7744,27 @@ namespace ts { * * If 'node' is a CallExpression or a NewExpression, then its argument list is returned. * If 'node' is a TaggedTemplateExpression, a new argument list is constructed from the substitution - * expressions, where the first element of the list is the template for error reporting purposes. + * expressions, where the first element of the list is `undefined`. + * If 'node' is a Decorator, the argument list will be `undefined`, and its arguments and types + * will be supplied from calls to `getEffectiveArgumentCount` and `getEffectiveArgumentType`. */ function getEffectiveCallArguments(node: CallLikeExpression): Expression[] { let args: Expression[]; if (node.kind === SyntaxKind.TaggedTemplateExpression) { let template = (node).template; - args = [template]; - + args = [undefined]; if (template.kind === SyntaxKind.TemplateExpression) { forEach((template).templateSpans, span => { args.push(span.expression); }); } } + else if (node.kind === SyntaxKind.Decorator) { + // For a decorator, we return undefined as we will determine + // the number and types of arguments for a decorator using + // `getEffectiveArgumentCount` and `getEffectiveArgumentType` below. + return undefined; + } else { args = (node).arguments || emptyArray; } @@ -7715,12 +7772,284 @@ namespace ts { return args; } - function resolveCall(node: CallLikeExpression, signatures: Signature[], candidatesOutArray: Signature[]): Signature { + + /** + * Returns the effective argument count for a node that works like a function invocation. + * If 'node' is a Decorator, the number of arguments is derived from the decoration + * target and the signature: + * If 'node.target' is a class declaration or class expression, the effective argument + * count is 1. + * If 'node.target' is a parameter declaration, the effective argument count is 3. + * If 'node.target' is a property declaration, the effective argument count is 2. + * If 'node.target' is a method or accessor declaration, the effective argument count + * is 3, although it can be 2 if the signature only accepts two arguments, allowing + * us to match a property decorator. + * Otherwise, the argument count is the length of the 'args' array. + */ + function getEffectiveArgumentCount(node: CallLikeExpression, args: Expression[], signature: Signature) { + if (node.kind === SyntaxKind.Decorator) { + switch (node.parent.kind) { + case SyntaxKind.ClassDeclaration: + case SyntaxKind.ClassExpression: + // A class decorator will have one argument (see `ClassDecorator` in core.d.ts) + return 1; + + case SyntaxKind.PropertyDeclaration: + // A property declaration decorator will have two arguments (see + // `PropertyDecorator` in core.d.ts) + return 2; + + case SyntaxKind.MethodDeclaration: + case SyntaxKind.GetAccessor: + case SyntaxKind.SetAccessor: + // A method or accessor declaration decorator will have two or three arguments (see + // `PropertyDecorator` and `MethodDecorator` in core.d.ts) + // If the method decorator signature only accepts a target and a key, we will only + // type check those arguments. + return signature.parameters.length >= 3 ? 3 : 2; + + case SyntaxKind.Parameter: + // A parameter declaration decorator will have three arguments (see + // `ParameterDecorator` in core.d.ts) + + return 3; + } + } + else { + return args.length; + } + } + + /** + * Returns the effective type of the first argument to a decorator. + * If 'node' is a class declaration or class expression, the effective argument type + * is the type of the static side of the class. + * If 'node' is a parameter declaration, the effective argument type is either the type + * of the static or instance side of the class for the parameter's parent method, + * depending on whether the method is declared static. + * For a constructor, the type is always the type of the static side of the class. + * If 'node' is a property, method, or accessor declaration, the effective argument + * type is the type of the static or instance side of the parent class for class + * element, depending on whether the element is declared static. + */ + function getEffectiveDecoratorFirstArgumentType(node: Node): Type { + // The first argument to a decorator is its `target`. + switch (node.kind) { + case SyntaxKind.ClassDeclaration: + case SyntaxKind.ClassExpression: + // For a class decorator, the `target` is the type of the class (e.g. the + // "static" or "constructor" side of the class) + let classSymbol = getSymbolOfNode(node); + return getTypeOfSymbol(classSymbol); + + case SyntaxKind.Parameter: + // For a parameter decorator, the `target` is the parent type of the + // parameter's containing method. + node = node.parent; + if (node.kind === SyntaxKind.Constructor) { + let classSymbol = getSymbolOfNode(node); + return getTypeOfSymbol(classSymbol); + } + + // fall-through + + case SyntaxKind.PropertyDeclaration: + case SyntaxKind.MethodDeclaration: + case SyntaxKind.GetAccessor: + case SyntaxKind.SetAccessor: + // For a property or method decorator, the `target` is the + // "static"-side type of the parent of the member if the member is + // declared "static"; otherwise, it is the "instance"-side type of the + // parent of the member. + return getParentTypeOfClassElement(node); + + default: + Debug.fail("Unsupported decorator target."); + return unknownType; + } + } + + /** + * Returns the effective type for the second argument to a decorator. + * If 'node' is a parameter, its effective argument type is one of the following: + * If 'node.parent' is a constructor, the effective argument type is 'any', as we + * will emit `undefined`. + * If 'node.parent' is a member with an identifier, numeric, or string literal name, + * the effective argument type will be a string literal type for the member name. + * If 'node.parent' is a computed property name, the effective argument type will + * either be a symbol type or the string type. + * If 'node' is a member with an identifier, numeric, or string literal name, the + * effective argument type will be a string literal type for the member name. + * If 'node' is a computed property name, the effective argument type will either + * be a symbol type or the string type. + * A class decorator does not have a second argument type. + */ + function getEffectiveDecoratorSecondArgumentType(node: Node) { + // The second argument to a decorator is its `propertyKey` + switch (node.kind) { + case SyntaxKind.ClassDeclaration: + Debug.fail("Class decorators should not have a second synthetic argument."); + return unknownType; + + case SyntaxKind.Parameter: + node = node.parent; + if (node.kind === SyntaxKind.Constructor) { + // For a constructor parameter decorator, the `propertyKey` will be `undefined`. + return anyType; + } + + // For a non-constructor parameter decorator, the `propertyKey` will be either + // a string or a symbol, based on the name of the parameter's containing method. + + // fall-through + + case SyntaxKind.PropertyDeclaration: + case SyntaxKind.MethodDeclaration: + case SyntaxKind.GetAccessor: + case SyntaxKind.SetAccessor: + // The `propertyKey` for a property or method decorator will be a + // string literal type if the member name is an identifier, number, or string; + // otherwise, if the member name is a computed property name it will + // be either string or symbol. + let element = node; + switch (element.name.kind) { + case SyntaxKind.Identifier: + case SyntaxKind.NumericLiteral: + case SyntaxKind.StringLiteral: + return getStringLiteralType(element.name); + + case SyntaxKind.ComputedPropertyName: + let nameType = checkComputedPropertyName(element.name); + if (allConstituentTypesHaveKind(nameType, TypeFlags.ESSymbol)) { + return nameType; + } + else { + return stringType; + } + + default: + Debug.fail("Unsupported property name."); + return unknownType; + } + + + default: + Debug.fail("Unsupported decorator target."); + return unknownType; + } + } + + /** + * Returns the effective argument type for the third argument to a decorator. + * If 'node' is a parameter, the effective argument type is the number type. + * If 'node' is a method or accessor, the effective argument type is a + * `TypedPropertyDescriptor` instantiated with the type of the member. + * Class and property decorators do not have a third effective argument. + */ + function getEffectiveDecoratorThirdArgumentType(node: Node) { + // The third argument to a decorator is either its `descriptor` for a method decorator + // or its `parameterIndex` for a paramter decorator + switch (node.kind) { + case SyntaxKind.ClassDeclaration: + Debug.fail("Class decorators should not have a third synthetic argument."); + return unknownType; + + case SyntaxKind.Parameter: + // The `parameterIndex` for a parameter decorator is always a number + return numberType; + + case SyntaxKind.PropertyDeclaration: + Debug.fail("Property decorators should not have a third synthetic argument."); + return unknownType; + + case SyntaxKind.MethodDeclaration: + case SyntaxKind.GetAccessor: + case SyntaxKind.SetAccessor: + // The `descriptor` for a method decorator will be a `TypedPropertyDescriptor` + // for the type of the member. + let propertyType = getTypeOfNode(node); + return createTypedPropertyDescriptorType(propertyType); + + default: + Debug.fail("Unsupported decorator target."); + return unknownType; + } + } + + /** + * Returns the effective argument type for the provided argument to a decorator. + */ + function getEffectiveDecoratorArgumentType(node: Decorator, argIndex: number): Type { + if (argIndex === 0) { + return getEffectiveDecoratorFirstArgumentType(node.parent); + } + else if (argIndex === 1) { + return getEffectiveDecoratorSecondArgumentType(node.parent); + } + else if (argIndex === 2) { + return getEffectiveDecoratorThirdArgumentType(node.parent); + } + + Debug.fail("Decorators should not have a fourth synthetic argument."); + return unknownType; + } + + /** + * Gets the effective argument type for an argument in a call expression. + */ + function getEffectiveArgumentType(node: CallLikeExpression, argIndex: number, arg: Expression): Type { + // Decorators provide special arguments, a tagged template expression provides + // a special first argument, and string literals get string literal types + // unless we're reporting errors + if (node.kind === SyntaxKind.Decorator) { + return getEffectiveDecoratorArgumentType(node, argIndex); + } + else if (argIndex === 0 && node.kind === SyntaxKind.TaggedTemplateExpression) { + return globalTemplateStringsArrayType; + } + + // This is not a synthetic argument, so we return 'undefined' + // to signal that the caller needs to check the argument. + return undefined; + } + + /** + * Gets the effective argument expression for an argument in a call expression. + */ + function getEffectiveArgument(node: CallLikeExpression, args: Expression[], argIndex: number) { + // For a decorator or the first argument of a tagged template expression we return undefined. + if (node.kind === SyntaxKind.Decorator || + (argIndex === 0 && node.kind === SyntaxKind.TaggedTemplateExpression)) { + return undefined; + } + + return args[argIndex]; + } + + /** + * Gets the error node to use when reporting errors for an effective argument. + */ + function getEffectiveArgumentErrorNode(node: CallLikeExpression, argIndex: number, arg: Expression) { + if (node.kind === SyntaxKind.Decorator) { + // For a decorator, we use the expression of the decorator for error reporting. + return (node).expression; + } + else if (argIndex === 0 && node.kind === SyntaxKind.TaggedTemplateExpression) { + // For a the first argument of a tagged template expression, we use the template of the tag for error reporting. + return (node).template; + } + else { + return arg; + } + } + + function resolveCall(node: CallLikeExpression, signatures: Signature[], candidatesOutArray: Signature[], headMessage?: DiagnosticMessage): Signature { let isTaggedTemplate = node.kind === SyntaxKind.TaggedTemplateExpression; + let isDecorator = node.kind === SyntaxKind.Decorator; let typeArguments: TypeNode[]; - if (!isTaggedTemplate) { + if (!isTaggedTemplate && !isDecorator) { typeArguments = (node).typeArguments; // We already perform checking on the type arguments on the class declaration itself. @@ -7733,7 +8062,7 @@ namespace ts { // reorderCandidates fills up the candidates array directly reorderCandidates(signatures, candidates); if (!candidates.length) { - error(node, Diagnostics.Supplied_parameters_do_not_match_any_signature_of_call_target); + reportError(Diagnostics.Supplied_parameters_do_not_match_any_signature_of_call_target); return resolveErrorCall(node); } @@ -7750,13 +8079,20 @@ namespace ts { // // For a tagged template, then the first argument be 'undefined' if necessary // because it represents a TemplateStringsArray. + // + // For a decorator, no arguments are susceptible to contextual typing due to the fact + // decorators are applied to a declaration by the emitter, and not to an expression. let excludeArgument: boolean[]; - for (let i = isTaggedTemplate ? 1 : 0; i < args.length; i++) { - if (isContextSensitive(args[i])) { - if (!excludeArgument) { - excludeArgument = new Array(args.length); + if (!isDecorator) { + // We do not need to call `getEffectiveArgumentCount` here as it only + // applies when calculating the number of arguments for a decorator. + for (let i = isTaggedTemplate ? 1 : 0; i < args.length; i++) { + if (isContextSensitive(args[i])) { + if (!excludeArgument) { + excludeArgument = new Array(args.length); + } + excludeArgument[i] = true; } - excludeArgument[i] = true; } } @@ -7823,8 +8159,8 @@ namespace ts { checkApplicableSignature(node, args, candidateForArgumentError, assignableRelation, /*excludeArgument*/ undefined, /*reportErrors*/ true); } else if (candidateForTypeArgumentError) { - if (!isTaggedTemplate && typeArguments) { - checkTypeArguments(candidateForTypeArgumentError, typeArguments, [], /*reportErrors*/ true) + if (!isTaggedTemplate && !isDecorator && typeArguments) { + checkTypeArguments(candidateForTypeArgumentError, (node).typeArguments, [], /*reportErrors*/ true, headMessage) } else { Debug.assert(resultOfFailedInference.failedTypeParameterIndex >= 0); @@ -7834,12 +8170,16 @@ namespace ts { let diagnosticChainHead = chainDiagnosticMessages(/*details*/ undefined, // details will be provided by call to reportNoCommonSupertypeError Diagnostics.The_type_argument_for_type_parameter_0_cannot_be_inferred_from_the_usage_Consider_specifying_the_type_arguments_explicitly, typeToString(failedTypeParameter)); + + if (headMessage) { + diagnosticChainHead = chainDiagnosticMessages(diagnosticChainHead, headMessage); + } reportNoCommonSupertypeError(inferenceCandidates, (node).expression || (node).tag, diagnosticChainHead); } } else { - error(node, Diagnostics.Supplied_parameters_do_not_match_any_signature_of_call_target); + reportError(Diagnostics.Supplied_parameters_do_not_match_any_signature_of_call_target); } // No signature was applicable. We have already reported the errors for the invalid signature. @@ -7856,6 +8196,16 @@ namespace ts { } return resolveErrorCall(node); + + function reportError(message: DiagnosticMessage, arg0?: string, arg1?: string, arg2?: string): void { + let errorInfo: DiagnosticMessageChain; + errorInfo = chainDiagnosticMessages(errorInfo, message, arg0, arg1, arg2); + if (headMessage) { + errorInfo = chainDiagnosticMessages(errorInfo, headMessage); + } + + diagnostics.add(createDiagnosticForNodeFromMessageChain(node, errorInfo)); + } function chooseOverload(candidates: Signature[], relation: Map) { for (let originalCandidate of candidates) { @@ -7878,7 +8228,7 @@ namespace ts { typeArgumentsAreValid = checkTypeArguments(candidate, typeArguments, typeArgumentTypes, /*reportErrors*/ false) } else { - inferTypeArguments(candidate, args, excludeArgument, inferenceContext); + inferTypeArguments(node, candidate, args, excludeArgument, inferenceContext); typeArgumentsAreValid = inferenceContext.failedTypeParameterIndex === undefined; typeArgumentTypes = inferenceContext.inferredTypes; } @@ -7931,7 +8281,7 @@ namespace ts { if (superType !== unknownType) { // In super call, the candidate signatures are the matching arity signatures of the base constructor function instantiated // with the type arguments specified in the extends clause. - let baseTypeNode = getClassExtendsHeritageClauseElement(getAncestor(node, SyntaxKind.ClassDeclaration)); + let baseTypeNode = getClassExtendsHeritageClauseElement(getContainingClass(node)); let baseConstructors = getInstantiatedConstructorsForTypeArguments(superType, baseTypeNode.typeArguments); return resolveCall(node, baseConstructors, candidatesOutArray); } @@ -8062,6 +8412,55 @@ namespace ts { return resolveCall(node, callSignatures, candidatesOutArray); } + + /** + * Gets the localized diagnostic head message to use for errors when resolving a decorator as a call expression. + */ + function getDiagnosticHeadMessageForDecoratorResolution(node: Decorator) { + switch (node.parent.kind) { + case SyntaxKind.ClassDeclaration: + case SyntaxKind.ClassExpression: + return Diagnostics.Unable_to_resolve_signature_of_class_decorator_when_called_as_an_expression; + + case SyntaxKind.Parameter: + return Diagnostics.Unable_to_resolve_signature_of_parameter_decorator_when_called_as_an_expression; + + case SyntaxKind.PropertyDeclaration: + return Diagnostics.Unable_to_resolve_signature_of_property_decorator_when_called_as_an_expression; + + case SyntaxKind.MethodDeclaration: + case SyntaxKind.GetAccessor: + case SyntaxKind.SetAccessor: + return Diagnostics.Unable_to_resolve_signature_of_method_decorator_when_called_as_an_expression; + } + } + + /** + * Resolves a decorator as if it were a call expression. + */ + function resolveDecorator(node: Decorator, candidatesOutArray: Signature[]): Signature { + let funcType = checkExpression(node.expression); + let apparentType = getApparentType(funcType); + if (apparentType === unknownType) { + return resolveErrorCall(node); + } + + let callSignatures = getSignaturesOfType(apparentType, SignatureKind.Call); + if (funcType === anyType || (!callSignatures.length && !(funcType.flags & TypeFlags.Union) && isTypeAssignableTo(funcType, globalFunctionType))) { + return resolveUntypedCall(node); + } + + let headMessage = getDiagnosticHeadMessageForDecoratorResolution(node); + if (!callSignatures.length) { + let errorInfo: DiagnosticMessageChain; + errorInfo = chainDiagnosticMessages(errorInfo, Diagnostics.Cannot_invoke_an_expression_whose_type_lacks_a_call_signature); + errorInfo = chainDiagnosticMessages(errorInfo, headMessage); + diagnostics.add(createDiagnosticForNodeFromMessageChain(node, errorInfo)); + return resolveErrorCall(node); + } + + return resolveCall(node, callSignatures, candidatesOutArray, headMessage); + } // candidatesOutArray is passed by signature help in the language service, and collectCandidates // must fill it up with the appropriate candidate signatures @@ -8083,6 +8482,9 @@ namespace ts { else if (node.kind === SyntaxKind.TaggedTemplateExpression) { links.resolvedSignature = resolveTaggedTemplateExpression(node, candidatesOutArray); } + else if (node.kind === SyntaxKind.Decorator) { + links.resolvedSignature = resolveDecorator(node, candidatesOutArray); + } else { Debug.fail("Branch in 'getResolvedSignature' should be unreachable."); } @@ -8360,7 +8762,7 @@ namespace ts { if (node.type) { checkTypeAssignableTo(exprType, getTypeFromTypeNode(node.type), node.body, /*headMessage*/ undefined); } - checkFunctionExpressionBodies(node.body); + checkFunctionAndClassExpressionBodies(node.body); } } } @@ -8457,12 +8859,12 @@ namespace ts { } function checkTypeOfExpression(node: TypeOfExpression): Type { - let operandType = checkExpression(node.expression); + checkExpression(node.expression); return stringType; } function checkVoidExpression(node: VoidExpression): Type { - let operandType = checkExpression(node.expression); + checkExpression(node.expression); return undefinedType; } @@ -8858,7 +9260,7 @@ namespace ts { if (isFunctionLike(parent) && current === (parent).body) { return false; } - else if (current.kind === SyntaxKind.ClassDeclaration || current.kind === SyntaxKind.ClassExpression) { + else if (isClassLike(current)) { return true; } @@ -9886,35 +10288,54 @@ namespace ts { /** Check a decorator */ function checkDecorator(node: Decorator): void { - let expression: Expression = node.expression; - let exprType = checkExpression(expression); - + let signature = getResolvedSignature(node); + let returnType = getReturnTypeOfSignature(signature); + if (returnType.flags & TypeFlags.Any) { + return; + } + + let expectedReturnType: Type; + let headMessage = getDiagnosticHeadMessageForDecoratorResolution(node); + let errorInfo: DiagnosticMessageChain; switch (node.parent.kind) { case SyntaxKind.ClassDeclaration: let classSymbol = getSymbolOfNode(node.parent); let classConstructorType = getTypeOfSymbol(classSymbol); - let classDecoratorType = instantiateSingleCallFunctionType(getGlobalClassDecoratorType(), [classConstructorType]); - checkTypeAssignableTo(exprType, classDecoratorType, node); + expectedReturnType = getUnionType([classConstructorType, voidType]); break; + case SyntaxKind.Parameter: + expectedReturnType = voidType; + errorInfo = chainDiagnosticMessages( + errorInfo, + Diagnostics.The_return_type_of_a_parameter_decorator_function_must_be_either_void_or_any); + + break; + case SyntaxKind.PropertyDeclaration: - checkTypeAssignableTo(exprType, getGlobalPropertyDecoratorType(), node); + expectedReturnType = voidType; + errorInfo = chainDiagnosticMessages( + errorInfo, + Diagnostics.The_return_type_of_a_property_decorator_function_must_be_either_void_or_any); break; case SyntaxKind.MethodDeclaration: case SyntaxKind.GetAccessor: case SyntaxKind.SetAccessor: let methodType = getTypeOfNode(node.parent); - let methodDecoratorType = instantiateSingleCallFunctionType(getGlobalMethodDecoratorType(), [methodType]); - checkTypeAssignableTo(exprType, methodDecoratorType, node); - break; - - case SyntaxKind.Parameter: - checkTypeAssignableTo(exprType, getGlobalParameterDecoratorType(), node); + let descriptorType = createTypedPropertyDescriptorType(methodType); + expectedReturnType = getUnionType([descriptorType, voidType]); break; } + + checkTypeAssignableTo( + returnType, + expectedReturnType, + node, + headMessage, + errorInfo); } - + /** Checks a type reference node as an expression. */ function checkTypeNodeAsExpression(node: TypeNode) { // When we are emitting type metadata for decorators, we need to try to check the type @@ -10085,7 +10506,7 @@ namespace ts { forEach(node.statements, checkSourceElement); if (isFunctionBlock(node) || node.kind === SyntaxKind.ModuleBlock) { - checkFunctionExpressionBodies(node); + checkFunctionAndClassExpressionBodies(node); } } @@ -10161,7 +10582,7 @@ namespace ts { } // bubble up and find containing type - let enclosingClass = getAncestor(node, SyntaxKind.ClassDeclaration); + let enclosingClass = getContainingClass(node); // if containing type was not found or it is ambient - exit (no codegen) if (!enclosingClass || isInAmbientContext(enclosingClass)) { return; @@ -10969,8 +11390,8 @@ namespace ts { checkIndexConstraintForProperty(prop, propType, type, declaredNumberIndexer, numberIndexType, IndexKind.Number); }); - if (type.flags & TypeFlags.Class && type.symbol.valueDeclaration.kind === SyntaxKind.ClassDeclaration) { - let classDeclaration = type.symbol.valueDeclaration; + if (type.flags & TypeFlags.Class && isClassLike(type.symbol.valueDeclaration)) { + let classDeclaration = type.symbol.valueDeclaration; for (let member of classDeclaration.members) { // Only process instance properties with computed names here. // Static properties cannot be in conflict with indexers, @@ -11076,17 +11497,19 @@ namespace ts { } function checkClassExpression(node: ClassExpression): Type { - grammarErrorOnNode(node, Diagnostics.class_expressions_are_not_currently_supported); - forEach(node.members, checkSourceElement); - return unknownType; + checkClassLikeDeclaration(node); + return getTypeOfSymbol(getSymbolOfNode(node)); } function checkClassDeclaration(node: ClassDeclaration) { - // Grammar checking if (!node.name && !(node.flags & NodeFlags.Default)) { grammarErrorOnFirstToken(node, Diagnostics.A_class_declaration_without_the_default_modifier_must_have_a_name); } + checkClassLikeDeclaration(node); + forEach(node.members, checkSourceElement); + } + function checkClassLikeDeclaration(node: ClassLikeDeclaration) { checkGrammarClassDeclarationHeritageClauses(node); checkDecorators(node); if (node.name) { @@ -11154,7 +11577,6 @@ namespace ts { }); } - forEach(node.members, checkSourceElement); if (produceDiagnostics) { checkIndexConstraints(type); checkTypeForDuplicateIndexSignatures(node); @@ -12027,8 +12449,8 @@ namespace ts { } } - // Function expression bodies are checked after all statements in the enclosing body. This is to ensure - // constructs like the following are permitted: + // Function and class expression bodies are checked after all statements in the enclosing body. This is + // to ensure constructs like the following are permitted: // let foo = function () { // let s = foo(); // return "hello"; @@ -12036,17 +12458,20 @@ namespace ts { // Here, performing a full type check of the body of the function expression whilst in the process of // determining the type of foo would cause foo to be given type any because of the recursive reference. // Delaying the type check of the body ensures foo has been assigned a type. - function checkFunctionExpressionBodies(node: Node): void { + function checkFunctionAndClassExpressionBodies(node: Node): void { switch (node.kind) { case SyntaxKind.FunctionExpression: case SyntaxKind.ArrowFunction: - forEach((node).parameters, checkFunctionExpressionBodies); + forEach((node).parameters, checkFunctionAndClassExpressionBodies); checkFunctionExpressionOrObjectLiteralMethodBody(node); break; + case SyntaxKind.ClassExpression: + forEach((node).members, checkSourceElement); + break; case SyntaxKind.MethodDeclaration: case SyntaxKind.MethodSignature: - forEach(node.decorators, checkFunctionExpressionBodies); - forEach((node).parameters, checkFunctionExpressionBodies); + forEach(node.decorators, checkFunctionAndClassExpressionBodies); + forEach((node).parameters, checkFunctionAndClassExpressionBodies); if (isObjectLiteralMethod(node)) { checkFunctionExpressionOrObjectLiteralMethodBody(node); } @@ -12055,10 +12480,10 @@ namespace ts { case SyntaxKind.GetAccessor: case SyntaxKind.SetAccessor: case SyntaxKind.FunctionDeclaration: - forEach((node).parameters, checkFunctionExpressionBodies); + forEach((node).parameters, checkFunctionAndClassExpressionBodies); break; case SyntaxKind.WithStatement: - checkFunctionExpressionBodies((node).expression); + checkFunctionAndClassExpressionBodies((node).expression); break; case SyntaxKind.Decorator: case SyntaxKind.Parameter: @@ -12122,7 +12547,7 @@ namespace ts { case SyntaxKind.JsxAttribute: case SyntaxKind.JsxSpreadAttribute: case SyntaxKind.JsxOpeningElement: - forEachChild(node, checkFunctionExpressionBodies); + forEachChild(node, checkFunctionAndClassExpressionBodies); break; } } @@ -12154,7 +12579,7 @@ namespace ts { potentialThisCollisions.length = 0; forEach(node.statements, checkSourceElement); - checkFunctionExpressionBodies(node); + checkFunctionAndClassExpressionBodies(node); if (isExternalModule(node)) { checkExternalModuleExports(node); @@ -12247,6 +12672,11 @@ namespace ts { case SyntaxKind.EnumDeclaration: copySymbols(getSymbolOfNode(location).exports, meaning & SymbolFlags.EnumMember); break; + case SyntaxKind.ClassExpression: + if ((location).name) { + copySymbol(location.symbol, meaning); + } + // Fall through case SyntaxKind.ClassDeclaration: case SyntaxKind.InterfaceDeclaration: if (!(memberFlags & NodeFlags.Static)) { @@ -12286,42 +12716,6 @@ namespace ts { } } } - - if (isInsideWithStatementBody(location)) { - // We cannot answer semantic questions within a with block, do not proceed any further - return []; - } - - while (location) { - if (location.locals && !isGlobalSourceFile(location)) { - copySymbols(location.locals, meaning); - } - switch (location.kind) { - case SyntaxKind.SourceFile: - if (!isExternalModule(location)) break; - case SyntaxKind.ModuleDeclaration: - copySymbols(getSymbolOfNode(location).exports, meaning & SymbolFlags.ModuleMember); - break; - case SyntaxKind.EnumDeclaration: - copySymbols(getSymbolOfNode(location).exports, meaning & SymbolFlags.EnumMember); - break; - case SyntaxKind.ClassDeclaration: - case SyntaxKind.InterfaceDeclaration: - if (!(memberFlags & NodeFlags.Static)) { - copySymbols(getSymbolOfNode(location).members, meaning & SymbolFlags.Type); - } - break; - case SyntaxKind.FunctionExpression: - if ((location).name) { - copySymbol(location.symbol, meaning); - } - break; - } - memberFlags = location.flags; - location = location.parent; - } - copySymbols(globals, meaning); - return symbolsToArray(symbols); } function isTypeDeclarationName(name: Node): boolean { @@ -12447,6 +12841,10 @@ namespace ts { return getJsxAttributePropertySymbol(entityName.parent); } + if (entityName.parent.kind === SyntaxKind.TypePredicate) { + return resolveEntityName(entityName, /*meaning*/ SymbolFlags.FunctionScopedVariable); + } + // Do we want to return undefined here? return undefined; } @@ -12489,7 +12887,6 @@ namespace ts { case SyntaxKind.StringLiteral: // External module name in an import declaration - let moduleName: Expression; if ((isExternalModuleImportEqualsDeclaration(node.parent.parent) && getExternalModuleImportEqualsDeclarationExpression(node.parent.parent) === node) || ((node.parent.kind === SyntaxKind.ImportDeclaration || node.parent.kind === SyntaxKind.ExportDeclaration) && @@ -12497,7 +12894,7 @@ namespace ts { return resolveExternalModuleName(node, node); } - // Intentional fall-through + // fall through case SyntaxKind.NumericLiteral: // index access if (node.parent.kind === SyntaxKind.ElementAccessExpression && (node.parent).argumentExpression === node) { @@ -12564,6 +12961,10 @@ namespace ts { return symbol && getTypeOfSymbol(symbol); } + if (isBindingPattern(node)) { + return getTypeForVariableLikeDeclaration(node.parent); + } + if (isInRightSideOfImportOrExportAssignment(node)) { let symbol = getSymbolInfo(node); let declaredType = symbol && getDeclaredTypeOfSymbol(symbol); @@ -12581,6 +12982,17 @@ namespace ts { return checkExpression(expr); } + /** + * Gets either the static or instance type of a class element, based on + * whether the element is declared as "static". + */ + function getParentTypeOfClassElement(node: ClassElement) { + let classSymbol = getSymbolOfNode(node.parent); + return node.flags & NodeFlags.Static + ? getTypeOfSymbol(classSymbol) + : getDeclaredTypeOfSymbol(classSymbol); + } + // Return the list of properties of the given type, augmented with properties from Function // if the type has call or construct signatures function getAugmentedPropertiesOfType(type: Type): Symbol[] { @@ -13122,6 +13534,7 @@ namespace ts { getGlobalPropertyDecoratorType = memoize(() => getGlobalType("PropertyDecorator")); getGlobalMethodDecoratorType = memoize(() => getGlobalType("MethodDecorator")); getGlobalParameterDecoratorType = memoize(() => getGlobalType("ParameterDecorator")); + getGlobalTypedPropertyDescriptorType = memoize(() => getGlobalType("TypedPropertyDescriptor", /*arity*/ 1)); // If we're in ES6 mode, load the TemplateStringsArray. // Otherwise, default to 'unknown' for the purposes of type checking in LS scenarios. @@ -13477,7 +13890,7 @@ namespace ts { } } - function checkGrammarClassDeclarationHeritageClauses(node: ClassDeclaration) { + function checkGrammarClassDeclarationHeritageClauses(node: ClassLikeDeclaration) { let seenExtendsClause = false; let seenImplementsClause = false; @@ -13763,7 +14176,7 @@ namespace ts { } } - if (node.parent.kind === SyntaxKind.ClassDeclaration) { + if (isClassLike(node.parent)) { if (checkGrammarForInvalidQuestionMark(node, node.questionToken, Diagnostics.A_class_member_cannot_be_declared_optional)) { return true; } @@ -14060,7 +14473,7 @@ namespace ts { } function checkGrammarProperty(node: PropertyDeclaration) { - if (node.parent.kind === SyntaxKind.ClassDeclaration) { + if (isClassLike(node.parent)) { if (checkGrammarForInvalidQuestionMark(node, node.questionToken, Diagnostics.A_class_member_cannot_be_declared_optional) || checkGrammarForNonSymbolComputedProperty(node.name, Diagnostics.A_computed_property_name_in_a_class_property_declaration_must_directly_refer_to_a_built_in_symbol)) { return true; diff --git a/src/compiler/declarationEmitter.ts b/src/compiler/declarationEmitter.ts index 2ba88f1ac29..54d0d6ff854 100644 --- a/src/compiler/declarationEmitter.ts +++ b/src/compiler/declarationEmitter.ts @@ -40,7 +40,6 @@ namespace ts { function emitDeclarations(host: EmitHost, resolver: EmitResolver, diagnostics: Diagnostic[], jsFilePath: string, root?: SourceFile): DeclarationEmit { let newLine = host.getNewLine(); let compilerOptions = host.getCompilerOptions(); - let languageVersion = compilerOptions.target || ScriptTarget.ES3; let write: (s: string) => void; let writeLine: () => void; diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index 04db6f21048..ec9c444e9e9 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -20,22 +20,16 @@ namespace ts { An_index_signature_must_have_a_type_annotation: { code: 1021, category: DiagnosticCategory.Error, key: "An index signature must have a type annotation." }, An_index_signature_parameter_must_have_a_type_annotation: { code: 1022, category: DiagnosticCategory.Error, key: "An index signature parameter must have a type annotation." }, An_index_signature_parameter_type_must_be_string_or_number: { code: 1023, category: DiagnosticCategory.Error, key: "An index signature parameter type must be 'string' or 'number'." }, - A_class_or_interface_declaration_can_only_have_one_extends_clause: { code: 1024, category: DiagnosticCategory.Error, key: "A class or interface declaration can only have one 'extends' clause." }, - An_extends_clause_must_precede_an_implements_clause: { code: 1025, category: DiagnosticCategory.Error, key: "An 'extends' clause must precede an 'implements' clause." }, - A_class_can_only_extend_a_single_class: { code: 1026, category: DiagnosticCategory.Error, key: "A class can only extend a single class." }, - A_class_declaration_can_only_have_one_implements_clause: { code: 1027, category: DiagnosticCategory.Error, key: "A class declaration can only have one 'implements' clause." }, Accessibility_modifier_already_seen: { code: 1028, category: DiagnosticCategory.Error, key: "Accessibility modifier already seen." }, _0_modifier_must_precede_1_modifier: { code: 1029, category: DiagnosticCategory.Error, key: "'{0}' modifier must precede '{1}' modifier." }, _0_modifier_already_seen: { code: 1030, category: DiagnosticCategory.Error, key: "'{0}' modifier already seen." }, _0_modifier_cannot_appear_on_a_class_element: { code: 1031, category: DiagnosticCategory.Error, key: "'{0}' modifier cannot appear on a class element." }, - An_interface_declaration_cannot_have_an_implements_clause: { code: 1032, category: DiagnosticCategory.Error, key: "An interface declaration cannot have an 'implements' clause." }, super_must_be_followed_by_an_argument_list_or_member_access: { code: 1034, category: DiagnosticCategory.Error, key: "'super' must be followed by an argument list or member access." }, Only_ambient_modules_can_use_quoted_names: { code: 1035, category: DiagnosticCategory.Error, key: "Only ambient modules can use quoted names." }, Statements_are_not_allowed_in_ambient_contexts: { code: 1036, category: DiagnosticCategory.Error, key: "Statements are not allowed in ambient contexts." }, A_declare_modifier_cannot_be_used_in_an_already_ambient_context: { code: 1038, category: DiagnosticCategory.Error, key: "A 'declare' modifier cannot be used in an already ambient context." }, Initializers_are_not_allowed_in_ambient_contexts: { code: 1039, category: DiagnosticCategory.Error, key: "Initializers are not allowed in ambient contexts." }, _0_modifier_cannot_appear_on_a_module_element: { code: 1044, category: DiagnosticCategory.Error, key: "'{0}' modifier cannot appear on a module element." }, - A_declare_modifier_cannot_be_used_with_an_interface_declaration: { code: 1045, category: DiagnosticCategory.Error, key: "A 'declare' modifier cannot be used with an interface declaration." }, A_declare_modifier_is_required_for_a_top_level_declaration_in_a_d_ts_file: { code: 1046, category: DiagnosticCategory.Error, key: "A 'declare' modifier is required for a top level declaration in a .d.ts file." }, A_rest_parameter_cannot_be_optional: { code: 1047, category: DiagnosticCategory.Error, key: "A rest parameter cannot be optional." }, A_rest_parameter_cannot_have_an_initializer: { code: 1048, category: DiagnosticCategory.Error, key: "A rest parameter cannot have an initializer." }, @@ -94,7 +88,6 @@ namespace ts { case_or_default_expected: { code: 1130, category: DiagnosticCategory.Error, key: "'case' or 'default' expected." }, Property_or_signature_expected: { code: 1131, category: DiagnosticCategory.Error, key: "Property or signature expected." }, Enum_member_expected: { code: 1132, category: DiagnosticCategory.Error, key: "Enum member expected." }, - Type_reference_expected: { code: 1133, category: DiagnosticCategory.Error, key: "Type reference expected." }, Variable_declaration_expected: { code: 1134, category: DiagnosticCategory.Error, key: "Variable declaration expected." }, Argument_expression_expected: { code: 1135, category: DiagnosticCategory.Error, key: "Argument expression expected." }, Property_assignment_expected: { code: 1136, category: DiagnosticCategory.Error, key: "Property assignment expected." }, @@ -111,9 +104,6 @@ namespace ts { Cannot_compile_modules_unless_the_module_flag_is_provided: { code: 1148, category: DiagnosticCategory.Error, key: "Cannot compile modules unless the '--module' flag is provided." }, File_name_0_differs_from_already_included_file_name_1_only_in_casing: { code: 1149, category: DiagnosticCategory.Error, key: "File name '{0}' differs from already included file name '{1}' only in casing" }, new_T_cannot_be_used_to_create_an_array_Use_new_Array_T_instead: { code: 1150, category: DiagnosticCategory.Error, key: "'new T[]' cannot be used to create an array. Use 'new Array()' instead." }, - 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." }, @@ -124,7 +114,6 @@ namespace ts { Computed_property_names_are_not_allowed_in_enums: { code: 1164, category: DiagnosticCategory.Error, key: "Computed property names are not allowed in enums." }, A_computed_property_name_in_an_ambient_context_must_directly_refer_to_a_built_in_symbol: { code: 1165, category: DiagnosticCategory.Error, key: "A computed property name in an ambient context must directly refer to a built-in symbol." }, A_computed_property_name_in_a_class_property_declaration_must_directly_refer_to_a_built_in_symbol: { code: 1166, category: DiagnosticCategory.Error, key: "A computed property name in a class property declaration must directly refer to a built-in symbol." }, - Computed_property_names_are_only_available_when_targeting_ECMAScript_6_and_higher: { code: 1167, category: DiagnosticCategory.Error, key: "Computed property names are only available when targeting ECMAScript 6 and higher." }, A_computed_property_name_in_a_method_overload_must_directly_refer_to_a_built_in_symbol: { code: 1168, category: DiagnosticCategory.Error, key: "A computed property name in a method overload must directly refer to a built-in symbol." }, A_computed_property_name_in_an_interface_must_directly_refer_to_a_built_in_symbol: { code: 1169, category: DiagnosticCategory.Error, key: "A computed property name in an interface must directly refer to a built-in symbol." }, A_computed_property_name_in_a_type_literal_must_directly_refer_to_a_built_in_symbol: { code: 1170, category: DiagnosticCategory.Error, key: "A computed property name in a type literal must directly refer to a built-in symbol." }, @@ -140,7 +129,6 @@ namespace ts { Property_destructuring_pattern_expected: { code: 1180, category: DiagnosticCategory.Error, key: "Property destructuring pattern expected." }, Array_element_destructuring_pattern_expected: { code: 1181, category: DiagnosticCategory.Error, key: "Array element destructuring pattern expected." }, A_destructuring_declaration_must_have_an_initializer: { code: 1182, category: DiagnosticCategory.Error, key: "A destructuring declaration must have an initializer." }, - Destructuring_declarations_are_not_allowed_in_ambient_contexts: { code: 1183, category: DiagnosticCategory.Error, key: "Destructuring declarations are not allowed in ambient contexts." }, An_implementation_cannot_be_declared_in_ambient_contexts: { code: 1184, category: DiagnosticCategory.Error, key: "An implementation cannot be declared in ambient contexts." }, Modifiers_cannot_appear_here: { code: 1184, category: DiagnosticCategory.Error, key: "Modifiers cannot appear here." }, Merge_conflict_marker_encountered: { code: 1185, category: DiagnosticCategory.Error, key: "Merge conflict marker encountered." }, @@ -191,6 +179,12 @@ namespace ts { An_export_declaration_can_only_be_used_in_a_module: { code: 1233, category: DiagnosticCategory.Error, key: "An export declaration can only be used in a module." }, An_ambient_module_declaration_is_only_allowed_at_the_top_level_in_a_file: { code: 1234, category: DiagnosticCategory.Error, key: "An ambient module declaration is only allowed at the top level in a file." }, A_namespace_declaration_is_only_allowed_in_a_namespace_or_module: { code: 1235, category: DiagnosticCategory.Error, key: "A namespace declaration is only allowed in a namespace or module." }, + The_return_type_of_a_property_decorator_function_must_be_either_void_or_any: { code: 1236, category: DiagnosticCategory.Error, key: "The return type of a property decorator function must be either 'void' or 'any'." }, + The_return_type_of_a_parameter_decorator_function_must_be_either_void_or_any: { code: 1237, category: DiagnosticCategory.Error, key: "The return type of a parameter decorator function must be either 'void' or 'any'." }, + Unable_to_resolve_signature_of_class_decorator_when_called_as_an_expression: { code: 1238, category: DiagnosticCategory.Error, key: "Unable to resolve signature of class decorator when called as an expression." }, + Unable_to_resolve_signature_of_parameter_decorator_when_called_as_an_expression: { code: 1239, category: DiagnosticCategory.Error, key: "Unable to resolve signature of parameter decorator when called as an expression." }, + Unable_to_resolve_signature_of_property_decorator_when_called_as_an_expression: { code: 1240, category: DiagnosticCategory.Error, key: "Unable to resolve signature of property decorator when called as an expression." }, + Unable_to_resolve_signature_of_method_decorator_when_called_as_an_expression: { code: 1241, category: DiagnosticCategory.Error, key: "Unable to resolve signature of method decorator when called as an expression." }, 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." }, @@ -199,7 +193,6 @@ namespace ts { Module_0_has_no_exported_member_1: { code: 2305, category: DiagnosticCategory.Error, key: "Module '{0}' has no exported member '{1}'." }, File_0_is_not_a_module: { code: 2306, category: DiagnosticCategory.Error, key: "File '{0}' is not a module." }, Cannot_find_module_0: { code: 2307, category: DiagnosticCategory.Error, key: "Cannot find module '{0}'." }, - A_module_cannot_have_more_than_one_export_assignment: { code: 2308, category: DiagnosticCategory.Error, key: "A module cannot have more than one export assignment." }, An_export_assignment_cannot_be_used_in_a_module_with_other_exported_elements: { code: 2309, category: DiagnosticCategory.Error, key: "An export assignment cannot be used in a module with other exported elements." }, Type_0_recursively_references_itself_as_a_base_type: { code: 2310, category: DiagnosticCategory.Error, key: "Type '{0}' recursively references itself as a base type." }, A_class_may_only_extend_another_class: { code: 2311, category: DiagnosticCategory.Error, key: "A class may only extend another class." }, @@ -535,7 +528,6 @@ namespace ts { File_0_has_unsupported_extension_The_only_supported_extensions_are_1: { code: 6054, category: DiagnosticCategory.Error, key: "File '{0}' has unsupported extension. The only supported extensions are {1}." }, Suppress_noImplicitAny_errors_for_indexing_objects_lacking_index_signatures: { code: 6055, category: DiagnosticCategory.Message, key: "Suppress noImplicitAny errors for indexing objects lacking index signatures." }, Do_not_emit_declarations_for_code_that_has_an_internal_annotation: { code: 6056, category: DiagnosticCategory.Message, key: "Do not emit declarations for code that has an '@internal' annotation." }, - Preserve_new_lines_when_emitting_code: { code: 6057, category: DiagnosticCategory.Message, key: "Preserve new-lines when emitting code." }, Specifies_the_root_directory_of_input_files_Use_to_control_the_output_directory_structure_with_outDir: { code: 6058, category: DiagnosticCategory.Message, key: "Specifies the root directory of input files. Use to control the output directory structure with --outDir." }, File_0_is_not_under_rootDir_1_rootDir_is_expected_to_contain_all_source_files: { code: 6059, category: DiagnosticCategory.Error, key: "File '{0}' is not under 'rootDir' '{1}'. 'rootDir' is expected to contain all source files." }, Specifies_the_end_of_line_sequence_to_be_used_when_emitting_files_Colon_CRLF_dos_or_LF_unix: { code: 6060, category: DiagnosticCategory.Message, key: "Specifies the end of line sequence to be used when emitting files: 'CRLF' (dos) or 'LF' (unix)." }, diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index f21150d9323..f0c02e7f34e 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -67,22 +67,6 @@ "category": "Error", "code": 1023 }, - "A class or interface declaration can only have one 'extends' clause.": { - "category": "Error", - "code": 1024 - }, - "An 'extends' clause must precede an 'implements' clause.": { - "category": "Error", - "code": 1025 - }, - "A class can only extend a single class.": { - "category": "Error", - "code": 1026 - }, - "A class declaration can only have one 'implements' clause.": { - "category": "Error", - "code": 1027 - }, "Accessibility modifier already seen.": { "category": "Error", "code": 1028 @@ -99,10 +83,6 @@ "category": "Error", "code": 1031 }, - "An interface declaration cannot have an 'implements' clause.": { - "category": "Error", - "code": 1032 - }, "'super' must be followed by an argument list or member access.": { "category": "Error", "code": 1034 @@ -127,10 +107,6 @@ "category": "Error", "code": 1044 }, - "A 'declare' modifier cannot be used with an interface declaration.": { - "category": "Error", - "code": 1045 - }, "A 'declare' modifier is required for a top level declaration in a .d.ts file.": { "category": "Error", "code": 1046 @@ -363,10 +339,6 @@ "category": "Error", "code": 1132 }, - "Type reference expected.": { - "category": "Error", - "code": 1133 - }, "Variable declaration expected.": { "category": "Error", "code": 1134 @@ -431,18 +403,6 @@ "category": "Error", "code": 1150 }, - "'var', 'let' or 'const' expected.": { - "category": "Error", - "code": 1152 - }, - "'let' declarations are only available when targeting ECMAScript 6 and higher.": { - "category": "Error", - "code": 1153 - }, - "'const' declarations are only available when targeting ECMAScript 6 and higher.": { - "category": "Error", - "code": 1154 - }, "'const' declarations must be initialized": { "category": "Error", "code": 1155 @@ -483,10 +443,6 @@ "category": "Error", "code": 1166 }, - "Computed property names are only available when targeting ECMAScript 6 and higher.": { - "category": "Error", - "code": 1167 - }, "A computed property name in a method overload must directly refer to a built-in symbol.": { "category": "Error", "code": 1168 @@ -547,10 +503,6 @@ "category": "Error", "code": 1182 }, - "Destructuring declarations are not allowed in ambient contexts.": { - "category": "Error", - "code": 1183 - }, "An implementation cannot be declared in ambient contexts.": { "category": "Error", "code": 1184 @@ -753,6 +705,31 @@ }, + "The return type of a property decorator function must be either 'void' or 'any'.": { + "category": "Error", + "code": 1236 + }, + "The return type of a parameter decorator function must be either 'void' or 'any'.": { + "category": "Error", + "code": 1237 + }, + "Unable to resolve signature of class decorator when called as an expression.": { + "category": "Error", + "code": 1238 + }, + "Unable to resolve signature of parameter decorator when called as an expression.": { + "category": "Error", + "code": 1239 + }, + "Unable to resolve signature of property decorator when called as an expression.": { + "category": "Error", + "code": 1240 + }, + "Unable to resolve signature of method decorator when called as an expression.": { + "category": "Error", + "code": 1241 + }, + "Duplicate identifier '{0}'.": { "category": "Error", "code": 2300 @@ -785,10 +762,6 @@ "category": "Error", "code": 2307 }, - "A module cannot have more than one export assignment.": { - "category": "Error", - "code": 2308 - }, "An export assignment cannot be used in a module with other exported elements.": { "category": "Error", "code": 2309 @@ -2132,10 +2105,6 @@ "category": "Message", "code": 6056 }, - "Preserve new-lines when emitting code.": { - "category": "Message", - "code": 6057 - }, "Specifies the root directory of input files. Use to control the output directory structure with --outDir.": { "category": "Message", "code": 6058 diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 4e6bc5f687d..451f32cc36b 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -267,6 +267,10 @@ var __param = (this && this.__param) || function (paramIndex, decorator) { return makeUniqueName("default"); } + function generateNameForClassExpression() { + return makeUniqueName("class"); + } + function generateNameForNode(node: Node) { switch (node.kind) { case SyntaxKind.Identifier: @@ -279,9 +283,10 @@ var __param = (this && this.__param) || function (paramIndex, decorator) { return generateNameForImportOrExportDeclaration(node); case SyntaxKind.FunctionDeclaration: case SyntaxKind.ClassDeclaration: - case SyntaxKind.ClassExpression: case SyntaxKind.ExportAssignment: return generateNameForExportDefault(); + case SyntaxKind.ClassExpression: + return generateNameForClassExpression(); } } @@ -2001,7 +2006,21 @@ var __param = (this && this.__param) || function (paramIndex, decorator) { emit(node.expression); let indentedBeforeDot = indentIfOnDifferentLines(node, node.expression, node.dotToken); - write("."); + + // 1 .toString is a valid property access, emit a space after the literal + let shouldEmitSpace: boolean; + if (!indentedBeforeDot && node.expression.kind === SyntaxKind.NumericLiteral) { + let text = getSourceTextOfNodeFromSourceFile(currentSourceFile, node.expression); + shouldEmitSpace = text.indexOf(tokenToString(SyntaxKind.DotToken)) < 0; + } + + if (shouldEmitSpace) { + write(" ."); + } + else { + write("."); + } + let indentedAfterDot = indentIfOnDifferentLines(node, node.dotToken, node.name); emit(node.name); decreaseIndentIf(indentedBeforeDot, indentedAfterDot); @@ -3358,33 +3377,49 @@ var __param = (this && this.__param) || function (paramIndex, decorator) { function emitDefaultValueAssignments(node: FunctionLikeDeclaration) { if (languageVersion < ScriptTarget.ES6) { let tempIndex = 0; - forEach(node.parameters, p => { + forEach(node.parameters, parameter => { // A rest parameter cannot have a binding pattern or an initializer, // so let's just ignore it. - if (p.dotDotDotToken) { + if (parameter.dotDotDotToken) { return; } - if (isBindingPattern(p.name)) { - writeLine(); - write("var "); - emitDestructuring(p, /*isAssignmentExpressionStatement*/ false, tempParameters[tempIndex]); - write(";"); - tempIndex++; + let { name: paramName, initializer } = parameter; + if (isBindingPattern(paramName)) { + // In cases where a binding pattern is simply '[]' or '{}', + // we usually don't want to emit a var declaration; however, in the presence + // of an initializer, we must emit that expression to preserve side effects. + let hasBindingElements = paramName.elements.length > 0; + if (hasBindingElements || initializer) { + writeLine(); + write("var "); + + if (hasBindingElements) { + emitDestructuring(parameter, /*isAssignmentExpressionStatement*/ false, tempParameters[tempIndex]); + } + else { + emit(tempParameters[tempIndex]); + write(" = "); + emit(initializer); + } + + write(";"); + tempIndex++; + } } - else if (p.initializer) { + else if (initializer) { writeLine(); - emitStart(p); + emitStart(parameter); write("if ("); - emitNodeWithoutSourceMap(p.name); + emitNodeWithoutSourceMap(paramName); write(" === void 0)"); - emitEnd(p); + emitEnd(parameter); write(" { "); - emitStart(p); - emitNodeWithoutSourceMap(p.name); + emitStart(parameter); + emitNodeWithoutSourceMap(paramName); write(" = "); - emitNodeWithoutSourceMap(p.initializer); - emitEnd(p); + emitNodeWithoutSourceMap(initializer); + emitEnd(parameter); write("; }"); } }); diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index b5cba38f39f..866d7d9b261 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -5618,7 +5618,6 @@ namespace ts { let atToken = createNode(SyntaxKind.AtToken, pos - 1); atToken.end = pos; - let startPos = pos; let tagName = scanIdentifier(); if (!tagName) { return; diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 2af9ad9987d..09bd6fbdd28 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -337,7 +337,6 @@ namespace ts { function processSourceFile(fileName: string, isDefaultLib: boolean, refFile?: SourceFile, refPos?: number, refEnd?: number) { let start: number; let length: number; - let extensions: string; let diagnosticArgument: string[]; if (refEnd !== undefined && refPos !== undefined) { start = refPos; diff --git a/src/compiler/tsc.ts b/src/compiler/tsc.ts index 2903c3a31f4..2a01774fbca 100644 --- a/src/compiler/tsc.ts +++ b/src/compiler/tsc.ts @@ -191,7 +191,8 @@ namespace ts { return sys.exit(ExitStatus.Success); } - if (commandLine.options.watch) { + // Firefox has Object.prototype.watch + if (commandLine.options.watch && commandLine.options.hasOwnProperty("watch")) { if (!sys.watchFile) { reportDiagnostic(createCompilerDiagnostic(Diagnostics.The_current_host_does_not_support_the_0_option, "--watch")); return sys.exit(ExitStatus.DiagnosticsPresent_OutputsSkipped); diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 0b7605ef77f..b2b48ba48b0 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -821,7 +821,7 @@ namespace ts { template: LiteralExpression | TemplateExpression; } - export type CallLikeExpression = CallExpression | NewExpression | TaggedTemplateExpression; + export type CallLikeExpression = CallExpression | NewExpression | TaggedTemplateExpression | Decorator; export interface AsExpression extends Expression { expression: Expression; @@ -1971,7 +1971,7 @@ namespace ts { CarriageReturnLineFeed = 0, LineFeed = 1, } - + export interface LineAndCharacter { line: number; /* diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index b326d5256f0..750482bc8b0 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -542,6 +542,7 @@ namespace ts { case SyntaxKind.ModuleDeclaration: case SyntaxKind.TypeAliasDeclaration: case SyntaxKind.ClassDeclaration: + case SyntaxKind.ClassExpression: // These are not allowed inside a generator now, but eventually they may be allowed // as local types. Regardless, any yield statements contained within them should be // skipped in this traversal. @@ -579,26 +580,15 @@ namespace ts { return true; } } - return false; } export function isAccessor(node: Node): boolean { - if (node) { - switch (node.kind) { - case SyntaxKind.GetAccessor: - case SyntaxKind.SetAccessor: - return true; - } - } - - return false; + return node && (node.kind === SyntaxKind.GetAccessor || node.kind === SyntaxKind.SetAccessor); } export function isClassLike(node: Node): boolean { - if (node) { - return node.kind === SyntaxKind.ClassDeclaration || node.kind === SyntaxKind.ClassExpression; - } + return node && (node.kind === SyntaxKind.ClassDeclaration || node.kind === SyntaxKind.ClassExpression); } export function isFunctionLike(node: Node): boolean { @@ -620,7 +610,6 @@ namespace ts { return true; } } - return false; } @@ -641,6 +630,15 @@ namespace ts { } } + export function getContainingClass(node: Node): ClassLikeDeclaration { + while (true) { + node = node.parent; + if (!node || isClassLike(node)) { + return node; + } + } + } + export function getThisContainer(node: Node, includeArrowFunctions: boolean): Node { while (true) { node = node.parent; @@ -653,7 +651,7 @@ namespace ts { // then the computed property is not a 'this' container. // A computed property name in a class needs to be a this container // so that we can error on it. - if (node.parent.parent.kind === SyntaxKind.ClassDeclaration) { + if (isClassLike(node.parent.parent)) { return node; } // If this is a computed property, then the parent should not @@ -708,7 +706,7 @@ namespace ts { // then the computed property is not a 'super' container. // A computed property name in a class needs to be a super container // so that we can error on it. - if (node.parent.parent.kind === SyntaxKind.ClassDeclaration) { + if (isClassLike(node.parent.parent)) { return node; } // If this is a computed property, then the parent should not @@ -754,8 +752,8 @@ namespace ts { return (node).tag; } - // Will either be a CallExpression or NewExpression. - return (node).expression; + // Will either be a CallExpression, NewExpression, or Decorator. + return (node).expression; } export function nodeCanBeDecorated(node: Node): boolean { @@ -1071,7 +1069,7 @@ namespace ts { return SyntaxKind.FirstTemplateToken <= kind && kind <= SyntaxKind.LastTemplateToken; } - export function isBindingPattern(node: Node) { + export function isBindingPattern(node: Node): node is BindingPattern { return !!node && (node.kind === SyntaxKind.ArrayBindingPattern || node.kind === SyntaxKind.ObjectBindingPattern); } @@ -1091,6 +1089,7 @@ namespace ts { case SyntaxKind.ArrowFunction: case SyntaxKind.BindingElement: case SyntaxKind.ClassDeclaration: + case SyntaxKind.ClassExpression: case SyntaxKind.Constructor: case SyntaxKind.EnumDeclaration: case SyntaxKind.EnumMember: @@ -1239,7 +1238,7 @@ namespace ts { return heritageClause && heritageClause.types.length > 0 ? heritageClause.types[0] : undefined; } - export function getClassImplementsHeritageClauseElements(node: ClassDeclaration) { + export function getClassImplementsHeritageClauseElements(node: ClassLikeDeclaration) { let heritageClause = getHeritageClause(node.heritageClauses, SyntaxKind.ImplementsKeyword); return heritageClause ? heritageClause.types : undefined; } @@ -1928,7 +1927,7 @@ namespace ts { export function isExpressionWithTypeArgumentsInClassExtendsClause(node: Node): boolean { return node.kind === SyntaxKind.ExpressionWithTypeArguments && (node.parent).token === SyntaxKind.ExtendsKeyword && - node.parent.parent.kind === SyntaxKind.ClassDeclaration; + isClassLike(node.parent.parent); } // Returns false if this heritage clause element's expression contains something unsupported @@ -1973,7 +1972,6 @@ namespace ts { function getExpandedCharCodes(input: string): number[] { let output: number[] = []; let length = input.length; - let leadSurrogate: number = undefined; for (let i = 0; i < length; i++) { let charCode = input.charCodeAt(i); diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index 5915698462c..ff5baddbb70 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -660,8 +660,7 @@ module FourSlash { } errorMsg += "]\n"; - Harness.IO.log(errorMsg); - this.raiseError("Member list is not empty at Caret"); + this.raiseError("Member list is not empty at Caret: " + errorMsg); } } diff --git a/src/lib/es6.d.ts b/src/lib/es6.d.ts index 625a4eca9e1..71df6d77436 100644 --- a/src/lib/es6.d.ts +++ b/src/lib/es6.d.ts @@ -694,6 +694,7 @@ interface Map { } interface MapConstructor { + new (): Map; new (): Map; new (iterable: Iterable<[K, V]>): Map; prototype: Map; @@ -710,6 +711,7 @@ interface WeakMap { } interface WeakMapConstructor { + new (): WeakMap; new (): WeakMap; new (iterable: Iterable<[K, V]>): WeakMap; prototype: WeakMap; @@ -731,6 +733,7 @@ interface Set { } interface SetConstructor { + new (): Set; new (): Set; new (iterable: Iterable): Set; prototype: Set; @@ -746,6 +749,7 @@ interface WeakSet { } interface WeakSetConstructor { + new (): WeakSet; new (): WeakSet; new (iterable: Iterable): WeakSet; prototype: WeakSet; diff --git a/src/services/formatting/rules.ts b/src/services/formatting/rules.ts index 8c20bab92ad..da132754311 100644 --- a/src/services/formatting/rules.ts +++ b/src/services/formatting/rules.ts @@ -318,7 +318,7 @@ namespace ts.formatting { this.NoSpaceAfterModuleImport = new Rule(RuleDescriptor.create2(Shared.TokenRange.FromTokens([SyntaxKind.ModuleKeyword, SyntaxKind.RequireKeyword]), SyntaxKind.OpenParenToken), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext), RuleAction.Delete)); // Add a space around certain TypeScript keywords - this.SpaceAfterCertainTypeScriptKeywords = new Rule(RuleDescriptor.create4(Shared.TokenRange.FromTokens([SyntaxKind.ClassKeyword, SyntaxKind.DeclareKeyword, SyntaxKind.EnumKeyword, SyntaxKind.ExportKeyword, SyntaxKind.ExtendsKeyword, SyntaxKind.GetKeyword, SyntaxKind.ImplementsKeyword, SyntaxKind.ImportKeyword, SyntaxKind.InterfaceKeyword, SyntaxKind.ModuleKeyword, SyntaxKind.NamespaceKeyword, SyntaxKind.PrivateKeyword, SyntaxKind.PublicKeyword, SyntaxKind.SetKeyword, SyntaxKind.StaticKeyword]), Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext), RuleAction.Space)); + this.SpaceAfterCertainTypeScriptKeywords = new Rule(RuleDescriptor.create4(Shared.TokenRange.FromTokens([SyntaxKind.ClassKeyword, SyntaxKind.DeclareKeyword, SyntaxKind.DefaultKeyword, SyntaxKind.EnumKeyword, SyntaxKind.ExportKeyword, SyntaxKind.ExtendsKeyword, SyntaxKind.GetKeyword, SyntaxKind.ImplementsKeyword, SyntaxKind.ImportKeyword, SyntaxKind.InterfaceKeyword, SyntaxKind.ModuleKeyword, SyntaxKind.NamespaceKeyword, SyntaxKind.PrivateKeyword, SyntaxKind.PublicKeyword, SyntaxKind.ProtectedKeyword, SyntaxKind.SetKeyword, SyntaxKind.StaticKeyword]), Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext), RuleAction.Space)); this.SpaceBeforeCertainTypeScriptKeywords = new Rule(RuleDescriptor.create4(Shared.TokenRange.Any, Shared.TokenRange.FromTokens([SyntaxKind.ExtendsKeyword, SyntaxKind.ImplementsKeyword])), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext), RuleAction.Space)); // Treat string literals in module names as identifiers, and add a space between the literal and the opening Brace braces, e.g.: module "m2" { diff --git a/src/services/formatting/smartIndenter.ts b/src/services/formatting/smartIndenter.ts index a82e57f050f..db748f7f494 100644 --- a/src/services/formatting/smartIndenter.ts +++ b/src/services/formatting/smartIndenter.ts @@ -26,7 +26,7 @@ namespace ts.formatting { precedingToken.kind === SyntaxKind.TemplateHead || precedingToken.kind === SyntaxKind.TemplateMiddle || precedingToken.kind === SyntaxKind.TemplateTail; - if (precedingTokenIsLiteral && precedingToken.getStart(sourceFile) <= position && precedingToken.end > position) { + if (precedingTokenIsLiteral && precedingToken.getStart(sourceFile) <= position && precedingToken.end > position) { return 0; } @@ -66,6 +66,10 @@ namespace ts.formatting { if (actualIndentation !== Value.Unknown) { return actualIndentation; } + actualIndentation = getLineIndentationWhenExpressionIsInMultiLine(current, sourceFile, options); + if (actualIndentation !== Value.Unknown) { + return actualIndentation + options.IndentSize; + } previous = current; current = current.parent; @@ -122,6 +126,10 @@ namespace ts.formatting { if (actualIndentation !== Value.Unknown) { return actualIndentation + indentationDelta; } + actualIndentation = getLineIndentationWhenExpressionIsInMultiLine(current, sourceFile, options); + if (actualIndentation !== Value.Unknown) { + return actualIndentation + indentationDelta; + } } // increase indentation if parent node wants its content to be indented and parent and child nodes don't start on the same line @@ -287,6 +295,55 @@ namespace ts.formatting { } } + function getLineIndentationWhenExpressionIsInMultiLine(node: Node, sourceFile: SourceFile, options: EditorOptions): number { + // actual indentation should not be used when: + // - node is close parenthesis - this is the end of the expression + if (node.kind === SyntaxKind.CloseParenToken) { + return Value.Unknown; + } + + if (node.parent && ( + node.parent.kind === SyntaxKind.CallExpression || + node.parent.kind === SyntaxKind.NewExpression) && + (node.parent).expression !== node) { + + let fullCallOrNewExpression = (node.parent).expression; + let startingExpression = getStartingExpression(fullCallOrNewExpression); + + if (fullCallOrNewExpression === startingExpression) { + return Value.Unknown; + } + + let fullCallOrNewExpressionEnd = sourceFile.getLineAndCharacterOfPosition(fullCallOrNewExpression.end); + let startingExpressionEnd = sourceFile.getLineAndCharacterOfPosition(startingExpression.end); + + if (fullCallOrNewExpressionEnd.line === startingExpressionEnd.line) { + return Value.Unknown; + } + + return findColumnForFirstNonWhitespaceCharacterInLine(fullCallOrNewExpressionEnd, sourceFile, options); + } + + return Value.Unknown; + + function getStartingExpression(node: PropertyAccessExpression | CallExpression | ElementAccessExpression) { + while (true) { + switch (node.kind) { + case SyntaxKind.CallExpression: + case SyntaxKind.NewExpression: + case SyntaxKind.PropertyAccessExpression: + case SyntaxKind.ElementAccessExpression: + + node = node.expression; + break; + default: + return node; + } + } + return node; + } + } + function deriveActualIndentationFromList(list: Node[], index: number, sourceFile: SourceFile, options: EditorOptions): number { Debug.assert(index >= 0 && index < list.length); let node = list[index]; diff --git a/src/services/services.ts b/src/services/services.ts index d2229bdbf91..d78ad9d8aa4 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -95,7 +95,6 @@ namespace ts { export module ScriptSnapshot { class StringScriptSnapshot implements IScriptSnapshot { - private _lineStartPositions: number[] = undefined; constructor(private text: string) { } @@ -1800,7 +1799,7 @@ namespace ts { let outputText: string; // Create a compilerHost object to allow the compiler to read and write files - var compilerHost: CompilerHost = { + let compilerHost: CompilerHost = { getSourceFile: (fileName, target) => fileName === inputFileName ? sourceFile : undefined, writeFile: (name, text, writeByteOrderMark) => { Debug.assert(outputText === undefined, "Unexpected multiple outputs for the file: " + name); @@ -1813,7 +1812,7 @@ namespace ts { getNewLine: () => newLine }; - var program = createProgram([inputFileName], options, compilerHost); + let program = createProgram([inputFileName], options, compilerHost); addRange(/*to*/ diagnostics, /*from*/ program.getSyntacticDiagnostics(sourceFile)); addRange(/*to*/ diagnostics, /*from*/ program.getOptionsDiagnostics()); @@ -2897,7 +2896,6 @@ namespace ts { return undefined; } - let location = getTouchingPropertyName(sourceFile, position); let options = program.getCompilerOptions(); let jsx = options.jsx !== JsxEmit.None; let target = options.target; @@ -2909,6 +2907,7 @@ namespace ts { let isRightOfDot = false; let isRightOfOpenTag = false; + let location = getTouchingPropertyName(sourceFile, position); if(contextToken) { let kind = contextToken.kind; if (kind === SyntaxKind.DotToken && contextToken.parent.kind === SyntaxKind.PropertyAccessExpression) { @@ -3009,22 +3008,32 @@ namespace ts { } function tryGetGlobalSymbols(): boolean { - let containingObjectLiteral = getContainingObjectLiteralApplicableForCompletion(contextToken); - - if (containingObjectLiteral) { + let objectLikeContainer = tryGetObjectLikeCompletionContainer(contextToken); + if (objectLikeContainer) { // Object literal expression, look up possible property names from contextual type isMemberCompletion = true; isNewIdentifierLocation = true; - let contextualType = typeChecker.getContextualType(containingObjectLiteral); - if (!contextualType) { + let typeForObject: Type; + let existingMembers: Declaration[]; + + if (objectLikeContainer.kind === SyntaxKind.ObjectLiteralExpression) { + typeForObject = typeChecker.getContextualType(objectLikeContainer); + existingMembers = (objectLikeContainer).properties; + } + else { + typeForObject = typeChecker.getTypeAtLocation(objectLikeContainer); + existingMembers = (objectLikeContainer).elements; + } + + if (!typeForObject) { return false; } - let contextualTypeMembers = typeChecker.getPropertiesOfType(contextualType); - if (contextualTypeMembers && contextualTypeMembers.length > 0) { + let typeMembers = typeChecker.getPropertiesOfType(typeForObject); + if (typeMembers && typeMembers.length > 0) { // Add filtered items to the completion list - symbols = filterContextualMembersList(contextualTypeMembers, containingObjectLiteral.properties); + symbols = filterObjectMembersList(typeMembers, existingMembers); } return true; } @@ -3127,7 +3136,7 @@ namespace ts { * accurately aggregate locals from the closest containing scope. */ function getScopeNode(initialToken: Node, position: number, sourceFile: SourceFile) { - var scope = initialToken; + let scope = initialToken; while (scope && !positionBelongsToNode(scope, position, sourceFile)) { scope = scope.parent; } @@ -3239,17 +3248,18 @@ namespace ts { return false; } - function getContainingObjectLiteralApplicableForCompletion(previousToken: Node): ObjectLiteralExpression { - // The locations in an object literal expression that are applicable for completion are property name definition locations. - - if (previousToken) { - let parent = previousToken.parent; - - switch (previousToken.kind) { + /** + * Returns the immediate owning object literal or binding pattern of a context token, + * on the condition that one exists and that the context implies completion should be given. + */ + function tryGetObjectLikeCompletionContainer(contextToken: Node): ObjectLiteralExpression | BindingPattern { + if (contextToken) { + switch (contextToken.kind) { case SyntaxKind.OpenBraceToken: // let x = { | case SyntaxKind.CommaToken: // let x = { a: 0, | - if (parent && parent.kind === SyntaxKind.ObjectLiteralExpression) { - return parent; + let parent = contextToken.parent; + if (parent && (parent.kind === SyntaxKind.ObjectLiteralExpression || parent.kind === SyntaxKind.ObjectBindingPattern)) { + return parent; } break; } @@ -3288,8 +3298,7 @@ namespace ts { containingNodeKind === SyntaxKind.ClassDeclaration || // class A !lookUp(exisingImports, e.name)); } - function filterContextualMembersList(contextualMemberSymbols: Symbol[], existingMembers: Declaration[]): Symbol[] { + function filterObjectMembersList(contextualMemberSymbols: Symbol[], existingMembers: Declaration[]): Symbol[] { if (!existingMembers || existingMembers.length === 0) { return contextualMemberSymbols; } let existingMemberNames: Map = {}; - forEach(existingMembers, m => { - if (m.kind !== SyntaxKind.PropertyAssignment && m.kind !== SyntaxKind.ShorthandPropertyAssignment) { - // Ignore omitted expressions for missing members in the object literal - return; + for (let m of existingMembers) { + // Ignore omitted expressions for missing members + if (m.kind !== SyntaxKind.PropertyAssignment && + m.kind !== SyntaxKind.ShorthandPropertyAssignment && + m.kind !== SyntaxKind.BindingElement) { + continue; } + // If this is the current item we are editing right now, do not filter it out if (m.getStart() <= position && position <= m.getEnd()) { - // If this is the current item we are editing right now, do not filter it out - return; + continue; } - // TODO(jfreeman): Account for computed property name - existingMemberNames[(m.name).text] = true; - }); + let existingName: string; + + if (m.kind === SyntaxKind.BindingElement && (m).propertyName) { + existingName = (m).propertyName.text; + } + else { + // TODO(jfreeman): Account for computed property name + // NOTE: if one only performs this step when m.name is an identifier, + // things like '__proto__' are not filtered out. + existingName = (m.name).text; + } + + existingMemberNames[existingName] = true; + } let filteredMembers: Symbol[] = []; forEach(contextualMemberSymbols, s => { @@ -3516,10 +3537,10 @@ namespace ts { function getCompletionEntriesFromSymbols(symbols: Symbol[]): CompletionEntry[] { let start = new Date().getTime(); - var entries: CompletionEntry[] = []; + let entries: CompletionEntry[] = []; if (symbols) { - var nameToSymbol: Map = {}; + let nameToSymbol: Map = {}; for (let symbol of symbols) { let entry = createCompletionEntry(symbol, location); if (entry) { @@ -3553,13 +3574,13 @@ namespace ts { let symbol = forEach(symbols, s => getCompletionEntryDisplayNameForSymbol(s, target, /*performCharacterChecks:*/ false) === entryName ? s : undefined); if (symbol) { - let displayPartsDocumentationsAndSymbolKind = getSymbolDisplayPartsDocumentationAndSymbolKind(symbol, getValidSourceFile(fileName), location, location, SemanticMeaning.All); + let { displayParts, documentation, symbolKind } = getSymbolDisplayPartsDocumentationAndSymbolKind(symbol, getValidSourceFile(fileName), location, location, SemanticMeaning.All); return { name: entryName, - kind: displayPartsDocumentationsAndSymbolKind.symbolKind, kindModifiers: getSymbolModifiers(symbol), - displayParts: displayPartsDocumentationsAndSymbolKind.displayParts, - documentation: displayPartsDocumentationsAndSymbolKind.documentation + kind: symbolKind, + displayParts, + documentation }; } } @@ -4234,7 +4255,7 @@ namespace ts { } if (type.flags & TypeFlags.Union) { - var result: DefinitionInfo[] = []; + let result: DefinitionInfo[] = []; forEach((type).types, t => { if (t.symbol) { addRange(/*to*/ result, /*from*/ getDefinitionFromSymbol(t.symbol, node)); @@ -4334,7 +4355,7 @@ namespace ts { function getSyntacticDocumentHighlights(node: Node): DocumentHighlights[] { let fileName = sourceFile.fileName; - var highlightSpans = getHighlightSpans(node); + let highlightSpans = getHighlightSpans(node); if (!highlightSpans || highlightSpans.length === 0) { return undefined; } @@ -4912,17 +4933,17 @@ namespace ts { } function findRenameLocations(fileName: string, position: number, findInStrings: boolean, findInComments: boolean): RenameLocation[] { - var referencedSymbols = findReferencedSymbols(fileName, position, findInStrings, findInComments); + let referencedSymbols = findReferencedSymbols(fileName, position, findInStrings, findInComments); return convertReferences(referencedSymbols); } function getReferencesAtPosition(fileName: string, position: number): ReferenceEntry[] { - var referencedSymbols = findReferencedSymbols(fileName, position, /*findInStrings:*/ false, /*findInComments:*/ false); + let referencedSymbols = findReferencedSymbols(fileName, position, /*findInStrings:*/ false, /*findInComments:*/ false); return convertReferences(referencedSymbols); } - function findReferences(fileName: string, position: number): ReferencedSymbol[] { - var referencedSymbols = findReferencedSymbols(fileName, position, /*findInStrings:*/ false, /*findInComments:*/ false); + function findReferences(fileName: string, position: number): ReferencedSymbol[]{ + let referencedSymbols = findReferencedSymbols(fileName, position, /*findInStrings:*/ false, /*findInComments:*/ false); // Only include referenced symbols that have a valid definition. return filter(referencedSymbols, rs => !!rs.definition); @@ -5221,7 +5242,7 @@ namespace ts { } }); - var definition: DefinitionInfo = { + let definition: DefinitionInfo = { containerKind: "", containerName: "", fileName: targetLabel.getSourceFile().fileName, @@ -5317,10 +5338,10 @@ namespace ts { if (referenceSymbol) { let referenceSymbolDeclaration = referenceSymbol.valueDeclaration; let shorthandValueSymbol = typeChecker.getShorthandAssignmentValueSymbol(referenceSymbolDeclaration); - var relatedSymbol = getRelatedSymbol(searchSymbols, referenceSymbol, referenceLocation); + let relatedSymbol = getRelatedSymbol(searchSymbols, referenceSymbol, referenceLocation); if (relatedSymbol) { - var referencedSymbol = getReferencedSymbol(relatedSymbol); + let referencedSymbol = getReferencedSymbol(relatedSymbol); referencedSymbol.references.push(getReferenceEntryFromNode(referenceLocation)); } /* Because in short-hand property assignment, an identifier which stored as name of the short-hand property assignment @@ -5330,7 +5351,7 @@ namespace ts { * position of property accessing, the referenceEntry of such position will be handled in the first case. */ else if (!(referenceSymbol.flags & SymbolFlags.Transient) && searchSymbols.indexOf(shorthandValueSymbol) >= 0) { - var referencedSymbol = getReferencedSymbol(shorthandValueSymbol); + let referencedSymbol = getReferencedSymbol(shorthandValueSymbol); referencedSymbol.references.push(getReferenceEntryFromNode(referenceSymbolDeclaration.name)); } } @@ -5340,8 +5361,8 @@ namespace ts { return; function getReferencedSymbol(symbol: Symbol): ReferencedSymbol { - var symbolId = getSymbolId(symbol); - var index = symbolToIndex[symbolId]; + let symbolId = getSymbolId(symbol); + let index = symbolToIndex[symbolId]; if (index === undefined) { index = result.length; symbolToIndex[symbolId] = index; @@ -5428,7 +5449,7 @@ namespace ts { } }); - var definition = getDefinition(searchSpaceNode.symbol); + let definition = getDefinition(searchSpaceNode.symbol); return [{ definition, references }]; } @@ -5623,7 +5644,7 @@ namespace ts { // If the reference symbol is an alias, check if what it is aliasing is one of the search // symbols. if (isImportOrExportSpecifierImportSymbol(referenceSymbol)) { - var aliasedSymbol = typeChecker.getAliasedSymbol(referenceSymbol); + let aliasedSymbol = typeChecker.getAliasedSymbol(referenceSymbol); if (searchSymbols.indexOf(aliasedSymbol) >= 0) { return aliasedSymbol; } @@ -6352,6 +6373,10 @@ namespace ts { } function classifyToken(token: Node): void { + if (nodeIsMissing(token)) { + return; + } + let tokenStart = classifyLeadingTriviaAndGetTokenStart(token); let tokenWidth = token.end - tokenStart; @@ -6936,7 +6961,7 @@ namespace ts { } function convertClassifications(classifications: Classifications, text: string): ClassificationResult { - var entries: ClassificationInfo[] = []; + let entries: ClassificationInfo[] = []; let dense = classifications.spans; let lastEnd = 0; diff --git a/tests/baselines/reference/anonymousClassExpression1.errors.txt b/tests/baselines/reference/anonymousClassExpression1.errors.txt deleted file mode 100644 index db4c5b4ce3d..00000000000 --- a/tests/baselines/reference/anonymousClassExpression1.errors.txt +++ /dev/null @@ -1,9 +0,0 @@ -tests/cases/compiler/anonymousClassExpression1.ts(2,19): error TS9003: 'class' expressions are not currently supported. - - -==== tests/cases/compiler/anonymousClassExpression1.ts (1 errors) ==== - function f() { - return typeof class {} === "function"; - ~~~~~ -!!! error TS9003: 'class' expressions are not currently supported. - } \ No newline at end of file diff --git a/tests/baselines/reference/anonymousClassExpression1.js b/tests/baselines/reference/anonymousClassExpression1.js index 78cf5b05c51..5ced5120979 100644 --- a/tests/baselines/reference/anonymousClassExpression1.js +++ b/tests/baselines/reference/anonymousClassExpression1.js @@ -6,8 +6,8 @@ function f() { //// [anonymousClassExpression1.js] function f() { return typeof (function () { - function default_1() { + function class_1() { } - return default_1; + return class_1; })() === "function"; } diff --git a/tests/baselines/reference/anonymousClassExpression1.symbols b/tests/baselines/reference/anonymousClassExpression1.symbols new file mode 100644 index 00000000000..114bfc96097 --- /dev/null +++ b/tests/baselines/reference/anonymousClassExpression1.symbols @@ -0,0 +1,6 @@ +=== tests/cases/compiler/anonymousClassExpression1.ts === +function f() { +>f : Symbol(f, Decl(anonymousClassExpression1.ts, 0, 0)) + + return typeof class {} === "function"; +} diff --git a/tests/baselines/reference/anonymousClassExpression1.types b/tests/baselines/reference/anonymousClassExpression1.types new file mode 100644 index 00000000000..1e38399f01e --- /dev/null +++ b/tests/baselines/reference/anonymousClassExpression1.types @@ -0,0 +1,10 @@ +=== tests/cases/compiler/anonymousClassExpression1.ts === +function f() { +>f : () => boolean + + return typeof class {} === "function"; +>typeof class {} === "function" : boolean +>typeof class {} : string +>class {} : typeof (Anonymous class) +>"function" : string +} diff --git a/tests/baselines/reference/classExpression.errors.txt b/tests/baselines/reference/classExpression.errors.txt deleted file mode 100644 index c8266d0e879..00000000000 --- a/tests/baselines/reference/classExpression.errors.txt +++ /dev/null @@ -1,24 +0,0 @@ -tests/cases/conformance/classes/classExpression.ts(1,15): error TS9003: 'class' expressions are not currently supported. -tests/cases/conformance/classes/classExpression.ts(5,16): error TS9003: 'class' expressions are not currently supported. -tests/cases/conformance/classes/classExpression.ts(10,19): error TS9003: 'class' expressions are not currently supported. - - -==== tests/cases/conformance/classes/classExpression.ts (3 errors) ==== - var x = class C { - ~ -!!! error TS9003: 'class' expressions are not currently supported. - } - - var y = { - foo: class C2 { - ~~ -!!! error TS9003: 'class' expressions are not currently supported. - } - } - - module M { - var z = class C4 { - ~~ -!!! error TS9003: 'class' expressions are not currently supported. - } - } \ No newline at end of file diff --git a/tests/baselines/reference/classExpression.symbols b/tests/baselines/reference/classExpression.symbols new file mode 100644 index 00000000000..f4d44236499 --- /dev/null +++ b/tests/baselines/reference/classExpression.symbols @@ -0,0 +1,23 @@ +=== tests/cases/conformance/classes/classExpression.ts === +var x = class C { +>x : Symbol(x, Decl(classExpression.ts, 0, 3)) +>C : Symbol(C, Decl(classExpression.ts, 0, 7)) +} + +var y = { +>y : Symbol(y, Decl(classExpression.ts, 3, 3)) + + foo: class C2 { +>foo : Symbol(foo, Decl(classExpression.ts, 3, 9)) +>C2 : Symbol(C2, Decl(classExpression.ts, 4, 8)) + } +} + +module M { +>M : Symbol(M, Decl(classExpression.ts, 6, 1)) + + var z = class C4 { +>z : Symbol(z, Decl(classExpression.ts, 9, 7)) +>C4 : Symbol(C4, Decl(classExpression.ts, 9, 11)) + } +} diff --git a/tests/baselines/reference/classExpression.types b/tests/baselines/reference/classExpression.types new file mode 100644 index 00000000000..1c55ce89544 --- /dev/null +++ b/tests/baselines/reference/classExpression.types @@ -0,0 +1,27 @@ +=== tests/cases/conformance/classes/classExpression.ts === +var x = class C { +>x : typeof C +>class C {} : typeof C +>C : typeof C +} + +var y = { +>y : { foo: typeof C2; } +>{ foo: class C2 { }} : { foo: typeof C2; } + + foo: class C2 { +>foo : typeof C2 +>class C2 { } : typeof C2 +>C2 : typeof C2 + } +} + +module M { +>M : typeof M + + var z = class C4 { +>z : typeof C4 +>class C4 { } : typeof C4 +>C4 : typeof C4 + } +} diff --git a/tests/baselines/reference/classExpression1.errors.txt b/tests/baselines/reference/classExpression1.errors.txt deleted file mode 100644 index 9d7d14d8571..00000000000 --- a/tests/baselines/reference/classExpression1.errors.txt +++ /dev/null @@ -1,7 +0,0 @@ -tests/cases/conformance/classes/classExpressions/classExpression1.ts(1,15): error TS9003: 'class' expressions are not currently supported. - - -==== tests/cases/conformance/classes/classExpressions/classExpression1.ts (1 errors) ==== - var v = class C {}; - ~ -!!! error TS9003: 'class' expressions are not currently supported. \ No newline at end of file diff --git a/tests/baselines/reference/classExpression1.symbols b/tests/baselines/reference/classExpression1.symbols new file mode 100644 index 00000000000..8d3bad269b4 --- /dev/null +++ b/tests/baselines/reference/classExpression1.symbols @@ -0,0 +1,5 @@ +=== tests/cases/conformance/classes/classExpressions/classExpression1.ts === +var v = class C {}; +>v : Symbol(v, Decl(classExpression1.ts, 0, 3)) +>C : Symbol(C, Decl(classExpression1.ts, 0, 7)) + diff --git a/tests/baselines/reference/classExpression1.types b/tests/baselines/reference/classExpression1.types new file mode 100644 index 00000000000..4bea3183118 --- /dev/null +++ b/tests/baselines/reference/classExpression1.types @@ -0,0 +1,6 @@ +=== tests/cases/conformance/classes/classExpressions/classExpression1.ts === +var v = class C {}; +>v : typeof C +>class C {} : typeof C +>C : typeof C + diff --git a/tests/baselines/reference/classExpression2.errors.txt b/tests/baselines/reference/classExpression2.errors.txt deleted file mode 100644 index e2f3ccd77cd..00000000000 --- a/tests/baselines/reference/classExpression2.errors.txt +++ /dev/null @@ -1,8 +0,0 @@ -tests/cases/conformance/classes/classExpressions/classExpression2.ts(2,15): error TS9003: 'class' expressions are not currently supported. - - -==== tests/cases/conformance/classes/classExpressions/classExpression2.ts (1 errors) ==== - class D { } - var v = class C extends D {}; - ~ -!!! error TS9003: 'class' expressions are not currently supported. \ No newline at end of file diff --git a/tests/baselines/reference/classExpression2.js b/tests/baselines/reference/classExpression2.js index 4220b88fb11..f74bb8bd5e2 100644 --- a/tests/baselines/reference/classExpression2.js +++ b/tests/baselines/reference/classExpression2.js @@ -3,6 +3,11 @@ class D { } var v = class C extends D {}; //// [classExpression2.js] +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; var D = (function () { function D() { } diff --git a/tests/baselines/reference/classExpression2.symbols b/tests/baselines/reference/classExpression2.symbols new file mode 100644 index 00000000000..11c78a2cad2 --- /dev/null +++ b/tests/baselines/reference/classExpression2.symbols @@ -0,0 +1,9 @@ +=== tests/cases/conformance/classes/classExpressions/classExpression2.ts === +class D { } +>D : Symbol(D, Decl(classExpression2.ts, 0, 0)) + +var v = class C extends D {}; +>v : Symbol(v, Decl(classExpression2.ts, 1, 3)) +>C : Symbol(C, Decl(classExpression2.ts, 1, 7)) +>D : Symbol(D, Decl(classExpression2.ts, 0, 0)) + diff --git a/tests/baselines/reference/classExpression2.types b/tests/baselines/reference/classExpression2.types new file mode 100644 index 00000000000..4dd6595fb49 --- /dev/null +++ b/tests/baselines/reference/classExpression2.types @@ -0,0 +1,10 @@ +=== tests/cases/conformance/classes/classExpressions/classExpression2.ts === +class D { } +>D : D + +var v = class C extends D {}; +>v : typeof C +>class C extends D {} : typeof C +>C : typeof C +>D : D + diff --git a/tests/baselines/reference/classExpression3.js b/tests/baselines/reference/classExpression3.js new file mode 100644 index 00000000000..ec9581eaf39 --- /dev/null +++ b/tests/baselines/reference/classExpression3.js @@ -0,0 +1,38 @@ +//// [classExpression3.ts] +let C = class extends class extends class { a = 1 } { b = 2 } { c = 3 }; +let c = new C(); +c.a; +c.b; +c.c; + + +//// [classExpression3.js] +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var C = (function (_super) { + __extends(class_1, _super); + function class_1() { + _super.apply(this, arguments); + this.c = 3; + } + return class_1; +})((function (_super) { + __extends(class_2, _super); + function class_2() { + _super.apply(this, arguments); + this.b = 2; + } + return class_2; +})((function () { + function class_3() { + this.a = 1; + } + return class_3; +})())); +var c = new C(); +c.a; +c.b; +c.c; diff --git a/tests/baselines/reference/classExpression3.symbols b/tests/baselines/reference/classExpression3.symbols new file mode 100644 index 00000000000..bc1b263a000 --- /dev/null +++ b/tests/baselines/reference/classExpression3.symbols @@ -0,0 +1,26 @@ +=== tests/cases/conformance/classes/classExpressions/classExpression3.ts === +let C = class extends class extends class { a = 1 } { b = 2 } { c = 3 }; +>C : Symbol(C, Decl(classExpression3.ts, 0, 3)) +>a : Symbol((Anonymous class).a, Decl(classExpression3.ts, 0, 43)) +>b : Symbol((Anonymous class).b, Decl(classExpression3.ts, 0, 53)) +>c : Symbol((Anonymous class).c, Decl(classExpression3.ts, 0, 63)) + +let c = new C(); +>c : Symbol(c, Decl(classExpression3.ts, 1, 3)) +>C : Symbol(C, Decl(classExpression3.ts, 0, 3)) + +c.a; +>c.a : Symbol((Anonymous class).a, Decl(classExpression3.ts, 0, 43)) +>c : Symbol(c, Decl(classExpression3.ts, 1, 3)) +>a : Symbol((Anonymous class).a, Decl(classExpression3.ts, 0, 43)) + +c.b; +>c.b : Symbol((Anonymous class).b, Decl(classExpression3.ts, 0, 53)) +>c : Symbol(c, Decl(classExpression3.ts, 1, 3)) +>b : Symbol((Anonymous class).b, Decl(classExpression3.ts, 0, 53)) + +c.c; +>c.c : Symbol((Anonymous class).c, Decl(classExpression3.ts, 0, 63)) +>c : Symbol(c, Decl(classExpression3.ts, 1, 3)) +>c : Symbol((Anonymous class).c, Decl(classExpression3.ts, 0, 63)) + diff --git a/tests/baselines/reference/classExpression3.types b/tests/baselines/reference/classExpression3.types new file mode 100644 index 00000000000..87423ecf0bd --- /dev/null +++ b/tests/baselines/reference/classExpression3.types @@ -0,0 +1,33 @@ +=== tests/cases/conformance/classes/classExpressions/classExpression3.ts === +let C = class extends class extends class { a = 1 } { b = 2 } { c = 3 }; +>C : typeof (Anonymous class) +>class extends class extends class { a = 1 } { b = 2 } { c = 3 } : typeof (Anonymous class) +>class extends class { a = 1 } { b = 2 } : (Anonymous class) +>class { a = 1 } : (Anonymous class) +>a : number +>1 : number +>b : number +>2 : number +>c : number +>3 : number + +let c = new C(); +>c : (Anonymous class) +>new C() : (Anonymous class) +>C : typeof (Anonymous class) + +c.a; +>c.a : number +>c : (Anonymous class) +>a : number + +c.b; +>c.b : number +>c : (Anonymous class) +>b : number + +c.c; +>c.c : number +>c : (Anonymous class) +>c : number + diff --git a/tests/baselines/reference/classExpression4.js b/tests/baselines/reference/classExpression4.js new file mode 100644 index 00000000000..c2ead0474e2 --- /dev/null +++ b/tests/baselines/reference/classExpression4.js @@ -0,0 +1,19 @@ +//// [classExpression4.ts] +let C = class { + foo() { + return new C(); + } +}; +let x = (new C).foo(); + + +//// [classExpression4.js] +var C = (function () { + function class_1() { + } + class_1.prototype.foo = function () { + return new C(); + }; + return class_1; +})(); +var x = (new C).foo(); diff --git a/tests/baselines/reference/classExpression4.symbols b/tests/baselines/reference/classExpression4.symbols new file mode 100644 index 00000000000..4df5302cecc --- /dev/null +++ b/tests/baselines/reference/classExpression4.symbols @@ -0,0 +1,17 @@ +=== tests/cases/conformance/classes/classExpressions/classExpression4.ts === +let C = class { +>C : Symbol(C, Decl(classExpression4.ts, 0, 3)) + + foo() { +>foo : Symbol((Anonymous class).foo, Decl(classExpression4.ts, 0, 15)) + + return new C(); +>C : Symbol(C, Decl(classExpression4.ts, 0, 3)) + } +}; +let x = (new C).foo(); +>x : Symbol(x, Decl(classExpression4.ts, 5, 3)) +>(new C).foo : Symbol((Anonymous class).foo, Decl(classExpression4.ts, 0, 15)) +>C : Symbol(C, Decl(classExpression4.ts, 0, 3)) +>foo : Symbol((Anonymous class).foo, Decl(classExpression4.ts, 0, 15)) + diff --git a/tests/baselines/reference/classExpression4.types b/tests/baselines/reference/classExpression4.types new file mode 100644 index 00000000000..066f169ae74 --- /dev/null +++ b/tests/baselines/reference/classExpression4.types @@ -0,0 +1,22 @@ +=== tests/cases/conformance/classes/classExpressions/classExpression4.ts === +let C = class { +>C : typeof (Anonymous class) +>class { foo() { return new C(); }} : typeof (Anonymous class) + + foo() { +>foo : () => (Anonymous class) + + return new C(); +>new C() : (Anonymous class) +>C : typeof (Anonymous class) + } +}; +let x = (new C).foo(); +>x : (Anonymous class) +>(new C).foo() : (Anonymous class) +>(new C).foo : () => (Anonymous class) +>(new C) : (Anonymous class) +>new C : (Anonymous class) +>C : typeof (Anonymous class) +>foo : () => (Anonymous class) + diff --git a/tests/baselines/reference/classExpressionES61.errors.txt b/tests/baselines/reference/classExpressionES61.errors.txt deleted file mode 100644 index abaa5ab893c..00000000000 --- a/tests/baselines/reference/classExpressionES61.errors.txt +++ /dev/null @@ -1,7 +0,0 @@ -tests/cases/conformance/es6/classExpressions/classExpressionES61.ts(1,15): error TS9003: 'class' expressions are not currently supported. - - -==== tests/cases/conformance/es6/classExpressions/classExpressionES61.ts (1 errors) ==== - var v = class C {}; - ~ -!!! error TS9003: 'class' expressions are not currently supported. \ No newline at end of file diff --git a/tests/baselines/reference/classExpressionES61.symbols b/tests/baselines/reference/classExpressionES61.symbols new file mode 100644 index 00000000000..1f49229fbc7 --- /dev/null +++ b/tests/baselines/reference/classExpressionES61.symbols @@ -0,0 +1,5 @@ +=== tests/cases/conformance/es6/classExpressions/classExpressionES61.ts === +var v = class C {}; +>v : Symbol(v, Decl(classExpressionES61.ts, 0, 3)) +>C : Symbol(C, Decl(classExpressionES61.ts, 0, 7)) + diff --git a/tests/baselines/reference/classExpressionES61.types b/tests/baselines/reference/classExpressionES61.types new file mode 100644 index 00000000000..e04570308e8 --- /dev/null +++ b/tests/baselines/reference/classExpressionES61.types @@ -0,0 +1,6 @@ +=== tests/cases/conformance/es6/classExpressions/classExpressionES61.ts === +var v = class C {}; +>v : typeof C +>class C {} : typeof C +>C : typeof C + diff --git a/tests/baselines/reference/classExpressionES62.errors.txt b/tests/baselines/reference/classExpressionES62.errors.txt deleted file mode 100644 index 1e28367a17e..00000000000 --- a/tests/baselines/reference/classExpressionES62.errors.txt +++ /dev/null @@ -1,8 +0,0 @@ -tests/cases/conformance/es6/classExpressions/classExpressionES62.ts(2,15): error TS9003: 'class' expressions are not currently supported. - - -==== tests/cases/conformance/es6/classExpressions/classExpressionES62.ts (1 errors) ==== - class D { } - var v = class C extends D {}; - ~ -!!! error TS9003: 'class' expressions are not currently supported. \ No newline at end of file diff --git a/tests/baselines/reference/classExpressionES62.symbols b/tests/baselines/reference/classExpressionES62.symbols new file mode 100644 index 00000000000..18e1a48ca30 --- /dev/null +++ b/tests/baselines/reference/classExpressionES62.symbols @@ -0,0 +1,9 @@ +=== tests/cases/conformance/es6/classExpressions/classExpressionES62.ts === +class D { } +>D : Symbol(D, Decl(classExpressionES62.ts, 0, 0)) + +var v = class C extends D {}; +>v : Symbol(v, Decl(classExpressionES62.ts, 1, 3)) +>C : Symbol(C, Decl(classExpressionES62.ts, 1, 7)) +>D : Symbol(D, Decl(classExpressionES62.ts, 0, 0)) + diff --git a/tests/baselines/reference/classExpressionES62.types b/tests/baselines/reference/classExpressionES62.types new file mode 100644 index 00000000000..8bb4e1a39ff --- /dev/null +++ b/tests/baselines/reference/classExpressionES62.types @@ -0,0 +1,10 @@ +=== tests/cases/conformance/es6/classExpressions/classExpressionES62.ts === +class D { } +>D : D + +var v = class C extends D {}; +>v : typeof C +>class C extends D {} : typeof C +>C : typeof C +>D : D + diff --git a/tests/baselines/reference/classExpressionES63.js b/tests/baselines/reference/classExpressionES63.js new file mode 100644 index 00000000000..6d357af7c5a --- /dev/null +++ b/tests/baselines/reference/classExpressionES63.js @@ -0,0 +1,31 @@ +//// [classExpressionES63.ts] +let C = class extends class extends class { a = 1 } { b = 2 } { c = 3 }; +let c = new C(); +c.a; +c.b; +c.c; + + +//// [classExpressionES63.js] +let C = class class_1 extends class class_2 extends class class_3 { + constructor() { + this.a = 1; + } +} + { + constructor(...args) { + super(...args); + this.b = 2; + } +} + { + constructor(...args) { + super(...args); + this.c = 3; + } +} +; +let c = new C(); +c.a; +c.b; +c.c; diff --git a/tests/baselines/reference/classExpressionES63.symbols b/tests/baselines/reference/classExpressionES63.symbols new file mode 100644 index 00000000000..4e52d5ee9dd --- /dev/null +++ b/tests/baselines/reference/classExpressionES63.symbols @@ -0,0 +1,26 @@ +=== tests/cases/conformance/es6/classExpressions/classExpressionES63.ts === +let C = class extends class extends class { a = 1 } { b = 2 } { c = 3 }; +>C : Symbol(C, Decl(classExpressionES63.ts, 0, 3)) +>a : Symbol((Anonymous class).a, Decl(classExpressionES63.ts, 0, 43)) +>b : Symbol((Anonymous class).b, Decl(classExpressionES63.ts, 0, 53)) +>c : Symbol((Anonymous class).c, Decl(classExpressionES63.ts, 0, 63)) + +let c = new C(); +>c : Symbol(c, Decl(classExpressionES63.ts, 1, 3)) +>C : Symbol(C, Decl(classExpressionES63.ts, 0, 3)) + +c.a; +>c.a : Symbol((Anonymous class).a, Decl(classExpressionES63.ts, 0, 43)) +>c : Symbol(c, Decl(classExpressionES63.ts, 1, 3)) +>a : Symbol((Anonymous class).a, Decl(classExpressionES63.ts, 0, 43)) + +c.b; +>c.b : Symbol((Anonymous class).b, Decl(classExpressionES63.ts, 0, 53)) +>c : Symbol(c, Decl(classExpressionES63.ts, 1, 3)) +>b : Symbol((Anonymous class).b, Decl(classExpressionES63.ts, 0, 53)) + +c.c; +>c.c : Symbol((Anonymous class).c, Decl(classExpressionES63.ts, 0, 63)) +>c : Symbol(c, Decl(classExpressionES63.ts, 1, 3)) +>c : Symbol((Anonymous class).c, Decl(classExpressionES63.ts, 0, 63)) + diff --git a/tests/baselines/reference/classExpressionES63.types b/tests/baselines/reference/classExpressionES63.types new file mode 100644 index 00000000000..5b07bf79692 --- /dev/null +++ b/tests/baselines/reference/classExpressionES63.types @@ -0,0 +1,33 @@ +=== tests/cases/conformance/es6/classExpressions/classExpressionES63.ts === +let C = class extends class extends class { a = 1 } { b = 2 } { c = 3 }; +>C : typeof (Anonymous class) +>class extends class extends class { a = 1 } { b = 2 } { c = 3 } : typeof (Anonymous class) +>class extends class { a = 1 } { b = 2 } : (Anonymous class) +>class { a = 1 } : (Anonymous class) +>a : number +>1 : number +>b : number +>2 : number +>c : number +>3 : number + +let c = new C(); +>c : (Anonymous class) +>new C() : (Anonymous class) +>C : typeof (Anonymous class) + +c.a; +>c.a : number +>c : (Anonymous class) +>a : number + +c.b; +>c.b : number +>c : (Anonymous class) +>b : number + +c.c; +>c.c : number +>c : (Anonymous class) +>c : number + diff --git a/tests/baselines/reference/classExpressionTest2.errors.txt b/tests/baselines/reference/classExpressionTest2.errors.txt deleted file mode 100644 index 424eb590611..00000000000 --- a/tests/baselines/reference/classExpressionTest2.errors.txt +++ /dev/null @@ -1,21 +0,0 @@ -tests/cases/compiler/classExpressionTest2.ts(2,19): error TS9003: 'class' expressions are not currently supported. -tests/cases/compiler/classExpressionTest2.ts(5,20): error TS2304: Cannot find name 'X'. - - -==== tests/cases/compiler/classExpressionTest2.ts (2 errors) ==== - function M() { - var m = class C { - ~ -!!! error TS9003: 'class' expressions are not currently supported. - f() { - var t: T; - var x: X; - ~ -!!! error TS2304: Cannot find name 'X'. - return { t, x }; - } - } - - var v = new m(); - return v.f(); - } \ No newline at end of file diff --git a/tests/baselines/reference/classExpressionTest2.symbols b/tests/baselines/reference/classExpressionTest2.symbols new file mode 100644 index 00000000000..62143cf0b9f --- /dev/null +++ b/tests/baselines/reference/classExpressionTest2.symbols @@ -0,0 +1,36 @@ +=== tests/cases/compiler/classExpressionTest2.ts === +function M() { +>M : Symbol(M, Decl(classExpressionTest2.ts, 0, 0)) + + var m = class C { +>m : Symbol(m, Decl(classExpressionTest2.ts, 1, 7)) +>C : Symbol(C, Decl(classExpressionTest2.ts, 1, 11)) +>X : Symbol(X, Decl(classExpressionTest2.ts, 1, 20)) + + f() { +>f : Symbol(C.f, Decl(classExpressionTest2.ts, 1, 24)) +>T : Symbol(T, Decl(classExpressionTest2.ts, 2, 10)) + + var t: T; +>t : Symbol(t, Decl(classExpressionTest2.ts, 3, 15)) +>T : Symbol(T, Decl(classExpressionTest2.ts, 2, 10)) + + var x: X; +>x : Symbol(x, Decl(classExpressionTest2.ts, 4, 15)) +>X : Symbol(X, Decl(classExpressionTest2.ts, 1, 20)) + + return { t, x }; +>t : Symbol(t, Decl(classExpressionTest2.ts, 5, 20)) +>x : Symbol(x, Decl(classExpressionTest2.ts, 5, 23)) + } + } + + var v = new m(); +>v : Symbol(v, Decl(classExpressionTest2.ts, 9, 7)) +>m : Symbol(m, Decl(classExpressionTest2.ts, 1, 7)) + + return v.f(); +>v.f : Symbol(C.f, Decl(classExpressionTest2.ts, 1, 24)) +>v : Symbol(v, Decl(classExpressionTest2.ts, 9, 7)) +>f : Symbol(C.f, Decl(classExpressionTest2.ts, 1, 24)) +} diff --git a/tests/baselines/reference/classExpressionTest2.types b/tests/baselines/reference/classExpressionTest2.types new file mode 100644 index 00000000000..5586b451d3a --- /dev/null +++ b/tests/baselines/reference/classExpressionTest2.types @@ -0,0 +1,40 @@ +=== tests/cases/compiler/classExpressionTest2.ts === +function M() { +>M : () => { t: string; x: number; } + + var m = class C { +>m : typeof C +>class C { f() { var t: T; var x: X; return { t, x }; } } : typeof C +>C : typeof C +>X : X + + f() { +>f : () => { t: T; x: X; } +>T : T + + var t: T; +>t : T +>T : T + + var x: X; +>x : X +>X : X + + return { t, x }; +>{ t, x } : { t: T; x: X; } +>t : T +>x : X + } + } + + var v = new m(); +>v : +>new m() : +>m : typeof C + + return v.f(); +>v.f() : { t: string; x: number; } +>v.f : () => { t: T; x: number; } +>v : +>f : () => { t: T; x: number; } +} diff --git a/tests/baselines/reference/classExpressionWithResolutionOfNamespaceOfSameName01.errors.txt b/tests/baselines/reference/classExpressionWithResolutionOfNamespaceOfSameName01.errors.txt deleted file mode 100644 index 8edc1d8f74b..00000000000 --- a/tests/baselines/reference/classExpressionWithResolutionOfNamespaceOfSameName01.errors.txt +++ /dev/null @@ -1,14 +0,0 @@ -tests/cases/compiler/classExpressionWithResolutionOfNamespaceOfSameName01.ts(6,15): error TS9003: 'class' expressions are not currently supported. - - -==== tests/cases/compiler/classExpressionWithResolutionOfNamespaceOfSameName01.ts (1 errors) ==== - namespace C { - export interface type { - } - } - - var x = class C { - ~ -!!! error TS9003: 'class' expressions are not currently supported. - prop: C.type; - } \ No newline at end of file diff --git a/tests/baselines/reference/classExpressionWithResolutionOfNamespaceOfSameName01.symbols b/tests/baselines/reference/classExpressionWithResolutionOfNamespaceOfSameName01.symbols new file mode 100644 index 00000000000..fcd4f0388db --- /dev/null +++ b/tests/baselines/reference/classExpressionWithResolutionOfNamespaceOfSameName01.symbols @@ -0,0 +1,18 @@ +=== tests/cases/compiler/classExpressionWithResolutionOfNamespaceOfSameName01.ts === +namespace C { +>C : Symbol(C, Decl(classExpressionWithResolutionOfNamespaceOfSameName01.ts, 0, 0)) + + export interface type { +>type : Symbol(type, Decl(classExpressionWithResolutionOfNamespaceOfSameName01.ts, 0, 13)) + } +} + +var x = class C { +>x : Symbol(x, Decl(classExpressionWithResolutionOfNamespaceOfSameName01.ts, 5, 3)) +>C : Symbol(C, Decl(classExpressionWithResolutionOfNamespaceOfSameName01.ts, 5, 7)) + + prop: C.type; +>prop : Symbol(C.prop, Decl(classExpressionWithResolutionOfNamespaceOfSameName01.ts, 5, 17)) +>C : Symbol(C, Decl(classExpressionWithResolutionOfNamespaceOfSameName01.ts, 0, 0)) +>type : Symbol(C.type, Decl(classExpressionWithResolutionOfNamespaceOfSameName01.ts, 0, 13)) +} diff --git a/tests/baselines/reference/classExpressionWithResolutionOfNamespaceOfSameName01.types b/tests/baselines/reference/classExpressionWithResolutionOfNamespaceOfSameName01.types new file mode 100644 index 00000000000..643cf65d2e0 --- /dev/null +++ b/tests/baselines/reference/classExpressionWithResolutionOfNamespaceOfSameName01.types @@ -0,0 +1,19 @@ +=== tests/cases/compiler/classExpressionWithResolutionOfNamespaceOfSameName01.ts === +namespace C { +>C : any + + export interface type { +>type : type + } +} + +var x = class C { +>x : typeof C +>class C { prop: C.type;} : typeof C +>C : typeof C + + prop: C.type; +>prop : C.type +>C : any +>type : C.type +} diff --git a/tests/baselines/reference/classExpressionWithStaticProperties1.errors.txt b/tests/baselines/reference/classExpressionWithStaticProperties1.errors.txt deleted file mode 100644 index 28e42dd33f1..00000000000 --- a/tests/baselines/reference/classExpressionWithStaticProperties1.errors.txt +++ /dev/null @@ -1,7 +0,0 @@ -tests/cases/compiler/classExpressionWithStaticProperties1.ts(1,15): error TS9003: 'class' expressions are not currently supported. - - -==== tests/cases/compiler/classExpressionWithStaticProperties1.ts (1 errors) ==== - var v = class C { static a = 1; static b = 2 }; - ~ -!!! error TS9003: 'class' expressions are not currently supported. \ No newline at end of file diff --git a/tests/baselines/reference/classExpressionWithStaticProperties1.symbols b/tests/baselines/reference/classExpressionWithStaticProperties1.symbols new file mode 100644 index 00000000000..d4c811daebe --- /dev/null +++ b/tests/baselines/reference/classExpressionWithStaticProperties1.symbols @@ -0,0 +1,7 @@ +=== tests/cases/compiler/classExpressionWithStaticProperties1.ts === +var v = class C { static a = 1; static b = 2 }; +>v : Symbol(v, Decl(classExpressionWithStaticProperties1.ts, 0, 3)) +>C : Symbol(C, Decl(classExpressionWithStaticProperties1.ts, 0, 7)) +>a : Symbol(C.a, Decl(classExpressionWithStaticProperties1.ts, 0, 17)) +>b : Symbol(C.b, Decl(classExpressionWithStaticProperties1.ts, 0, 31)) + diff --git a/tests/baselines/reference/classExpressionWithStaticProperties1.types b/tests/baselines/reference/classExpressionWithStaticProperties1.types new file mode 100644 index 00000000000..b014f78abf7 --- /dev/null +++ b/tests/baselines/reference/classExpressionWithStaticProperties1.types @@ -0,0 +1,10 @@ +=== tests/cases/compiler/classExpressionWithStaticProperties1.ts === +var v = class C { static a = 1; static b = 2 }; +>v : typeof C +>class C { static a = 1; static b = 2 } : typeof C +>C : typeof C +>a : number +>1 : number +>b : number +>2 : number + diff --git a/tests/baselines/reference/classExpressionWithStaticProperties2.errors.txt b/tests/baselines/reference/classExpressionWithStaticProperties2.errors.txt deleted file mode 100644 index 9a915f70193..00000000000 --- a/tests/baselines/reference/classExpressionWithStaticProperties2.errors.txt +++ /dev/null @@ -1,7 +0,0 @@ -tests/cases/compiler/classExpressionWithStaticProperties2.ts(1,15): error TS9003: 'class' expressions are not currently supported. - - -==== tests/cases/compiler/classExpressionWithStaticProperties2.ts (1 errors) ==== - var v = class C { static a = 1; static b }; - ~ -!!! error TS9003: 'class' expressions are not currently supported. \ No newline at end of file diff --git a/tests/baselines/reference/classExpressionWithStaticProperties2.symbols b/tests/baselines/reference/classExpressionWithStaticProperties2.symbols new file mode 100644 index 00000000000..480123a1c3b --- /dev/null +++ b/tests/baselines/reference/classExpressionWithStaticProperties2.symbols @@ -0,0 +1,7 @@ +=== tests/cases/compiler/classExpressionWithStaticProperties2.ts === +var v = class C { static a = 1; static b }; +>v : Symbol(v, Decl(classExpressionWithStaticProperties2.ts, 0, 3)) +>C : Symbol(C, Decl(classExpressionWithStaticProperties2.ts, 0, 7)) +>a : Symbol(C.a, Decl(classExpressionWithStaticProperties2.ts, 0, 17)) +>b : Symbol(C.b, Decl(classExpressionWithStaticProperties2.ts, 0, 31)) + diff --git a/tests/baselines/reference/classExpressionWithStaticProperties2.types b/tests/baselines/reference/classExpressionWithStaticProperties2.types new file mode 100644 index 00000000000..9bfd6732350 --- /dev/null +++ b/tests/baselines/reference/classExpressionWithStaticProperties2.types @@ -0,0 +1,9 @@ +=== tests/cases/compiler/classExpressionWithStaticProperties2.ts === +var v = class C { static a = 1; static b }; +>v : typeof C +>class C { static a = 1; static b } : typeof C +>C : typeof C +>a : number +>1 : number +>b : any + diff --git a/tests/baselines/reference/classExpressionWithStaticPropertiesES61.errors.txt b/tests/baselines/reference/classExpressionWithStaticPropertiesES61.errors.txt deleted file mode 100644 index bc015a3d8f0..00000000000 --- a/tests/baselines/reference/classExpressionWithStaticPropertiesES61.errors.txt +++ /dev/null @@ -1,7 +0,0 @@ -tests/cases/compiler/classExpressionWithStaticPropertiesES61.ts(1,15): error TS9003: 'class' expressions are not currently supported. - - -==== tests/cases/compiler/classExpressionWithStaticPropertiesES61.ts (1 errors) ==== - var v = class C { static a = 1; static b = 2 }; - ~ -!!! error TS9003: 'class' expressions are not currently supported. \ No newline at end of file diff --git a/tests/baselines/reference/classExpressionWithStaticPropertiesES61.symbols b/tests/baselines/reference/classExpressionWithStaticPropertiesES61.symbols new file mode 100644 index 00000000000..c5f53e19bff --- /dev/null +++ b/tests/baselines/reference/classExpressionWithStaticPropertiesES61.symbols @@ -0,0 +1,7 @@ +=== tests/cases/compiler/classExpressionWithStaticPropertiesES61.ts === +var v = class C { static a = 1; static b = 2 }; +>v : Symbol(v, Decl(classExpressionWithStaticPropertiesES61.ts, 0, 3)) +>C : Symbol(C, Decl(classExpressionWithStaticPropertiesES61.ts, 0, 7)) +>a : Symbol(C.a, Decl(classExpressionWithStaticPropertiesES61.ts, 0, 17)) +>b : Symbol(C.b, Decl(classExpressionWithStaticPropertiesES61.ts, 0, 31)) + diff --git a/tests/baselines/reference/classExpressionWithStaticPropertiesES61.types b/tests/baselines/reference/classExpressionWithStaticPropertiesES61.types new file mode 100644 index 00000000000..02c385b7525 --- /dev/null +++ b/tests/baselines/reference/classExpressionWithStaticPropertiesES61.types @@ -0,0 +1,10 @@ +=== tests/cases/compiler/classExpressionWithStaticPropertiesES61.ts === +var v = class C { static a = 1; static b = 2 }; +>v : typeof C +>class C { static a = 1; static b = 2 } : typeof C +>C : typeof C +>a : number +>1 : number +>b : number +>2 : number + diff --git a/tests/baselines/reference/classExpressionWithStaticPropertiesES62.errors.txt b/tests/baselines/reference/classExpressionWithStaticPropertiesES62.errors.txt deleted file mode 100644 index bed4b2c01aa..00000000000 --- a/tests/baselines/reference/classExpressionWithStaticPropertiesES62.errors.txt +++ /dev/null @@ -1,7 +0,0 @@ -tests/cases/compiler/classExpressionWithStaticPropertiesES62.ts(1,15): error TS9003: 'class' expressions are not currently supported. - - -==== tests/cases/compiler/classExpressionWithStaticPropertiesES62.ts (1 errors) ==== - var v = class C { static a = 1; static b }; - ~ -!!! error TS9003: 'class' expressions are not currently supported. \ No newline at end of file diff --git a/tests/baselines/reference/classExpressionWithStaticPropertiesES62.symbols b/tests/baselines/reference/classExpressionWithStaticPropertiesES62.symbols new file mode 100644 index 00000000000..be57a289f53 --- /dev/null +++ b/tests/baselines/reference/classExpressionWithStaticPropertiesES62.symbols @@ -0,0 +1,7 @@ +=== tests/cases/compiler/classExpressionWithStaticPropertiesES62.ts === +var v = class C { static a = 1; static b }; +>v : Symbol(v, Decl(classExpressionWithStaticPropertiesES62.ts, 0, 3)) +>C : Symbol(C, Decl(classExpressionWithStaticPropertiesES62.ts, 0, 7)) +>a : Symbol(C.a, Decl(classExpressionWithStaticPropertiesES62.ts, 0, 17)) +>b : Symbol(C.b, Decl(classExpressionWithStaticPropertiesES62.ts, 0, 31)) + diff --git a/tests/baselines/reference/classExpressionWithStaticPropertiesES62.types b/tests/baselines/reference/classExpressionWithStaticPropertiesES62.types new file mode 100644 index 00000000000..e8ded1422f1 --- /dev/null +++ b/tests/baselines/reference/classExpressionWithStaticPropertiesES62.types @@ -0,0 +1,9 @@ +=== tests/cases/compiler/classExpressionWithStaticPropertiesES62.ts === +var v = class C { static a = 1; static b }; +>v : typeof C +>class C { static a = 1; static b } : typeof C +>C : typeof C +>a : number +>1 : number +>b : any + diff --git a/tests/baselines/reference/declarationEmitDestructuring4.js b/tests/baselines/reference/declarationEmitDestructuring4.js index f5d9df09175..16e6b49a4cf 100644 --- a/tests/baselines/reference/declarationEmitDestructuring4.js +++ b/tests/baselines/reference/declarationEmitDestructuring4.js @@ -15,20 +15,16 @@ function baz4({} = { x: 10 }) { } // For an array binding pattern with empty elements, // we will not make any modification and will emit // the similar binding pattern users' have written -function baz(_a) { - var ; -} +function baz(_a) { } function baz1(_a) { - var _b = _a === void 0 ? [1, 2, 3] : _a; + var _a = [1, 2, 3]; } function baz2(_a) { var _b = (_a === void 0 ? [[1, 2, 3]] : _a)[0]; } -function baz3(_a) { - var ; -} +function baz3(_a) { } function baz4(_a) { - var _b = _a === void 0 ? { x: 10 } : _a; + var _a = { x: 10 }; } diff --git a/tests/baselines/reference/decoratedClassFromExternalModule.js b/tests/baselines/reference/decoratedClassFromExternalModule.js index 163a4a094b4..aca1d28b952 100644 --- a/tests/baselines/reference/decoratedClassFromExternalModule.js +++ b/tests/baselines/reference/decoratedClassFromExternalModule.js @@ -1,7 +1,7 @@ //// [tests/cases/conformance/decorators/class/decoratedClassFromExternalModule.ts] //// //// [decorated.ts] -function decorate() { } +function decorate(target: any) { } @decorate export default class Decorated { } @@ -18,7 +18,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key, case 4: return decorators.reduceRight(function(o, d) { return (d && d(target, key, o)) || o; }, desc); } }; -function decorate() { } +function decorate(target) { } let Decorated = class { }; Decorated = __decorate([ diff --git a/tests/baselines/reference/decoratedClassFromExternalModule.symbols b/tests/baselines/reference/decoratedClassFromExternalModule.symbols index aa17dde616a..60e4a892ec0 100644 --- a/tests/baselines/reference/decoratedClassFromExternalModule.symbols +++ b/tests/baselines/reference/decoratedClassFromExternalModule.symbols @@ -1,12 +1,13 @@ === tests/cases/conformance/decorators/class/decorated.ts === -function decorate() { } +function decorate(target: any) { } >decorate : Symbol(decorate, Decl(decorated.ts, 0, 0)) +>target : Symbol(target, Decl(decorated.ts, 0, 18)) @decorate >decorate : Symbol(decorate, Decl(decorated.ts, 0, 0)) export default class Decorated { } ->Decorated : Symbol(Decorated, Decl(decorated.ts, 0, 23)) +>Decorated : Symbol(Decorated, Decl(decorated.ts, 0, 34)) === tests/cases/conformance/decorators/class/undecorated.ts === import Decorated from 'decorated'; diff --git a/tests/baselines/reference/decoratedClassFromExternalModule.types b/tests/baselines/reference/decoratedClassFromExternalModule.types index 4234b6a4b15..d4bc3239e46 100644 --- a/tests/baselines/reference/decoratedClassFromExternalModule.types +++ b/tests/baselines/reference/decoratedClassFromExternalModule.types @@ -1,9 +1,10 @@ === tests/cases/conformance/decorators/class/decorated.ts === -function decorate() { } ->decorate : () => void +function decorate(target: any) { } +>decorate : (target: any) => void +>target : any @decorate ->decorate : () => void +>decorate : (target: any) => void export default class Decorated { } >Decorated : Decorated diff --git a/tests/baselines/reference/decoratorChecksFunctionBodies.errors.txt b/tests/baselines/reference/decoratorChecksFunctionBodies.errors.txt index c8166b538fd..cef2f90f704 100644 --- a/tests/baselines/reference/decoratorChecksFunctionBodies.errors.txt +++ b/tests/baselines/reference/decoratorChecksFunctionBodies.errors.txt @@ -8,7 +8,7 @@ tests/cases/conformance/decorators/class/decoratorChecksFunctionBodies.ts(9,14): } class A { - @(x => { + @((x, p) => { var a = 3; func(a); ~ diff --git a/tests/baselines/reference/decoratorChecksFunctionBodies.js b/tests/baselines/reference/decoratorChecksFunctionBodies.js index 020bc775aea..adb710efccc 100644 --- a/tests/baselines/reference/decoratorChecksFunctionBodies.js +++ b/tests/baselines/reference/decoratorChecksFunctionBodies.js @@ -5,7 +5,7 @@ function func(s: string): void { } class A { - @(x => { + @((x, p) => { var a = 3; func(a); return x; @@ -34,7 +34,7 @@ var A = (function () { }; Object.defineProperty(A.prototype, "m", __decorate([ - (function (x) { + (function (x, p) { var a = 3; func(a); return x; diff --git a/tests/baselines/reference/decoratorInstantiateModulesInFunctionBodies.js b/tests/baselines/reference/decoratorInstantiateModulesInFunctionBodies.js index 313d77fa5ce..08ba6e9ea7e 100644 --- a/tests/baselines/reference/decoratorInstantiateModulesInFunctionBodies.js +++ b/tests/baselines/reference/decoratorInstantiateModulesInFunctionBodies.js @@ -9,7 +9,7 @@ export var test = 'abc'; import { test } from './a'; function filter(handler: any) { - return function (target: any) { + return function (target: any, propertyKey: string) { // ... }; } @@ -35,7 +35,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key, }; var a_1 = require('./a'); function filter(handler) { - return function (target) { + return function (target, propertyKey) { // ... }; } diff --git a/tests/baselines/reference/decoratorInstantiateModulesInFunctionBodies.symbols b/tests/baselines/reference/decoratorInstantiateModulesInFunctionBodies.symbols index 5088e740a57..f7c96097caf 100644 --- a/tests/baselines/reference/decoratorInstantiateModulesInFunctionBodies.symbols +++ b/tests/baselines/reference/decoratorInstantiateModulesInFunctionBodies.symbols @@ -12,8 +12,9 @@ function filter(handler: any) { >filter : Symbol(filter, Decl(b.ts, 0, 27)) >handler : Symbol(handler, Decl(b.ts, 2, 16)) - return function (target: any) { + return function (target: any, propertyKey: string) { >target : Symbol(target, Decl(b.ts, 3, 21)) +>propertyKey : Symbol(propertyKey, Decl(b.ts, 3, 33)) // ... }; diff --git a/tests/baselines/reference/decoratorInstantiateModulesInFunctionBodies.types b/tests/baselines/reference/decoratorInstantiateModulesInFunctionBodies.types index 18d993af9bb..d0f930b7ad4 100644 --- a/tests/baselines/reference/decoratorInstantiateModulesInFunctionBodies.types +++ b/tests/baselines/reference/decoratorInstantiateModulesInFunctionBodies.types @@ -10,12 +10,13 @@ import { test } from './a'; >test : string function filter(handler: any) { ->filter : (handler: any) => (target: any) => void +>filter : (handler: any) => (target: any, propertyKey: string) => void >handler : any - return function (target: any) { ->function (target: any) { // ... } : (target: any) => void + return function (target: any, propertyKey: string) { +>function (target: any, propertyKey: string) { // ... } : (target: any, propertyKey: string) => void >target : any +>propertyKey : string // ... }; @@ -25,8 +26,8 @@ class Wat { >Wat : Wat @filter(() => test == 'abc') ->filter(() => test == 'abc') : (target: any) => void ->filter : (handler: any) => (target: any) => void +>filter(() => test == 'abc') : (target: any, propertyKey: string) => void +>filter : (handler: any) => (target: any, propertyKey: string) => void >() => test == 'abc' : () => boolean >test == 'abc' : boolean >test : string diff --git a/tests/baselines/reference/decoratorOnClass8.errors.txt b/tests/baselines/reference/decoratorOnClass8.errors.txt index 0a9fbf2956c..f9ca7fca210 100644 --- a/tests/baselines/reference/decoratorOnClass8.errors.txt +++ b/tests/baselines/reference/decoratorOnClass8.errors.txt @@ -1,4 +1,5 @@ -tests/cases/conformance/decorators/class/decoratorOnClass8.ts(3,1): error TS2322: Type '(target: Function, paramIndex: number) => void' is not assignable to type '(target: typeof C) => void | typeof C'. +tests/cases/conformance/decorators/class/decoratorOnClass8.ts(3,1): error TS1238: Unable to resolve signature of class decorator when called as an expression. + Supplied parameters do not match any signature of call target. ==== tests/cases/conformance/decorators/class/decoratorOnClass8.ts (1 errors) ==== @@ -6,6 +7,7 @@ tests/cases/conformance/decorators/class/decoratorOnClass8.ts(3,1): error TS2322 @dec() ~~~~~~ -!!! error TS2322: Type '(target: Function, paramIndex: number) => void' is not assignable to type '(target: typeof C) => void | typeof C'. +!!! error TS1238: Unable to resolve signature of class decorator when called as an expression. +!!! error TS1238: Supplied parameters do not match any signature of call target. class C { } \ No newline at end of file diff --git a/tests/baselines/reference/decoratorOnClassMethod10.errors.txt b/tests/baselines/reference/decoratorOnClassMethod10.errors.txt index cd331473b7c..6499aa44e53 100644 --- a/tests/baselines/reference/decoratorOnClassMethod10.errors.txt +++ b/tests/baselines/reference/decoratorOnClassMethod10.errors.txt @@ -1,7 +1,5 @@ -tests/cases/conformance/decorators/class/method/decoratorOnClassMethod10.ts(4,5): error TS2322: Type '(target: Function, paramIndex: number) => void' is not assignable to type '(target: Object, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor<() => void>) => void | TypedPropertyDescriptor<() => void>'. - Types of parameters 'paramIndex' and 'propertyKey' are incompatible. - Type 'number' is not assignable to type 'string | symbol'. - Type 'number' is not assignable to type 'symbol'. +tests/cases/conformance/decorators/class/method/decoratorOnClassMethod10.ts(4,6): error TS2345: Argument of type 'C' is not assignable to parameter of type 'Function'. + Property 'apply' is missing in type 'C'. ==== tests/cases/conformance/decorators/class/method/decoratorOnClassMethod10.ts (1 errors) ==== @@ -9,9 +7,7 @@ tests/cases/conformance/decorators/class/method/decoratorOnClassMethod10.ts(4,5) class C { @dec method() {} - ~~~~ -!!! error TS2322: Type '(target: Function, paramIndex: number) => void' is not assignable to type '(target: Object, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor<() => void>) => void | TypedPropertyDescriptor<() => void>'. -!!! error TS2322: Types of parameters 'paramIndex' and 'propertyKey' are incompatible. -!!! error TS2322: Type 'number' is not assignable to type 'string | symbol'. -!!! error TS2322: Type 'number' is not assignable to type 'symbol'. + ~~~ +!!! error TS2345: Argument of type 'C' is not assignable to parameter of type 'Function'. +!!! error TS2345: Property 'apply' is missing in type 'C'. } \ No newline at end of file diff --git a/tests/baselines/reference/decoratorOnClassMethod13.js b/tests/baselines/reference/decoratorOnClassMethod13.js index 967cc05ba4d..b39fa63686a 100644 --- a/tests/baselines/reference/decoratorOnClassMethod13.js +++ b/tests/baselines/reference/decoratorOnClassMethod13.js @@ -1,5 +1,5 @@ //// [decoratorOnClassMethod13.ts] -declare function dec(): (target: any, propertyKey: string, descriptor: TypedPropertyDescriptor) => TypedPropertyDescriptor; +declare function dec(target: any, propertyKey: string, descriptor: TypedPropertyDescriptor): TypedPropertyDescriptor; class C { @dec ["1"]() { } diff --git a/tests/baselines/reference/decoratorOnClassMethod13.symbols b/tests/baselines/reference/decoratorOnClassMethod13.symbols index af3819924f4..42f44d885ee 100644 --- a/tests/baselines/reference/decoratorOnClassMethod13.symbols +++ b/tests/baselines/reference/decoratorOnClassMethod13.symbols @@ -1,17 +1,17 @@ === tests/cases/conformance/decorators/class/method/decoratorOnClassMethod13.ts === -declare function dec(): (target: any, propertyKey: string, descriptor: TypedPropertyDescriptor) => TypedPropertyDescriptor; +declare function dec(target: any, propertyKey: string, descriptor: TypedPropertyDescriptor): TypedPropertyDescriptor; >dec : Symbol(dec, Decl(decoratorOnClassMethod13.ts, 0, 0)) ->T : Symbol(T, Decl(decoratorOnClassMethod13.ts, 0, 25)) ->target : Symbol(target, Decl(decoratorOnClassMethod13.ts, 0, 28)) ->propertyKey : Symbol(propertyKey, Decl(decoratorOnClassMethod13.ts, 0, 40)) ->descriptor : Symbol(descriptor, Decl(decoratorOnClassMethod13.ts, 0, 61)) +>T : Symbol(T, Decl(decoratorOnClassMethod13.ts, 0, 21)) +>target : Symbol(target, Decl(decoratorOnClassMethod13.ts, 0, 24)) +>propertyKey : Symbol(propertyKey, Decl(decoratorOnClassMethod13.ts, 0, 36)) +>descriptor : Symbol(descriptor, Decl(decoratorOnClassMethod13.ts, 0, 57)) >TypedPropertyDescriptor : Symbol(TypedPropertyDescriptor, Decl(lib.d.ts, 1171, 36)) ->T : Symbol(T, Decl(decoratorOnClassMethod13.ts, 0, 25)) +>T : Symbol(T, Decl(decoratorOnClassMethod13.ts, 0, 21)) >TypedPropertyDescriptor : Symbol(TypedPropertyDescriptor, Decl(lib.d.ts, 1171, 36)) ->T : Symbol(T, Decl(decoratorOnClassMethod13.ts, 0, 25)) +>T : Symbol(T, Decl(decoratorOnClassMethod13.ts, 0, 21)) class C { ->C : Symbol(C, Decl(decoratorOnClassMethod13.ts, 0, 132)) +>C : Symbol(C, Decl(decoratorOnClassMethod13.ts, 0, 126)) @dec ["1"]() { } >dec : Symbol(dec, Decl(decoratorOnClassMethod13.ts, 0, 0)) diff --git a/tests/baselines/reference/decoratorOnClassMethod13.types b/tests/baselines/reference/decoratorOnClassMethod13.types index 2858f8877bd..5fdbe071828 100644 --- a/tests/baselines/reference/decoratorOnClassMethod13.types +++ b/tests/baselines/reference/decoratorOnClassMethod13.types @@ -1,6 +1,6 @@ === tests/cases/conformance/decorators/class/method/decoratorOnClassMethod13.ts === -declare function dec(): (target: any, propertyKey: string, descriptor: TypedPropertyDescriptor) => TypedPropertyDescriptor; ->dec : () => (target: any, propertyKey: string, descriptor: TypedPropertyDescriptor) => TypedPropertyDescriptor +declare function dec(target: any, propertyKey: string, descriptor: TypedPropertyDescriptor): TypedPropertyDescriptor; +>dec : (target: any, propertyKey: string, descriptor: TypedPropertyDescriptor) => TypedPropertyDescriptor >T : T >target : any >propertyKey : string @@ -14,10 +14,10 @@ class C { >C : C @dec ["1"]() { } ->dec : () => (target: any, propertyKey: string, descriptor: TypedPropertyDescriptor) => TypedPropertyDescriptor +>dec : (target: any, propertyKey: string, descriptor: TypedPropertyDescriptor) => TypedPropertyDescriptor >"1" : string @dec ["b"]() { } ->dec : () => (target: any, propertyKey: string, descriptor: TypedPropertyDescriptor) => TypedPropertyDescriptor +>dec : (target: any, propertyKey: string, descriptor: TypedPropertyDescriptor) => TypedPropertyDescriptor >"b" : string } diff --git a/tests/baselines/reference/decoratorOnClassMethod6.errors.txt b/tests/baselines/reference/decoratorOnClassMethod6.errors.txt new file mode 100644 index 00000000000..c8ee66717ef --- /dev/null +++ b/tests/baselines/reference/decoratorOnClassMethod6.errors.txt @@ -0,0 +1,13 @@ +tests/cases/conformance/decorators/class/method/decoratorOnClassMethod6.ts(4,5): error TS1241: Unable to resolve signature of method decorator when called as an expression. + Supplied parameters do not match any signature of call target. + + +==== tests/cases/conformance/decorators/class/method/decoratorOnClassMethod6.ts (1 errors) ==== + declare function dec(): (target: any, propertyKey: string, descriptor: TypedPropertyDescriptor) => TypedPropertyDescriptor; + + class C { + @dec ["method"]() {} + ~~~~ +!!! error TS1241: Unable to resolve signature of method decorator when called as an expression. +!!! error TS1241: Supplied parameters do not match any signature of call target. + } \ No newline at end of file diff --git a/tests/baselines/reference/decoratorOnClassMethod6.symbols b/tests/baselines/reference/decoratorOnClassMethod6.symbols deleted file mode 100644 index 8dcdd99a8e9..00000000000 --- a/tests/baselines/reference/decoratorOnClassMethod6.symbols +++ /dev/null @@ -1,18 +0,0 @@ -=== tests/cases/conformance/decorators/class/method/decoratorOnClassMethod6.ts === -declare function dec(): (target: any, propertyKey: string, descriptor: TypedPropertyDescriptor) => TypedPropertyDescriptor; ->dec : Symbol(dec, Decl(decoratorOnClassMethod6.ts, 0, 0)) ->T : Symbol(T, Decl(decoratorOnClassMethod6.ts, 0, 25)) ->target : Symbol(target, Decl(decoratorOnClassMethod6.ts, 0, 28)) ->propertyKey : Symbol(propertyKey, Decl(decoratorOnClassMethod6.ts, 0, 40)) ->descriptor : Symbol(descriptor, Decl(decoratorOnClassMethod6.ts, 0, 61)) ->TypedPropertyDescriptor : Symbol(TypedPropertyDescriptor, Decl(lib.d.ts, 1171, 36)) ->T : Symbol(T, Decl(decoratorOnClassMethod6.ts, 0, 25)) ->TypedPropertyDescriptor : Symbol(TypedPropertyDescriptor, Decl(lib.d.ts, 1171, 36)) ->T : Symbol(T, Decl(decoratorOnClassMethod6.ts, 0, 25)) - -class C { ->C : Symbol(C, Decl(decoratorOnClassMethod6.ts, 0, 132)) - - @dec ["method"]() {} ->dec : Symbol(dec, Decl(decoratorOnClassMethod6.ts, 0, 0)) -} diff --git a/tests/baselines/reference/decoratorOnClassMethod6.types b/tests/baselines/reference/decoratorOnClassMethod6.types deleted file mode 100644 index 9da71791763..00000000000 --- a/tests/baselines/reference/decoratorOnClassMethod6.types +++ /dev/null @@ -1,19 +0,0 @@ -=== tests/cases/conformance/decorators/class/method/decoratorOnClassMethod6.ts === -declare function dec(): (target: any, propertyKey: string, descriptor: TypedPropertyDescriptor) => TypedPropertyDescriptor; ->dec : () => (target: any, propertyKey: string, descriptor: TypedPropertyDescriptor) => TypedPropertyDescriptor ->T : T ->target : any ->propertyKey : string ->descriptor : TypedPropertyDescriptor ->TypedPropertyDescriptor : TypedPropertyDescriptor ->T : T ->TypedPropertyDescriptor : TypedPropertyDescriptor ->T : T - -class C { ->C : C - - @dec ["method"]() {} ->dec : () => (target: any, propertyKey: string, descriptor: TypedPropertyDescriptor) => TypedPropertyDescriptor ->"method" : string -} diff --git a/tests/baselines/reference/decoratorOnClassMethod8.errors.txt b/tests/baselines/reference/decoratorOnClassMethod8.errors.txt new file mode 100644 index 00000000000..f522dc01df9 --- /dev/null +++ b/tests/baselines/reference/decoratorOnClassMethod8.errors.txt @@ -0,0 +1,13 @@ +tests/cases/conformance/decorators/class/method/decoratorOnClassMethod8.ts(4,5): error TS1241: Unable to resolve signature of method decorator when called as an expression. + Supplied parameters do not match any signature of call target. + + +==== tests/cases/conformance/decorators/class/method/decoratorOnClassMethod8.ts (1 errors) ==== + declare function dec(target: T): T; + + class C { + @dec method() {} + ~~~~ +!!! error TS1241: Unable to resolve signature of method decorator when called as an expression. +!!! error TS1241: Supplied parameters do not match any signature of call target. + } \ No newline at end of file diff --git a/tests/baselines/reference/decoratorOnClassMethod8.symbols b/tests/baselines/reference/decoratorOnClassMethod8.symbols deleted file mode 100644 index 84b68b81421..00000000000 --- a/tests/baselines/reference/decoratorOnClassMethod8.symbols +++ /dev/null @@ -1,15 +0,0 @@ -=== tests/cases/conformance/decorators/class/method/decoratorOnClassMethod8.ts === -declare function dec(target: T): T; ->dec : Symbol(dec, Decl(decoratorOnClassMethod8.ts, 0, 0)) ->T : Symbol(T, Decl(decoratorOnClassMethod8.ts, 0, 21)) ->target : Symbol(target, Decl(decoratorOnClassMethod8.ts, 0, 24)) ->T : Symbol(T, Decl(decoratorOnClassMethod8.ts, 0, 21)) ->T : Symbol(T, Decl(decoratorOnClassMethod8.ts, 0, 21)) - -class C { ->C : Symbol(C, Decl(decoratorOnClassMethod8.ts, 0, 38)) - - @dec method() {} ->dec : Symbol(dec, Decl(decoratorOnClassMethod8.ts, 0, 0)) ->method : Symbol(method, Decl(decoratorOnClassMethod8.ts, 2, 9)) -} diff --git a/tests/baselines/reference/decoratorOnClassMethod8.types b/tests/baselines/reference/decoratorOnClassMethod8.types deleted file mode 100644 index 20890b09846..00000000000 --- a/tests/baselines/reference/decoratorOnClassMethod8.types +++ /dev/null @@ -1,15 +0,0 @@ -=== tests/cases/conformance/decorators/class/method/decoratorOnClassMethod8.ts === -declare function dec(target: T): T; ->dec : (target: T) => T ->T : T ->target : T ->T : T ->T : T - -class C { ->C : C - - @dec method() {} ->dec : (target: T) => T ->method : () => void -} diff --git a/tests/baselines/reference/decoratorOnClassMethodParameter1.js b/tests/baselines/reference/decoratorOnClassMethodParameter1.js index 4a3ed36eec5..a6ab1704acc 100644 --- a/tests/baselines/reference/decoratorOnClassMethodParameter1.js +++ b/tests/baselines/reference/decoratorOnClassMethodParameter1.js @@ -1,5 +1,5 @@ //// [decoratorOnClassMethodParameter1.ts] -declare function dec(target: Function, propertyKey: string | symbol, parameterIndex: number): void; +declare function dec(target: Object, propertyKey: string | symbol, parameterIndex: number): void; class C { method(@dec p: number) {} diff --git a/tests/baselines/reference/decoratorOnClassMethodParameter1.symbols b/tests/baselines/reference/decoratorOnClassMethodParameter1.symbols index 0ced8829766..47c5999ff47 100644 --- a/tests/baselines/reference/decoratorOnClassMethodParameter1.symbols +++ b/tests/baselines/reference/decoratorOnClassMethodParameter1.symbols @@ -1,13 +1,13 @@ === tests/cases/conformance/decorators/class/method/parameter/decoratorOnClassMethodParameter1.ts === -declare function dec(target: Function, propertyKey: string | symbol, parameterIndex: number): void; +declare function dec(target: Object, propertyKey: string | symbol, parameterIndex: number): void; >dec : Symbol(dec, Decl(decoratorOnClassMethodParameter1.ts, 0, 0)) >target : Symbol(target, Decl(decoratorOnClassMethodParameter1.ts, 0, 21)) ->Function : Symbol(Function, Decl(lib.d.ts, 223, 38), Decl(lib.d.ts, 269, 11)) ->propertyKey : Symbol(propertyKey, Decl(decoratorOnClassMethodParameter1.ts, 0, 38)) ->parameterIndex : Symbol(parameterIndex, Decl(decoratorOnClassMethodParameter1.ts, 0, 68)) +>Object : Symbol(Object, Decl(lib.d.ts, 92, 1), Decl(lib.d.ts, 223, 11)) +>propertyKey : Symbol(propertyKey, Decl(decoratorOnClassMethodParameter1.ts, 0, 36)) +>parameterIndex : Symbol(parameterIndex, Decl(decoratorOnClassMethodParameter1.ts, 0, 66)) class C { ->C : Symbol(C, Decl(decoratorOnClassMethodParameter1.ts, 0, 99)) +>C : Symbol(C, Decl(decoratorOnClassMethodParameter1.ts, 0, 97)) method(@dec p: number) {} >method : Symbol(method, Decl(decoratorOnClassMethodParameter1.ts, 2, 9)) diff --git a/tests/baselines/reference/decoratorOnClassMethodParameter1.types b/tests/baselines/reference/decoratorOnClassMethodParameter1.types index 0b75471471f..74aa04a8985 100644 --- a/tests/baselines/reference/decoratorOnClassMethodParameter1.types +++ b/tests/baselines/reference/decoratorOnClassMethodParameter1.types @@ -1,8 +1,8 @@ === tests/cases/conformance/decorators/class/method/parameter/decoratorOnClassMethodParameter1.ts === -declare function dec(target: Function, propertyKey: string | symbol, parameterIndex: number): void; ->dec : (target: Function, propertyKey: string | symbol, parameterIndex: number) => void ->target : Function ->Function : Function +declare function dec(target: Object, propertyKey: string | symbol, parameterIndex: number): void; +>dec : (target: Object, propertyKey: string | symbol, parameterIndex: number) => void +>target : Object +>Object : Object >propertyKey : string | symbol >parameterIndex : number @@ -11,6 +11,6 @@ class C { method(@dec p: number) {} >method : (p: number) => void ->dec : (target: Function, propertyKey: string | symbol, parameterIndex: number) => void +>dec : (target: Object, propertyKey: string | symbol, parameterIndex: number) => void >p : number } diff --git a/tests/baselines/reference/decoratorOnClassProperty11.errors.txt b/tests/baselines/reference/decoratorOnClassProperty11.errors.txt new file mode 100644 index 00000000000..6ff700564e8 --- /dev/null +++ b/tests/baselines/reference/decoratorOnClassProperty11.errors.txt @@ -0,0 +1,13 @@ +tests/cases/conformance/decorators/class/property/decoratorOnClassProperty11.ts(4,5): error TS1240: Unable to resolve signature of property decorator when called as an expression. + Supplied parameters do not match any signature of call target. + + +==== tests/cases/conformance/decorators/class/property/decoratorOnClassProperty11.ts (1 errors) ==== + declare function dec(): (target: any, propertyKey: string) => void; + + class C { + @dec prop; + ~~~~ +!!! error TS1240: Unable to resolve signature of property decorator when called as an expression. +!!! error TS1240: Supplied parameters do not match any signature of call target. + } \ No newline at end of file diff --git a/tests/baselines/reference/decoratorOnClassProperty11.symbols b/tests/baselines/reference/decoratorOnClassProperty11.symbols deleted file mode 100644 index c7d6e39c713..00000000000 --- a/tests/baselines/reference/decoratorOnClassProperty11.symbols +++ /dev/null @@ -1,14 +0,0 @@ -=== tests/cases/conformance/decorators/class/property/decoratorOnClassProperty11.ts === -declare function dec(): (target: any, propertyKey: string) => void; ->dec : Symbol(dec, Decl(decoratorOnClassProperty11.ts, 0, 0)) ->T : Symbol(T, Decl(decoratorOnClassProperty11.ts, 0, 25)) ->target : Symbol(target, Decl(decoratorOnClassProperty11.ts, 0, 28)) ->propertyKey : Symbol(propertyKey, Decl(decoratorOnClassProperty11.ts, 0, 40)) - -class C { ->C : Symbol(C, Decl(decoratorOnClassProperty11.ts, 0, 70)) - - @dec prop; ->dec : Symbol(dec, Decl(decoratorOnClassProperty11.ts, 0, 0)) ->prop : Symbol(prop, Decl(decoratorOnClassProperty11.ts, 2, 9)) -} diff --git a/tests/baselines/reference/decoratorOnClassProperty11.types b/tests/baselines/reference/decoratorOnClassProperty11.types deleted file mode 100644 index 5caa467d3ba..00000000000 --- a/tests/baselines/reference/decoratorOnClassProperty11.types +++ /dev/null @@ -1,14 +0,0 @@ -=== tests/cases/conformance/decorators/class/property/decoratorOnClassProperty11.ts === -declare function dec(): (target: any, propertyKey: string) => void; ->dec : () => (target: any, propertyKey: string) => void ->T : T ->target : any ->propertyKey : string - -class C { ->C : C - - @dec prop; ->dec : () => (target: any, propertyKey: string) => void ->prop : any -} diff --git a/tests/baselines/reference/decoratorOnClassProperty6.errors.txt b/tests/baselines/reference/decoratorOnClassProperty6.errors.txt new file mode 100644 index 00000000000..dbb104e8cd3 --- /dev/null +++ b/tests/baselines/reference/decoratorOnClassProperty6.errors.txt @@ -0,0 +1,13 @@ +tests/cases/conformance/decorators/class/property/decoratorOnClassProperty6.ts(4,5): error TS1240: Unable to resolve signature of property decorator when called as an expression. + Supplied parameters do not match any signature of call target. + + +==== tests/cases/conformance/decorators/class/property/decoratorOnClassProperty6.ts (1 errors) ==== + declare function dec(target: Function): void; + + class C { + @dec prop; + ~~~~ +!!! error TS1240: Unable to resolve signature of property decorator when called as an expression. +!!! error TS1240: Supplied parameters do not match any signature of call target. + } \ No newline at end of file diff --git a/tests/baselines/reference/decoratorOnClassProperty6.symbols b/tests/baselines/reference/decoratorOnClassProperty6.symbols deleted file mode 100644 index 7b9857e0a19..00000000000 --- a/tests/baselines/reference/decoratorOnClassProperty6.symbols +++ /dev/null @@ -1,13 +0,0 @@ -=== tests/cases/conformance/decorators/class/property/decoratorOnClassProperty6.ts === -declare function dec(target: Function): void; ->dec : Symbol(dec, Decl(decoratorOnClassProperty6.ts, 0, 0)) ->target : Symbol(target, Decl(decoratorOnClassProperty6.ts, 0, 21)) ->Function : Symbol(Function, Decl(lib.d.ts, 223, 38), Decl(lib.d.ts, 269, 11)) - -class C { ->C : Symbol(C, Decl(decoratorOnClassProperty6.ts, 0, 45)) - - @dec prop; ->dec : Symbol(dec, Decl(decoratorOnClassProperty6.ts, 0, 0)) ->prop : Symbol(prop, Decl(decoratorOnClassProperty6.ts, 2, 9)) -} diff --git a/tests/baselines/reference/decoratorOnClassProperty6.types b/tests/baselines/reference/decoratorOnClassProperty6.types deleted file mode 100644 index 59d03678330..00000000000 --- a/tests/baselines/reference/decoratorOnClassProperty6.types +++ /dev/null @@ -1,13 +0,0 @@ -=== tests/cases/conformance/decorators/class/property/decoratorOnClassProperty6.ts === -declare function dec(target: Function): void; ->dec : (target: Function) => void ->target : Function ->Function : Function - -class C { ->C : C - - @dec prop; ->dec : (target: Function) => void ->prop : any -} diff --git a/tests/baselines/reference/decoratorOnClassProperty7.errors.txt b/tests/baselines/reference/decoratorOnClassProperty7.errors.txt index 8b93d0ab38e..41396acd17e 100644 --- a/tests/baselines/reference/decoratorOnClassProperty7.errors.txt +++ b/tests/baselines/reference/decoratorOnClassProperty7.errors.txt @@ -1,4 +1,5 @@ -tests/cases/conformance/decorators/class/property/decoratorOnClassProperty7.ts(4,5): error TS2322: Type '(target: Function, propertyKey: string | symbol, paramIndex: number) => void' is not assignable to type '(target: Object, propertyKey: string | symbol) => void'. +tests/cases/conformance/decorators/class/property/decoratorOnClassProperty7.ts(4,5): error TS1240: Unable to resolve signature of property decorator when called as an expression. + Supplied parameters do not match any signature of call target. ==== tests/cases/conformance/decorators/class/property/decoratorOnClassProperty7.ts (1 errors) ==== @@ -7,5 +8,6 @@ tests/cases/conformance/decorators/class/property/decoratorOnClassProperty7.ts(4 class C { @dec prop; ~~~~ -!!! error TS2322: Type '(target: Function, propertyKey: string | symbol, paramIndex: number) => void' is not assignable to type '(target: Object, propertyKey: string | symbol) => void'. +!!! error TS1240: Unable to resolve signature of property decorator when called as an expression. +!!! error TS1240: Supplied parameters do not match any signature of call target. } \ No newline at end of file diff --git a/tests/baselines/reference/emptyArrayBindingPatternParameter01.js b/tests/baselines/reference/emptyArrayBindingPatternParameter01.js new file mode 100644 index 00000000000..05b59b7d5f2 --- /dev/null +++ b/tests/baselines/reference/emptyArrayBindingPatternParameter01.js @@ -0,0 +1,11 @@ +//// [emptyArrayBindingPatternParameter01.ts] + + +function f([]) { + var x, y, z; +} + +//// [emptyArrayBindingPatternParameter01.js] +function f(_a) { + var x, y, z; +} diff --git a/tests/baselines/reference/emptyArrayBindingPatternParameter01.symbols b/tests/baselines/reference/emptyArrayBindingPatternParameter01.symbols new file mode 100644 index 00000000000..3207ca97dec --- /dev/null +++ b/tests/baselines/reference/emptyArrayBindingPatternParameter01.symbols @@ -0,0 +1,11 @@ +=== tests/cases/conformance/es6/destructuring/emptyArrayBindingPatternParameter01.ts === + + +function f([]) { +>f : Symbol(f, Decl(emptyArrayBindingPatternParameter01.ts, 0, 0)) + + var x, y, z; +>x : Symbol(x, Decl(emptyArrayBindingPatternParameter01.ts, 3, 4)) +>y : Symbol(y, Decl(emptyArrayBindingPatternParameter01.ts, 3, 7)) +>z : Symbol(z, Decl(emptyArrayBindingPatternParameter01.ts, 3, 10)) +} diff --git a/tests/baselines/reference/emptyArrayBindingPatternParameter01.types b/tests/baselines/reference/emptyArrayBindingPatternParameter01.types new file mode 100644 index 00000000000..e93394b7371 --- /dev/null +++ b/tests/baselines/reference/emptyArrayBindingPatternParameter01.types @@ -0,0 +1,11 @@ +=== tests/cases/conformance/es6/destructuring/emptyArrayBindingPatternParameter01.ts === + + +function f([]) { +>f : ([]: any[]) => void + + var x, y, z; +>x : any +>y : any +>z : any +} diff --git a/tests/baselines/reference/emptyArrayBindingPatternParameter02.js b/tests/baselines/reference/emptyArrayBindingPatternParameter02.js new file mode 100644 index 00000000000..dbd86e843a8 --- /dev/null +++ b/tests/baselines/reference/emptyArrayBindingPatternParameter02.js @@ -0,0 +1,11 @@ +//// [emptyArrayBindingPatternParameter02.ts] + + +function f(a, []) { + var x, y, z; +} + +//// [emptyArrayBindingPatternParameter02.js] +function f(a, _a) { + var x, y, z; +} diff --git a/tests/baselines/reference/emptyArrayBindingPatternParameter02.symbols b/tests/baselines/reference/emptyArrayBindingPatternParameter02.symbols new file mode 100644 index 00000000000..48cdcfaf93d --- /dev/null +++ b/tests/baselines/reference/emptyArrayBindingPatternParameter02.symbols @@ -0,0 +1,12 @@ +=== tests/cases/conformance/es6/destructuring/emptyArrayBindingPatternParameter02.ts === + + +function f(a, []) { +>f : Symbol(f, Decl(emptyArrayBindingPatternParameter02.ts, 0, 0)) +>a : Symbol(a, Decl(emptyArrayBindingPatternParameter02.ts, 2, 11)) + + var x, y, z; +>x : Symbol(x, Decl(emptyArrayBindingPatternParameter02.ts, 3, 7)) +>y : Symbol(y, Decl(emptyArrayBindingPatternParameter02.ts, 3, 10)) +>z : Symbol(z, Decl(emptyArrayBindingPatternParameter02.ts, 3, 13)) +} diff --git a/tests/baselines/reference/emptyArrayBindingPatternParameter02.types b/tests/baselines/reference/emptyArrayBindingPatternParameter02.types new file mode 100644 index 00000000000..a58fe6b91d3 --- /dev/null +++ b/tests/baselines/reference/emptyArrayBindingPatternParameter02.types @@ -0,0 +1,12 @@ +=== tests/cases/conformance/es6/destructuring/emptyArrayBindingPatternParameter02.ts === + + +function f(a, []) { +>f : (a: any, []: any[]) => void +>a : any + + var x, y, z; +>x : any +>y : any +>z : any +} diff --git a/tests/baselines/reference/emptyArrayBindingPatternParameter03.js b/tests/baselines/reference/emptyArrayBindingPatternParameter03.js new file mode 100644 index 00000000000..e2c3f7196e6 --- /dev/null +++ b/tests/baselines/reference/emptyArrayBindingPatternParameter03.js @@ -0,0 +1,11 @@ +//// [emptyArrayBindingPatternParameter03.ts] + + +function f(a, []) { + var x, y, z; +} + +//// [emptyArrayBindingPatternParameter03.js] +function f(a, _a) { + var x, y, z; +} diff --git a/tests/baselines/reference/emptyArrayBindingPatternParameter03.symbols b/tests/baselines/reference/emptyArrayBindingPatternParameter03.symbols new file mode 100644 index 00000000000..d3ec078df78 --- /dev/null +++ b/tests/baselines/reference/emptyArrayBindingPatternParameter03.symbols @@ -0,0 +1,12 @@ +=== tests/cases/conformance/es6/destructuring/emptyArrayBindingPatternParameter03.ts === + + +function f(a, []) { +>f : Symbol(f, Decl(emptyArrayBindingPatternParameter03.ts, 0, 0)) +>a : Symbol(a, Decl(emptyArrayBindingPatternParameter03.ts, 2, 11)) + + var x, y, z; +>x : Symbol(x, Decl(emptyArrayBindingPatternParameter03.ts, 3, 7)) +>y : Symbol(y, Decl(emptyArrayBindingPatternParameter03.ts, 3, 10)) +>z : Symbol(z, Decl(emptyArrayBindingPatternParameter03.ts, 3, 13)) +} diff --git a/tests/baselines/reference/emptyArrayBindingPatternParameter03.types b/tests/baselines/reference/emptyArrayBindingPatternParameter03.types new file mode 100644 index 00000000000..43f0af63ace --- /dev/null +++ b/tests/baselines/reference/emptyArrayBindingPatternParameter03.types @@ -0,0 +1,12 @@ +=== tests/cases/conformance/es6/destructuring/emptyArrayBindingPatternParameter03.ts === + + +function f(a, []) { +>f : (a: any, []: any[]) => void +>a : any + + var x, y, z; +>x : any +>y : any +>z : any +} diff --git a/tests/baselines/reference/emptyArrayBindingPatternParameter04.js b/tests/baselines/reference/emptyArrayBindingPatternParameter04.js new file mode 100644 index 00000000000..e0715499ffe --- /dev/null +++ b/tests/baselines/reference/emptyArrayBindingPatternParameter04.js @@ -0,0 +1,12 @@ +//// [emptyArrayBindingPatternParameter04.ts] + + +function f([] = [1,2,3,4]) { + var x, y, z; +} + +//// [emptyArrayBindingPatternParameter04.js] +function f(_a) { + var _a = [1, 2, 3, 4]; + var x, y, z; +} diff --git a/tests/baselines/reference/emptyArrayBindingPatternParameter04.symbols b/tests/baselines/reference/emptyArrayBindingPatternParameter04.symbols new file mode 100644 index 00000000000..bb76a2c5925 --- /dev/null +++ b/tests/baselines/reference/emptyArrayBindingPatternParameter04.symbols @@ -0,0 +1,11 @@ +=== tests/cases/conformance/es6/destructuring/emptyArrayBindingPatternParameter04.ts === + + +function f([] = [1,2,3,4]) { +>f : Symbol(f, Decl(emptyArrayBindingPatternParameter04.ts, 0, 0)) + + var x, y, z; +>x : Symbol(x, Decl(emptyArrayBindingPatternParameter04.ts, 3, 7)) +>y : Symbol(y, Decl(emptyArrayBindingPatternParameter04.ts, 3, 10)) +>z : Symbol(z, Decl(emptyArrayBindingPatternParameter04.ts, 3, 13)) +} diff --git a/tests/baselines/reference/emptyArrayBindingPatternParameter04.types b/tests/baselines/reference/emptyArrayBindingPatternParameter04.types new file mode 100644 index 00000000000..6f00a994f7b --- /dev/null +++ b/tests/baselines/reference/emptyArrayBindingPatternParameter04.types @@ -0,0 +1,16 @@ +=== tests/cases/conformance/es6/destructuring/emptyArrayBindingPatternParameter04.ts === + + +function f([] = [1,2,3,4]) { +>f : ([]?: number[]) => void +>[1,2,3,4] : number[] +>1 : number +>2 : number +>3 : number +>4 : number + + var x, y, z; +>x : any +>y : any +>z : any +} diff --git a/tests/baselines/reference/emptyObjectBindingPatternParameter01.js b/tests/baselines/reference/emptyObjectBindingPatternParameter01.js new file mode 100644 index 00000000000..28cc30d2a0b --- /dev/null +++ b/tests/baselines/reference/emptyObjectBindingPatternParameter01.js @@ -0,0 +1,11 @@ +//// [emptyObjectBindingPatternParameter01.ts] + + +function f({}) { + var x, y, z; +} + +//// [emptyObjectBindingPatternParameter01.js] +function f(_a) { + var x, y, z; +} diff --git a/tests/baselines/reference/emptyObjectBindingPatternParameter01.symbols b/tests/baselines/reference/emptyObjectBindingPatternParameter01.symbols new file mode 100644 index 00000000000..98829df994f --- /dev/null +++ b/tests/baselines/reference/emptyObjectBindingPatternParameter01.symbols @@ -0,0 +1,11 @@ +=== tests/cases/conformance/es6/destructuring/emptyObjectBindingPatternParameter01.ts === + + +function f({}) { +>f : Symbol(f, Decl(emptyObjectBindingPatternParameter01.ts, 0, 0)) + + var x, y, z; +>x : Symbol(x, Decl(emptyObjectBindingPatternParameter01.ts, 3, 7)) +>y : Symbol(y, Decl(emptyObjectBindingPatternParameter01.ts, 3, 10)) +>z : Symbol(z, Decl(emptyObjectBindingPatternParameter01.ts, 3, 13)) +} diff --git a/tests/baselines/reference/emptyObjectBindingPatternParameter01.types b/tests/baselines/reference/emptyObjectBindingPatternParameter01.types new file mode 100644 index 00000000000..c46569ea770 --- /dev/null +++ b/tests/baselines/reference/emptyObjectBindingPatternParameter01.types @@ -0,0 +1,11 @@ +=== tests/cases/conformance/es6/destructuring/emptyObjectBindingPatternParameter01.ts === + + +function f({}) { +>f : ({}: {}) => void + + var x, y, z; +>x : any +>y : any +>z : any +} diff --git a/tests/baselines/reference/emptyObjectBindingPatternParameter02.js b/tests/baselines/reference/emptyObjectBindingPatternParameter02.js new file mode 100644 index 00000000000..8488428ea51 --- /dev/null +++ b/tests/baselines/reference/emptyObjectBindingPatternParameter02.js @@ -0,0 +1,11 @@ +//// [emptyObjectBindingPatternParameter02.ts] + + +function f(a, {}) { + var x, y, z; +} + +//// [emptyObjectBindingPatternParameter02.js] +function f(a, _a) { + var x, y, z; +} diff --git a/tests/baselines/reference/emptyObjectBindingPatternParameter02.symbols b/tests/baselines/reference/emptyObjectBindingPatternParameter02.symbols new file mode 100644 index 00000000000..fb0fa946b6f --- /dev/null +++ b/tests/baselines/reference/emptyObjectBindingPatternParameter02.symbols @@ -0,0 +1,12 @@ +=== tests/cases/conformance/es6/destructuring/emptyObjectBindingPatternParameter02.ts === + + +function f(a, {}) { +>f : Symbol(f, Decl(emptyObjectBindingPatternParameter02.ts, 0, 0)) +>a : Symbol(a, Decl(emptyObjectBindingPatternParameter02.ts, 2, 11)) + + var x, y, z; +>x : Symbol(x, Decl(emptyObjectBindingPatternParameter02.ts, 3, 7)) +>y : Symbol(y, Decl(emptyObjectBindingPatternParameter02.ts, 3, 10)) +>z : Symbol(z, Decl(emptyObjectBindingPatternParameter02.ts, 3, 13)) +} diff --git a/tests/baselines/reference/emptyObjectBindingPatternParameter02.types b/tests/baselines/reference/emptyObjectBindingPatternParameter02.types new file mode 100644 index 00000000000..0a77fac8588 --- /dev/null +++ b/tests/baselines/reference/emptyObjectBindingPatternParameter02.types @@ -0,0 +1,12 @@ +=== tests/cases/conformance/es6/destructuring/emptyObjectBindingPatternParameter02.ts === + + +function f(a, {}) { +>f : (a: any, {}: {}) => void +>a : any + + var x, y, z; +>x : any +>y : any +>z : any +} diff --git a/tests/baselines/reference/emptyObjectBindingPatternParameter03.js b/tests/baselines/reference/emptyObjectBindingPatternParameter03.js new file mode 100644 index 00000000000..0279744e386 --- /dev/null +++ b/tests/baselines/reference/emptyObjectBindingPatternParameter03.js @@ -0,0 +1,11 @@ +//// [emptyObjectBindingPatternParameter03.ts] + + +function f({}, a) { + var x, y, z; +} + +//// [emptyObjectBindingPatternParameter03.js] +function f(_a, a) { + var x, y, z; +} diff --git a/tests/baselines/reference/emptyObjectBindingPatternParameter03.symbols b/tests/baselines/reference/emptyObjectBindingPatternParameter03.symbols new file mode 100644 index 00000000000..4e658e21ccf --- /dev/null +++ b/tests/baselines/reference/emptyObjectBindingPatternParameter03.symbols @@ -0,0 +1,12 @@ +=== tests/cases/conformance/es6/destructuring/emptyObjectBindingPatternParameter03.ts === + + +function f({}, a) { +>f : Symbol(f, Decl(emptyObjectBindingPatternParameter03.ts, 0, 0)) +>a : Symbol(a, Decl(emptyObjectBindingPatternParameter03.ts, 2, 14)) + + var x, y, z; +>x : Symbol(x, Decl(emptyObjectBindingPatternParameter03.ts, 3, 7)) +>y : Symbol(y, Decl(emptyObjectBindingPatternParameter03.ts, 3, 10)) +>z : Symbol(z, Decl(emptyObjectBindingPatternParameter03.ts, 3, 13)) +} diff --git a/tests/baselines/reference/emptyObjectBindingPatternParameter03.types b/tests/baselines/reference/emptyObjectBindingPatternParameter03.types new file mode 100644 index 00000000000..873c748dd9b --- /dev/null +++ b/tests/baselines/reference/emptyObjectBindingPatternParameter03.types @@ -0,0 +1,12 @@ +=== tests/cases/conformance/es6/destructuring/emptyObjectBindingPatternParameter03.ts === + + +function f({}, a) { +>f : ({}: {}, a: any) => void +>a : any + + var x, y, z; +>x : any +>y : any +>z : any +} diff --git a/tests/baselines/reference/emptyObjectBindingPatternParameter04.js b/tests/baselines/reference/emptyObjectBindingPatternParameter04.js new file mode 100644 index 00000000000..fc3e41d0709 --- /dev/null +++ b/tests/baselines/reference/emptyObjectBindingPatternParameter04.js @@ -0,0 +1,12 @@ +//// [emptyObjectBindingPatternParameter04.ts] + + +function f({} = {a: 1, b: "2", c: true}) { + var x, y, z; +} + +//// [emptyObjectBindingPatternParameter04.js] +function f(_a) { + var _a = { a: 1, b: "2", c: true }; + var x, y, z; +} diff --git a/tests/baselines/reference/emptyObjectBindingPatternParameter04.symbols b/tests/baselines/reference/emptyObjectBindingPatternParameter04.symbols new file mode 100644 index 00000000000..9922d4cd074 --- /dev/null +++ b/tests/baselines/reference/emptyObjectBindingPatternParameter04.symbols @@ -0,0 +1,14 @@ +=== tests/cases/conformance/es6/destructuring/emptyObjectBindingPatternParameter04.ts === + + +function f({} = {a: 1, b: "2", c: true}) { +>f : Symbol(f, Decl(emptyObjectBindingPatternParameter04.ts, 0, 0)) +>a : Symbol(a, Decl(emptyObjectBindingPatternParameter04.ts, 2, 17)) +>b : Symbol(b, Decl(emptyObjectBindingPatternParameter04.ts, 2, 22)) +>c : Symbol(c, Decl(emptyObjectBindingPatternParameter04.ts, 2, 30)) + + var x, y, z; +>x : Symbol(x, Decl(emptyObjectBindingPatternParameter04.ts, 3, 7)) +>y : Symbol(y, Decl(emptyObjectBindingPatternParameter04.ts, 3, 10)) +>z : Symbol(z, Decl(emptyObjectBindingPatternParameter04.ts, 3, 13)) +} diff --git a/tests/baselines/reference/emptyObjectBindingPatternParameter04.types b/tests/baselines/reference/emptyObjectBindingPatternParameter04.types new file mode 100644 index 00000000000..5ee32d422a9 --- /dev/null +++ b/tests/baselines/reference/emptyObjectBindingPatternParameter04.types @@ -0,0 +1,18 @@ +=== tests/cases/conformance/es6/destructuring/emptyObjectBindingPatternParameter04.ts === + + +function f({} = {a: 1, b: "2", c: true}) { +>f : ({}?: { a: number; b: string; c: boolean; }) => void +>{a: 1, b: "2", c: true} : { a: number; b: string; c: boolean; } +>a : number +>1 : number +>b : string +>"2" : string +>c : boolean +>true : boolean + + var x, y, z; +>x : any +>y : any +>z : any +} diff --git a/tests/baselines/reference/exportAssignNonIdentifier.errors.txt b/tests/baselines/reference/exportAssignNonIdentifier.errors.txt index 09e86ec12c4..c3d58c9b36f 100644 --- a/tests/baselines/reference/exportAssignNonIdentifier.errors.txt +++ b/tests/baselines/reference/exportAssignNonIdentifier.errors.txt @@ -1,5 +1,4 @@ tests/cases/conformance/externalModules/foo1.ts(2,1): error TS1148: Cannot compile modules unless the '--module' flag is provided. -tests/cases/conformance/externalModules/foo3.ts(1,16): error TS9003: 'class' expressions are not currently supported. tests/cases/conformance/externalModules/foo6.ts(1,14): error TS1109: Expression expected. @@ -12,10 +11,8 @@ tests/cases/conformance/externalModules/foo6.ts(1,14): error TS1109: Expression ==== tests/cases/conformance/externalModules/foo2.ts (0 errors) ==== export = "sausages"; // Ok -==== tests/cases/conformance/externalModules/foo3.ts (1 errors) ==== +==== tests/cases/conformance/externalModules/foo3.ts (0 errors) ==== export = class Foo3 {}; // Error, not an expression - ~~~~ -!!! error TS9003: 'class' expressions are not currently supported. ==== tests/cases/conformance/externalModules/foo4.ts (0 errors) ==== export = true; // Ok diff --git a/tests/baselines/reference/for-of37.symbols b/tests/baselines/reference/for-of37.symbols index 739d9be0af0..11de20174a7 100644 --- a/tests/baselines/reference/for-of37.symbols +++ b/tests/baselines/reference/for-of37.symbols @@ -1,7 +1,7 @@ === tests/cases/conformance/es6/for-ofStatements/for-of37.ts === var map = new Map([["", true]]); >map : Symbol(map, Decl(for-of37.ts, 0, 3)) ->Map : Symbol(Map, Decl(lib.d.ts, 1864, 1), Decl(lib.d.ts, 1886, 11)) +>Map : Symbol(Map, Decl(lib.d.ts, 1864, 1), Decl(lib.d.ts, 1887, 11)) for (var v of map) { >v : Symbol(v, Decl(for-of37.ts, 1, 8)) diff --git a/tests/baselines/reference/for-of38.symbols b/tests/baselines/reference/for-of38.symbols index 9322fea69e6..20af2cb65fb 100644 --- a/tests/baselines/reference/for-of38.symbols +++ b/tests/baselines/reference/for-of38.symbols @@ -1,7 +1,7 @@ === tests/cases/conformance/es6/for-ofStatements/for-of38.ts === var map = new Map([["", true]]); >map : Symbol(map, Decl(for-of38.ts, 0, 3)) ->Map : Symbol(Map, Decl(lib.d.ts, 1864, 1), Decl(lib.d.ts, 1886, 11)) +>Map : Symbol(Map, Decl(lib.d.ts, 1864, 1), Decl(lib.d.ts, 1887, 11)) for (var [k, v] of map) { >k : Symbol(k, Decl(for-of38.ts, 1, 10)) diff --git a/tests/baselines/reference/for-of40.symbols b/tests/baselines/reference/for-of40.symbols index 72bbf78884e..eb77e578510 100644 --- a/tests/baselines/reference/for-of40.symbols +++ b/tests/baselines/reference/for-of40.symbols @@ -1,7 +1,7 @@ === tests/cases/conformance/es6/for-ofStatements/for-of40.ts === var map = new Map([["", true]]); >map : Symbol(map, Decl(for-of40.ts, 0, 3)) ->Map : Symbol(Map, Decl(lib.d.ts, 1864, 1), Decl(lib.d.ts, 1886, 11)) +>Map : Symbol(Map, Decl(lib.d.ts, 1864, 1), Decl(lib.d.ts, 1887, 11)) for (var [k = "", v = false] of map) { >k : Symbol(k, Decl(for-of40.ts, 1, 10)) diff --git a/tests/baselines/reference/for-of45.symbols b/tests/baselines/reference/for-of45.symbols index e1e7717269f..b9e5bbacbfa 100644 --- a/tests/baselines/reference/for-of45.symbols +++ b/tests/baselines/reference/for-of45.symbols @@ -5,7 +5,7 @@ var k: string, v: boolean; var map = new Map([["", true]]); >map : Symbol(map, Decl(for-of45.ts, 1, 3)) ->Map : Symbol(Map, Decl(lib.d.ts, 1864, 1), Decl(lib.d.ts, 1886, 11)) +>Map : Symbol(Map, Decl(lib.d.ts, 1864, 1), Decl(lib.d.ts, 1887, 11)) for ([k = "", v = false] of map) { >k : Symbol(k, Decl(for-of45.ts, 0, 3)) diff --git a/tests/baselines/reference/for-of50.symbols b/tests/baselines/reference/for-of50.symbols index 571dd9dc389..f3bd38be1df 100644 --- a/tests/baselines/reference/for-of50.symbols +++ b/tests/baselines/reference/for-of50.symbols @@ -1,7 +1,7 @@ === tests/cases/conformance/es6/for-ofStatements/for-of50.ts === var map = new Map([["", true]]); >map : Symbol(map, Decl(for-of50.ts, 0, 3)) ->Map : Symbol(Map, Decl(lib.d.ts, 1864, 1), Decl(lib.d.ts, 1886, 11)) +>Map : Symbol(Map, Decl(lib.d.ts, 1864, 1), Decl(lib.d.ts, 1887, 11)) for (const [k, v] of map) { >k : Symbol(k, Decl(for-of50.ts, 1, 12)) diff --git a/tests/baselines/reference/generatorTypeCheck55.errors.txt b/tests/baselines/reference/generatorTypeCheck55.errors.txt index 0846d1c28ad..854c1801efd 100644 --- a/tests/baselines/reference/generatorTypeCheck55.errors.txt +++ b/tests/baselines/reference/generatorTypeCheck55.errors.txt @@ -1,9 +1,12 @@ -tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck55.ts(2,19): error TS9003: 'class' expressions are not currently supported. +tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck55.ts(2,29): error TS2507: Type 'any' is not a constructor function type. +tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck55.ts(2,30): error TS1163: A 'yield' expression is only allowed in a generator body. -==== tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck55.ts (1 errors) ==== +==== tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck55.ts (2 errors) ==== function* g() { var x = class C extends (yield) {}; - ~ -!!! error TS9003: 'class' expressions are not currently supported. + ~~~~~~~ +!!! error TS2507: Type 'any' is not a constructor function type. + ~~~~~ +!!! error TS1163: A 'yield' expression is only allowed in a generator body. } \ No newline at end of file diff --git a/tests/baselines/reference/generatorTypeCheck56.errors.txt b/tests/baselines/reference/generatorTypeCheck56.errors.txt index 99e3b00de41..20961935807 100644 --- a/tests/baselines/reference/generatorTypeCheck56.errors.txt +++ b/tests/baselines/reference/generatorTypeCheck56.errors.txt @@ -1,12 +1,9 @@ -tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck56.ts(2,19): error TS9003: 'class' expressions are not currently supported. tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck56.ts(3,11): error TS1163: A 'yield' expression is only allowed in a generator body. -==== tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck56.ts (2 errors) ==== +==== tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck56.ts (1 errors) ==== function* g() { var x = class C { - ~ -!!! error TS9003: 'class' expressions are not currently supported. *[yield 0]() { ~~~~~ !!! error TS1163: A 'yield' expression is only allowed in a generator body. diff --git a/tests/baselines/reference/iterableArrayPattern30.symbols b/tests/baselines/reference/iterableArrayPattern30.symbols index 715dd79c97a..38dacc59cc2 100644 --- a/tests/baselines/reference/iterableArrayPattern30.symbols +++ b/tests/baselines/reference/iterableArrayPattern30.symbols @@ -4,5 +4,5 @@ const [[k1, v1], [k2, v2]] = new Map([["", true], ["hello", true]]) >v1 : Symbol(v1, Decl(iterableArrayPattern30.ts, 0, 11)) >k2 : Symbol(k2, Decl(iterableArrayPattern30.ts, 0, 18)) >v2 : Symbol(v2, Decl(iterableArrayPattern30.ts, 0, 21)) ->Map : Symbol(Map, Decl(lib.d.ts, 1864, 1), Decl(lib.d.ts, 1886, 11)) +>Map : Symbol(Map, Decl(lib.d.ts, 1864, 1), Decl(lib.d.ts, 1887, 11)) diff --git a/tests/baselines/reference/missingDecoratorType.errors.txt b/tests/baselines/reference/missingDecoratorType.errors.txt index 0b159a8fcb2..f2af7d49b57 100644 --- a/tests/baselines/reference/missingDecoratorType.errors.txt +++ b/tests/baselines/reference/missingDecoratorType.errors.txt @@ -1,7 +1,7 @@ -error TS2318: Cannot find global type 'ClassDecorator'. +error TS2318: Cannot find global type 'TypedPropertyDescriptor'. -!!! error TS2318: Cannot find global type 'ClassDecorator'. +!!! error TS2318: Cannot find global type 'TypedPropertyDescriptor'. ==== tests/cases/conformance/decorators/a.ts (0 errors) ==== interface Object { } @@ -14,10 +14,11 @@ error TS2318: Cannot find global type 'ClassDecorator'. interface IArguments { } ==== tests/cases/conformance/decorators/b.ts (0 errors) ==== - declare var dec: any; + declare function dec(t, k, d); - @dec class C { + @dec + method() {} } \ No newline at end of file diff --git a/tests/baselines/reference/missingDecoratorType.js b/tests/baselines/reference/missingDecoratorType.js index 4460abdc798..ad6be3a646e 100644 --- a/tests/baselines/reference/missingDecoratorType.js +++ b/tests/baselines/reference/missingDecoratorType.js @@ -12,10 +12,11 @@ interface RegExp { } interface IArguments { } //// [b.ts] -declare var dec: any; +declare function dec(t, k, d); -@dec class C { + @dec + method() {} } @@ -33,8 +34,10 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key, var C = (function () { function C() { } - C = __decorate([ - dec - ], C); + C.prototype.method = function () { }; + Object.defineProperty(C.prototype, "method", + __decorate([ + dec + ], C.prototype, "method", Object.getOwnPropertyDescriptor(C.prototype, "method"))); return C; })(); diff --git a/tests/baselines/reference/noEmitHelpers2.js b/tests/baselines/reference/noEmitHelpers2.js index 1bd42377679..66e2ff78b64 100644 --- a/tests/baselines/reference/noEmitHelpers2.js +++ b/tests/baselines/reference/noEmitHelpers2.js @@ -1,6 +1,6 @@ //// [noEmitHelpers2.ts] -function decorator() { } +declare var decorator: any; @decorator class A { @@ -9,7 +9,6 @@ class A { } //// [noEmitHelpers2.js] -function decorator() { } var A = (function () { function A(a, b) { } diff --git a/tests/baselines/reference/noEmitHelpers2.symbols b/tests/baselines/reference/noEmitHelpers2.symbols index 3a3e3ec94c7..044026a3db7 100644 --- a/tests/baselines/reference/noEmitHelpers2.symbols +++ b/tests/baselines/reference/noEmitHelpers2.symbols @@ -1,17 +1,17 @@ === tests/cases/compiler/noEmitHelpers2.ts === -function decorator() { } ->decorator : Symbol(decorator, Decl(noEmitHelpers2.ts, 0, 0)) +declare var decorator: any; +>decorator : Symbol(decorator, Decl(noEmitHelpers2.ts, 1, 11)) @decorator ->decorator : Symbol(decorator, Decl(noEmitHelpers2.ts, 0, 0)) +>decorator : Symbol(decorator, Decl(noEmitHelpers2.ts, 1, 11)) class A { ->A : Symbol(A, Decl(noEmitHelpers2.ts, 1, 24)) +>A : Symbol(A, Decl(noEmitHelpers2.ts, 1, 27)) constructor(a: number, @decorator b: string) { >a : Symbol(a, Decl(noEmitHelpers2.ts, 5, 16)) ->decorator : Symbol(decorator, Decl(noEmitHelpers2.ts, 0, 0)) +>decorator : Symbol(decorator, Decl(noEmitHelpers2.ts, 1, 11)) >b : Symbol(b, Decl(noEmitHelpers2.ts, 5, 26)) } } diff --git a/tests/baselines/reference/noEmitHelpers2.types b/tests/baselines/reference/noEmitHelpers2.types index 2a5b5413a7e..14260e4f95c 100644 --- a/tests/baselines/reference/noEmitHelpers2.types +++ b/tests/baselines/reference/noEmitHelpers2.types @@ -1,17 +1,17 @@ === tests/cases/compiler/noEmitHelpers2.ts === -function decorator() { } ->decorator : () => void +declare var decorator: any; +>decorator : any @decorator ->decorator : () => void +>decorator : any class A { >A : A constructor(a: number, @decorator b: string) { >a : number ->decorator : () => void +>decorator : any >b : string } } diff --git a/tests/baselines/reference/numLit.errors.txt b/tests/baselines/reference/numLit.errors.txt deleted file mode 100644 index 98b84791e35..00000000000 --- a/tests/baselines/reference/numLit.errors.txt +++ /dev/null @@ -1,13 +0,0 @@ -tests/cases/compiler/numLit.ts(3,3): error TS1005: ';' expected. -tests/cases/compiler/numLit.ts(3,3): error TS2304: Cannot find name 'toString'. - - -==== tests/cases/compiler/numLit.ts (2 errors) ==== - 1..toString(); - 1.0.toString(); - 1.toString(); - ~~~~~~~~ -!!! error TS1005: ';' expected. - ~~~~~~~~ -!!! error TS2304: Cannot find name 'toString'. - 1.+2.0 + 3. ; \ No newline at end of file diff --git a/tests/baselines/reference/numLit.js b/tests/baselines/reference/numLit.js deleted file mode 100644 index aaec91cde5d..00000000000 --- a/tests/baselines/reference/numLit.js +++ /dev/null @@ -1,12 +0,0 @@ -//// [numLit.ts] -1..toString(); -1.0.toString(); -1.toString(); -1.+2.0 + 3. ; - -//// [numLit.js] -1..toString(); -1.0.toString(); -1.; -toString(); -1. + 2.0 + 3.; diff --git a/tests/baselines/reference/numericLiteralsWithTrailingDecimalPoints01.errors.txt b/tests/baselines/reference/numericLiteralsWithTrailingDecimalPoints01.errors.txt new file mode 100644 index 00000000000..f08750ff0a6 --- /dev/null +++ b/tests/baselines/reference/numericLiteralsWithTrailingDecimalPoints01.errors.txt @@ -0,0 +1,33 @@ +tests/cases/compiler/numericLiteralsWithTrailingDecimalPoints01.ts(3,3): error TS1005: ';' expected. +tests/cases/compiler/numericLiteralsWithTrailingDecimalPoints01.ts(9,15): error TS1005: ',' expected. +tests/cases/compiler/numericLiteralsWithTrailingDecimalPoints01.ts(9,23): error TS1005: '=' expected. +tests/cases/compiler/numericLiteralsWithTrailingDecimalPoints01.ts(9,24): error TS1109: Expression expected. + + +==== tests/cases/compiler/numericLiteralsWithTrailingDecimalPoints01.ts (4 errors) ==== + 1..toString(); + 1.0.toString(); + 1.toString(); + ~~~~~~~~ +!!! error TS1005: ';' expected. + 1.+2.0 + 3. ; + + // Preserve whitespace where important for JS compatibility + var i: number = 1; + var test1 = i.toString(); + var test2 = 2.toString(); + ~~~~~~~~ +!!! error TS1005: ',' expected. + ~ +!!! error TS1005: '=' expected. + ~ +!!! error TS1109: Expression expected. + var test3 = 3 .toString(); + var test4 = 3 .toString(); + var test5 = 3 .toString(); + var test6 = 3.['toString'](); + var test7 = 3 + .toString(); + var test8 = new Number(4).toString(); + var test9 = 3. + 3. + \ No newline at end of file diff --git a/tests/baselines/reference/numericLiteralsWithTrailingDecimalPoints01.js b/tests/baselines/reference/numericLiteralsWithTrailingDecimalPoints01.js new file mode 100644 index 00000000000..0b1ce1f0736 --- /dev/null +++ b/tests/baselines/reference/numericLiteralsWithTrailingDecimalPoints01.js @@ -0,0 +1,38 @@ +//// [numericLiteralsWithTrailingDecimalPoints01.ts] +1..toString(); +1.0.toString(); +1.toString(); +1.+2.0 + 3. ; + +// Preserve whitespace where important for JS compatibility +var i: number = 1; +var test1 = i.toString(); +var test2 = 2.toString(); +var test3 = 3 .toString(); +var test4 = 3 .toString(); +var test5 = 3 .toString(); +var test6 = 3.['toString'](); +var test7 = 3 +.toString(); +var test8 = new Number(4).toString(); +var test9 = 3. + 3. + + +//// [numericLiteralsWithTrailingDecimalPoints01.js] +1..toString(); +1.0.toString(); +1.; +toString(); +1. + 2.0 + 3.; +// Preserve whitespace where important for JS compatibility +var i = 1; +var test1 = i.toString(); +var test2 = 2., toString = (); +var test3 = 3 .toString(); +var test4 = 3 .toString(); +var test5 = 3 .toString(); +var test6 = 3.['toString'](); +var test7 = 3 + .toString(); +var test8 = new Number(4).toString(); +var test9 = 3. + 3.; diff --git a/tests/baselines/reference/promiseVoidErrorCallback.symbols b/tests/baselines/reference/promiseVoidErrorCallback.symbols index 9a6e2ef47ba..d9e329885aa 100644 --- a/tests/baselines/reference/promiseVoidErrorCallback.symbols +++ b/tests/baselines/reference/promiseVoidErrorCallback.symbols @@ -22,13 +22,13 @@ interface T3 { function f1(): Promise { >f1 : Symbol(f1, Decl(promiseVoidErrorCallback.ts, 10, 1)) ->Promise : Symbol(Promise, Decl(lib.d.ts, 4766, 1), Decl(lib.d.ts, 4851, 11)) +>Promise : Symbol(Promise, Decl(lib.d.ts, 4770, 1), Decl(lib.d.ts, 4855, 11)) >T1 : Symbol(T1, Decl(promiseVoidErrorCallback.ts, 0, 0)) return Promise.resolve({ __t1: "foo_t1" }); ->Promise.resolve : Symbol(PromiseConstructor.resolve, Decl(lib.d.ts, 4833, 39), Decl(lib.d.ts, 4840, 54)) ->Promise : Symbol(Promise, Decl(lib.d.ts, 4766, 1), Decl(lib.d.ts, 4851, 11)) ->resolve : Symbol(PromiseConstructor.resolve, Decl(lib.d.ts, 4833, 39), Decl(lib.d.ts, 4840, 54)) +>Promise.resolve : Symbol(PromiseConstructor.resolve, Decl(lib.d.ts, 4837, 39), Decl(lib.d.ts, 4844, 54)) +>Promise : Symbol(Promise, Decl(lib.d.ts, 4770, 1), Decl(lib.d.ts, 4855, 11)) +>resolve : Symbol(PromiseConstructor.resolve, Decl(lib.d.ts, 4837, 39), Decl(lib.d.ts, 4844, 54)) >__t1 : Symbol(__t1, Decl(promiseVoidErrorCallback.ts, 13, 28)) } @@ -47,12 +47,12 @@ function f2(x: T1): T2 { var x3 = f1() >x3 : Symbol(x3, Decl(promiseVoidErrorCallback.ts, 20, 3)) ->f1() .then(f2, (e: Error) => { throw e;}) .then : Symbol(Promise.then, Decl(lib.d.ts, 4771, 22), Decl(lib.d.ts, 4778, 158)) ->f1() .then : Symbol(Promise.then, Decl(lib.d.ts, 4771, 22), Decl(lib.d.ts, 4778, 158)) +>f1() .then(f2, (e: Error) => { throw e;}) .then : Symbol(Promise.then, Decl(lib.d.ts, 4775, 22), Decl(lib.d.ts, 4782, 158)) +>f1() .then : Symbol(Promise.then, Decl(lib.d.ts, 4775, 22), Decl(lib.d.ts, 4782, 158)) >f1 : Symbol(f1, Decl(promiseVoidErrorCallback.ts, 10, 1)) .then(f2, (e: Error) => { ->then : Symbol(Promise.then, Decl(lib.d.ts, 4771, 22), Decl(lib.d.ts, 4778, 158)) +>then : Symbol(Promise.then, Decl(lib.d.ts, 4775, 22), Decl(lib.d.ts, 4782, 158)) >f2 : Symbol(f2, Decl(promiseVoidErrorCallback.ts, 14, 1)) >e : Symbol(e, Decl(promiseVoidErrorCallback.ts, 21, 15)) >Error : Symbol(Error, Decl(lib.d.ts, 876, 38), Decl(lib.d.ts, 889, 11)) @@ -62,7 +62,7 @@ var x3 = f1() }) .then((x: T2) => { ->then : Symbol(Promise.then, Decl(lib.d.ts, 4771, 22), Decl(lib.d.ts, 4778, 158)) +>then : Symbol(Promise.then, Decl(lib.d.ts, 4775, 22), Decl(lib.d.ts, 4782, 158)) >x : Symbol(x, Decl(promiseVoidErrorCallback.ts, 24, 11)) >T2 : Symbol(T2, Decl(promiseVoidErrorCallback.ts, 2, 1)) diff --git a/tests/baselines/reference/sourceMapValidationDecorators.js b/tests/baselines/reference/sourceMapValidationDecorators.js index f858aeff586..5196d3b0dd8 100644 --- a/tests/baselines/reference/sourceMapValidationDecorators.js +++ b/tests/baselines/reference/sourceMapValidationDecorators.js @@ -3,8 +3,8 @@ declare function ClassDecorator1(target: Function): void; declare function ClassDecorator2(x: number): (target: Function) => void; declare function PropertyDecorator1(target: Object, key: string | symbol, descriptor?: PropertyDescriptor): void; declare function PropertyDecorator2(x: number): (target: Object, key: string | symbol, descriptor?: PropertyDescriptor) => void; -declare function ParameterDecorator1(target: Function, key: string | symbol, paramIndex: number): void; -declare function ParameterDecorator2(x: number): (target: Function, key: string | symbol, paramIndex: number) => void; +declare function ParameterDecorator1(target: Object, key: string | symbol, paramIndex: number): void; +declare function ParameterDecorator2(x: number): (target: Object, key: string | symbol, paramIndex: number) => void; @ClassDecorator1 @ClassDecorator2(10) diff --git a/tests/baselines/reference/sourceMapValidationDecorators.sourcemap.txt b/tests/baselines/reference/sourceMapValidationDecorators.sourcemap.txt index 68ad353db9f..b7036723a85 100644 --- a/tests/baselines/reference/sourceMapValidationDecorators.sourcemap.txt +++ b/tests/baselines/reference/sourceMapValidationDecorators.sourcemap.txt @@ -26,8 +26,8 @@ sourceFile:sourceMapValidationDecorators.ts >declare function ClassDecorator2(x: number): (target: Function) => void; >declare function PropertyDecorator1(target: Object, key: string | symbol, descriptor?: PropertyDescriptor): void; >declare function PropertyDecorator2(x: number): (target: Object, key: string | symbol, descriptor?: PropertyDescriptor) => void; - >declare function ParameterDecorator1(target: Function, key: string | symbol, paramIndex: number): void; - >declare function ParameterDecorator2(x: number): (target: Function, key: string | symbol, paramIndex: number) => void; + >declare function ParameterDecorator1(target: Object, key: string | symbol, paramIndex: number): void; + >declare function ParameterDecorator2(x: number): (target: Object, key: string | symbol, paramIndex: number) => void; > > 1 >Emitted(12, 1) Source(8, 1) + SourceIndex(0) diff --git a/tests/baselines/reference/sourceMapValidationDecorators.symbols b/tests/baselines/reference/sourceMapValidationDecorators.symbols index 37db95d3e05..e22afb7b7fc 100644 --- a/tests/baselines/reference/sourceMapValidationDecorators.symbols +++ b/tests/baselines/reference/sourceMapValidationDecorators.symbols @@ -27,20 +27,20 @@ declare function PropertyDecorator2(x: number): (target: Object, key: string | s >descriptor : Symbol(descriptor, Decl(sourceMapValidationDecorators.ts, 3, 86)) >PropertyDescriptor : Symbol(PropertyDescriptor, Decl(lib.d.ts, 79, 66)) -declare function ParameterDecorator1(target: Function, key: string | symbol, paramIndex: number): void; +declare function ParameterDecorator1(target: Object, key: string | symbol, paramIndex: number): void; >ParameterDecorator1 : Symbol(ParameterDecorator1, Decl(sourceMapValidationDecorators.ts, 3, 128)) >target : Symbol(target, Decl(sourceMapValidationDecorators.ts, 4, 37)) ->Function : Symbol(Function, Decl(lib.d.ts, 223, 38), Decl(lib.d.ts, 269, 11)) ->key : Symbol(key, Decl(sourceMapValidationDecorators.ts, 4, 54)) ->paramIndex : Symbol(paramIndex, Decl(sourceMapValidationDecorators.ts, 4, 76)) +>Object : Symbol(Object, Decl(lib.d.ts, 92, 1), Decl(lib.d.ts, 223, 11)) +>key : Symbol(key, Decl(sourceMapValidationDecorators.ts, 4, 52)) +>paramIndex : Symbol(paramIndex, Decl(sourceMapValidationDecorators.ts, 4, 74)) -declare function ParameterDecorator2(x: number): (target: Function, key: string | symbol, paramIndex: number) => void; ->ParameterDecorator2 : Symbol(ParameterDecorator2, Decl(sourceMapValidationDecorators.ts, 4, 103)) +declare function ParameterDecorator2(x: number): (target: Object, key: string | symbol, paramIndex: number) => void; +>ParameterDecorator2 : Symbol(ParameterDecorator2, Decl(sourceMapValidationDecorators.ts, 4, 101)) >x : Symbol(x, Decl(sourceMapValidationDecorators.ts, 5, 37)) >target : Symbol(target, Decl(sourceMapValidationDecorators.ts, 5, 50)) ->Function : Symbol(Function, Decl(lib.d.ts, 223, 38), Decl(lib.d.ts, 269, 11)) ->key : Symbol(key, Decl(sourceMapValidationDecorators.ts, 5, 67)) ->paramIndex : Symbol(paramIndex, Decl(sourceMapValidationDecorators.ts, 5, 89)) +>Object : Symbol(Object, Decl(lib.d.ts, 92, 1), Decl(lib.d.ts, 223, 11)) +>key : Symbol(key, Decl(sourceMapValidationDecorators.ts, 5, 65)) +>paramIndex : Symbol(paramIndex, Decl(sourceMapValidationDecorators.ts, 5, 87)) @ClassDecorator1 >ClassDecorator1 : Symbol(ClassDecorator1, Decl(sourceMapValidationDecorators.ts, 0, 0)) @@ -49,14 +49,14 @@ declare function ParameterDecorator2(x: number): (target: Function, key: string >ClassDecorator2 : Symbol(ClassDecorator2, Decl(sourceMapValidationDecorators.ts, 0, 57)) class Greeter { ->Greeter : Symbol(Greeter, Decl(sourceMapValidationDecorators.ts, 5, 118)) +>Greeter : Symbol(Greeter, Decl(sourceMapValidationDecorators.ts, 5, 116)) constructor( @ParameterDecorator1 >ParameterDecorator1 : Symbol(ParameterDecorator1, Decl(sourceMapValidationDecorators.ts, 3, 128)) @ParameterDecorator2(20) ->ParameterDecorator2 : Symbol(ParameterDecorator2, Decl(sourceMapValidationDecorators.ts, 4, 103)) +>ParameterDecorator2 : Symbol(ParameterDecorator2, Decl(sourceMapValidationDecorators.ts, 4, 101)) public greeting: string, >greeting : Symbol(greeting, Decl(sourceMapValidationDecorators.ts, 10, 16)) @@ -65,7 +65,7 @@ class Greeter { >ParameterDecorator1 : Symbol(ParameterDecorator1, Decl(sourceMapValidationDecorators.ts, 3, 128)) @ParameterDecorator2(30) ->ParameterDecorator2 : Symbol(ParameterDecorator2, Decl(sourceMapValidationDecorators.ts, 4, 103)) +>ParameterDecorator2 : Symbol(ParameterDecorator2, Decl(sourceMapValidationDecorators.ts, 4, 101)) ...b: string[]) { >b : Symbol(b, Decl(sourceMapValidationDecorators.ts, 13, 30)) @@ -82,7 +82,7 @@ class Greeter { return "

" + this.greeting + "

"; >this.greeting : Symbol(greeting, Decl(sourceMapValidationDecorators.ts, 10, 16)) ->this : Symbol(Greeter, Decl(sourceMapValidationDecorators.ts, 5, 118)) +>this : Symbol(Greeter, Decl(sourceMapValidationDecorators.ts, 5, 116)) >greeting : Symbol(greeting, Decl(sourceMapValidationDecorators.ts, 10, 16)) } @@ -111,14 +111,14 @@ class Greeter { >ParameterDecorator1 : Symbol(ParameterDecorator1, Decl(sourceMapValidationDecorators.ts, 3, 128)) @ParameterDecorator2(70) ->ParameterDecorator2 : Symbol(ParameterDecorator2, Decl(sourceMapValidationDecorators.ts, 4, 103)) +>ParameterDecorator2 : Symbol(ParameterDecorator2, Decl(sourceMapValidationDecorators.ts, 4, 101)) x: number) { >x : Symbol(x, Decl(sourceMapValidationDecorators.ts, 34, 15)) return this.greeting; >this.greeting : Symbol(greeting, Decl(sourceMapValidationDecorators.ts, 10, 16)) ->this : Symbol(Greeter, Decl(sourceMapValidationDecorators.ts, 5, 118)) +>this : Symbol(Greeter, Decl(sourceMapValidationDecorators.ts, 5, 116)) >greeting : Symbol(greeting, Decl(sourceMapValidationDecorators.ts, 10, 16)) } @@ -133,7 +133,7 @@ class Greeter { return this.greeting; >this.greeting : Symbol(greeting, Decl(sourceMapValidationDecorators.ts, 10, 16)) ->this : Symbol(Greeter, Decl(sourceMapValidationDecorators.ts, 5, 118)) +>this : Symbol(Greeter, Decl(sourceMapValidationDecorators.ts, 5, 116)) >greeting : Symbol(greeting, Decl(sourceMapValidationDecorators.ts, 10, 16)) } @@ -144,14 +144,14 @@ class Greeter { >ParameterDecorator1 : Symbol(ParameterDecorator1, Decl(sourceMapValidationDecorators.ts, 3, 128)) @ParameterDecorator2(90) ->ParameterDecorator2 : Symbol(ParameterDecorator2, Decl(sourceMapValidationDecorators.ts, 4, 103)) +>ParameterDecorator2 : Symbol(ParameterDecorator2, Decl(sourceMapValidationDecorators.ts, 4, 101)) greetings: string) { >greetings : Symbol(greetings, Decl(sourceMapValidationDecorators.ts, 47, 18)) this.greeting = greetings; >this.greeting : Symbol(greeting, Decl(sourceMapValidationDecorators.ts, 10, 16)) ->this : Symbol(Greeter, Decl(sourceMapValidationDecorators.ts, 5, 118)) +>this : Symbol(Greeter, Decl(sourceMapValidationDecorators.ts, 5, 116)) >greeting : Symbol(greeting, Decl(sourceMapValidationDecorators.ts, 10, 16)) >greetings : Symbol(greetings, Decl(sourceMapValidationDecorators.ts, 47, 18)) } diff --git a/tests/baselines/reference/sourceMapValidationDecorators.types b/tests/baselines/reference/sourceMapValidationDecorators.types index 182f68570bc..9e83bb03509 100644 --- a/tests/baselines/reference/sourceMapValidationDecorators.types +++ b/tests/baselines/reference/sourceMapValidationDecorators.types @@ -27,18 +27,18 @@ declare function PropertyDecorator2(x: number): (target: Object, key: string | s >descriptor : PropertyDescriptor >PropertyDescriptor : PropertyDescriptor -declare function ParameterDecorator1(target: Function, key: string | symbol, paramIndex: number): void; ->ParameterDecorator1 : (target: Function, key: string | symbol, paramIndex: number) => void ->target : Function ->Function : Function +declare function ParameterDecorator1(target: Object, key: string | symbol, paramIndex: number): void; +>ParameterDecorator1 : (target: Object, key: string | symbol, paramIndex: number) => void +>target : Object +>Object : Object >key : string | symbol >paramIndex : number -declare function ParameterDecorator2(x: number): (target: Function, key: string | symbol, paramIndex: number) => void; ->ParameterDecorator2 : (x: number) => (target: Function, key: string | symbol, paramIndex: number) => void +declare function ParameterDecorator2(x: number): (target: Object, key: string | symbol, paramIndex: number) => void; +>ParameterDecorator2 : (x: number) => (target: Object, key: string | symbol, paramIndex: number) => void >x : number ->target : Function ->Function : Function +>target : Object +>Object : Object >key : string | symbol >paramIndex : number @@ -55,22 +55,22 @@ class Greeter { constructor( @ParameterDecorator1 ->ParameterDecorator1 : (target: Function, key: string | symbol, paramIndex: number) => void +>ParameterDecorator1 : (target: Object, key: string | symbol, paramIndex: number) => void @ParameterDecorator2(20) ->ParameterDecorator2(20) : (target: Function, key: string | symbol, paramIndex: number) => void ->ParameterDecorator2 : (x: number) => (target: Function, key: string | symbol, paramIndex: number) => void +>ParameterDecorator2(20) : (target: Object, key: string | symbol, paramIndex: number) => void +>ParameterDecorator2 : (x: number) => (target: Object, key: string | symbol, paramIndex: number) => void >20 : number public greeting: string, >greeting : string @ParameterDecorator1 ->ParameterDecorator1 : (target: Function, key: string | symbol, paramIndex: number) => void +>ParameterDecorator1 : (target: Object, key: string | symbol, paramIndex: number) => void @ParameterDecorator2(30) ->ParameterDecorator2(30) : (target: Function, key: string | symbol, paramIndex: number) => void ->ParameterDecorator2 : (x: number) => (target: Function, key: string | symbol, paramIndex: number) => void +>ParameterDecorator2(30) : (target: Object, key: string | symbol, paramIndex: number) => void +>ParameterDecorator2 : (x: number) => (target: Object, key: string | symbol, paramIndex: number) => void >30 : number ...b: string[]) { @@ -125,11 +125,11 @@ class Greeter { >fn : (x: number) => string @ParameterDecorator1 ->ParameterDecorator1 : (target: Function, key: string | symbol, paramIndex: number) => void +>ParameterDecorator1 : (target: Object, key: string | symbol, paramIndex: number) => void @ParameterDecorator2(70) ->ParameterDecorator2(70) : (target: Function, key: string | symbol, paramIndex: number) => void ->ParameterDecorator2 : (x: number) => (target: Function, key: string | symbol, paramIndex: number) => void +>ParameterDecorator2(70) : (target: Object, key: string | symbol, paramIndex: number) => void +>ParameterDecorator2 : (x: number) => (target: Object, key: string | symbol, paramIndex: number) => void >70 : number x: number) { @@ -162,11 +162,11 @@ class Greeter { >greetings : string @ParameterDecorator1 ->ParameterDecorator1 : (target: Function, key: string | symbol, paramIndex: number) => void +>ParameterDecorator1 : (target: Object, key: string | symbol, paramIndex: number) => void @ParameterDecorator2(90) ->ParameterDecorator2(90) : (target: Function, key: string | symbol, paramIndex: number) => void ->ParameterDecorator2 : (x: number) => (target: Function, key: string | symbol, paramIndex: number) => void +>ParameterDecorator2(90) : (target: Object, key: string | symbol, paramIndex: number) => void +>ParameterDecorator2 : (x: number) => (target: Object, key: string | symbol, paramIndex: number) => void >90 : number greetings: string) { diff --git a/tests/baselines/reference/strictModeReservedWord.errors.txt b/tests/baselines/reference/strictModeReservedWord.errors.txt index b6e9161ce7e..6f6a387429d 100644 --- a/tests/baselines/reference/strictModeReservedWord.errors.txt +++ b/tests/baselines/reference/strictModeReservedWord.errors.txt @@ -17,8 +17,8 @@ tests/cases/compiler/strictModeReservedWord.ts(13,11): error TS1212: Identifier tests/cases/compiler/strictModeReservedWord.ts(13,20): error TS1212: Identifier expected. 'public' is a reserved word in strict mode tests/cases/compiler/strictModeReservedWord.ts(13,28): error TS1212: Identifier expected. 'package' is a reserved word in strict mode tests/cases/compiler/strictModeReservedWord.ts(15,25): error TS1213: Identifier expected. 'package' is a reserved word in strict mode. Class definitions are automatically in strict mode. -tests/cases/compiler/strictModeReservedWord.ts(15,25): error TS9003: 'class' expressions are not currently supported. tests/cases/compiler/strictModeReservedWord.ts(15,41): error TS1213: Identifier expected. 'public' is a reserved word in strict mode. Class definitions are automatically in strict mode. +tests/cases/compiler/strictModeReservedWord.ts(15,41): error TS2507: Type 'number' is not a constructor function type. tests/cases/compiler/strictModeReservedWord.ts(17,9): error TS2300: Duplicate identifier 'b'. tests/cases/compiler/strictModeReservedWord.ts(17,12): error TS1212: Identifier expected. 'public' is a reserved word in strict mode tests/cases/compiler/strictModeReservedWord.ts(17,12): error TS2503: Cannot find namespace 'public'. @@ -95,10 +95,10 @@ tests/cases/compiler/strictModeReservedWord.ts(24,5): error TS2349: Cannot invok var myClass = class package extends public {} ~~~~~~~ !!! error TS1213: Identifier expected. 'package' is a reserved word in strict mode. Class definitions are automatically in strict mode. - ~~~~~~~ -!!! error TS9003: 'class' expressions are not currently supported. ~~~~~~ !!! error TS1213: Identifier expected. 'public' is a reserved word in strict mode. Class definitions are automatically in strict mode. + ~~~~~~ +!!! error TS2507: Type 'number' is not a constructor function type. var b: public.bar; ~ diff --git a/tests/baselines/reference/strictModeReservedWord.js b/tests/baselines/reference/strictModeReservedWord.js index 9be21b20ae6..bec159dee6f 100644 --- a/tests/baselines/reference/strictModeReservedWord.js +++ b/tests/baselines/reference/strictModeReservedWord.js @@ -28,6 +28,11 @@ function foo() { //// [strictModeReservedWord.js] +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; var let = 10; function foo() { "use strict"; diff --git a/tests/baselines/reference/typeGuardFunction.symbols b/tests/baselines/reference/typeGuardFunction.symbols index c315e721085..13ad30de5c5 100644 --- a/tests/baselines/reference/typeGuardFunction.symbols +++ b/tests/baselines/reference/typeGuardFunction.symbols @@ -25,16 +25,19 @@ class C extends A { declare function isA(p1: any): p1 is A; >isA : Symbol(isA, Decl(typeGuardFunction.ts, 11, 1)) >p1 : Symbol(p1, Decl(typeGuardFunction.ts, 13, 21)) +>p1 : Symbol(p1, Decl(typeGuardFunction.ts, 13, 21)) >A : Symbol(A, Decl(typeGuardFunction.ts, 0, 0)) declare function isB(p1: any): p1 is B; >isB : Symbol(isB, Decl(typeGuardFunction.ts, 13, 39)) >p1 : Symbol(p1, Decl(typeGuardFunction.ts, 14, 21)) +>p1 : Symbol(p1, Decl(typeGuardFunction.ts, 14, 21)) >B : Symbol(B, Decl(typeGuardFunction.ts, 3, 1)) declare function isC(p1: any): p1 is C; >isC : Symbol(isC, Decl(typeGuardFunction.ts, 14, 39)) >p1 : Symbol(p1, Decl(typeGuardFunction.ts, 15, 21)) +>p1 : Symbol(p1, Decl(typeGuardFunction.ts, 15, 21)) >C : Symbol(C, Decl(typeGuardFunction.ts, 7, 1)) declare function retC(): C; @@ -98,6 +101,7 @@ interface I1 { (p1: A): p1 is C; >p1 : Symbol(p1, Decl(typeGuardFunction.ts, 41, 5)) >A : Symbol(A, Decl(typeGuardFunction.ts, 0, 0)) +>p1 : Symbol(p1, Decl(typeGuardFunction.ts, 41, 5)) >C : Symbol(C, Decl(typeGuardFunction.ts, 7, 1)) } @@ -107,6 +111,7 @@ declare function isC_multipleParams(p1, p2): p1 is C; >isC_multipleParams : Symbol(isC_multipleParams, Decl(typeGuardFunction.ts, 42, 1)) >p1 : Symbol(p1, Decl(typeGuardFunction.ts, 46, 36)) >p2 : Symbol(p2, Decl(typeGuardFunction.ts, 46, 39)) +>p1 : Symbol(p1, Decl(typeGuardFunction.ts, 46, 36)) >C : Symbol(C, Decl(typeGuardFunction.ts, 7, 1)) if (isC_multipleParams(a, 0)) { @@ -127,6 +132,7 @@ var obj: { >func1 : Symbol(func1, Decl(typeGuardFunction.ts, 52, 10)) >p1 : Symbol(p1, Decl(typeGuardFunction.ts, 53, 10)) >A : Symbol(A, Decl(typeGuardFunction.ts, 0, 0)) +>p1 : Symbol(p1, Decl(typeGuardFunction.ts, 53, 10)) >C : Symbol(C, Decl(typeGuardFunction.ts, 7, 1)) } class D { @@ -136,6 +142,7 @@ class D { >method1 : Symbol(method1, Decl(typeGuardFunction.ts, 55, 9)) >p1 : Symbol(p1, Decl(typeGuardFunction.ts, 56, 12)) >A : Symbol(A, Decl(typeGuardFunction.ts, 0, 0)) +>p1 : Symbol(p1, Decl(typeGuardFunction.ts, 56, 12)) >C : Symbol(C, Decl(typeGuardFunction.ts, 7, 1)) return true; @@ -147,6 +154,7 @@ let f1 = (p1: A): p1 is C => false; >f1 : Symbol(f1, Decl(typeGuardFunction.ts, 62, 3)) >p1 : Symbol(p1, Decl(typeGuardFunction.ts, 62, 10)) >A : Symbol(A, Decl(typeGuardFunction.ts, 0, 0)) +>p1 : Symbol(p1, Decl(typeGuardFunction.ts, 62, 10)) >C : Symbol(C, Decl(typeGuardFunction.ts, 7, 1)) // Function type @@ -155,6 +163,7 @@ declare function f2(p1: (p1: A) => p1 is C); >p1 : Symbol(p1, Decl(typeGuardFunction.ts, 65, 20)) >p1 : Symbol(p1, Decl(typeGuardFunction.ts, 65, 25)) >A : Symbol(A, Decl(typeGuardFunction.ts, 0, 0)) +>p1 : Symbol(p1, Decl(typeGuardFunction.ts, 65, 25)) >C : Symbol(C, Decl(typeGuardFunction.ts, 7, 1)) // Function expressions @@ -162,6 +171,7 @@ f2(function(p1: A): p1 is C { >f2 : Symbol(f2, Decl(typeGuardFunction.ts, 62, 35)) >p1 : Symbol(p1, Decl(typeGuardFunction.ts, 68, 12)) >A : Symbol(A, Decl(typeGuardFunction.ts, 0, 0)) +>p1 : Symbol(p1, Decl(typeGuardFunction.ts, 68, 12)) >C : Symbol(C, Decl(typeGuardFunction.ts, 7, 1)) return true; @@ -182,6 +192,7 @@ declare function acceptingTypeGuardFunction(p1: (item) => item is A); >acceptingTypeGuardFunction : Symbol(acceptingTypeGuardFunction, Decl(typeGuardFunction.ts, 74, 25)) >p1 : Symbol(p1, Decl(typeGuardFunction.ts, 77, 44)) >item : Symbol(item, Decl(typeGuardFunction.ts, 77, 49)) +>item : Symbol(item, Decl(typeGuardFunction.ts, 77, 49)) >A : Symbol(A, Decl(typeGuardFunction.ts, 0, 0)) acceptingTypeGuardFunction(isA); diff --git a/tests/baselines/reference/typeGuardFunctionGenerics.symbols b/tests/baselines/reference/typeGuardFunctionGenerics.symbols index 0ad8fab2fdb..100d610070d 100644 --- a/tests/baselines/reference/typeGuardFunctionGenerics.symbols +++ b/tests/baselines/reference/typeGuardFunctionGenerics.symbols @@ -25,11 +25,13 @@ class C extends A { declare function isB(p1): p1 is B; >isB : Symbol(isB, Decl(typeGuardFunctionGenerics.ts, 11, 1)) >p1 : Symbol(p1, Decl(typeGuardFunctionGenerics.ts, 13, 21)) +>p1 : Symbol(p1, Decl(typeGuardFunctionGenerics.ts, 13, 21)) >B : Symbol(B, Decl(typeGuardFunctionGenerics.ts, 3, 1)) declare function isC(p1): p1 is C; >isC : Symbol(isC, Decl(typeGuardFunctionGenerics.ts, 13, 34)) >p1 : Symbol(p1, Decl(typeGuardFunctionGenerics.ts, 14, 21)) +>p1 : Symbol(p1, Decl(typeGuardFunctionGenerics.ts, 14, 21)) >C : Symbol(C, Decl(typeGuardFunctionGenerics.ts, 7, 1)) declare function retC(x): C; @@ -52,6 +54,7 @@ declare function funB(p1: (p1) => T, p2: any): p2 is T; >p1 : Symbol(p1, Decl(typeGuardFunctionGenerics.ts, 18, 30)) >T : Symbol(T, Decl(typeGuardFunctionGenerics.ts, 18, 22)) >p2 : Symbol(p2, Decl(typeGuardFunctionGenerics.ts, 18, 39)) +>p2 : Symbol(p2, Decl(typeGuardFunctionGenerics.ts, 18, 39)) >T : Symbol(T, Decl(typeGuardFunctionGenerics.ts, 18, 22)) declare function funC(p1: (p1) => p1 is T): T; @@ -59,6 +62,7 @@ declare function funC(p1: (p1) => p1 is T): T; >T : Symbol(T, Decl(typeGuardFunctionGenerics.ts, 19, 22)) >p1 : Symbol(p1, Decl(typeGuardFunctionGenerics.ts, 19, 25)) >p1 : Symbol(p1, Decl(typeGuardFunctionGenerics.ts, 19, 30)) +>p1 : Symbol(p1, Decl(typeGuardFunctionGenerics.ts, 19, 30)) >T : Symbol(T, Decl(typeGuardFunctionGenerics.ts, 19, 22)) >T : Symbol(T, Decl(typeGuardFunctionGenerics.ts, 19, 22)) @@ -67,8 +71,10 @@ declare function funD(p1: (p1) => p1 is T, p2: any): p2 is T; >T : Symbol(T, Decl(typeGuardFunctionGenerics.ts, 20, 22)) >p1 : Symbol(p1, Decl(typeGuardFunctionGenerics.ts, 20, 25)) >p1 : Symbol(p1, Decl(typeGuardFunctionGenerics.ts, 20, 30)) +>p1 : Symbol(p1, Decl(typeGuardFunctionGenerics.ts, 20, 30)) >T : Symbol(T, Decl(typeGuardFunctionGenerics.ts, 20, 22)) >p2 : Symbol(p2, Decl(typeGuardFunctionGenerics.ts, 20, 45)) +>p2 : Symbol(p2, Decl(typeGuardFunctionGenerics.ts, 20, 45)) >T : Symbol(T, Decl(typeGuardFunctionGenerics.ts, 20, 22)) declare function funE(p1: (p1) => p1 is T, p2: U): T; @@ -77,6 +83,7 @@ declare function funE(p1: (p1) => p1 is T, p2: U): T; >U : Symbol(U, Decl(typeGuardFunctionGenerics.ts, 21, 24)) >p1 : Symbol(p1, Decl(typeGuardFunctionGenerics.ts, 21, 28)) >p1 : Symbol(p1, Decl(typeGuardFunctionGenerics.ts, 21, 33)) +>p1 : Symbol(p1, Decl(typeGuardFunctionGenerics.ts, 21, 33)) >T : Symbol(T, Decl(typeGuardFunctionGenerics.ts, 21, 22)) >p2 : Symbol(p2, Decl(typeGuardFunctionGenerics.ts, 21, 48)) >U : Symbol(U, Decl(typeGuardFunctionGenerics.ts, 21, 24)) diff --git a/tests/baselines/reference/typeGuardOfFormIsType.symbols b/tests/baselines/reference/typeGuardOfFormIsType.symbols index a7bd0f4c165..e7e8965673d 100644 --- a/tests/baselines/reference/typeGuardOfFormIsType.symbols +++ b/tests/baselines/reference/typeGuardOfFormIsType.symbols @@ -31,6 +31,7 @@ var strOrNum: string | number; function isC1(x: any): x is C1 { >isC1 : Symbol(isC1, Decl(typeGuardOfFormIsType.ts, 12, 30)) >x : Symbol(x, Decl(typeGuardOfFormIsType.ts, 14, 14)) +>x : Symbol(x, Decl(typeGuardOfFormIsType.ts, 14, 14)) >C1 : Symbol(C1, Decl(typeGuardOfFormIsType.ts, 0, 0)) return true; @@ -39,6 +40,7 @@ function isC1(x: any): x is C1 { function isC2(x: any): x is C2 { >isC2 : Symbol(isC2, Decl(typeGuardOfFormIsType.ts, 16, 1)) >x : Symbol(x, Decl(typeGuardOfFormIsType.ts, 18, 14)) +>x : Symbol(x, Decl(typeGuardOfFormIsType.ts, 18, 14)) >C2 : Symbol(C2, Decl(typeGuardOfFormIsType.ts, 3, 1)) return true; @@ -47,6 +49,7 @@ function isC2(x: any): x is C2 { function isD1(x: any): x is D1 { >isD1 : Symbol(isD1, Decl(typeGuardOfFormIsType.ts, 20, 1)) >x : Symbol(x, Decl(typeGuardOfFormIsType.ts, 22, 14)) +>x : Symbol(x, Decl(typeGuardOfFormIsType.ts, 22, 14)) >D1 : Symbol(D1, Decl(typeGuardOfFormIsType.ts, 6, 1)) return true; diff --git a/tests/baselines/reference/typeGuardOfFormIsTypeOnInterfaces.symbols b/tests/baselines/reference/typeGuardOfFormIsTypeOnInterfaces.symbols index 37249ef7659..641d20d95cd 100644 --- a/tests/baselines/reference/typeGuardOfFormIsTypeOnInterfaces.symbols +++ b/tests/baselines/reference/typeGuardOfFormIsTypeOnInterfaces.symbols @@ -50,6 +50,7 @@ var strOrNum: string | number; function isC1(x: any): x is C1 { >isC1 : Symbol(isC1, Decl(typeGuardOfFormIsTypeOnInterfaces.ts, 17, 30)) >x : Symbol(x, Decl(typeGuardOfFormIsTypeOnInterfaces.ts, 20, 14)) +>x : Symbol(x, Decl(typeGuardOfFormIsTypeOnInterfaces.ts, 20, 14)) >C1 : Symbol(C1, Decl(typeGuardOfFormIsTypeOnInterfaces.ts, 0, 0)) return true; @@ -58,6 +59,7 @@ function isC1(x: any): x is C1 { function isC2(x: any): x is C2 { >isC2 : Symbol(isC2, Decl(typeGuardOfFormIsTypeOnInterfaces.ts, 22, 1)) >x : Symbol(x, Decl(typeGuardOfFormIsTypeOnInterfaces.ts, 24, 14)) +>x : Symbol(x, Decl(typeGuardOfFormIsTypeOnInterfaces.ts, 24, 14)) >C2 : Symbol(C2, Decl(typeGuardOfFormIsTypeOnInterfaces.ts, 5, 1)) return true; @@ -66,6 +68,7 @@ function isC2(x: any): x is C2 { function isD1(x: any): x is D1 { >isD1 : Symbol(isD1, Decl(typeGuardOfFormIsTypeOnInterfaces.ts, 26, 1)) >x : Symbol(x, Decl(typeGuardOfFormIsTypeOnInterfaces.ts, 28, 14)) +>x : Symbol(x, Decl(typeGuardOfFormIsTypeOnInterfaces.ts, 28, 14)) >D1 : Symbol(D1, Decl(typeGuardOfFormIsTypeOnInterfaces.ts, 10, 1)) return true; diff --git a/tests/baselines/reference/typedArrays.symbols b/tests/baselines/reference/typedArrays.symbols index 4ea9d0283a9..a6b8cb52a86 100644 --- a/tests/baselines/reference/typedArrays.symbols +++ b/tests/baselines/reference/typedArrays.symbols @@ -8,39 +8,39 @@ function CreateTypedArrayTypes() { typedArrays[0] = Int8Array; >typedArrays : Symbol(typedArrays, Decl(typedArrays.ts, 2, 7)) ->Int8Array : Symbol(Int8Array, Decl(lib.d.ts, 2104, 42), Decl(lib.d.ts, 2394, 11)) +>Int8Array : Symbol(Int8Array, Decl(lib.d.ts, 2108, 42), Decl(lib.d.ts, 2398, 11)) typedArrays[1] = Uint8Array; >typedArrays : Symbol(typedArrays, Decl(typedArrays.ts, 2, 7)) ->Uint8Array : Symbol(Uint8Array, Decl(lib.d.ts, 2394, 44), Decl(lib.d.ts, 2684, 11)) +>Uint8Array : Symbol(Uint8Array, Decl(lib.d.ts, 2398, 44), Decl(lib.d.ts, 2688, 11)) typedArrays[2] = Int16Array; >typedArrays : Symbol(typedArrays, Decl(typedArrays.ts, 2, 7)) ->Int16Array : Symbol(Int16Array, Decl(lib.d.ts, 2974, 60), Decl(lib.d.ts, 3264, 11)) +>Int16Array : Symbol(Int16Array, Decl(lib.d.ts, 2978, 60), Decl(lib.d.ts, 3268, 11)) typedArrays[3] = Uint16Array; >typedArrays : Symbol(typedArrays, Decl(typedArrays.ts, 2, 7)) ->Uint16Array : Symbol(Uint16Array, Decl(lib.d.ts, 3264, 46), Decl(lib.d.ts, 3554, 11)) +>Uint16Array : Symbol(Uint16Array, Decl(lib.d.ts, 3268, 46), Decl(lib.d.ts, 3558, 11)) typedArrays[4] = Int32Array; >typedArrays : Symbol(typedArrays, Decl(typedArrays.ts, 2, 7)) ->Int32Array : Symbol(Int32Array, Decl(lib.d.ts, 3554, 48), Decl(lib.d.ts, 3844, 11)) +>Int32Array : Symbol(Int32Array, Decl(lib.d.ts, 3558, 48), Decl(lib.d.ts, 3848, 11)) typedArrays[5] = Uint32Array; >typedArrays : Symbol(typedArrays, Decl(typedArrays.ts, 2, 7)) ->Uint32Array : Symbol(Uint32Array, Decl(lib.d.ts, 3844, 46), Decl(lib.d.ts, 4134, 11)) +>Uint32Array : Symbol(Uint32Array, Decl(lib.d.ts, 3848, 46), Decl(lib.d.ts, 4138, 11)) typedArrays[6] = Float32Array; >typedArrays : Symbol(typedArrays, Decl(typedArrays.ts, 2, 7)) ->Float32Array : Symbol(Float32Array, Decl(lib.d.ts, 4134, 48), Decl(lib.d.ts, 4424, 11)) +>Float32Array : Symbol(Float32Array, Decl(lib.d.ts, 4138, 48), Decl(lib.d.ts, 4428, 11)) typedArrays[7] = Float64Array; >typedArrays : Symbol(typedArrays, Decl(typedArrays.ts, 2, 7)) ->Float64Array : Symbol(Float64Array, Decl(lib.d.ts, 4424, 50), Decl(lib.d.ts, 4714, 11)) +>Float64Array : Symbol(Float64Array, Decl(lib.d.ts, 4428, 50), Decl(lib.d.ts, 4718, 11)) typedArrays[8] = Uint8ClampedArray; >typedArrays : Symbol(typedArrays, Decl(typedArrays.ts, 2, 7)) ->Uint8ClampedArray : Symbol(Uint8ClampedArray, Decl(lib.d.ts, 2684, 46), Decl(lib.d.ts, 2974, 11)) +>Uint8ClampedArray : Symbol(Uint8ClampedArray, Decl(lib.d.ts, 2688, 46), Decl(lib.d.ts, 2978, 11)) return typedArrays; >typedArrays : Symbol(typedArrays, Decl(typedArrays.ts, 2, 7)) @@ -55,47 +55,47 @@ function CreateTypedArrayInstancesFromLength(obj: number) { typedArrays[0] = new Int8Array(obj); >typedArrays : Symbol(typedArrays, Decl(typedArrays.ts, 17, 7)) ->Int8Array : Symbol(Int8Array, Decl(lib.d.ts, 2104, 42), Decl(lib.d.ts, 2394, 11)) +>Int8Array : Symbol(Int8Array, Decl(lib.d.ts, 2108, 42), Decl(lib.d.ts, 2398, 11)) >obj : Symbol(obj, Decl(typedArrays.ts, 16, 45)) typedArrays[1] = new Uint8Array(obj); >typedArrays : Symbol(typedArrays, Decl(typedArrays.ts, 17, 7)) ->Uint8Array : Symbol(Uint8Array, Decl(lib.d.ts, 2394, 44), Decl(lib.d.ts, 2684, 11)) +>Uint8Array : Symbol(Uint8Array, Decl(lib.d.ts, 2398, 44), Decl(lib.d.ts, 2688, 11)) >obj : Symbol(obj, Decl(typedArrays.ts, 16, 45)) typedArrays[2] = new Int16Array(obj); >typedArrays : Symbol(typedArrays, Decl(typedArrays.ts, 17, 7)) ->Int16Array : Symbol(Int16Array, Decl(lib.d.ts, 2974, 60), Decl(lib.d.ts, 3264, 11)) +>Int16Array : Symbol(Int16Array, Decl(lib.d.ts, 2978, 60), Decl(lib.d.ts, 3268, 11)) >obj : Symbol(obj, Decl(typedArrays.ts, 16, 45)) typedArrays[3] = new Uint16Array(obj); >typedArrays : Symbol(typedArrays, Decl(typedArrays.ts, 17, 7)) ->Uint16Array : Symbol(Uint16Array, Decl(lib.d.ts, 3264, 46), Decl(lib.d.ts, 3554, 11)) +>Uint16Array : Symbol(Uint16Array, Decl(lib.d.ts, 3268, 46), Decl(lib.d.ts, 3558, 11)) >obj : Symbol(obj, Decl(typedArrays.ts, 16, 45)) typedArrays[4] = new Int32Array(obj); >typedArrays : Symbol(typedArrays, Decl(typedArrays.ts, 17, 7)) ->Int32Array : Symbol(Int32Array, Decl(lib.d.ts, 3554, 48), Decl(lib.d.ts, 3844, 11)) +>Int32Array : Symbol(Int32Array, Decl(lib.d.ts, 3558, 48), Decl(lib.d.ts, 3848, 11)) >obj : Symbol(obj, Decl(typedArrays.ts, 16, 45)) typedArrays[5] = new Uint32Array(obj); >typedArrays : Symbol(typedArrays, Decl(typedArrays.ts, 17, 7)) ->Uint32Array : Symbol(Uint32Array, Decl(lib.d.ts, 3844, 46), Decl(lib.d.ts, 4134, 11)) +>Uint32Array : Symbol(Uint32Array, Decl(lib.d.ts, 3848, 46), Decl(lib.d.ts, 4138, 11)) >obj : Symbol(obj, Decl(typedArrays.ts, 16, 45)) typedArrays[6] = new Float32Array(obj); >typedArrays : Symbol(typedArrays, Decl(typedArrays.ts, 17, 7)) ->Float32Array : Symbol(Float32Array, Decl(lib.d.ts, 4134, 48), Decl(lib.d.ts, 4424, 11)) +>Float32Array : Symbol(Float32Array, Decl(lib.d.ts, 4138, 48), Decl(lib.d.ts, 4428, 11)) >obj : Symbol(obj, Decl(typedArrays.ts, 16, 45)) typedArrays[7] = new Float64Array(obj); >typedArrays : Symbol(typedArrays, Decl(typedArrays.ts, 17, 7)) ->Float64Array : Symbol(Float64Array, Decl(lib.d.ts, 4424, 50), Decl(lib.d.ts, 4714, 11)) +>Float64Array : Symbol(Float64Array, Decl(lib.d.ts, 4428, 50), Decl(lib.d.ts, 4718, 11)) >obj : Symbol(obj, Decl(typedArrays.ts, 16, 45)) typedArrays[8] = new Uint8ClampedArray(obj); >typedArrays : Symbol(typedArrays, Decl(typedArrays.ts, 17, 7)) ->Uint8ClampedArray : Symbol(Uint8ClampedArray, Decl(lib.d.ts, 2684, 46), Decl(lib.d.ts, 2974, 11)) +>Uint8ClampedArray : Symbol(Uint8ClampedArray, Decl(lib.d.ts, 2688, 46), Decl(lib.d.ts, 2978, 11)) >obj : Symbol(obj, Decl(typedArrays.ts, 16, 45)) return typedArrays; @@ -111,47 +111,47 @@ function CreateTypedArrayInstancesFromArray(obj: number[]) { typedArrays[0] = new Int8Array(obj); >typedArrays : Symbol(typedArrays, Decl(typedArrays.ts, 32, 7)) ->Int8Array : Symbol(Int8Array, Decl(lib.d.ts, 2104, 42), Decl(lib.d.ts, 2394, 11)) +>Int8Array : Symbol(Int8Array, Decl(lib.d.ts, 2108, 42), Decl(lib.d.ts, 2398, 11)) >obj : Symbol(obj, Decl(typedArrays.ts, 31, 44)) typedArrays[1] = new Uint8Array(obj); >typedArrays : Symbol(typedArrays, Decl(typedArrays.ts, 32, 7)) ->Uint8Array : Symbol(Uint8Array, Decl(lib.d.ts, 2394, 44), Decl(lib.d.ts, 2684, 11)) +>Uint8Array : Symbol(Uint8Array, Decl(lib.d.ts, 2398, 44), Decl(lib.d.ts, 2688, 11)) >obj : Symbol(obj, Decl(typedArrays.ts, 31, 44)) typedArrays[2] = new Int16Array(obj); >typedArrays : Symbol(typedArrays, Decl(typedArrays.ts, 32, 7)) ->Int16Array : Symbol(Int16Array, Decl(lib.d.ts, 2974, 60), Decl(lib.d.ts, 3264, 11)) +>Int16Array : Symbol(Int16Array, Decl(lib.d.ts, 2978, 60), Decl(lib.d.ts, 3268, 11)) >obj : Symbol(obj, Decl(typedArrays.ts, 31, 44)) typedArrays[3] = new Uint16Array(obj); >typedArrays : Symbol(typedArrays, Decl(typedArrays.ts, 32, 7)) ->Uint16Array : Symbol(Uint16Array, Decl(lib.d.ts, 3264, 46), Decl(lib.d.ts, 3554, 11)) +>Uint16Array : Symbol(Uint16Array, Decl(lib.d.ts, 3268, 46), Decl(lib.d.ts, 3558, 11)) >obj : Symbol(obj, Decl(typedArrays.ts, 31, 44)) typedArrays[4] = new Int32Array(obj); >typedArrays : Symbol(typedArrays, Decl(typedArrays.ts, 32, 7)) ->Int32Array : Symbol(Int32Array, Decl(lib.d.ts, 3554, 48), Decl(lib.d.ts, 3844, 11)) +>Int32Array : Symbol(Int32Array, Decl(lib.d.ts, 3558, 48), Decl(lib.d.ts, 3848, 11)) >obj : Symbol(obj, Decl(typedArrays.ts, 31, 44)) typedArrays[5] = new Uint32Array(obj); >typedArrays : Symbol(typedArrays, Decl(typedArrays.ts, 32, 7)) ->Uint32Array : Symbol(Uint32Array, Decl(lib.d.ts, 3844, 46), Decl(lib.d.ts, 4134, 11)) +>Uint32Array : Symbol(Uint32Array, Decl(lib.d.ts, 3848, 46), Decl(lib.d.ts, 4138, 11)) >obj : Symbol(obj, Decl(typedArrays.ts, 31, 44)) typedArrays[6] = new Float32Array(obj); >typedArrays : Symbol(typedArrays, Decl(typedArrays.ts, 32, 7)) ->Float32Array : Symbol(Float32Array, Decl(lib.d.ts, 4134, 48), Decl(lib.d.ts, 4424, 11)) +>Float32Array : Symbol(Float32Array, Decl(lib.d.ts, 4138, 48), Decl(lib.d.ts, 4428, 11)) >obj : Symbol(obj, Decl(typedArrays.ts, 31, 44)) typedArrays[7] = new Float64Array(obj); >typedArrays : Symbol(typedArrays, Decl(typedArrays.ts, 32, 7)) ->Float64Array : Symbol(Float64Array, Decl(lib.d.ts, 4424, 50), Decl(lib.d.ts, 4714, 11)) +>Float64Array : Symbol(Float64Array, Decl(lib.d.ts, 4428, 50), Decl(lib.d.ts, 4718, 11)) >obj : Symbol(obj, Decl(typedArrays.ts, 31, 44)) typedArrays[8] = new Uint8ClampedArray(obj); >typedArrays : Symbol(typedArrays, Decl(typedArrays.ts, 32, 7)) ->Uint8ClampedArray : Symbol(Uint8ClampedArray, Decl(lib.d.ts, 2684, 46), Decl(lib.d.ts, 2974, 11)) +>Uint8ClampedArray : Symbol(Uint8ClampedArray, Decl(lib.d.ts, 2688, 46), Decl(lib.d.ts, 2978, 11)) >obj : Symbol(obj, Decl(typedArrays.ts, 31, 44)) return typedArrays; @@ -167,65 +167,65 @@ function CreateIntegerTypedArraysFromArray2(obj:number[]) { typedArrays[0] = Int8Array.from(obj); >typedArrays : Symbol(typedArrays, Decl(typedArrays.ts, 47, 7)) ->Int8Array.from : Symbol(Int8ArrayConstructor.from, Decl(lib.d.ts, 2384, 38)) ->Int8Array : Symbol(Int8Array, Decl(lib.d.ts, 2104, 42), Decl(lib.d.ts, 2394, 11)) ->from : Symbol(Int8ArrayConstructor.from, Decl(lib.d.ts, 2384, 38)) +>Int8Array.from : Symbol(Int8ArrayConstructor.from, Decl(lib.d.ts, 2388, 38)) +>Int8Array : Symbol(Int8Array, Decl(lib.d.ts, 2108, 42), Decl(lib.d.ts, 2398, 11)) +>from : Symbol(Int8ArrayConstructor.from, Decl(lib.d.ts, 2388, 38)) >obj : Symbol(obj, Decl(typedArrays.ts, 46, 44)) typedArrays[1] = Uint8Array.from(obj); >typedArrays : Symbol(typedArrays, Decl(typedArrays.ts, 47, 7)) ->Uint8Array.from : Symbol(Uint8ArrayConstructor.from, Decl(lib.d.ts, 2674, 39)) ->Uint8Array : Symbol(Uint8Array, Decl(lib.d.ts, 2394, 44), Decl(lib.d.ts, 2684, 11)) ->from : Symbol(Uint8ArrayConstructor.from, Decl(lib.d.ts, 2674, 39)) +>Uint8Array.from : Symbol(Uint8ArrayConstructor.from, Decl(lib.d.ts, 2678, 39)) +>Uint8Array : Symbol(Uint8Array, Decl(lib.d.ts, 2398, 44), Decl(lib.d.ts, 2688, 11)) +>from : Symbol(Uint8ArrayConstructor.from, Decl(lib.d.ts, 2678, 39)) >obj : Symbol(obj, Decl(typedArrays.ts, 46, 44)) typedArrays[2] = Int16Array.from(obj); >typedArrays : Symbol(typedArrays, Decl(typedArrays.ts, 47, 7)) ->Int16Array.from : Symbol(Int16ArrayConstructor.from, Decl(lib.d.ts, 3254, 39)) ->Int16Array : Symbol(Int16Array, Decl(lib.d.ts, 2974, 60), Decl(lib.d.ts, 3264, 11)) ->from : Symbol(Int16ArrayConstructor.from, Decl(lib.d.ts, 3254, 39)) +>Int16Array.from : Symbol(Int16ArrayConstructor.from, Decl(lib.d.ts, 3258, 39)) +>Int16Array : Symbol(Int16Array, Decl(lib.d.ts, 2978, 60), Decl(lib.d.ts, 3268, 11)) +>from : Symbol(Int16ArrayConstructor.from, Decl(lib.d.ts, 3258, 39)) >obj : Symbol(obj, Decl(typedArrays.ts, 46, 44)) typedArrays[3] = Uint16Array.from(obj); >typedArrays : Symbol(typedArrays, Decl(typedArrays.ts, 47, 7)) ->Uint16Array.from : Symbol(Uint16ArrayConstructor.from, Decl(lib.d.ts, 3544, 40)) ->Uint16Array : Symbol(Uint16Array, Decl(lib.d.ts, 3264, 46), Decl(lib.d.ts, 3554, 11)) ->from : Symbol(Uint16ArrayConstructor.from, Decl(lib.d.ts, 3544, 40)) +>Uint16Array.from : Symbol(Uint16ArrayConstructor.from, Decl(lib.d.ts, 3548, 40)) +>Uint16Array : Symbol(Uint16Array, Decl(lib.d.ts, 3268, 46), Decl(lib.d.ts, 3558, 11)) +>from : Symbol(Uint16ArrayConstructor.from, Decl(lib.d.ts, 3548, 40)) >obj : Symbol(obj, Decl(typedArrays.ts, 46, 44)) typedArrays[4] = Int32Array.from(obj); >typedArrays : Symbol(typedArrays, Decl(typedArrays.ts, 47, 7)) ->Int32Array.from : Symbol(Int32ArrayConstructor.from, Decl(lib.d.ts, 3834, 39)) ->Int32Array : Symbol(Int32Array, Decl(lib.d.ts, 3554, 48), Decl(lib.d.ts, 3844, 11)) ->from : Symbol(Int32ArrayConstructor.from, Decl(lib.d.ts, 3834, 39)) +>Int32Array.from : Symbol(Int32ArrayConstructor.from, Decl(lib.d.ts, 3838, 39)) +>Int32Array : Symbol(Int32Array, Decl(lib.d.ts, 3558, 48), Decl(lib.d.ts, 3848, 11)) +>from : Symbol(Int32ArrayConstructor.from, Decl(lib.d.ts, 3838, 39)) >obj : Symbol(obj, Decl(typedArrays.ts, 46, 44)) typedArrays[5] = Uint32Array.from(obj); >typedArrays : Symbol(typedArrays, Decl(typedArrays.ts, 47, 7)) ->Uint32Array.from : Symbol(Uint32ArrayConstructor.from, Decl(lib.d.ts, 4124, 40)) ->Uint32Array : Symbol(Uint32Array, Decl(lib.d.ts, 3844, 46), Decl(lib.d.ts, 4134, 11)) ->from : Symbol(Uint32ArrayConstructor.from, Decl(lib.d.ts, 4124, 40)) +>Uint32Array.from : Symbol(Uint32ArrayConstructor.from, Decl(lib.d.ts, 4128, 40)) +>Uint32Array : Symbol(Uint32Array, Decl(lib.d.ts, 3848, 46), Decl(lib.d.ts, 4138, 11)) +>from : Symbol(Uint32ArrayConstructor.from, Decl(lib.d.ts, 4128, 40)) >obj : Symbol(obj, Decl(typedArrays.ts, 46, 44)) typedArrays[6] = Float32Array.from(obj); >typedArrays : Symbol(typedArrays, Decl(typedArrays.ts, 47, 7)) ->Float32Array.from : Symbol(Float32ArrayConstructor.from, Decl(lib.d.ts, 4414, 41)) ->Float32Array : Symbol(Float32Array, Decl(lib.d.ts, 4134, 48), Decl(lib.d.ts, 4424, 11)) ->from : Symbol(Float32ArrayConstructor.from, Decl(lib.d.ts, 4414, 41)) +>Float32Array.from : Symbol(Float32ArrayConstructor.from, Decl(lib.d.ts, 4418, 41)) +>Float32Array : Symbol(Float32Array, Decl(lib.d.ts, 4138, 48), Decl(lib.d.ts, 4428, 11)) +>from : Symbol(Float32ArrayConstructor.from, Decl(lib.d.ts, 4418, 41)) >obj : Symbol(obj, Decl(typedArrays.ts, 46, 44)) typedArrays[7] = Float64Array.from(obj); >typedArrays : Symbol(typedArrays, Decl(typedArrays.ts, 47, 7)) ->Float64Array.from : Symbol(Float64ArrayConstructor.from, Decl(lib.d.ts, 4704, 41)) ->Float64Array : Symbol(Float64Array, Decl(lib.d.ts, 4424, 50), Decl(lib.d.ts, 4714, 11)) ->from : Symbol(Float64ArrayConstructor.from, Decl(lib.d.ts, 4704, 41)) +>Float64Array.from : Symbol(Float64ArrayConstructor.from, Decl(lib.d.ts, 4708, 41)) +>Float64Array : Symbol(Float64Array, Decl(lib.d.ts, 4428, 50), Decl(lib.d.ts, 4718, 11)) +>from : Symbol(Float64ArrayConstructor.from, Decl(lib.d.ts, 4708, 41)) >obj : Symbol(obj, Decl(typedArrays.ts, 46, 44)) typedArrays[8] = Uint8ClampedArray.from(obj); >typedArrays : Symbol(typedArrays, Decl(typedArrays.ts, 47, 7)) ->Uint8ClampedArray.from : Symbol(Uint8ClampedArrayConstructor.from, Decl(lib.d.ts, 2964, 46)) ->Uint8ClampedArray : Symbol(Uint8ClampedArray, Decl(lib.d.ts, 2684, 46), Decl(lib.d.ts, 2974, 11)) ->from : Symbol(Uint8ClampedArrayConstructor.from, Decl(lib.d.ts, 2964, 46)) +>Uint8ClampedArray.from : Symbol(Uint8ClampedArrayConstructor.from, Decl(lib.d.ts, 2968, 46)) +>Uint8ClampedArray : Symbol(Uint8ClampedArray, Decl(lib.d.ts, 2688, 46), Decl(lib.d.ts, 2978, 11)) +>from : Symbol(Uint8ClampedArrayConstructor.from, Decl(lib.d.ts, 2968, 46)) >obj : Symbol(obj, Decl(typedArrays.ts, 46, 44)) return typedArrays; @@ -242,65 +242,65 @@ function CreateIntegerTypedArraysFromArrayLike(obj:ArrayLike) { typedArrays[0] = Int8Array.from(obj); >typedArrays : Symbol(typedArrays, Decl(typedArrays.ts, 62, 7)) ->Int8Array.from : Symbol(Int8ArrayConstructor.from, Decl(lib.d.ts, 2384, 38)) ->Int8Array : Symbol(Int8Array, Decl(lib.d.ts, 2104, 42), Decl(lib.d.ts, 2394, 11)) ->from : Symbol(Int8ArrayConstructor.from, Decl(lib.d.ts, 2384, 38)) +>Int8Array.from : Symbol(Int8ArrayConstructor.from, Decl(lib.d.ts, 2388, 38)) +>Int8Array : Symbol(Int8Array, Decl(lib.d.ts, 2108, 42), Decl(lib.d.ts, 2398, 11)) +>from : Symbol(Int8ArrayConstructor.from, Decl(lib.d.ts, 2388, 38)) >obj : Symbol(obj, Decl(typedArrays.ts, 61, 47)) typedArrays[1] = Uint8Array.from(obj); >typedArrays : Symbol(typedArrays, Decl(typedArrays.ts, 62, 7)) ->Uint8Array.from : Symbol(Uint8ArrayConstructor.from, Decl(lib.d.ts, 2674, 39)) ->Uint8Array : Symbol(Uint8Array, Decl(lib.d.ts, 2394, 44), Decl(lib.d.ts, 2684, 11)) ->from : Symbol(Uint8ArrayConstructor.from, Decl(lib.d.ts, 2674, 39)) +>Uint8Array.from : Symbol(Uint8ArrayConstructor.from, Decl(lib.d.ts, 2678, 39)) +>Uint8Array : Symbol(Uint8Array, Decl(lib.d.ts, 2398, 44), Decl(lib.d.ts, 2688, 11)) +>from : Symbol(Uint8ArrayConstructor.from, Decl(lib.d.ts, 2678, 39)) >obj : Symbol(obj, Decl(typedArrays.ts, 61, 47)) typedArrays[2] = Int16Array.from(obj); >typedArrays : Symbol(typedArrays, Decl(typedArrays.ts, 62, 7)) ->Int16Array.from : Symbol(Int16ArrayConstructor.from, Decl(lib.d.ts, 3254, 39)) ->Int16Array : Symbol(Int16Array, Decl(lib.d.ts, 2974, 60), Decl(lib.d.ts, 3264, 11)) ->from : Symbol(Int16ArrayConstructor.from, Decl(lib.d.ts, 3254, 39)) +>Int16Array.from : Symbol(Int16ArrayConstructor.from, Decl(lib.d.ts, 3258, 39)) +>Int16Array : Symbol(Int16Array, Decl(lib.d.ts, 2978, 60), Decl(lib.d.ts, 3268, 11)) +>from : Symbol(Int16ArrayConstructor.from, Decl(lib.d.ts, 3258, 39)) >obj : Symbol(obj, Decl(typedArrays.ts, 61, 47)) typedArrays[3] = Uint16Array.from(obj); >typedArrays : Symbol(typedArrays, Decl(typedArrays.ts, 62, 7)) ->Uint16Array.from : Symbol(Uint16ArrayConstructor.from, Decl(lib.d.ts, 3544, 40)) ->Uint16Array : Symbol(Uint16Array, Decl(lib.d.ts, 3264, 46), Decl(lib.d.ts, 3554, 11)) ->from : Symbol(Uint16ArrayConstructor.from, Decl(lib.d.ts, 3544, 40)) +>Uint16Array.from : Symbol(Uint16ArrayConstructor.from, Decl(lib.d.ts, 3548, 40)) +>Uint16Array : Symbol(Uint16Array, Decl(lib.d.ts, 3268, 46), Decl(lib.d.ts, 3558, 11)) +>from : Symbol(Uint16ArrayConstructor.from, Decl(lib.d.ts, 3548, 40)) >obj : Symbol(obj, Decl(typedArrays.ts, 61, 47)) typedArrays[4] = Int32Array.from(obj); >typedArrays : Symbol(typedArrays, Decl(typedArrays.ts, 62, 7)) ->Int32Array.from : Symbol(Int32ArrayConstructor.from, Decl(lib.d.ts, 3834, 39)) ->Int32Array : Symbol(Int32Array, Decl(lib.d.ts, 3554, 48), Decl(lib.d.ts, 3844, 11)) ->from : Symbol(Int32ArrayConstructor.from, Decl(lib.d.ts, 3834, 39)) +>Int32Array.from : Symbol(Int32ArrayConstructor.from, Decl(lib.d.ts, 3838, 39)) +>Int32Array : Symbol(Int32Array, Decl(lib.d.ts, 3558, 48), Decl(lib.d.ts, 3848, 11)) +>from : Symbol(Int32ArrayConstructor.from, Decl(lib.d.ts, 3838, 39)) >obj : Symbol(obj, Decl(typedArrays.ts, 61, 47)) typedArrays[5] = Uint32Array.from(obj); >typedArrays : Symbol(typedArrays, Decl(typedArrays.ts, 62, 7)) ->Uint32Array.from : Symbol(Uint32ArrayConstructor.from, Decl(lib.d.ts, 4124, 40)) ->Uint32Array : Symbol(Uint32Array, Decl(lib.d.ts, 3844, 46), Decl(lib.d.ts, 4134, 11)) ->from : Symbol(Uint32ArrayConstructor.from, Decl(lib.d.ts, 4124, 40)) +>Uint32Array.from : Symbol(Uint32ArrayConstructor.from, Decl(lib.d.ts, 4128, 40)) +>Uint32Array : Symbol(Uint32Array, Decl(lib.d.ts, 3848, 46), Decl(lib.d.ts, 4138, 11)) +>from : Symbol(Uint32ArrayConstructor.from, Decl(lib.d.ts, 4128, 40)) >obj : Symbol(obj, Decl(typedArrays.ts, 61, 47)) typedArrays[6] = Float32Array.from(obj); >typedArrays : Symbol(typedArrays, Decl(typedArrays.ts, 62, 7)) ->Float32Array.from : Symbol(Float32ArrayConstructor.from, Decl(lib.d.ts, 4414, 41)) ->Float32Array : Symbol(Float32Array, Decl(lib.d.ts, 4134, 48), Decl(lib.d.ts, 4424, 11)) ->from : Symbol(Float32ArrayConstructor.from, Decl(lib.d.ts, 4414, 41)) +>Float32Array.from : Symbol(Float32ArrayConstructor.from, Decl(lib.d.ts, 4418, 41)) +>Float32Array : Symbol(Float32Array, Decl(lib.d.ts, 4138, 48), Decl(lib.d.ts, 4428, 11)) +>from : Symbol(Float32ArrayConstructor.from, Decl(lib.d.ts, 4418, 41)) >obj : Symbol(obj, Decl(typedArrays.ts, 61, 47)) typedArrays[7] = Float64Array.from(obj); >typedArrays : Symbol(typedArrays, Decl(typedArrays.ts, 62, 7)) ->Float64Array.from : Symbol(Float64ArrayConstructor.from, Decl(lib.d.ts, 4704, 41)) ->Float64Array : Symbol(Float64Array, Decl(lib.d.ts, 4424, 50), Decl(lib.d.ts, 4714, 11)) ->from : Symbol(Float64ArrayConstructor.from, Decl(lib.d.ts, 4704, 41)) +>Float64Array.from : Symbol(Float64ArrayConstructor.from, Decl(lib.d.ts, 4708, 41)) +>Float64Array : Symbol(Float64Array, Decl(lib.d.ts, 4428, 50), Decl(lib.d.ts, 4718, 11)) +>from : Symbol(Float64ArrayConstructor.from, Decl(lib.d.ts, 4708, 41)) >obj : Symbol(obj, Decl(typedArrays.ts, 61, 47)) typedArrays[8] = Uint8ClampedArray.from(obj); >typedArrays : Symbol(typedArrays, Decl(typedArrays.ts, 62, 7)) ->Uint8ClampedArray.from : Symbol(Uint8ClampedArrayConstructor.from, Decl(lib.d.ts, 2964, 46)) ->Uint8ClampedArray : Symbol(Uint8ClampedArray, Decl(lib.d.ts, 2684, 46), Decl(lib.d.ts, 2974, 11)) ->from : Symbol(Uint8ClampedArrayConstructor.from, Decl(lib.d.ts, 2964, 46)) +>Uint8ClampedArray.from : Symbol(Uint8ClampedArrayConstructor.from, Decl(lib.d.ts, 2968, 46)) +>Uint8ClampedArray : Symbol(Uint8ClampedArray, Decl(lib.d.ts, 2688, 46), Decl(lib.d.ts, 2978, 11)) +>from : Symbol(Uint8ClampedArrayConstructor.from, Decl(lib.d.ts, 2968, 46)) >obj : Symbol(obj, Decl(typedArrays.ts, 61, 47)) return typedArrays; @@ -332,57 +332,57 @@ function CreateTypedArraysOf2() { typedArrays[0] = Int8Array.of(1,2,3,4); >typedArrays : Symbol(typedArrays, Decl(typedArrays.ts, 94, 7)) ->Int8Array.of : Symbol(Int8ArrayConstructor.of, Decl(lib.d.ts, 2378, 30)) ->Int8Array : Symbol(Int8Array, Decl(lib.d.ts, 2104, 42), Decl(lib.d.ts, 2394, 11)) ->of : Symbol(Int8ArrayConstructor.of, Decl(lib.d.ts, 2378, 30)) +>Int8Array.of : Symbol(Int8ArrayConstructor.of, Decl(lib.d.ts, 2382, 30)) +>Int8Array : Symbol(Int8Array, Decl(lib.d.ts, 2108, 42), Decl(lib.d.ts, 2398, 11)) +>of : Symbol(Int8ArrayConstructor.of, Decl(lib.d.ts, 2382, 30)) typedArrays[1] = Uint8Array.of(1,2,3,4); >typedArrays : Symbol(typedArrays, Decl(typedArrays.ts, 94, 7)) ->Uint8Array.of : Symbol(Uint8ArrayConstructor.of, Decl(lib.d.ts, 2668, 30)) ->Uint8Array : Symbol(Uint8Array, Decl(lib.d.ts, 2394, 44), Decl(lib.d.ts, 2684, 11)) ->of : Symbol(Uint8ArrayConstructor.of, Decl(lib.d.ts, 2668, 30)) +>Uint8Array.of : Symbol(Uint8ArrayConstructor.of, Decl(lib.d.ts, 2672, 30)) +>Uint8Array : Symbol(Uint8Array, Decl(lib.d.ts, 2398, 44), Decl(lib.d.ts, 2688, 11)) +>of : Symbol(Uint8ArrayConstructor.of, Decl(lib.d.ts, 2672, 30)) typedArrays[2] = Int16Array.of(1,2,3,4); >typedArrays : Symbol(typedArrays, Decl(typedArrays.ts, 94, 7)) ->Int16Array.of : Symbol(Int16ArrayConstructor.of, Decl(lib.d.ts, 3248, 30)) ->Int16Array : Symbol(Int16Array, Decl(lib.d.ts, 2974, 60), Decl(lib.d.ts, 3264, 11)) ->of : Symbol(Int16ArrayConstructor.of, Decl(lib.d.ts, 3248, 30)) +>Int16Array.of : Symbol(Int16ArrayConstructor.of, Decl(lib.d.ts, 3252, 30)) +>Int16Array : Symbol(Int16Array, Decl(lib.d.ts, 2978, 60), Decl(lib.d.ts, 3268, 11)) +>of : Symbol(Int16ArrayConstructor.of, Decl(lib.d.ts, 3252, 30)) typedArrays[3] = Uint16Array.of(1,2,3,4); >typedArrays : Symbol(typedArrays, Decl(typedArrays.ts, 94, 7)) ->Uint16Array.of : Symbol(Uint16ArrayConstructor.of, Decl(lib.d.ts, 3538, 30)) ->Uint16Array : Symbol(Uint16Array, Decl(lib.d.ts, 3264, 46), Decl(lib.d.ts, 3554, 11)) ->of : Symbol(Uint16ArrayConstructor.of, Decl(lib.d.ts, 3538, 30)) +>Uint16Array.of : Symbol(Uint16ArrayConstructor.of, Decl(lib.d.ts, 3542, 30)) +>Uint16Array : Symbol(Uint16Array, Decl(lib.d.ts, 3268, 46), Decl(lib.d.ts, 3558, 11)) +>of : Symbol(Uint16ArrayConstructor.of, Decl(lib.d.ts, 3542, 30)) typedArrays[4] = Int32Array.of(1,2,3,4); >typedArrays : Symbol(typedArrays, Decl(typedArrays.ts, 94, 7)) ->Int32Array.of : Symbol(Int32ArrayConstructor.of, Decl(lib.d.ts, 3828, 30)) ->Int32Array : Symbol(Int32Array, Decl(lib.d.ts, 3554, 48), Decl(lib.d.ts, 3844, 11)) ->of : Symbol(Int32ArrayConstructor.of, Decl(lib.d.ts, 3828, 30)) +>Int32Array.of : Symbol(Int32ArrayConstructor.of, Decl(lib.d.ts, 3832, 30)) +>Int32Array : Symbol(Int32Array, Decl(lib.d.ts, 3558, 48), Decl(lib.d.ts, 3848, 11)) +>of : Symbol(Int32ArrayConstructor.of, Decl(lib.d.ts, 3832, 30)) typedArrays[5] = Uint32Array.of(1,2,3,4); >typedArrays : Symbol(typedArrays, Decl(typedArrays.ts, 94, 7)) ->Uint32Array.of : Symbol(Uint32ArrayConstructor.of, Decl(lib.d.ts, 4118, 30)) ->Uint32Array : Symbol(Uint32Array, Decl(lib.d.ts, 3844, 46), Decl(lib.d.ts, 4134, 11)) ->of : Symbol(Uint32ArrayConstructor.of, Decl(lib.d.ts, 4118, 30)) +>Uint32Array.of : Symbol(Uint32ArrayConstructor.of, Decl(lib.d.ts, 4122, 30)) +>Uint32Array : Symbol(Uint32Array, Decl(lib.d.ts, 3848, 46), Decl(lib.d.ts, 4138, 11)) +>of : Symbol(Uint32ArrayConstructor.of, Decl(lib.d.ts, 4122, 30)) typedArrays[6] = Float32Array.of(1,2,3,4); >typedArrays : Symbol(typedArrays, Decl(typedArrays.ts, 94, 7)) ->Float32Array.of : Symbol(Float32ArrayConstructor.of, Decl(lib.d.ts, 4408, 30)) ->Float32Array : Symbol(Float32Array, Decl(lib.d.ts, 4134, 48), Decl(lib.d.ts, 4424, 11)) ->of : Symbol(Float32ArrayConstructor.of, Decl(lib.d.ts, 4408, 30)) +>Float32Array.of : Symbol(Float32ArrayConstructor.of, Decl(lib.d.ts, 4412, 30)) +>Float32Array : Symbol(Float32Array, Decl(lib.d.ts, 4138, 48), Decl(lib.d.ts, 4428, 11)) +>of : Symbol(Float32ArrayConstructor.of, Decl(lib.d.ts, 4412, 30)) typedArrays[7] = Float64Array.of(1,2,3,4); >typedArrays : Symbol(typedArrays, Decl(typedArrays.ts, 94, 7)) ->Float64Array.of : Symbol(Float64ArrayConstructor.of, Decl(lib.d.ts, 4698, 30)) ->Float64Array : Symbol(Float64Array, Decl(lib.d.ts, 4424, 50), Decl(lib.d.ts, 4714, 11)) ->of : Symbol(Float64ArrayConstructor.of, Decl(lib.d.ts, 4698, 30)) +>Float64Array.of : Symbol(Float64ArrayConstructor.of, Decl(lib.d.ts, 4702, 30)) +>Float64Array : Symbol(Float64Array, Decl(lib.d.ts, 4428, 50), Decl(lib.d.ts, 4718, 11)) +>of : Symbol(Float64ArrayConstructor.of, Decl(lib.d.ts, 4702, 30)) typedArrays[8] = Uint8ClampedArray.of(1,2,3,4); >typedArrays : Symbol(typedArrays, Decl(typedArrays.ts, 94, 7)) ->Uint8ClampedArray.of : Symbol(Uint8ClampedArrayConstructor.of, Decl(lib.d.ts, 2958, 30)) ->Uint8ClampedArray : Symbol(Uint8ClampedArray, Decl(lib.d.ts, 2684, 46), Decl(lib.d.ts, 2974, 11)) ->of : Symbol(Uint8ClampedArrayConstructor.of, Decl(lib.d.ts, 2958, 30)) +>Uint8ClampedArray.of : Symbol(Uint8ClampedArrayConstructor.of, Decl(lib.d.ts, 2962, 30)) +>Uint8ClampedArray : Symbol(Uint8ClampedArray, Decl(lib.d.ts, 2688, 46), Decl(lib.d.ts, 2978, 11)) +>of : Symbol(Uint8ClampedArrayConstructor.of, Decl(lib.d.ts, 2962, 30)) return typedArrays; >typedArrays : Symbol(typedArrays, Decl(typedArrays.ts, 94, 7)) @@ -401,73 +401,73 @@ function CreateTypedArraysFromMapFn(obj:ArrayLike, mapFn: (n:number, v:n typedArrays[0] = Int8Array.from(obj, mapFn); >typedArrays : Symbol(typedArrays, Decl(typedArrays.ts, 109, 7)) ->Int8Array.from : Symbol(Int8ArrayConstructor.from, Decl(lib.d.ts, 2384, 38)) ->Int8Array : Symbol(Int8Array, Decl(lib.d.ts, 2104, 42), Decl(lib.d.ts, 2394, 11)) ->from : Symbol(Int8ArrayConstructor.from, Decl(lib.d.ts, 2384, 38)) +>Int8Array.from : Symbol(Int8ArrayConstructor.from, Decl(lib.d.ts, 2388, 38)) +>Int8Array : Symbol(Int8Array, Decl(lib.d.ts, 2108, 42), Decl(lib.d.ts, 2398, 11)) +>from : Symbol(Int8ArrayConstructor.from, Decl(lib.d.ts, 2388, 38)) >obj : Symbol(obj, Decl(typedArrays.ts, 108, 36)) >mapFn : Symbol(mapFn, Decl(typedArrays.ts, 108, 58)) typedArrays[1] = Uint8Array.from(obj, mapFn); >typedArrays : Symbol(typedArrays, Decl(typedArrays.ts, 109, 7)) ->Uint8Array.from : Symbol(Uint8ArrayConstructor.from, Decl(lib.d.ts, 2674, 39)) ->Uint8Array : Symbol(Uint8Array, Decl(lib.d.ts, 2394, 44), Decl(lib.d.ts, 2684, 11)) ->from : Symbol(Uint8ArrayConstructor.from, Decl(lib.d.ts, 2674, 39)) +>Uint8Array.from : Symbol(Uint8ArrayConstructor.from, Decl(lib.d.ts, 2678, 39)) +>Uint8Array : Symbol(Uint8Array, Decl(lib.d.ts, 2398, 44), Decl(lib.d.ts, 2688, 11)) +>from : Symbol(Uint8ArrayConstructor.from, Decl(lib.d.ts, 2678, 39)) >obj : Symbol(obj, Decl(typedArrays.ts, 108, 36)) >mapFn : Symbol(mapFn, Decl(typedArrays.ts, 108, 58)) typedArrays[2] = Int16Array.from(obj, mapFn); >typedArrays : Symbol(typedArrays, Decl(typedArrays.ts, 109, 7)) ->Int16Array.from : Symbol(Int16ArrayConstructor.from, Decl(lib.d.ts, 3254, 39)) ->Int16Array : Symbol(Int16Array, Decl(lib.d.ts, 2974, 60), Decl(lib.d.ts, 3264, 11)) ->from : Symbol(Int16ArrayConstructor.from, Decl(lib.d.ts, 3254, 39)) +>Int16Array.from : Symbol(Int16ArrayConstructor.from, Decl(lib.d.ts, 3258, 39)) +>Int16Array : Symbol(Int16Array, Decl(lib.d.ts, 2978, 60), Decl(lib.d.ts, 3268, 11)) +>from : Symbol(Int16ArrayConstructor.from, Decl(lib.d.ts, 3258, 39)) >obj : Symbol(obj, Decl(typedArrays.ts, 108, 36)) >mapFn : Symbol(mapFn, Decl(typedArrays.ts, 108, 58)) typedArrays[3] = Uint16Array.from(obj, mapFn); >typedArrays : Symbol(typedArrays, Decl(typedArrays.ts, 109, 7)) ->Uint16Array.from : Symbol(Uint16ArrayConstructor.from, Decl(lib.d.ts, 3544, 40)) ->Uint16Array : Symbol(Uint16Array, Decl(lib.d.ts, 3264, 46), Decl(lib.d.ts, 3554, 11)) ->from : Symbol(Uint16ArrayConstructor.from, Decl(lib.d.ts, 3544, 40)) +>Uint16Array.from : Symbol(Uint16ArrayConstructor.from, Decl(lib.d.ts, 3548, 40)) +>Uint16Array : Symbol(Uint16Array, Decl(lib.d.ts, 3268, 46), Decl(lib.d.ts, 3558, 11)) +>from : Symbol(Uint16ArrayConstructor.from, Decl(lib.d.ts, 3548, 40)) >obj : Symbol(obj, Decl(typedArrays.ts, 108, 36)) >mapFn : Symbol(mapFn, Decl(typedArrays.ts, 108, 58)) typedArrays[4] = Int32Array.from(obj, mapFn); >typedArrays : Symbol(typedArrays, Decl(typedArrays.ts, 109, 7)) ->Int32Array.from : Symbol(Int32ArrayConstructor.from, Decl(lib.d.ts, 3834, 39)) ->Int32Array : Symbol(Int32Array, Decl(lib.d.ts, 3554, 48), Decl(lib.d.ts, 3844, 11)) ->from : Symbol(Int32ArrayConstructor.from, Decl(lib.d.ts, 3834, 39)) +>Int32Array.from : Symbol(Int32ArrayConstructor.from, Decl(lib.d.ts, 3838, 39)) +>Int32Array : Symbol(Int32Array, Decl(lib.d.ts, 3558, 48), Decl(lib.d.ts, 3848, 11)) +>from : Symbol(Int32ArrayConstructor.from, Decl(lib.d.ts, 3838, 39)) >obj : Symbol(obj, Decl(typedArrays.ts, 108, 36)) >mapFn : Symbol(mapFn, Decl(typedArrays.ts, 108, 58)) typedArrays[5] = Uint32Array.from(obj, mapFn); >typedArrays : Symbol(typedArrays, Decl(typedArrays.ts, 109, 7)) ->Uint32Array.from : Symbol(Uint32ArrayConstructor.from, Decl(lib.d.ts, 4124, 40)) ->Uint32Array : Symbol(Uint32Array, Decl(lib.d.ts, 3844, 46), Decl(lib.d.ts, 4134, 11)) ->from : Symbol(Uint32ArrayConstructor.from, Decl(lib.d.ts, 4124, 40)) +>Uint32Array.from : Symbol(Uint32ArrayConstructor.from, Decl(lib.d.ts, 4128, 40)) +>Uint32Array : Symbol(Uint32Array, Decl(lib.d.ts, 3848, 46), Decl(lib.d.ts, 4138, 11)) +>from : Symbol(Uint32ArrayConstructor.from, Decl(lib.d.ts, 4128, 40)) >obj : Symbol(obj, Decl(typedArrays.ts, 108, 36)) >mapFn : Symbol(mapFn, Decl(typedArrays.ts, 108, 58)) typedArrays[6] = Float32Array.from(obj, mapFn); >typedArrays : Symbol(typedArrays, Decl(typedArrays.ts, 109, 7)) ->Float32Array.from : Symbol(Float32ArrayConstructor.from, Decl(lib.d.ts, 4414, 41)) ->Float32Array : Symbol(Float32Array, Decl(lib.d.ts, 4134, 48), Decl(lib.d.ts, 4424, 11)) ->from : Symbol(Float32ArrayConstructor.from, Decl(lib.d.ts, 4414, 41)) +>Float32Array.from : Symbol(Float32ArrayConstructor.from, Decl(lib.d.ts, 4418, 41)) +>Float32Array : Symbol(Float32Array, Decl(lib.d.ts, 4138, 48), Decl(lib.d.ts, 4428, 11)) +>from : Symbol(Float32ArrayConstructor.from, Decl(lib.d.ts, 4418, 41)) >obj : Symbol(obj, Decl(typedArrays.ts, 108, 36)) >mapFn : Symbol(mapFn, Decl(typedArrays.ts, 108, 58)) typedArrays[7] = Float64Array.from(obj, mapFn); >typedArrays : Symbol(typedArrays, Decl(typedArrays.ts, 109, 7)) ->Float64Array.from : Symbol(Float64ArrayConstructor.from, Decl(lib.d.ts, 4704, 41)) ->Float64Array : Symbol(Float64Array, Decl(lib.d.ts, 4424, 50), Decl(lib.d.ts, 4714, 11)) ->from : Symbol(Float64ArrayConstructor.from, Decl(lib.d.ts, 4704, 41)) +>Float64Array.from : Symbol(Float64ArrayConstructor.from, Decl(lib.d.ts, 4708, 41)) +>Float64Array : Symbol(Float64Array, Decl(lib.d.ts, 4428, 50), Decl(lib.d.ts, 4718, 11)) +>from : Symbol(Float64ArrayConstructor.from, Decl(lib.d.ts, 4708, 41)) >obj : Symbol(obj, Decl(typedArrays.ts, 108, 36)) >mapFn : Symbol(mapFn, Decl(typedArrays.ts, 108, 58)) typedArrays[8] = Uint8ClampedArray.from(obj, mapFn); >typedArrays : Symbol(typedArrays, Decl(typedArrays.ts, 109, 7)) ->Uint8ClampedArray.from : Symbol(Uint8ClampedArrayConstructor.from, Decl(lib.d.ts, 2964, 46)) ->Uint8ClampedArray : Symbol(Uint8ClampedArray, Decl(lib.d.ts, 2684, 46), Decl(lib.d.ts, 2974, 11)) ->from : Symbol(Uint8ClampedArrayConstructor.from, Decl(lib.d.ts, 2964, 46)) +>Uint8ClampedArray.from : Symbol(Uint8ClampedArrayConstructor.from, Decl(lib.d.ts, 2968, 46)) +>Uint8ClampedArray : Symbol(Uint8ClampedArray, Decl(lib.d.ts, 2688, 46), Decl(lib.d.ts, 2978, 11)) +>from : Symbol(Uint8ClampedArrayConstructor.from, Decl(lib.d.ts, 2968, 46)) >obj : Symbol(obj, Decl(typedArrays.ts, 108, 36)) >mapFn : Symbol(mapFn, Decl(typedArrays.ts, 108, 58)) @@ -489,81 +489,81 @@ function CreateTypedArraysFromThisObj(obj:ArrayLike, mapFn: (n:number, v typedArrays[0] = Int8Array.from(obj, mapFn, thisArg); >typedArrays : Symbol(typedArrays, Decl(typedArrays.ts, 124, 7)) ->Int8Array.from : Symbol(Int8ArrayConstructor.from, Decl(lib.d.ts, 2384, 38)) ->Int8Array : Symbol(Int8Array, Decl(lib.d.ts, 2104, 42), Decl(lib.d.ts, 2394, 11)) ->from : Symbol(Int8ArrayConstructor.from, Decl(lib.d.ts, 2384, 38)) +>Int8Array.from : Symbol(Int8ArrayConstructor.from, Decl(lib.d.ts, 2388, 38)) +>Int8Array : Symbol(Int8Array, Decl(lib.d.ts, 2108, 42), Decl(lib.d.ts, 2398, 11)) +>from : Symbol(Int8ArrayConstructor.from, Decl(lib.d.ts, 2388, 38)) >obj : Symbol(obj, Decl(typedArrays.ts, 123, 38)) >mapFn : Symbol(mapFn, Decl(typedArrays.ts, 123, 60)) >thisArg : Symbol(thisArg, Decl(typedArrays.ts, 123, 98)) typedArrays[1] = Uint8Array.from(obj, mapFn, thisArg); >typedArrays : Symbol(typedArrays, Decl(typedArrays.ts, 124, 7)) ->Uint8Array.from : Symbol(Uint8ArrayConstructor.from, Decl(lib.d.ts, 2674, 39)) ->Uint8Array : Symbol(Uint8Array, Decl(lib.d.ts, 2394, 44), Decl(lib.d.ts, 2684, 11)) ->from : Symbol(Uint8ArrayConstructor.from, Decl(lib.d.ts, 2674, 39)) +>Uint8Array.from : Symbol(Uint8ArrayConstructor.from, Decl(lib.d.ts, 2678, 39)) +>Uint8Array : Symbol(Uint8Array, Decl(lib.d.ts, 2398, 44), Decl(lib.d.ts, 2688, 11)) +>from : Symbol(Uint8ArrayConstructor.from, Decl(lib.d.ts, 2678, 39)) >obj : Symbol(obj, Decl(typedArrays.ts, 123, 38)) >mapFn : Symbol(mapFn, Decl(typedArrays.ts, 123, 60)) >thisArg : Symbol(thisArg, Decl(typedArrays.ts, 123, 98)) typedArrays[2] = Int16Array.from(obj, mapFn, thisArg); >typedArrays : Symbol(typedArrays, Decl(typedArrays.ts, 124, 7)) ->Int16Array.from : Symbol(Int16ArrayConstructor.from, Decl(lib.d.ts, 3254, 39)) ->Int16Array : Symbol(Int16Array, Decl(lib.d.ts, 2974, 60), Decl(lib.d.ts, 3264, 11)) ->from : Symbol(Int16ArrayConstructor.from, Decl(lib.d.ts, 3254, 39)) +>Int16Array.from : Symbol(Int16ArrayConstructor.from, Decl(lib.d.ts, 3258, 39)) +>Int16Array : Symbol(Int16Array, Decl(lib.d.ts, 2978, 60), Decl(lib.d.ts, 3268, 11)) +>from : Symbol(Int16ArrayConstructor.from, Decl(lib.d.ts, 3258, 39)) >obj : Symbol(obj, Decl(typedArrays.ts, 123, 38)) >mapFn : Symbol(mapFn, Decl(typedArrays.ts, 123, 60)) >thisArg : Symbol(thisArg, Decl(typedArrays.ts, 123, 98)) typedArrays[3] = Uint16Array.from(obj, mapFn, thisArg); >typedArrays : Symbol(typedArrays, Decl(typedArrays.ts, 124, 7)) ->Uint16Array.from : Symbol(Uint16ArrayConstructor.from, Decl(lib.d.ts, 3544, 40)) ->Uint16Array : Symbol(Uint16Array, Decl(lib.d.ts, 3264, 46), Decl(lib.d.ts, 3554, 11)) ->from : Symbol(Uint16ArrayConstructor.from, Decl(lib.d.ts, 3544, 40)) +>Uint16Array.from : Symbol(Uint16ArrayConstructor.from, Decl(lib.d.ts, 3548, 40)) +>Uint16Array : Symbol(Uint16Array, Decl(lib.d.ts, 3268, 46), Decl(lib.d.ts, 3558, 11)) +>from : Symbol(Uint16ArrayConstructor.from, Decl(lib.d.ts, 3548, 40)) >obj : Symbol(obj, Decl(typedArrays.ts, 123, 38)) >mapFn : Symbol(mapFn, Decl(typedArrays.ts, 123, 60)) >thisArg : Symbol(thisArg, Decl(typedArrays.ts, 123, 98)) typedArrays[4] = Int32Array.from(obj, mapFn, thisArg); >typedArrays : Symbol(typedArrays, Decl(typedArrays.ts, 124, 7)) ->Int32Array.from : Symbol(Int32ArrayConstructor.from, Decl(lib.d.ts, 3834, 39)) ->Int32Array : Symbol(Int32Array, Decl(lib.d.ts, 3554, 48), Decl(lib.d.ts, 3844, 11)) ->from : Symbol(Int32ArrayConstructor.from, Decl(lib.d.ts, 3834, 39)) +>Int32Array.from : Symbol(Int32ArrayConstructor.from, Decl(lib.d.ts, 3838, 39)) +>Int32Array : Symbol(Int32Array, Decl(lib.d.ts, 3558, 48), Decl(lib.d.ts, 3848, 11)) +>from : Symbol(Int32ArrayConstructor.from, Decl(lib.d.ts, 3838, 39)) >obj : Symbol(obj, Decl(typedArrays.ts, 123, 38)) >mapFn : Symbol(mapFn, Decl(typedArrays.ts, 123, 60)) >thisArg : Symbol(thisArg, Decl(typedArrays.ts, 123, 98)) typedArrays[5] = Uint32Array.from(obj, mapFn, thisArg); >typedArrays : Symbol(typedArrays, Decl(typedArrays.ts, 124, 7)) ->Uint32Array.from : Symbol(Uint32ArrayConstructor.from, Decl(lib.d.ts, 4124, 40)) ->Uint32Array : Symbol(Uint32Array, Decl(lib.d.ts, 3844, 46), Decl(lib.d.ts, 4134, 11)) ->from : Symbol(Uint32ArrayConstructor.from, Decl(lib.d.ts, 4124, 40)) +>Uint32Array.from : Symbol(Uint32ArrayConstructor.from, Decl(lib.d.ts, 4128, 40)) +>Uint32Array : Symbol(Uint32Array, Decl(lib.d.ts, 3848, 46), Decl(lib.d.ts, 4138, 11)) +>from : Symbol(Uint32ArrayConstructor.from, Decl(lib.d.ts, 4128, 40)) >obj : Symbol(obj, Decl(typedArrays.ts, 123, 38)) >mapFn : Symbol(mapFn, Decl(typedArrays.ts, 123, 60)) >thisArg : Symbol(thisArg, Decl(typedArrays.ts, 123, 98)) typedArrays[6] = Float32Array.from(obj, mapFn, thisArg); >typedArrays : Symbol(typedArrays, Decl(typedArrays.ts, 124, 7)) ->Float32Array.from : Symbol(Float32ArrayConstructor.from, Decl(lib.d.ts, 4414, 41)) ->Float32Array : Symbol(Float32Array, Decl(lib.d.ts, 4134, 48), Decl(lib.d.ts, 4424, 11)) ->from : Symbol(Float32ArrayConstructor.from, Decl(lib.d.ts, 4414, 41)) +>Float32Array.from : Symbol(Float32ArrayConstructor.from, Decl(lib.d.ts, 4418, 41)) +>Float32Array : Symbol(Float32Array, Decl(lib.d.ts, 4138, 48), Decl(lib.d.ts, 4428, 11)) +>from : Symbol(Float32ArrayConstructor.from, Decl(lib.d.ts, 4418, 41)) >obj : Symbol(obj, Decl(typedArrays.ts, 123, 38)) >mapFn : Symbol(mapFn, Decl(typedArrays.ts, 123, 60)) >thisArg : Symbol(thisArg, Decl(typedArrays.ts, 123, 98)) typedArrays[7] = Float64Array.from(obj, mapFn, thisArg); >typedArrays : Symbol(typedArrays, Decl(typedArrays.ts, 124, 7)) ->Float64Array.from : Symbol(Float64ArrayConstructor.from, Decl(lib.d.ts, 4704, 41)) ->Float64Array : Symbol(Float64Array, Decl(lib.d.ts, 4424, 50), Decl(lib.d.ts, 4714, 11)) ->from : Symbol(Float64ArrayConstructor.from, Decl(lib.d.ts, 4704, 41)) +>Float64Array.from : Symbol(Float64ArrayConstructor.from, Decl(lib.d.ts, 4708, 41)) +>Float64Array : Symbol(Float64Array, Decl(lib.d.ts, 4428, 50), Decl(lib.d.ts, 4718, 11)) +>from : Symbol(Float64ArrayConstructor.from, Decl(lib.d.ts, 4708, 41)) >obj : Symbol(obj, Decl(typedArrays.ts, 123, 38)) >mapFn : Symbol(mapFn, Decl(typedArrays.ts, 123, 60)) >thisArg : Symbol(thisArg, Decl(typedArrays.ts, 123, 98)) typedArrays[8] = Uint8ClampedArray.from(obj, mapFn, thisArg); >typedArrays : Symbol(typedArrays, Decl(typedArrays.ts, 124, 7)) ->Uint8ClampedArray.from : Symbol(Uint8ClampedArrayConstructor.from, Decl(lib.d.ts, 2964, 46)) ->Uint8ClampedArray : Symbol(Uint8ClampedArray, Decl(lib.d.ts, 2684, 46), Decl(lib.d.ts, 2974, 11)) ->from : Symbol(Uint8ClampedArrayConstructor.from, Decl(lib.d.ts, 2964, 46)) +>Uint8ClampedArray.from : Symbol(Uint8ClampedArrayConstructor.from, Decl(lib.d.ts, 2968, 46)) +>Uint8ClampedArray : Symbol(Uint8ClampedArray, Decl(lib.d.ts, 2688, 46), Decl(lib.d.ts, 2978, 11)) +>from : Symbol(Uint8ClampedArrayConstructor.from, Decl(lib.d.ts, 2968, 46)) >obj : Symbol(obj, Decl(typedArrays.ts, 123, 38)) >mapFn : Symbol(mapFn, Decl(typedArrays.ts, 123, 60)) >thisArg : Symbol(thisArg, Decl(typedArrays.ts, 123, 98)) diff --git a/tests/cases/compiler/noEmitHelpers2.ts b/tests/cases/compiler/noEmitHelpers2.ts index ccc17f7066e..2487ffa1dd8 100644 --- a/tests/cases/compiler/noEmitHelpers2.ts +++ b/tests/cases/compiler/noEmitHelpers2.ts @@ -3,7 +3,7 @@ // @emitdecoratormetadata: true // @target: es5 -function decorator() { } +declare var decorator: any; @decorator class A { diff --git a/tests/cases/compiler/numLit.ts b/tests/cases/compiler/numLit.ts deleted file mode 100644 index 01e19e7c8fb..00000000000 --- a/tests/cases/compiler/numLit.ts +++ /dev/null @@ -1,4 +0,0 @@ -1..toString(); -1.0.toString(); -1.toString(); -1.+2.0 + 3. ; \ No newline at end of file diff --git a/tests/cases/compiler/numericLiteralsWithTrailingDecimalPoints01.ts b/tests/cases/compiler/numericLiteralsWithTrailingDecimalPoints01.ts new file mode 100644 index 00000000000..23cd2ba45f8 --- /dev/null +++ b/tests/cases/compiler/numericLiteralsWithTrailingDecimalPoints01.ts @@ -0,0 +1,17 @@ +1..toString(); +1.0.toString(); +1.toString(); +1.+2.0 + 3. ; + +// Preserve whitespace where important for JS compatibility +var i: number = 1; +var test1 = i.toString(); +var test2 = 2.toString(); +var test3 = 3 .toString(); +var test4 = 3 .toString(); +var test5 = 3 .toString(); +var test6 = 3.['toString'](); +var test7 = 3 +.toString(); +var test8 = new Number(4).toString(); +var test9 = 3. + 3. diff --git a/tests/cases/compiler/sourceMapValidationDecorators.ts b/tests/cases/compiler/sourceMapValidationDecorators.ts index 898d3f729b2..b600691e04b 100644 --- a/tests/cases/compiler/sourceMapValidationDecorators.ts +++ b/tests/cases/compiler/sourceMapValidationDecorators.ts @@ -5,8 +5,8 @@ declare function ClassDecorator1(target: Function): void; declare function ClassDecorator2(x: number): (target: Function) => void; declare function PropertyDecorator1(target: Object, key: string | symbol, descriptor?: PropertyDescriptor): void; declare function PropertyDecorator2(x: number): (target: Object, key: string | symbol, descriptor?: PropertyDescriptor) => void; -declare function ParameterDecorator1(target: Function, key: string | symbol, paramIndex: number): void; -declare function ParameterDecorator2(x: number): (target: Function, key: string | symbol, paramIndex: number) => void; +declare function ParameterDecorator1(target: Object, key: string | symbol, paramIndex: number): void; +declare function ParameterDecorator2(x: number): (target: Object, key: string | symbol, paramIndex: number) => void; @ClassDecorator1 @ClassDecorator2(10) diff --git a/tests/cases/conformance/classes/classExpressions/classExpression3.ts b/tests/cases/conformance/classes/classExpressions/classExpression3.ts new file mode 100644 index 00000000000..4267429f759 --- /dev/null +++ b/tests/cases/conformance/classes/classExpressions/classExpression3.ts @@ -0,0 +1,5 @@ +let C = class extends class extends class { a = 1 } { b = 2 } { c = 3 }; +let c = new C(); +c.a; +c.b; +c.c; diff --git a/tests/cases/conformance/classes/classExpressions/classExpression4.ts b/tests/cases/conformance/classes/classExpressions/classExpression4.ts new file mode 100644 index 00000000000..9365475fd87 --- /dev/null +++ b/tests/cases/conformance/classes/classExpressions/classExpression4.ts @@ -0,0 +1,6 @@ +let C = class { + foo() { + return new C(); + } +}; +let x = (new C).foo(); diff --git a/tests/cases/conformance/decorators/class/decoratedClassFromExternalModule.ts b/tests/cases/conformance/decorators/class/decoratedClassFromExternalModule.ts index 95f8bf4ab97..f2d9076cce2 100644 --- a/tests/cases/conformance/decorators/class/decoratedClassFromExternalModule.ts +++ b/tests/cases/conformance/decorators/class/decoratedClassFromExternalModule.ts @@ -1,7 +1,7 @@ // @target: es6 // @experimentaldecorators: true // @Filename: decorated.ts -function decorate() { } +function decorate(target: any) { } @decorate export default class Decorated { } diff --git a/tests/cases/conformance/decorators/class/decoratorChecksFunctionBodies.ts b/tests/cases/conformance/decorators/class/decoratorChecksFunctionBodies.ts index b1cbd1a679c..36237f3cb58 100644 --- a/tests/cases/conformance/decorators/class/decoratorChecksFunctionBodies.ts +++ b/tests/cases/conformance/decorators/class/decoratorChecksFunctionBodies.ts @@ -6,7 +6,7 @@ function func(s: string): void { } class A { - @(x => { + @((x, p) => { var a = 3; func(a); return x; diff --git a/tests/cases/conformance/decorators/class/decoratorInstantiateModulesInFunctionBodies.ts b/tests/cases/conformance/decorators/class/decoratorInstantiateModulesInFunctionBodies.ts index 9163ed0c384..7ba5a6839b9 100644 --- a/tests/cases/conformance/decorators/class/decoratorInstantiateModulesInFunctionBodies.ts +++ b/tests/cases/conformance/decorators/class/decoratorInstantiateModulesInFunctionBodies.ts @@ -10,7 +10,7 @@ export var test = 'abc'; import { test } from './a'; function filter(handler: any) { - return function (target: any) { + return function (target: any, propertyKey: string) { // ... }; } diff --git a/tests/cases/conformance/decorators/class/method/decoratorOnClassMethod13.ts b/tests/cases/conformance/decorators/class/method/decoratorOnClassMethod13.ts index f41481d4ad0..5ab3b39d7ab 100644 --- a/tests/cases/conformance/decorators/class/method/decoratorOnClassMethod13.ts +++ b/tests/cases/conformance/decorators/class/method/decoratorOnClassMethod13.ts @@ -1,6 +1,6 @@ // @target: ES6 // @experimentaldecorators: true -declare function dec(): (target: any, propertyKey: string, descriptor: TypedPropertyDescriptor) => TypedPropertyDescriptor; +declare function dec(target: any, propertyKey: string, descriptor: TypedPropertyDescriptor): TypedPropertyDescriptor; class C { @dec ["1"]() { } diff --git a/tests/cases/conformance/decorators/class/method/parameter/decoratorOnClassMethodParameter1.ts b/tests/cases/conformance/decorators/class/method/parameter/decoratorOnClassMethodParameter1.ts index 18a7fff6dd0..64de61bb8a9 100644 --- a/tests/cases/conformance/decorators/class/method/parameter/decoratorOnClassMethodParameter1.ts +++ b/tests/cases/conformance/decorators/class/method/parameter/decoratorOnClassMethodParameter1.ts @@ -1,6 +1,6 @@ // @target:es5 // @experimentaldecorators: true -declare function dec(target: Function, propertyKey: string | symbol, parameterIndex: number): void; +declare function dec(target: Object, propertyKey: string | symbol, parameterIndex: number): void; class C { method(@dec p: number) {} diff --git a/tests/cases/conformance/decorators/missingDecoratorType.ts b/tests/cases/conformance/decorators/missingDecoratorType.ts index 905edaf0756..9b8cdd276f2 100644 --- a/tests/cases/conformance/decorators/missingDecoratorType.ts +++ b/tests/cases/conformance/decorators/missingDecoratorType.ts @@ -13,9 +13,10 @@ interface RegExp { } interface IArguments { } // @Filename: b.ts -declare var dec: any; +declare function dec(t, k, d); -@dec class C { + @dec + method() {} } diff --git a/tests/cases/conformance/es6/classExpressions/classExpressionES63.ts b/tests/cases/conformance/es6/classExpressions/classExpressionES63.ts new file mode 100644 index 00000000000..cbbe0927c30 --- /dev/null +++ b/tests/cases/conformance/es6/classExpressions/classExpressionES63.ts @@ -0,0 +1,6 @@ +// @target: es6 +let C = class extends class extends class { a = 1 } { b = 2 } { c = 3 }; +let c = new C(); +c.a; +c.b; +c.c; diff --git a/tests/cases/conformance/es6/destructuring/emptyArrayBindingPatternParameter01.ts b/tests/cases/conformance/es6/destructuring/emptyArrayBindingPatternParameter01.ts new file mode 100644 index 00000000000..0dea1fe795c --- /dev/null +++ b/tests/cases/conformance/es6/destructuring/emptyArrayBindingPatternParameter01.ts @@ -0,0 +1,5 @@ + + +function f([]) { + var x, y, z; +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/destructuring/emptyArrayBindingPatternParameter02.ts b/tests/cases/conformance/es6/destructuring/emptyArrayBindingPatternParameter02.ts new file mode 100644 index 00000000000..39663a4bed7 --- /dev/null +++ b/tests/cases/conformance/es6/destructuring/emptyArrayBindingPatternParameter02.ts @@ -0,0 +1,5 @@ + + +function f(a, []) { + var x, y, z; +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/destructuring/emptyArrayBindingPatternParameter03.ts b/tests/cases/conformance/es6/destructuring/emptyArrayBindingPatternParameter03.ts new file mode 100644 index 00000000000..39663a4bed7 --- /dev/null +++ b/tests/cases/conformance/es6/destructuring/emptyArrayBindingPatternParameter03.ts @@ -0,0 +1,5 @@ + + +function f(a, []) { + var x, y, z; +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/destructuring/emptyArrayBindingPatternParameter04.ts b/tests/cases/conformance/es6/destructuring/emptyArrayBindingPatternParameter04.ts new file mode 100644 index 00000000000..313d4fe6708 --- /dev/null +++ b/tests/cases/conformance/es6/destructuring/emptyArrayBindingPatternParameter04.ts @@ -0,0 +1,5 @@ + + +function f([] = [1,2,3,4]) { + var x, y, z; +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/destructuring/emptyObjectBindingPatternParameter01.ts b/tests/cases/conformance/es6/destructuring/emptyObjectBindingPatternParameter01.ts new file mode 100644 index 00000000000..01aa5b54230 --- /dev/null +++ b/tests/cases/conformance/es6/destructuring/emptyObjectBindingPatternParameter01.ts @@ -0,0 +1,5 @@ + + +function f({}) { + var x, y, z; +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/destructuring/emptyObjectBindingPatternParameter02.ts b/tests/cases/conformance/es6/destructuring/emptyObjectBindingPatternParameter02.ts new file mode 100644 index 00000000000..f34503c1152 --- /dev/null +++ b/tests/cases/conformance/es6/destructuring/emptyObjectBindingPatternParameter02.ts @@ -0,0 +1,5 @@ + + +function f(a, {}) { + var x, y, z; +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/destructuring/emptyObjectBindingPatternParameter03.ts b/tests/cases/conformance/es6/destructuring/emptyObjectBindingPatternParameter03.ts new file mode 100644 index 00000000000..a940c659703 --- /dev/null +++ b/tests/cases/conformance/es6/destructuring/emptyObjectBindingPatternParameter03.ts @@ -0,0 +1,5 @@ + + +function f({}, a) { + var x, y, z; +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/destructuring/emptyObjectBindingPatternParameter04.ts b/tests/cases/conformance/es6/destructuring/emptyObjectBindingPatternParameter04.ts new file mode 100644 index 00000000000..da05e5cb428 --- /dev/null +++ b/tests/cases/conformance/es6/destructuring/emptyObjectBindingPatternParameter04.ts @@ -0,0 +1,5 @@ + + +function f({} = {a: 1, b: "2", c: true}) { + var x, y, z; +} \ No newline at end of file diff --git a/tests/cases/fourslash/completionListInObjectBindingPattern01.ts b/tests/cases/fourslash/completionListInObjectBindingPattern01.ts new file mode 100644 index 00000000000..128e95b8ed3 --- /dev/null +++ b/tests/cases/fourslash/completionListInObjectBindingPattern01.ts @@ -0,0 +1,13 @@ +/// + +////interface I { +//// property1: number; +//// property2: string; +////} +//// +////var foo: I; +////var { /**/ } = foo; + +goTo.marker(); +verify.completionListContains("property1"); +verify.completionListContains("property2"); \ No newline at end of file diff --git a/tests/cases/fourslash/completionListInObjectBindingPattern02.ts b/tests/cases/fourslash/completionListInObjectBindingPattern02.ts new file mode 100644 index 00000000000..6d2b7a6b516 --- /dev/null +++ b/tests/cases/fourslash/completionListInObjectBindingPattern02.ts @@ -0,0 +1,13 @@ +/// + +////interface I { +//// property1: number; +//// property2: string; +////} +//// +////var foo: I; +////var { property1, /**/ } = foo; + +goTo.marker(); +verify.completionListContains("property2"); +verify.not.completionListContains("property1"); \ No newline at end of file diff --git a/tests/cases/fourslash/completionListInObjectBindingPattern03.ts b/tests/cases/fourslash/completionListInObjectBindingPattern03.ts new file mode 100644 index 00000000000..72da68168bd --- /dev/null +++ b/tests/cases/fourslash/completionListInObjectBindingPattern03.ts @@ -0,0 +1,13 @@ +/// + +////interface I { +//// property1: number; +//// property2: string; +////} +//// +////var foo: I; +////var { property1: /**/ } = foo; + +goTo.marker(); +verify.completionListAllowsNewIdentifier(); +verify.completionListIsEmpty(); \ No newline at end of file diff --git a/tests/cases/fourslash/completionListInObjectBindingPattern04.ts b/tests/cases/fourslash/completionListInObjectBindingPattern04.ts new file mode 100644 index 00000000000..92b202a1b37 --- /dev/null +++ b/tests/cases/fourslash/completionListInObjectBindingPattern04.ts @@ -0,0 +1,13 @@ +/// + +////interface I { +//// property1: number; +//// property2: string; +////} +//// +////var foo: I; +////var { prope/**/ } = foo; + +goTo.marker(); +verify.completionListContains("property1"); +verify.completionListContains("property2"); \ No newline at end of file diff --git a/tests/cases/fourslash/completionListInObjectBindingPattern05.ts b/tests/cases/fourslash/completionListInObjectBindingPattern05.ts new file mode 100644 index 00000000000..d17e11810df --- /dev/null +++ b/tests/cases/fourslash/completionListInObjectBindingPattern05.ts @@ -0,0 +1,12 @@ +/// + +////interface I { +//// property1: number; +//// property2: string; +////} +//// +////var foo: I; +////var { property1/**/ } = foo; + +goTo.marker(); +verify.completionListContains("property1"); \ No newline at end of file diff --git a/tests/cases/fourslash/completionListInObjectBindingPattern06.ts b/tests/cases/fourslash/completionListInObjectBindingPattern06.ts new file mode 100644 index 00000000000..8060c2bde78 --- /dev/null +++ b/tests/cases/fourslash/completionListInObjectBindingPattern06.ts @@ -0,0 +1,12 @@ +/// + +////interface I { +//// property1: number; +//// property2: string; +////} +//// +////var foo: I; +////var { property1, property2, /**/ } = foo; + +goTo.marker(); +verify.completionListIsEmpty(); \ No newline at end of file diff --git a/tests/cases/fourslash/completionListInObjectBindingPattern07.ts b/tests/cases/fourslash/completionListInObjectBindingPattern07.ts new file mode 100644 index 00000000000..a3015346aa3 --- /dev/null +++ b/tests/cases/fourslash/completionListInObjectBindingPattern07.ts @@ -0,0 +1,18 @@ +/// + +////interface I { +//// propertyOfI_1: number; +//// propertyOfI_2: string; +////} +////interface J { +//// property1: I; +//// property2: string; +////} +//// +////var foo: J; +////var { property1: { /**/ } } = foo; + +goTo.marker(); +verify.completionListContains("propertyOfI_1"); +verify.completionListContains("propertyOfI_2"); +verify.not.completionListContains("property2"); \ No newline at end of file diff --git a/tests/cases/fourslash/completionListInObjectBindingPattern08.ts b/tests/cases/fourslash/completionListInObjectBindingPattern08.ts new file mode 100644 index 00000000000..6d6be330b83 --- /dev/null +++ b/tests/cases/fourslash/completionListInObjectBindingPattern08.ts @@ -0,0 +1,18 @@ +/// + +////interface I { +//// propertyOfI_1: number; +//// propertyOfI_2: string; +////} +////interface J { +//// property1: I; +//// property2: string; +////} +//// +////var foo: J; +////var { property1: { propertyOfI_1, /**/ } } = foo; + +goTo.marker(); +verify.completionListContains("propertyOfI_2"); +verify.not.completionListContains("propertyOfI_1"); +verify.not.completionListContains("property2"); \ No newline at end of file diff --git a/tests/cases/fourslash/completionListInObjectBindingPattern09.ts b/tests/cases/fourslash/completionListInObjectBindingPattern09.ts new file mode 100644 index 00000000000..2698e78667b --- /dev/null +++ b/tests/cases/fourslash/completionListInObjectBindingPattern09.ts @@ -0,0 +1,19 @@ +/// + +////interface I { +//// propertyOfI_1: number; +//// propertyOfI_2: string; +////} +////interface J { +//// property1: I; +//// property2: string; +////} +//// +////var foo: J; +////var { property1: { propertyOfI_1, }, /**/ } = foo; + +goTo.marker(); +verify.completionListContains("property2"); +verify.not.completionListContains("property1"); +verify.not.completionListContains("propertyOfI_2"); +verify.not.completionListContains("propertyOfI_1"); \ No newline at end of file diff --git a/tests/cases/fourslash/completionListInObjectBindingPattern10.ts b/tests/cases/fourslash/completionListInObjectBindingPattern10.ts new file mode 100644 index 00000000000..fcc09d1ead4 --- /dev/null +++ b/tests/cases/fourslash/completionListInObjectBindingPattern10.ts @@ -0,0 +1,23 @@ +/// + +////interface I { +//// propertyOfI_1: number; +//// propertyOfI_2: string; +////} +////interface J { +//// property1: I; +//// property2: string; +////} +//// +////var foo: J[]; +////var [{ property1: { propertyOfI_1, }, /*1*/ }, { /*2*/ }] = foo; + +goTo.marker("1"); +verify.completionListContains("property2"); +verify.not.completionListContains("property1"); +verify.not.completionListContains("propertyOfI_2"); +verify.not.completionListContains("propertyOfI_1"); + +goTo.marker("2"); +verify.completionListContains("property1"); +verify.completionListContains("property2"); \ No newline at end of file diff --git a/tests/cases/fourslash/completionListInObjectBindingPattern11.ts b/tests/cases/fourslash/completionListInObjectBindingPattern11.ts new file mode 100644 index 00000000000..25d6651a038 --- /dev/null +++ b/tests/cases/fourslash/completionListInObjectBindingPattern11.ts @@ -0,0 +1,13 @@ +/// + +////interface I { +//// property1: number; +//// property2: string; +////} +//// +////var { property1: prop1, /**/ }: I; + +goTo.marker(""); +verify.completionListContains("property2"); +verify.not.completionListContains("property1"); +verify.not.completionListContains("prop1"); \ No newline at end of file diff --git a/tests/cases/fourslash/completionListInObjectBindingPattern12.ts b/tests/cases/fourslash/completionListInObjectBindingPattern12.ts new file mode 100644 index 00000000000..f31206a21b6 --- /dev/null +++ b/tests/cases/fourslash/completionListInObjectBindingPattern12.ts @@ -0,0 +1,13 @@ +/// + +////interface I { +//// property1: number; +//// property2: string; +////} +//// +////function f({ property1, /**/ }: I): void { +////} + +goTo.marker(""); +verify.completionListContains("property2"); +verify.not.completionListContains("property1"); \ No newline at end of file diff --git a/tests/cases/fourslash/consistenceOnIndentionsOfChainedFunctionCalls.ts b/tests/cases/fourslash/consistenceOnIndentionsOfChainedFunctionCalls.ts index ec2ae9b3c22..3692974f5fb 100644 --- a/tests/cases/fourslash/consistenceOnIndentionsOfChainedFunctionCalls.ts +++ b/tests/cases/fourslash/consistenceOnIndentionsOfChainedFunctionCalls.ts @@ -18,4 +18,4 @@ goTo.marker("1"); edit.insert("\r\n"); goTo.marker("0"); // Won't-fixed: Smart indent during chained function calls -verify.indentationIs(4); \ No newline at end of file +verify.indentationIs(8); \ No newline at end of file diff --git a/tests/cases/fourslash/formattingOfExportDefault.ts b/tests/cases/fourslash/formattingOfExportDefault.ts new file mode 100644 index 00000000000..ff69440b861 --- /dev/null +++ b/tests/cases/fourslash/formattingOfExportDefault.ts @@ -0,0 +1,12 @@ +/// + +////module Foo { +/////*1*/ export default class Test { } +////} +/////*2*/export default function bar() { } + +format.document(); +goTo.marker("1"); +verify.currentLineContentIs(" export default class Test { }") +goTo.marker("2"); +verify.currentLineContentIs("export default function bar() { }") diff --git a/tests/cases/fourslash/formattingOnChainedCallbacks.ts b/tests/cases/fourslash/formattingOnChainedCallbacks.ts index 37fa6ff03f1..b8dbc55d8b6 100644 --- a/tests/cases/fourslash/formattingOnChainedCallbacks.ts +++ b/tests/cases/fourslash/formattingOnChainedCallbacks.ts @@ -13,10 +13,20 @@ //// })/*b*/ ////} +////Promise +//// .then( +//// /*n1*/ +//// ) +//// /*n2*/ +//// .then(); + + goTo.marker('1'); edit.insertLine(''); goTo.marker('2'); verify.currentLineContentIs(' ""'); +edit.insertLine(''); +verify.indentationIs(8); goTo.marker('4'); edit.insertLine(''); goTo.marker('3'); @@ -34,4 +44,9 @@ edit.insert(';'); verify.currentLineContentIs(' "";'); goTo.marker('b'); edit.insert(';'); -verify.currentLineContentIs(' });'); \ No newline at end of file +verify.currentLineContentIs(' });'); + +goTo.marker('n1'); +verify.indentationIs(8); +goTo.marker('n2'); +verify.indentationIs(4); \ No newline at end of file diff --git a/tests/cases/fourslash/formattingOnClasses.ts b/tests/cases/fourslash/formattingOnClasses.ts index 045ee91e427..0c259dae2ec 100644 --- a/tests/cases/fourslash/formattingOnClasses.ts +++ b/tests/cases/fourslash/formattingOnClasses.ts @@ -77,7 +77,9 @@ /////*60*/ private foo ( ns : any ) { /////*61*/ return ns.toString ( ) ; /////*62*/ } -/////*63*/} +/////*63*/ protected bar ( ) { } +/////*64*/ protected static bar2 ( ) { } +/////*65*/} format.document(); goTo.marker("1"); verify.currentLineContentIs("class a {"); @@ -204,4 +206,8 @@ verify.currentLineContentIs(" return ns.toString();"); goTo.marker("62"); verify.currentLineContentIs(" }"); goTo.marker("63"); +verify.currentLineContentIs(" protected bar() { }"); +goTo.marker("64"); +verify.currentLineContentIs(" protected static bar2() { }"); +goTo.marker("65"); verify.currentLineContentIs("}"); \ No newline at end of file diff --git a/tests/cases/fourslash/goToDefinitionExternamModuleName.ts b/tests/cases/fourslash/goToDefinitionExternalModuleName.ts similarity index 100% rename from tests/cases/fourslash/goToDefinitionExternamModuleName.ts rename to tests/cases/fourslash/goToDefinitionExternalModuleName.ts diff --git a/tests/cases/fourslash/goToDefinitionExternamModuleName2.ts b/tests/cases/fourslash/goToDefinitionExternalModuleName2.ts similarity index 100% rename from tests/cases/fourslash/goToDefinitionExternamModuleName2.ts rename to tests/cases/fourslash/goToDefinitionExternalModuleName2.ts diff --git a/tests/cases/fourslash/goToDefinitionExternamModuleName3.ts b/tests/cases/fourslash/goToDefinitionExternalModuleName3.ts similarity index 100% rename from tests/cases/fourslash/goToDefinitionExternamModuleName3.ts rename to tests/cases/fourslash/goToDefinitionExternalModuleName3.ts diff --git a/tests/cases/fourslash/goToDefinitionExternamModuleName4.ts b/tests/cases/fourslash/goToDefinitionExternalModuleName4.ts similarity index 100% rename from tests/cases/fourslash/goToDefinitionExternamModuleName4.ts rename to tests/cases/fourslash/goToDefinitionExternalModuleName4.ts diff --git a/tests/cases/fourslash/goToDefinitionExternamModuleName5.ts b/tests/cases/fourslash/goToDefinitionExternalModuleName5.ts similarity index 100% rename from tests/cases/fourslash/goToDefinitionExternamModuleName5.ts rename to tests/cases/fourslash/goToDefinitionExternalModuleName5.ts diff --git a/tests/cases/fourslash/goToDefinitionExternamModuleName6.ts b/tests/cases/fourslash/goToDefinitionExternalModuleName6.ts similarity index 100% rename from tests/cases/fourslash/goToDefinitionExternamModuleName6.ts rename to tests/cases/fourslash/goToDefinitionExternalModuleName6.ts diff --git a/tests/cases/fourslash/goToDefinitionExternamModuleName7.ts b/tests/cases/fourslash/goToDefinitionExternalModuleName7.ts similarity index 100% rename from tests/cases/fourslash/goToDefinitionExternamModuleName7.ts rename to tests/cases/fourslash/goToDefinitionExternalModuleName7.ts diff --git a/tests/cases/fourslash/goToDefinitionExternamModuleName8.ts b/tests/cases/fourslash/goToDefinitionExternalModuleName8.ts similarity index 100% rename from tests/cases/fourslash/goToDefinitionExternamModuleName8.ts rename to tests/cases/fourslash/goToDefinitionExternalModuleName8.ts diff --git a/tests/cases/fourslash/goToDefinitionExternamModuleName9.ts b/tests/cases/fourslash/goToDefinitionExternalModuleName9.ts similarity index 100% rename from tests/cases/fourslash/goToDefinitionExternamModuleName9.ts rename to tests/cases/fourslash/goToDefinitionExternalModuleName9.ts diff --git a/tests/cases/fourslash/goToDefinitionTypePredicate.ts b/tests/cases/fourslash/goToDefinitionTypePredicate.ts new file mode 100644 index 00000000000..40f1d1eb94c --- /dev/null +++ b/tests/cases/fourslash/goToDefinitionTypePredicate.ts @@ -0,0 +1,16 @@ +/// + +//// /*classDeclaration*/class A {} +//// function f(/*parameterDeclaration*/parameter: any): /*parameterName*/parameter is /*typeReference*/A { +//// return typeof parameter === "string"; +//// } + +goTo.marker('parameterName'); + +goTo.definition(); +verify.caretAtMarker('parameterDeclaration'); + +goTo.marker('typeReference'); + +goTo.definition(); +verify.caretAtMarker('classDeclaration'); \ No newline at end of file diff --git a/tests/cases/fourslash/scriptLexicalStructureBindingPatterns.ts b/tests/cases/fourslash/navigationBarItemsBindingPatterns.ts similarity index 100% rename from tests/cases/fourslash/scriptLexicalStructureBindingPatterns.ts rename to tests/cases/fourslash/navigationBarItemsBindingPatterns.ts diff --git a/tests/cases/fourslash/scriptLexicalStructureBindingPatternsInConstructor.ts b/tests/cases/fourslash/navigationBarItemsBindingPatternsInConstructor.ts similarity index 100% rename from tests/cases/fourslash/scriptLexicalStructureBindingPatternsInConstructor.ts rename to tests/cases/fourslash/navigationBarItemsBindingPatternsInConstructor.ts diff --git a/tests/cases/fourslash/scriptLexicalStructureEmptyConstructors.ts b/tests/cases/fourslash/navigationBarItemsEmptyConstructors.ts similarity index 100% rename from tests/cases/fourslash/scriptLexicalStructureEmptyConstructors.ts rename to tests/cases/fourslash/navigationBarItemsEmptyConstructors.ts diff --git a/tests/cases/fourslash/scriptLexicalStructureExports.ts b/tests/cases/fourslash/navigationBarItemsExports.ts similarity index 100% rename from tests/cases/fourslash/scriptLexicalStructureExports.ts rename to tests/cases/fourslash/navigationBarItemsExports.ts diff --git a/tests/cases/fourslash/scriptLexicalStructureFunctions.ts b/tests/cases/fourslash/navigationBarItemsFunctions.ts similarity index 100% rename from tests/cases/fourslash/scriptLexicalStructureFunctions.ts rename to tests/cases/fourslash/navigationBarItemsFunctions.ts diff --git a/tests/cases/fourslash/scriptLexicalStructureFunctionsBroken.ts b/tests/cases/fourslash/navigationBarItemsFunctionsBroken.ts similarity index 100% rename from tests/cases/fourslash/scriptLexicalStructureFunctionsBroken.ts rename to tests/cases/fourslash/navigationBarItemsFunctionsBroken.ts diff --git a/tests/cases/fourslash/scriptLexicalStructureFunctionsBroken2.ts b/tests/cases/fourslash/navigationBarItemsFunctionsBroken2.ts similarity index 100% rename from tests/cases/fourslash/scriptLexicalStructureFunctionsBroken2.ts rename to tests/cases/fourslash/navigationBarItemsFunctionsBroken2.ts diff --git a/tests/cases/fourslash/scriptLexicalStructureImports.ts b/tests/cases/fourslash/navigationBarItemsImports.ts similarity index 100% rename from tests/cases/fourslash/scriptLexicalStructureImports.ts rename to tests/cases/fourslash/navigationBarItemsImports.ts diff --git a/tests/cases/fourslash/scriptLexicalStructureItems.ts b/tests/cases/fourslash/navigationBarItemsItems.ts similarity index 100% rename from tests/cases/fourslash/scriptLexicalStructureItems.ts rename to tests/cases/fourslash/navigationBarItemsItems.ts diff --git a/tests/cases/fourslash/scriptLexicalStructureItems2.ts b/tests/cases/fourslash/navigationBarItemsItems2.ts similarity index 100% rename from tests/cases/fourslash/scriptLexicalStructureItems2.ts rename to tests/cases/fourslash/navigationBarItemsItems2.ts diff --git a/tests/cases/fourslash/scriptLexicalStructureItemsContainsNoAnonymousFunctions.ts b/tests/cases/fourslash/navigationBarItemsItemsContainsNoAnonymousFunctions.ts similarity index 100% rename from tests/cases/fourslash/scriptLexicalStructureItemsContainsNoAnonymousFunctions.ts rename to tests/cases/fourslash/navigationBarItemsItemsContainsNoAnonymousFunctions.ts diff --git a/tests/cases/fourslash/scriptLexicalStructureItemsExternalModules.ts b/tests/cases/fourslash/navigationBarItemsItemsExternalModules.ts similarity index 100% rename from tests/cases/fourslash/scriptLexicalStructureItemsExternalModules.ts rename to tests/cases/fourslash/navigationBarItemsItemsExternalModules.ts diff --git a/tests/cases/fourslash/scriptLexicalStructureItemsExternalModules2.ts b/tests/cases/fourslash/navigationBarItemsItemsExternalModules2.ts similarity index 100% rename from tests/cases/fourslash/scriptLexicalStructureItemsExternalModules2.ts rename to tests/cases/fourslash/navigationBarItemsItemsExternalModules2.ts diff --git a/tests/cases/fourslash/scriptLexicalStructureItemsExternalModules3.ts b/tests/cases/fourslash/navigationBarItemsItemsExternalModules3.ts similarity index 100% rename from tests/cases/fourslash/scriptLexicalStructureItemsExternalModules3.ts rename to tests/cases/fourslash/navigationBarItemsItemsExternalModules3.ts diff --git a/tests/cases/fourslash/scriptLexicalStructureItemsModuleVariables.ts b/tests/cases/fourslash/navigationBarItemsItemsModuleVariables.ts similarity index 100% rename from tests/cases/fourslash/scriptLexicalStructureItemsModuleVariables.ts rename to tests/cases/fourslash/navigationBarItemsItemsModuleVariables.ts diff --git a/tests/cases/fourslash/scriptLexicalStructureMissingName1.ts b/tests/cases/fourslash/navigationBarItemsMissingName1.ts similarity index 100% rename from tests/cases/fourslash/scriptLexicalStructureMissingName1.ts rename to tests/cases/fourslash/navigationBarItemsMissingName1.ts diff --git a/tests/cases/fourslash/scriptLexicalStructureMissingName2.ts b/tests/cases/fourslash/navigationBarItemsMissingName2.ts similarity index 100% rename from tests/cases/fourslash/scriptLexicalStructureMissingName2.ts rename to tests/cases/fourslash/navigationBarItemsMissingName2.ts diff --git a/tests/cases/fourslash/scriptLexicalStructureModules.ts b/tests/cases/fourslash/navigationBarItemsModules.ts similarity index 100% rename from tests/cases/fourslash/scriptLexicalStructureModules.ts rename to tests/cases/fourslash/navigationBarItemsModules.ts diff --git a/tests/cases/fourslash/scriptLexicalStructureMultilineStringIdentifiers.ts b/tests/cases/fourslash/navigationBarItemsMultilineStringIdentifiers.ts similarity index 100% rename from tests/cases/fourslash/scriptLexicalStructureMultilineStringIdentifiers.ts rename to tests/cases/fourslash/navigationBarItemsMultilineStringIdentifiers.ts diff --git a/tests/cases/fourslash/scriptLexicalStructurePropertiesDefinedInConstructors.ts b/tests/cases/fourslash/navigationBarItemsPropertiesDefinedInConstructors.ts similarity index 100% rename from tests/cases/fourslash/scriptLexicalStructurePropertiesDefinedInConstructors.ts rename to tests/cases/fourslash/navigationBarItemsPropertiesDefinedInConstructors.ts diff --git a/tests/cases/fourslash/scriptLexicalStructureSymbols1.ts b/tests/cases/fourslash/navigationBarItemsSymbols1.ts similarity index 100% rename from tests/cases/fourslash/scriptLexicalStructureSymbols1.ts rename to tests/cases/fourslash/navigationBarItemsSymbols1.ts diff --git a/tests/cases/fourslash/scriptLexicalStructureSymbols2.ts b/tests/cases/fourslash/navigationBarItemsSymbols2.ts similarity index 100% rename from tests/cases/fourslash/scriptLexicalStructureSymbols2.ts rename to tests/cases/fourslash/navigationBarItemsSymbols2.ts diff --git a/tests/cases/fourslash/scriptLexicalStructureSymbols3.ts b/tests/cases/fourslash/navigationBarItemsSymbols3.ts similarity index 100% rename from tests/cases/fourslash/scriptLexicalStructureSymbols3.ts rename to tests/cases/fourslash/navigationBarItemsSymbols3.ts diff --git a/tests/cases/fourslash/syntacticClassificationWithErrors.ts b/tests/cases/fourslash/syntacticClassificationWithErrors.ts new file mode 100644 index 00000000000..b4572d3e620 --- /dev/null +++ b/tests/cases/fourslash/syntacticClassificationWithErrors.ts @@ -0,0 +1,14 @@ +/// + +////class A { +//// a: +////} +////c = + +let c = classification +verify.syntacticClassificationsAre( + c.keyword("class"), c.className("A"), c.punctuation("{"), + c.text("a"), c.punctuation(":"), + c.punctuation("}"), + c.text("c"), c.operator("=") + ); \ No newline at end of file diff --git a/tests/cases/fourslash/underscoreTypings1.ts b/tests/cases/fourslash/underscoreTypings01.ts similarity index 100% rename from tests/cases/fourslash/underscoreTypings1.ts rename to tests/cases/fourslash/underscoreTypings01.ts diff --git a/tests/cases/fourslash/underscoreTyping1.ts b/tests/cases/fourslash/underscoreTypings02.ts similarity index 100% rename from tests/cases/fourslash/underscoreTyping1.ts rename to tests/cases/fourslash/underscoreTypings02.ts