diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index 796c9603423..4cacb5765db 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -230,6 +230,10 @@ namespace ts { // Should not be called on a declaration with a computed property name, // unless it is a well known Symbol. function getDeclarationName(node: Declaration): __String { + if (node.kind === SyntaxKind.ExportAssignment) { + return (node).isExportEquals ? InternalSymbolName.ExportEquals : InternalSymbolName.Default; + } + const name = getNameOfDeclaration(node); if (name) { if (isAmbientModule(node)) { @@ -261,8 +265,6 @@ namespace ts { return InternalSymbolName.Index; case SyntaxKind.ExportDeclaration: return InternalSymbolName.ExportStar; - case SyntaxKind.ExportAssignment: - return (node).isExportEquals ? InternalSymbolName.ExportEquals : InternalSymbolName.Default; case SyntaxKind.BinaryExpression: if (getSpecialPropertyAssignmentKind(node as BinaryExpression) === SpecialPropertyAssignmentKind.ModuleExports) { // module.exports = ... @@ -2144,7 +2146,7 @@ namespace ts { // falls through case SyntaxKind.JSDocPropertyTag: const propTag = node as JSDocPropertyLikeTag; - const flags = propTag.isBracketed || propTag.typeExpression.type.kind === SyntaxKind.JSDocOptionalType ? + const flags = propTag.isBracketed || propTag.typeExpression && propTag.typeExpression.type.kind === SyntaxKind.JSDocOptionalType ? SymbolFlags.Property | SymbolFlags.Optional : SymbolFlags.Property; return declareSymbolAndAddToSymbolTable(propTag, flags, SymbolFlags.PropertyExcludes); @@ -2269,16 +2271,13 @@ namespace ts { function isExportsOrModuleExportsOrAlias(node: Node): boolean { return isExportsIdentifier(node) || isModuleExportsPropertyAccessExpression(node) || - isNameOfExportsOrModuleExportsAliasDeclaration(node); + isIdentifier(node) && isNameOfExportsOrModuleExportsAliasDeclaration(node); } - function isNameOfExportsOrModuleExportsAliasDeclaration(node: Node) { - if (isIdentifier(node)) { - const symbol = lookupSymbolForName(node.escapedText); - return symbol && symbol.valueDeclaration && isVariableDeclaration(symbol.valueDeclaration) && - symbol.valueDeclaration.initializer && isExportsOrModuleExportsOrAliasOrAssignment(symbol.valueDeclaration.initializer); - } - return false; + function isNameOfExportsOrModuleExportsAliasDeclaration(node: Identifier): boolean { + const symbol = lookupSymbolForName(node.escapedText); + return symbol && symbol.valueDeclaration && isVariableDeclaration(symbol.valueDeclaration) && + symbol.valueDeclaration.initializer && isExportsOrModuleExportsOrAliasOrAssignment(symbol.valueDeclaration.initializer); } function isExportsOrModuleExportsOrAliasOrAssignment(node: Node): boolean { @@ -2352,20 +2351,22 @@ namespace ts { // Look up the function in the local scope, since prototype assignments should // follow the function declaration const leftSideOfAssignment = node.left as PropertyAccessExpression; - const target = leftSideOfAssignment.expression as Identifier; + const target = leftSideOfAssignment.expression; - // Fix up parent pointers since we're going to use these nodes before we bind into them - leftSideOfAssignment.parent = node; - target.parent = leftSideOfAssignment; + if (isIdentifier(target)) { + // Fix up parent pointers since we're going to use these nodes before we bind into them + leftSideOfAssignment.parent = node; + target.parent = leftSideOfAssignment; - if (isNameOfExportsOrModuleExportsAliasDeclaration(target)) { - // This can be an alias for the 'exports' or 'module.exports' names, e.g. - // var util = module.exports; - // util.property = function ... - bindExportsPropertyAssignment(node); - } - else { - bindPropertyAssignment(target.escapedText, leftSideOfAssignment, /*isPrototypeProperty*/ false); + if (isNameOfExportsOrModuleExportsAliasDeclaration(target)) { + // This can be an alias for the 'exports' or 'module.exports' names, e.g. + // var util = module.exports; + // util.property = function ... + bindExportsPropertyAssignment(node); + } + else { + bindPropertyAssignment(target.escapedText, leftSideOfAssignment, /*isPrototypeProperty*/ false); + } } } @@ -2697,6 +2698,12 @@ namespace ts { if (expression.kind === SyntaxKind.ImportKeyword) { transformFlags |= TransformFlags.ContainsDynamicImport; + + // A dynamic 'import()' call that contains a lexical 'this' will + // require a captured 'this' when emitting down-level. + if (subtreeFlags & TransformFlags.ContainsLexicalThis) { + transformFlags |= TransformFlags.ContainsCapturedLexicalThis; + } } node.transformFlags = transformFlags | TransformFlags.HasComputedFlags; diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 347d8c911f3..d47a77a7440 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -503,6 +503,12 @@ namespace ts { Inferential = 2, // Inferential typing } + const enum CallbackCheck { + None, + Bivariant, + Strict, + } + const builtinGlobals = createSymbolTable(); builtinGlobals.set(undefinedSymbol.escapedName, undefinedSymbol); @@ -902,6 +908,7 @@ namespace ts { const originalLocation = location; // needed for did-you-mean error reporting, which gathers candidates starting from the original location let result: Symbol; let lastLocation: Node; + let lastNonBlockLocation: Node; let propertyWithInvalidInitializer: Node; const errorLocation = location; let grandparent: Node; @@ -1120,6 +1127,9 @@ namespace ts { } break; } + if (location.kind !== SyntaxKind.Block) { + lastNonBlockLocation = location; + } lastLocation = location; location = location.parent; } @@ -1127,7 +1137,7 @@ namespace ts { // We just climbed up parents looking for the name, meaning that we started in a descendant node of `lastLocation`. // If `result === lastLocation.symbol`, that means that we are somewhere inside `lastLocation` looking up a name, and resolving to `lastLocation` itself. // That means that this is a self-reference of `lastLocation`, and shouldn't count this when considering whether `lastLocation` is used. - if (isUse && result && nameNotFoundMessage && noUnusedIdentifiers && result !== lastLocation.symbol) { + if (isUse && result && nameNotFoundMessage && noUnusedIdentifiers && result !== lastNonBlockLocation.symbol) { result.isReferenced = true; } @@ -8510,7 +8520,7 @@ namespace ts { function isSignatureAssignableTo(source: Signature, target: Signature, ignoreReturnTypes: boolean): boolean { - return compareSignaturesRelated(source, target, /*checkAsCallback*/ false, ignoreReturnTypes, /*reportErrors*/ false, + return compareSignaturesRelated(source, target, CallbackCheck.None, ignoreReturnTypes, /*reportErrors*/ false, /*errorReporter*/ undefined, compareTypesAssignable) !== Ternary.False; } @@ -8521,7 +8531,7 @@ namespace ts { */ function compareSignaturesRelated(source: Signature, target: Signature, - checkAsCallback: boolean, + callbackCheck: CallbackCheck, ignoreReturnTypes: boolean, reportErrors: boolean, errorReporter: ErrorReporter, @@ -8540,7 +8550,7 @@ namespace ts { } const kind = target.declaration ? target.declaration.kind : SyntaxKind.Unknown; - const strictVariance = strictFunctionTypes && kind !== SyntaxKind.MethodDeclaration && + const strictVariance = !callbackCheck && strictFunctionTypes && kind !== SyntaxKind.MethodDeclaration && kind !== SyntaxKind.MethodSignature && kind !== SyntaxKind.Constructor; let result = Ternary.True; @@ -8582,8 +8592,8 @@ namespace ts { const callbacks = sourceSig && targetSig && !sourceSig.typePredicate && !targetSig.typePredicate && (getFalsyFlags(sourceType) & TypeFlags.Nullable) === (getFalsyFlags(targetType) & TypeFlags.Nullable); const related = callbacks ? - compareSignaturesRelated(targetSig, sourceSig, /*checkAsCallback*/ true, /*ignoreReturnTypes*/ false, reportErrors, errorReporter, compareTypes) : - !checkAsCallback && !strictVariance && compareTypes(sourceType, targetType, /*reportErrors*/ false) || compareTypes(targetType, sourceType, reportErrors); + compareSignaturesRelated(targetSig, sourceSig, strictVariance ? CallbackCheck.Strict : CallbackCheck.Bivariant, /*ignoreReturnTypes*/ false, reportErrors, errorReporter, compareTypes) : + !callbackCheck && !strictVariance && compareTypes(sourceType, targetType, /*reportErrors*/ false) || compareTypes(targetType, sourceType, reportErrors); if (!related) { if (reportErrors) { errorReporter(Diagnostics.Types_of_parameters_0_and_1_are_incompatible, @@ -8618,7 +8628,7 @@ namespace ts { // When relating callback signatures, we still need to relate return types bi-variantly as otherwise // the containing type wouldn't be co-variant. For example, interface Foo { add(cb: () => T): void } // wouldn't be co-variant for T without this rule. - result &= checkAsCallback && compareTypes(targetReturnType, sourceReturnType, /*reportErrors*/ false) || + result &= callbackCheck === CallbackCheck.Bivariant && compareTypes(targetReturnType, sourceReturnType, /*reportErrors*/ false) || compareTypes(sourceReturnType, targetReturnType, reportErrors); } @@ -9062,6 +9072,13 @@ namespace ts { (isTypeSubsetOf(globalObjectType, target) || (!isComparingJsxAttributes && isEmptyObjectType(target)))) { return false; } + if (target.flags & TypeFlags.Union) { + const discriminantType = findMatchingDiscriminantType(source, target as UnionType); + if (discriminantType) { + // check excess properties against discriminant type only, not the entire union + return hasExcessProperties(source, discriminantType, reportErrors); + } + } for (const prop of getPropertiesOfObjectType(source)) { if (!isKnownProperty(target, prop.escapedName, isComparingJsxAttributes)) { if (reportErrors) { @@ -9138,20 +9155,24 @@ namespace ts { } function findMatchingDiscriminantType(source: Type, target: UnionOrIntersectionType) { + let match: Type; const sourceProperties = getPropertiesOfObjectType(source); if (sourceProperties) { - for (const sourceProperty of sourceProperties) { - if (isDiscriminantProperty(target, sourceProperty.escapedName)) { - const sourceType = getTypeOfSymbol(sourceProperty); - for (const type of target.types) { - const targetType = getTypeOfPropertyOfType(type, sourceProperty.escapedName); - if (targetType && isRelatedTo(sourceType, targetType)) { - return type; + const sourceProperty = findSingleDiscriminantProperty(sourceProperties, target); + if (sourceProperty) { + const sourceType = getTypeOfSymbol(sourceProperty); + for (const type of target.types) { + const targetType = getTypeOfPropertyOfType(type, sourceProperty.escapedName); + if (targetType && isRelatedTo(sourceType, targetType)) { + if (match) { + return undefined; } + match = type; } } } } + return match; } function typeRelatedToEachType(source: Type, target: IntersectionType, reportErrors: boolean): Ternary { @@ -9715,7 +9736,7 @@ namespace ts { */ function signatureRelatedTo(source: Signature, target: Signature, erase: boolean, reportErrors: boolean): Ternary { return compareSignaturesRelated(erase ? getErasedSignature(source) : source, erase ? getErasedSignature(target) : target, - /*checkAsCallback*/ false, /*ignoreReturnTypes*/ false, reportErrors, reportError, isRelatedTo); + CallbackCheck.None, /*ignoreReturnTypes*/ false, reportErrors, reportError, isRelatedTo); } function signaturesIdenticalTo(source: Type, target: Type, kind: SignatureKind): Ternary { @@ -11154,6 +11175,19 @@ namespace ts { return false; } + function findSingleDiscriminantProperty(sourceProperties: Symbol[], target: Type): Symbol | undefined { + let result: Symbol; + for (const sourceProperty of sourceProperties) { + if (isDiscriminantProperty(target, sourceProperty.escapedName)) { + if (result) { + return undefined; + } + result = sourceProperty; + } + } + return result; + } + function isOrContainsMatchingReference(source: Node, target: Node) { return isMatchingReference(source, target) || containsMatchingReference(source, target); } @@ -14796,11 +14830,7 @@ namespace ts { // where this references the constructor function object of a derived class, // a super property access is permitted and must specify a public static member function of the base class. if (languageVersion < ScriptTarget.ES2015) { - const hasNonMethodDeclaration = forEachProperty(prop, p => { - const propKind = getDeclarationKindFromSymbol(p); - return propKind !== SyntaxKind.MethodDeclaration && propKind !== SyntaxKind.MethodSignature; - }); - if (hasNonMethodDeclaration) { + if (symbolHasNonMethodDeclaration(prop)) { error(errorNode, Diagnostics.Only_public_and_protected_methods_of_the_base_class_are_accessible_via_the_super_keyword); return false; } @@ -14815,6 +14845,16 @@ namespace ts { } } + // Referencing Abstract Properties within Constructors is not allowed + if ((flags & ModifierFlags.Abstract) && symbolHasNonMethodDeclaration(prop)) { + const declaringClassDeclaration = getClassLikeDeclarationOfSymbol(getParentOfSymbol(prop)); + + if (declaringClassDeclaration && isNodeWithinConstructor(node, declaringClassDeclaration)) { + error(errorNode, Diagnostics.Abstract_property_0_in_class_1_cannot_be_accessed_in_the_constructor, symbolToString(prop), typeToString(getDeclaringClass(prop))); + return false; + } + } + // Public properties are otherwise accessible. if (!(flags & ModifierFlags.NonPublicAccessibilityModifier)) { return true; @@ -14866,6 +14906,13 @@ namespace ts { return true; } + function symbolHasNonMethodDeclaration(symbol: Symbol) { + return forEachProperty(symbol, prop => { + const propKind = getDeclarationKindFromSymbol(prop); + return propKind !== SyntaxKind.MethodDeclaration && propKind !== SyntaxKind.MethodSignature; + }); + } + function checkNonNullExpression(node: Expression | QualifiedName) { return checkNonNullType(checkExpression(node), node); } @@ -16548,6 +16595,12 @@ namespace ts { return resolveUntypedCall(node); } + if (isPotentiallyUncalledDecorator(node, callSignatures)) { + const nodeStr = getTextOfNode(node.expression, /*includeTrivia*/ false); + error(node, Diagnostics._0_accepts_too_few_arguments_to_be_used_as_a_decorator_here_Did_you_mean_to_call_it_first_and_write_0, nodeStr); + return resolveErrorCall(node); + } + const headMessage = getDiagnosticHeadMessageForDecoratorResolution(node); if (!callSignatures.length) { let errorInfo: DiagnosticMessageChain; @@ -16560,6 +16613,18 @@ namespace ts { return resolveCall(node, callSignatures, candidatesOutArray, headMessage); } + /** + * Sometimes, we have a decorator that could accept zero arguments, + * but is receiving too many arguments as part of the decorator invocation. + * In those cases, a user may have meant to *call* the expression before using it as a decorator. + */ + function isPotentiallyUncalledDecorator(decorator: Decorator, signatures: Signature[]) { + return signatures.length && every(signatures, signature => + signature.minArgumentCount === 0 && + !signature.hasRestParameter && + signature.parameters.length < getEffectiveArgumentCount(decorator, /*args*/ undefined, signature)); + } + /** * This function is similar to getResolvedSignature but is exclusively for trying to resolve JSX stateless-function component. * The main reason we have to use this function instead of getResolvedSignature because, the caller of this function will already check the type of openingLikeElement's tagName @@ -18433,9 +18498,8 @@ namespace ts { checkGrammarDecorators(node) || checkGrammarModifiers(node); checkVariableLikeDeclaration(node); - let func = getContainingFunction(node); + const func = getContainingFunction(node); if (hasModifier(node, ModifierFlags.ParameterPropertyModifier)) { - func = getContainingFunction(node); if (!(func.kind === SyntaxKind.Constructor && nodeIsPresent(func.body))) { error(node, Diagnostics.A_parameter_property_is_only_allowed_in_a_constructor_implementation); } @@ -19968,14 +20032,20 @@ namespace ts { } function checkJSDocAugmentsTag(node: JSDocAugmentsTag): void { - const cls = getJSDocHost(node); - if (!isClassDeclaration(cls) && !isClassExpression(cls)) { - error(cls, Diagnostics.JSDoc_augments_is_not_attached_to_a_class_declaration); + const classLike = getJSDocHost(node); + if (!isClassDeclaration(classLike) && !isClassExpression(classLike)) { + error(classLike, Diagnostics.JSDoc_augments_is_not_attached_to_a_class_declaration); return; } + const augmentsTags = getAllJSDocTagsOfKind(classLike, SyntaxKind.JSDocAugmentsTag); + Debug.assert(augmentsTags.length > 0); + if (augmentsTags.length > 1) { + error(augmentsTags[1], Diagnostics.Class_declarations_cannot_have_more_than_one_augments_or_extends_tag); + } + const name = getIdentifierFromEntityNameExpression(node.class.expression); - const extend = getClassExtendsHeritageClauseElement(cls); + const extend = getClassExtendsHeritageClauseElement(classLike); if (extend) { const className = getIdentifierFromEntityNameExpression(extend.expression); if (className && name.escapedText !== className.escapedText) { @@ -20251,7 +20321,7 @@ namespace ts { function checkCollisionWithArgumentsInGeneratedCode(node: SignatureDeclaration) { // no rest parameters \ declaration context \ overload - no codegen impact - if (!hasDeclaredRestParameter(node) || isInAmbientContext(node) || nodeIsMissing((node).body)) { + if (!hasRestParameter(node) || isInAmbientContext(node) || nodeIsMissing((node).body)) { return; } @@ -23092,6 +23162,19 @@ namespace ts { return result; } + function isNodeWithinConstructor(node: Node, classDeclaration: ClassLikeDeclaration) { + return findAncestor(node, element => { + if (isConstructorDeclaration(element) && nodeIsPresent(element.body)) { + return true; + } + else if (element === classDeclaration || isFunctionLikeDeclaration(element)) { + return "quit"; + } + + return false; + }); + } + function isNodeWithinClass(node: Node, classDeclaration: ClassLikeDeclaration) { return !!forEachEnclosingClass(node, n => n === classDeclaration); } diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 3b32ba174f1..91ad9e52bfd 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -907,6 +907,10 @@ "category": "Error", "code": 1328 }, + "'{0}' accepts too few arguments to be used as a decorator here. Did you mean to call it first and write '@{0}()'?": { + "category": "Error", + "code": 1329 + }, "Duplicate identifier '{0}'.": { "category": "Error", @@ -2216,6 +2220,10 @@ "category": "Error", "code": 2714 }, + "Abstract property '{0}' in class '{1}' cannot be accessed in the constructor.": { + "category": "Error", + "code": 2715 + }, "Import declaration '{0}' is using private name '{1}'.": { "category": "Error", @@ -3523,6 +3531,10 @@ "category": "Error", "code": 8024 }, + "Class declarations cannot have more than one `@augments` or `@extends` tag.": { + "category": "Error", + "code": 8025 + }, "Only identifiers/qualified-names with optional type arguments are currently supported in a class 'extends' clause.": { "category": "Error", "code": 9002 @@ -3705,6 +3717,10 @@ "category": "Message", "code": 90027 }, + "Call decorator expression.": { + "category": "Message", + "code": 90028 + }, "Convert function to an ES2015 class": { "category": "Message", diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts old mode 100755 new mode 100644 diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index ebdf390f5b2..e2bae71e6bf 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -6373,6 +6373,7 @@ namespace ts { if (tagName) { switch (tagName.escapedText) { case "augments": + case "extends": tag = parseAugmentsTag(atToken, tagName); break; case "class": @@ -6699,7 +6700,7 @@ namespace ts { if (typeExpression && typeExpression.type.kind === SyntaxKind.ArrayType) { jsdocTypeLiteral.isArrayType = true; } - typedefTag.typeExpression = childTypeTag && !isObjectOrObjectArrayTypeReference(childTypeTag.typeExpression.type) ? + typedefTag.typeExpression = childTypeTag && childTypeTag.typeExpression && !isObjectOrObjectArrayTypeReference(childTypeTag.typeExpression.type) ? childTypeTag.typeExpression : finishNode(jsdocTypeLiteral); } diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 24d7707f50d..82c4180c565 100755 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -1092,11 +1092,18 @@ namespace ts { return true; } - if (defaultLibraryPath && defaultLibraryPath.length !== 0) { - return containsPath(defaultLibraryPath, file.path, currentDirectory, /*ignoreCase*/ !host.useCaseSensitiveFileNames()); + if (!options.noLib) { + return false; } - return compareStrings(file.fileName, getDefaultLibraryFileName(), /*ignoreCase*/ !host.useCaseSensitiveFileNames()) === Comparison.EqualTo; + // If '--lib' is not specified, include default library file according to '--target' + // otherwise, using options specified in '--lib' instead of '--target' default library file + if (!options.lib) { + return compareStrings(file.fileName, getDefaultLibraryFileName(), /*ignoreCase*/ !host.useCaseSensitiveFileNames()) === Comparison.EqualTo; + } + else { + return forEach(options.lib, libFileName => compareStrings(file.fileName, combinePaths(defaultLibraryPath, libFileName), /*ignoreCase*/ !host.useCaseSensitiveFileNames()) === Comparison.EqualTo); + } } function getDiagnosticsProducingTypeChecker() { diff --git a/src/compiler/transformers/module/module.ts b/src/compiler/transformers/module/module.ts index 145ac07c2f2..ba262bf2c59 100644 --- a/src/compiler/transformers/module/module.ts +++ b/src/compiler/transformers/module/module.ts @@ -561,46 +561,89 @@ namespace ts { // }); const resolve = createUniqueName("resolve"); const reject = createUniqueName("reject"); - return createNew( - createIdentifier("Promise"), - /*typeArguments*/ undefined, - [createFunctionExpression( + const parameters = [ + createParameter(/*decorator*/ undefined, /*modifiers*/ undefined, /*dotDotDotToken*/ undefined, /*name*/ resolve), + createParameter(/*decorator*/ undefined, /*modifiers*/ undefined, /*dotDotDotToken*/ undefined, /*name*/ reject) + ]; + const body = createBlock([ + createStatement( + createCall( + createIdentifier("require"), + /*typeArguments*/ undefined, + [createArrayLiteral([firstOrUndefined(node.arguments) || createOmittedExpression()]), resolve, reject] + ) + ) + ]); + + let func: FunctionExpression | ArrowFunction; + if (languageVersion >= ScriptTarget.ES2015) { + func = createArrowFunction( + /*modifiers*/ undefined, + /*typeParameters*/ undefined, + parameters, + /*type*/ undefined, + /*equalsGreaterThanToken*/ undefined, + body); + } + else { + func = createFunctionExpression( /*modifiers*/ undefined, /*asteriskToken*/ undefined, /*name*/ undefined, /*typeParameters*/ undefined, - [createParameter(/*decorator*/ undefined, /*modifiers*/ undefined, /*dotDotDotToken*/ undefined, /*name*/ resolve), - createParameter(/*decorator*/ undefined, /*modifiers*/ undefined, /*dotDotDotToken*/ undefined, /*name*/ reject)], + parameters, /*type*/ undefined, - createBlock([createStatement( - createCall( - createIdentifier("require"), - /*typeArguments*/ undefined, - [createArrayLiteral([firstOrUndefined(node.arguments) || createOmittedExpression()]), resolve, reject] - ))]) - )]); + body); + + // if there is a lexical 'this' in the import call arguments, ensure we indicate + // that this new function expression indicates it captures 'this' so that the + // es2015 transformer will properly substitute 'this' with '_this'. + if (node.transformFlags & TransformFlags.ContainsLexicalThis) { + setEmitFlags(func, EmitFlags.CapturesThis); + } + } + + return createNew(createIdentifier("Promise"), /*typeArguments*/ undefined, [func]); } - function transformImportCallExpressionCommonJS(node: ImportCall): Expression { + function transformImportCallExpressionCommonJS(node: ImportCall): Expression { // import("./blah") // emit as // Promise.resolve().then(function () { return require(x); }) /*CommonJs Require*/ // We have to wrap require in then callback so that require is done in asynchronously // if we simply do require in resolve callback in Promise constructor. We will execute the loading immediately - return createCall( - createPropertyAccess( - createCall(createPropertyAccess(createIdentifier("Promise"), "resolve"), /*typeArguments*/ undefined, /*argumentsArray*/ []), - "then"), - /*typeArguments*/ undefined, - [createFunctionExpression( + const promiseResolveCall = createCall(createPropertyAccess(createIdentifier("Promise"), "resolve"), /*typeArguments*/ undefined, /*argumentsArray*/ []); + const requireCall = createCall(createIdentifier("require"), /*typeArguments*/ undefined, node.arguments); + + let func: FunctionExpression | ArrowFunction; + if (languageVersion >= ScriptTarget.ES2015) { + func = createArrowFunction( + /*modifiers*/ undefined, + /*typeParameters*/ undefined, + /*parameters*/ [], + /*type*/ undefined, + /*equalsGreaterThanToken*/ undefined, + requireCall); + } + else { + func = createFunctionExpression( /*modifiers*/ undefined, /*asteriskToken*/ undefined, /*name*/ undefined, /*typeParameters*/ undefined, - /*parameters*/ undefined, + /*parameters*/ [], /*type*/ undefined, - createBlock([createReturn(createCall(createIdentifier("require"), /*typeArguments*/ undefined, node.arguments))]) - )]); + createBlock([createReturn(requireCall)])); + + // if there is a lexical 'this' in the import call arguments, ensure we indicate + // that this new function expression indicates it captures 'this' so that the + // es2015 transformer will properly substitute 'this' with '_this'. + if (node.transformFlags & TransformFlags.ContainsLexicalThis) { + setEmitFlags(func, EmitFlags.CapturesThis); + } + } + + return createCall(createPropertyAccess(promiseResolveCall, "then"), /*typeArguments*/ undefined, [func]); } /** @@ -861,10 +904,10 @@ namespace ts { if (original && hasAssociatedEndOfDeclarationMarker(original)) { // Defer exports until we encounter an EndOfDeclarationMarker node const id = getOriginalNodeId(node); - deferredExports[id] = appendExportStatement(deferredExports[id], createIdentifier("default"), node.expression, /*location*/ node, /*allowComments*/ true); + deferredExports[id] = appendExportStatement(deferredExports[id], createIdentifier("default"), visitNode(node.expression, importCallExpressionVisitor), /*location*/ node, /*allowComments*/ true); } else { - statements = appendExportStatement(statements, createIdentifier("default"), node.expression, /*location*/ node, /*allowComments*/ true); + statements = appendExportStatement(statements, createIdentifier("default"), visitNode(node.expression, importCallExpressionVisitor), /*location*/ node, /*allowComments*/ true); } return singleOrMany(statements); diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 578c2d23c4f..67b8606df5e 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -2159,6 +2159,10 @@ namespace ts { kind: SyntaxKind.JSDocTag; } + /** + * Note that `@extends` is a synonym of `@augments`. + * Both tags are represented by this interface. + */ export interface JSDocAugmentsTag extends JSDocTag { kind: SyntaxKind.JSDocAugmentsTag; class: ExpressionWithTypeArguments & { expression: Identifier | PropertyAccessEntityNameExpression }; @@ -2194,7 +2198,7 @@ namespace ts { export interface JSDocPropertyLikeTag extends JSDocTag, Declaration { parent: JSDoc; name: EntityName; - typeExpression: JSDocTypeExpression; + typeExpression?: JSDocTypeExpression; /** Whether the property name came before the type -- non-standard for JSDoc, but Typescript-like */ isNameFirst: boolean; isBracketed: boolean; @@ -2649,6 +2653,10 @@ namespace ts { signatureToString(signature: Signature, enclosingDeclaration?: Node, flags?: TypeFormatFlags, kind?: SignatureKind): string; typeToString(type: Type, enclosingDeclaration?: Node, flags?: TypeFormatFlags): string; symbolToString(symbol: Symbol, enclosingDeclaration?: Node, meaning?: SymbolFlags): string; + /** + * @deprecated Use the createX factory functions or XToY typechecker methods and `createPrinter` or the `xToString` methods instead + * This will be removed in a future version. + */ getSymbolDisplayBuilder(): SymbolDisplayBuilder; getFullyQualifiedName(symbol: Symbol): string; getAugmentedPropertiesOfType(type: Type): Symbol[]; diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index f0eb394adb7..291e1f2fa66 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -1604,26 +1604,12 @@ namespace ts { } export function hasRestParameter(s: SignatureDeclaration): boolean { - return isRestParameter(lastOrUndefined(s.parameters)); + const last = lastOrUndefined(s.parameters); + return last && isRestParameter(last); } - export function hasDeclaredRestParameter(s: SignatureDeclaration): boolean { - return isDeclaredRestParam(lastOrUndefined(s.parameters)); - } - - export function isRestParameter(node: ParameterDeclaration) { - if (isInJavaScriptFile(node)) { - if (node.type && node.type.kind === SyntaxKind.JSDocVariadicType || - forEach(getJSDocParameterTags(node), - t => t.typeExpression && t.typeExpression.type.kind === SyntaxKind.JSDocVariadicType)) { - return true; - } - } - return isDeclaredRestParam(node); - } - - export function isDeclaredRestParam(node: ParameterDeclaration) { - return node && node.dotDotDotToken !== undefined; + export function isRestParameter(node: ParameterDeclaration): boolean { + return node.dotDotDotToken !== undefined; } export const enum AssignmentKind { @@ -4112,27 +4098,35 @@ namespace ts { if (!declaration) { return undefined; } - if (isJSDocPropertyLikeTag(declaration) && declaration.name.kind === SyntaxKind.QualifiedName) { - return declaration.name.right; - } - if (declaration.kind === SyntaxKind.BinaryExpression) { - const expr = declaration as BinaryExpression; - switch (getSpecialPropertyAssignmentKind(expr)) { - case SpecialPropertyAssignmentKind.ExportsProperty: - case SpecialPropertyAssignmentKind.ThisProperty: - case SpecialPropertyAssignmentKind.Property: - case SpecialPropertyAssignmentKind.PrototypeProperty: - return (expr.left as PropertyAccessExpression).name; - default: - return undefined; + switch (declaration.kind) { + case SyntaxKind.JSDocPropertyTag: + case SyntaxKind.JSDocParameterTag: { + const { name } = declaration as JSDocPropertyLikeTag; + if (name.kind === SyntaxKind.QualifiedName) { + return name.right; + } + break; + } + case SyntaxKind.BinaryExpression: { + const expr = declaration as BinaryExpression; + switch (getSpecialPropertyAssignmentKind(expr)) { + case SpecialPropertyAssignmentKind.ExportsProperty: + case SpecialPropertyAssignmentKind.ThisProperty: + case SpecialPropertyAssignmentKind.Property: + case SpecialPropertyAssignmentKind.PrototypeProperty: + return (expr.left as PropertyAccessExpression).name; + default: + return undefined; + } + } + case SyntaxKind.JSDocTypedefTag: + return getNameOfJSDocTypedef(declaration as JSDocTypedefTag); + case SyntaxKind.ExportAssignment: { + const { expression } = declaration as ExportAssignment; + return isIdentifier(expression) ? expression : undefined; } } - else if (declaration.kind === SyntaxKind.JSDocTypedefTag) { - return getNameOfJSDocTypedef(declaration as JSDocTypedefTag); - } - else { - return (declaration as NamedDeclaration).name; - } + return (declaration as NamedDeclaration).name; } /** @@ -4247,6 +4241,12 @@ namespace ts { return find(tags, doc => doc.kind === kind); } + /** Gets all JSDoc tags of a specified kind, or undefined if not present. */ + export function getAllJSDocTagsOfKind(node: Node, kind: SyntaxKind): ReadonlyArray | undefined { + const tags = getJSDocTags(node); + return filter(tags, doc => doc.kind === kind); + } + } // Simple node tests of the form `node.kind === SyntaxKind.Foo`. diff --git a/src/compiler/watch.ts b/src/compiler/watch.ts index 779efb62c46..2ab3ccc5ce6 100644 --- a/src/compiler/watch.ts +++ b/src/compiler/watch.ts @@ -249,10 +249,10 @@ namespace ts { let hasChangedAutomaticTypeDirectiveNames = false; // True if the automatic type directives have changed const loggingEnabled = compilerOptions.diagnostics || compilerOptions.extendedDiagnostics; - const writeLog: (s: string) => void = loggingEnabled ? s => system.write(s) : noop; - const watchFile = loggingEnabled ? ts.addFileWatcherWithLogging : ts.addFileWatcher; - const watchFilePath = loggingEnabled ? ts.addFilePathWatcherWithLogging : ts.addFilePathWatcher; - const watchDirectoryWorker = loggingEnabled ? ts.addDirectoryWatcherWithLogging : ts.addDirectoryWatcher; + const writeLog: (s: string) => void = loggingEnabled ? s => { system.write(s); system.write(system.newLine); } : noop; + const watchFile = compilerOptions.extendedDiagnostics ? ts.addFileWatcherWithLogging : loggingEnabled ? ts.addFileWatcherWithOnlyTriggerLogging : ts.addFileWatcher; + const watchFilePath = compilerOptions.extendedDiagnostics ? ts.addFilePathWatcherWithLogging : ts.addFilePathWatcher; + const watchDirectoryWorker = compilerOptions.extendedDiagnostics ? ts.addDirectoryWatcherWithLogging : ts.addDirectoryWatcher; watchingHost = watchingHost || createWatchingSystemHost(compilerOptions.pretty); const { system, parseConfigFile, reportDiagnostic, reportWatchDiagnostic, beforeCompile, afterCompile } = watchingHost; diff --git a/src/compiler/watchUtilities.ts b/src/compiler/watchUtilities.ts index de415293954..26bf689401a 100644 --- a/src/compiler/watchUtilities.ts +++ b/src/compiler/watchUtilities.ts @@ -82,7 +82,12 @@ namespace ts { export function addFileWatcherWithLogging(host: System, file: string, cb: FileWatcherCallback, log: (s: string) => void): FileWatcher { const watcherCaption = `FileWatcher:: `; - return createWatcherWithLogging(addFileWatcher, watcherCaption, log, host, file, cb); + return createWatcherWithLogging(addFileWatcher, watcherCaption, log, /*logOnlyTrigger*/ false, host, file, cb); + } + + export function addFileWatcherWithOnlyTriggerLogging(host: System, file: string, cb: FileWatcherCallback, log: (s: string) => void): FileWatcher { + const watcherCaption = `FileWatcher:: `; + return createWatcherWithLogging(addFileWatcher, watcherCaption, log, /*logOnlyTrigger*/ true, host, file, cb); } export type FilePathWatcherCallback = (fileName: string, eventKind: FileWatcherEventKind, filePath: Path) => void; @@ -92,7 +97,12 @@ namespace ts { export function addFilePathWatcherWithLogging(host: System, file: string, cb: FilePathWatcherCallback, path: Path, log: (s: string) => void): FileWatcher { const watcherCaption = `FileWatcher:: `; - return createWatcherWithLogging(addFileWatcher, watcherCaption, log, host, file, cb, path); + return createWatcherWithLogging(addFileWatcher, watcherCaption, log, /*logOnlyTrigger*/ false, host, file, cb, path); + } + + export function addFilePathWatcherWithOnlyTriggerLogging(host: System, file: string, cb: FilePathWatcherCallback, path: Path, log: (s: string) => void): FileWatcher { + const watcherCaption = `FileWatcher:: `; + return createWatcherWithLogging(addFileWatcher, watcherCaption, log, /*logOnlyTrigger*/ true, host, file, cb, path); } export function addDirectoryWatcher(host: System, directory: string, cb: DirectoryWatcherCallback, flags: WatchDirectoryFlags): FileWatcher { @@ -102,14 +112,21 @@ namespace ts { export function addDirectoryWatcherWithLogging(host: System, directory: string, cb: DirectoryWatcherCallback, flags: WatchDirectoryFlags, log: (s: string) => void): FileWatcher { const watcherCaption = `DirectoryWatcher ${(flags & WatchDirectoryFlags.Recursive) !== 0 ? "recursive" : ""}:: `; - return createWatcherWithLogging(addDirectoryWatcher, watcherCaption, log, host, directory, cb, flags); + return createWatcherWithLogging(addDirectoryWatcher, watcherCaption, log, /*logOnlyTrigger*/ false, host, directory, cb, flags); + } + + export function addDirectoryWatcherWithOnlyTriggerLogging(host: System, directory: string, cb: DirectoryWatcherCallback, flags: WatchDirectoryFlags, log: (s: string) => void): FileWatcher { + const watcherCaption = `DirectoryWatcher ${(flags & WatchDirectoryFlags.Recursive) !== 0 ? "recursive" : ""}:: `; + return createWatcherWithLogging(addDirectoryWatcher, watcherCaption, log, /*logOnlyTrigger*/ true, host, directory, cb, flags); } type WatchCallback = (fileName: string, cbOptional1?: T, optional?: U) => void; type AddWatch = (host: System, file: string, cb: WatchCallback, optional?: U) => FileWatcher; - function createWatcherWithLogging(addWatch: AddWatch, watcherCaption: string, log: (s: string) => void, host: System, file: string, cb: WatchCallback, optional?: U): FileWatcher { + function createWatcherWithLogging(addWatch: AddWatch, watcherCaption: string, log: (s: string) => void, logOnlyTrigger: boolean, host: System, file: string, cb: WatchCallback, optional?: U): FileWatcher { const info = `PathInfo: ${file}`; - log(`${watcherCaption}Added: ${info}`); + if (!logOnlyTrigger) { + log(`${watcherCaption}Added: ${info}`); + } const watcher = addWatch(host, file, (fileName, cbOptional1?) => { const optionalInfo = cbOptional1 !== undefined ? ` ${cbOptional1}` : ""; log(`${watcherCaption}Trigger: ${fileName}${optionalInfo} ${info}`); @@ -120,7 +137,9 @@ namespace ts { }, optional); return { close: () => { - log(`${watcherCaption}Close: ${info}`); + if (!logOnlyTrigger) { + log(`${watcherCaption}Close: ${info}`); + } watcher.close(); } }; diff --git a/src/harness/unittests/compileOnSave.ts b/src/harness/unittests/compileOnSave.ts index 4ddda5fcbea..1e765054eee 100644 --- a/src/harness/unittests/compileOnSave.ts +++ b/src/harness/unittests/compileOnSave.ts @@ -563,7 +563,7 @@ namespace ts.projectSystem { path: "/a/b/file3.js", content: "console.log('file3');" }; - const externalProjectName = "externalproject"; + const externalProjectName = "/a/b/externalproject"; const host = createServerHost([file1, file2, file3, libFile]); const session = createSession(host); const projectService = session.getProjectService(); @@ -588,5 +588,48 @@ namespace ts.projectSystem { assert.isTrue(outFileContent.indexOf(file2.content) === -1); assert.isTrue(outFileContent.indexOf(file3.content) === -1); }); + + it("should use project root as current directory so that compile on save results in correct file mapping", () => { + const inputFileName = "Foo.ts"; + const file1 = { + path: `/root/TypeScriptProject3/TypeScriptProject3/${inputFileName}`, + content: "consonle.log('file1');" + }; + const externalProjectName = "/root/TypeScriptProject3/TypeScriptProject3/TypeScriptProject3.csproj"; + const host = createServerHost([file1, libFile]); + const session = createSession(host); + const projectService = session.getProjectService(); + + const outFileName = "bar.js"; + projectService.openExternalProject({ + rootFiles: toExternalFiles([file1.path]), + options: { + outFile: outFileName, + sourceMap: true, + compileOnSave: true + }, + projectFileName: externalProjectName + }); + + const emitRequest = makeSessionRequest(CommandNames.CompileOnSaveEmitFile, { file: file1.path }); + session.executeCommand(emitRequest); + + // Verify js file + const expectedOutFileName = "/root/TypeScriptProject3/TypeScriptProject3/" + outFileName; + assert.isTrue(host.fileExists(expectedOutFileName)); + const outFileContent = host.readFile(expectedOutFileName); + verifyContentHasString(outFileContent, file1.content); + verifyContentHasString(outFileContent, `//# sourceMappingURL=${outFileName}.map`); + + // Verify map file + const expectedMapFileName = expectedOutFileName + ".map"; + assert.isTrue(host.fileExists(expectedMapFileName)); + const mapFileContent = host.readFile(expectedMapFileName); + verifyContentHasString(mapFileContent, `"sources":["${inputFileName}"]`); + + function verifyContentHasString(content: string, string: string) { + assert.isTrue(content.indexOf(string) !== -1, `Expected "${content}" to have "${string}"`); + } + }); }); } diff --git a/src/harness/unittests/publicApi.ts b/src/harness/unittests/publicApi.ts index bb37dbe9d8d..35acfec57f5 100644 --- a/src/harness/unittests/publicApi.ts +++ b/src/harness/unittests/publicApi.ts @@ -1,10 +1,34 @@ /// describe("Public APIs", () => { - it("for the language service and compiler should be acknowledged when they change", () => { - Harness.Baseline.runBaseline("api/typescript.d.ts", () => Harness.IO.readFile("built/local/typescript.d.ts")); + function verifyApi(fileName: string) { + const builtFile = `built/local/${fileName}`; + const api = `api/${fileName}`; + let fileContent: string; + before(() => { + fileContent = Harness.IO.readFile(builtFile); + }); + + it("should be acknowledged when they change", () => { + Harness.Baseline.runBaseline(api, () => fileContent); + }); + + it("should compile", () => { + const testFile: Harness.Compiler.TestFile = { + unitName: builtFile, + content: fileContent + }; + const inputFiles = [testFile]; + const output = Harness.Compiler.compileFiles(inputFiles, [], /*harnessSettings*/ undefined, /*options*/ {}, /*currentDirectory*/ undefined); + assert(!output.result.errors || !output.result.errors.length, Harness.Compiler.minimalDiagnosticsToString(output.result.errors, /*pretty*/ true)); + }); + } + + describe("for the language service and compiler", () => { + verifyApi("typescript.d.ts"); }); - it("for the language server should be acknowledged when they change", () => { - Harness.Baseline.runBaseline("api/tsserverlibrary.d.ts", () => Harness.IO.readFile("built/local/tsserverlibrary.d.ts")); + + describe("for the language server", () => { + verifyApi("tsserverlibrary.d.ts"); }); -}); \ No newline at end of file +}); diff --git a/src/harness/unittests/session.ts b/src/harness/unittests/session.ts index 1e5d9847ce8..3b5efc2d6de 100644 --- a/src/harness/unittests/session.ts +++ b/src/harness/unittests/session.ts @@ -16,8 +16,8 @@ namespace ts.server { directoryExists: () => false, getDirectories: () => [], createDirectory: noop, - getExecutingFilePath(): string { return void 0; }, - getCurrentDirectory(): string { return void 0; }, + getExecutingFilePath(): string { return ""; }, + getCurrentDirectory(): string { return ""; }, getEnvironmentVariable(): string { return ""; }, readDirectory() { return []; }, exit: noop, @@ -386,6 +386,61 @@ namespace ts.server { }); }); + describe("exceptions", () => { + const command = "testhandler"; + class TestSession extends Session { + lastSent: protocol.Message; + private exceptionRaisingHandler(_request: protocol.Request): { response?: any, responseRequired: boolean } { + f1(); + return; + function f1() { + throw new Error("myMessage"); + } + } + + constructor() { + super({ + host: mockHost, + cancellationToken: nullCancellationToken, + useSingleInferredProject: false, + useInferredProjectPerProjectRoot: false, + typingsInstaller: undefined, + byteLength: Utils.byteLength, + hrtime: process.hrtime, + logger: projectSystem.nullLogger, + canUseEvents: true + }); + this.addProtocolHandler(command, this.exceptionRaisingHandler); + } + send(msg: protocol.Message) { + this.lastSent = msg; + } + } + + it("raised in a protocol handler generate an event", () => { + + const session = new TestSession(); + + const request = { + command, + seq: 0, + type: "request" + }; + + session.onMessage(JSON.stringify(request)); + const lastSent = session.lastSent as protocol.Response; + + expect(lastSent).to.contain({ + seq: 0, + type: "response", + command, + success: false + }); + + expect(lastSent.message).has.string("myMessage").and.has.string("f1"); + }); + }); + describe("how Session is extendable via subclassing", () => { class TestSession extends Session { lastSent: protocol.Message; diff --git a/src/harness/unittests/tsserverProjectSystem.ts b/src/harness/unittests/tsserverProjectSystem.ts index e8b18ea3b54..3d244fd30f8 100644 --- a/src/harness/unittests/tsserverProjectSystem.ts +++ b/src/harness/unittests/tsserverProjectSystem.ts @@ -352,8 +352,6 @@ namespace ts.projectSystem { verifyDiagnostics(actual, []); } - const typeRootFromTsserverLocation = "/node_modules/@types"; - export function getTypeRootsFromLocation(currentDirectory: string) { currentDirectory = normalizePath(currentDirectory); const result: string[] = []; @@ -401,7 +399,7 @@ namespace ts.projectSystem { const configFiles = flatMap(configFileLocations, location => [location + "tsconfig.json", location + "jsconfig.json"]); checkWatchedFiles(host, configFiles.concat(libFile.path, moduleFile.path)); checkWatchedDirectories(host, [], /*recursive*/ false); - checkWatchedDirectories(host, ["/a/b/c", typeRootFromTsserverLocation], /*recursive*/ true); + checkWatchedDirectories(host, ["/a/b/c", ...getTypeRootsFromLocation(getDirectoryPath(appFile.path))], /*recursive*/ true); }); it("can handle tsconfig file name with difference casing", () => { @@ -4394,7 +4392,7 @@ namespace ts.projectSystem { function verifyCalledOnEachEntry(callback: CalledMaps, expectedKeys: Map) { const calledMap = calledMaps[callback]; - assert.equal(calledMap.size, expectedKeys.size, `${callback}: incorrect size of map: Actual keys: ${arrayFrom(calledMap.keys())} Expected: ${arrayFrom(expectedKeys.keys())}`); + ts.TestFSWithWatch.verifyMapSize(callback, calledMap, arrayFrom(expectedKeys.keys())); expectedKeys.forEach((called, name) => { assert.isTrue(calledMap.has(name), `${callback} is expected to contain ${name}, actual keys: ${arrayFrom(calledMap.keys())}`); assert.equal(calledMap.get(name).length, called, `${callback} is expected to be called ${called} times with ${name}. Actual entry: ${calledMap.get(name)}`); @@ -4476,6 +4474,7 @@ namespace ts.projectSystem { } const f2Lookups = getLocationsForModuleLookup("f2"); callsTrackingHost.verifyCalledOnEachEntryNTimes(CalledMapsWithSingleArg.fileExists, f2Lookups, 1); + const typeRootLocations = getTypeRootsFromLocation(getDirectoryPath(root.path)); const f2DirLookups = getLocationsForDirectoryLookup(); callsTrackingHost.verifyCalledOnEachEntry(CalledMapsWithSingleArg.directoryExists, f2DirLookups); callsTrackingHost.verifyNoCall(CalledMapsWithSingleArg.getDirectories); @@ -4486,7 +4485,7 @@ namespace ts.projectSystem { verifyImportedDiagnostics(); const f1Lookups = f2Lookups.map(s => s.replace("f2", "f1")); f1Lookups.length = f1Lookups.indexOf(imported.path) + 1; - const f1DirLookups = ["/c/d", "/c", typeRootFromTsserverLocation]; + const f1DirLookups = ["/c/d", "/c", ...typeRootLocations]; vertifyF1Lookups(); // setting compiler options discards module resolution cache @@ -4538,7 +4537,7 @@ namespace ts.projectSystem { function getLocationsForDirectoryLookup() { const result = createMap(); // Type root - result.set(typeRootFromTsserverLocation, 1); + typeRootLocations.forEach(location => result.set(location, 1)); forEachAncestorDirectory(getDirectoryPath(root.path), ancestor => { // To resolve modules result.set(ancestor, 2); diff --git a/src/harness/virtualFileSystemWithWatch.ts b/src/harness/virtualFileSystemWithWatch.ts index c16f57235e4..ff782bbf7d2 100644 --- a/src/harness/virtualFileSystemWithWatch.ts +++ b/src/harness/virtualFileSystemWithWatch.ts @@ -95,7 +95,7 @@ namespace ts.TestFSWithWatch { } } - function getDiffInKeys(map: Map, expectedKeys: ReadonlyArray) { + function getDiffInKeys(map: Map, expectedKeys: ReadonlyArray) { if (map.size === expectedKeys.length) { return ""; } @@ -122,8 +122,12 @@ namespace ts.TestFSWithWatch { return `\n\nNotInActual: ${notInActual}\nDuplicates: ${duplicates}\nInActualButNotInExpected: ${inActualNotExpected}`; } - function checkMapKeys(caption: string, map: Map, expectedKeys: ReadonlyArray) { + export function verifyMapSize(caption: string, map: Map, expectedKeys: ReadonlyArray) { assert.equal(map.size, expectedKeys.length, `${caption}: incorrect size of map: Actual keys: ${arrayFrom(map.keys())} Expected: ${expectedKeys}${getDiffInKeys(map, expectedKeys)}`); + } + + function checkMapKeys(caption: string, map: Map, expectedKeys: ReadonlyArray) { + verifyMapSize(caption, map, expectedKeys); for (const name of expectedKeys) { assert.isTrue(map.has(name), `${caption} is expected to contain ${name}, actual keys: ${arrayFrom(map.keys())}`); } @@ -548,7 +552,7 @@ namespace ts.TestFSWithWatch { const folder = this.toFolder(directoryName); // base folder has to be present - const base = getDirectoryPath(folder.fullPath); + const base = getDirectoryPath(folder.path); const baseFolder = this.fs.get(base) as Folder; Debug.assert(isFolder(baseFolder)); @@ -560,7 +564,7 @@ namespace ts.TestFSWithWatch { const file = this.toFile({ path, content }); // base folder has to be present - const base = getDirectoryPath(file.fullPath); + const base = getDirectoryPath(file.path); const folder = this.fs.get(base) as Folder; Debug.assert(isFolder(folder)); diff --git a/src/lib/es2015.core.d.ts b/src/lib/es2015.core.d.ts index 5c2438d9052..9ea773e3eef 100644 --- a/src/lib/es2015.core.d.ts +++ b/src/lib/es2015.core.d.ts @@ -10,6 +10,7 @@ interface Array { * @param thisArg If provided, it will be used as the this value for each invocation of * predicate. If it is not provided, undefined is used instead. */ + find(predicate: (this: void, value: T, index: number, obj: T[]) => value is S, thisArg?: any): S | undefined; find(predicate: (value: T, index: number, obj: T[]) => boolean, thisArg?: any): T | undefined; /** @@ -350,6 +351,7 @@ interface ReadonlyArray { * @param thisArg If provided, it will be used as the this value for each invocation of * predicate. If it is not provided, undefined is used instead. */ + find(predicate: (this: void, value: T, index: number, obj: ReadonlyArray) => value is S, thisArg?: any): S | undefined; find(predicate: (value: T, index: number, obj: ReadonlyArray) => boolean, thisArg?: any): T | undefined; /** diff --git a/src/lib/es2017.object.d.ts b/src/lib/es2017.object.d.ts index 1d8a52da758..4014e8c2927 100644 --- a/src/lib/es2017.object.d.ts +++ b/src/lib/es2017.object.d.ts @@ -3,7 +3,7 @@ interface ObjectConstructor { * Returns an array of values of the enumerable properties of an object * @param o Object that contains the properties and methods. This can be an object that you created or an existing Document Object Model (DOM) object. */ - values(o: { [s: string]: T }): T[]; + values(o: { [s: string]: T } | { [n: number]: T }): T[]; /** * Returns an array of values of the enumerable properties of an object @@ -15,7 +15,7 @@ interface ObjectConstructor { * Returns an array of key/values of the enumerable properties of an object * @param o Object that contains the properties and methods. This can be an object that you created or an existing Document Object Model (DOM) object. */ - entries(o: { [s: string]: T }): [string, T][]; + entries(o: { [s: string]: T } | { [n: number]: T }): [string, T][]; /** * Returns an array of key/values of the enumerable properties of an object diff --git a/src/lib/es5.d.ts b/src/lib/es5.d.ts index e08534d8ba9..fd2ae5b3fdf 100644 --- a/src/lib/es5.d.ts +++ b/src/lib/es5.d.ts @@ -1050,7 +1050,8 @@ interface ReadonlyArray { * @param callbackfn A function that accepts up to four arguments. The reduce method calls the callbackfn function one time for each element in the array. * @param initialValue If initialValue is specified, it is used as the initial value to start the accumulation. The first call to the callbackfn function provides this value as an argument instead of an array value. */ - reduce(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: ReadonlyArray) => T, initialValue?: T): T; + reduce(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: ReadonlyArray) => T): T; + reduce(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: ReadonlyArray) => T, initialValue: T): T; /** * Calls the specified callback function for all the elements in an array. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function. * @param callbackfn A function that accepts up to four arguments. The reduce method calls the callbackfn function one time for each element in the array. @@ -1062,7 +1063,8 @@ interface ReadonlyArray { * @param callbackfn A function that accepts up to four arguments. The reduceRight method calls the callbackfn function one time for each element in the array. * @param initialValue If initialValue is specified, it is used as the initial value to start the accumulation. The first call to the callbackfn function provides this value as an argument instead of an array value. */ - reduceRight(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: ReadonlyArray) => T, initialValue?: T): T; + reduceRight(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: ReadonlyArray) => T): T; + reduceRight(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: ReadonlyArray) => T, initialValue: T): T; /** * Calls the specified callback function for all the elements in an array, in descending order. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function. * @param callbackfn A function that accepts up to four arguments. The reduceRight method calls the callbackfn function one time for each element in the array. @@ -1200,7 +1202,8 @@ interface Array { * @param callbackfn A function that accepts up to four arguments. The reduce method calls the callbackfn function one time for each element in the array. * @param initialValue If initialValue is specified, it is used as the initial value to start the accumulation. The first call to the callbackfn function provides this value as an argument instead of an array value. */ - reduce(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T, initialValue?: T): T; + reduce(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T): T; + reduce(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T, initialValue: T): T; /** * Calls the specified callback function for all the elements in an array. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function. * @param callbackfn A function that accepts up to four arguments. The reduce method calls the callbackfn function one time for each element in the array. @@ -1212,7 +1215,8 @@ interface Array { * @param callbackfn A function that accepts up to four arguments. The reduceRight method calls the callbackfn function one time for each element in the array. * @param initialValue If initialValue is specified, it is used as the initial value to start the accumulation. The first call to the callbackfn function provides this value as an argument instead of an array value. */ - reduceRight(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T, initialValue?: T): T; + reduceRight(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T): T; + reduceRight(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T, initialValue: T): T; /** * Calls the specified callback function for all the elements in an array, in descending order. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function. * @param callbackfn A function that accepts up to four arguments. The reduceRight method calls the callbackfn function one time for each element in the array. @@ -1647,7 +1651,8 @@ interface Int8Array { * the accumulation. The first call to the callbackfn function provides this value as an argument * instead of an array value. */ - reduce(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: Int8Array) => number, initialValue?: number): number; + reduce(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: Int8Array) => number): number; + reduce(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: Int8Array) => number, initialValue: number): number; /** * Calls the specified callback function for all the elements in an array. The return value of @@ -1671,7 +1676,8 @@ interface Int8Array { * the accumulation. The first call to the callbackfn function provides this value as an * argument instead of an array value. */ - reduceRight(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: Int8Array) => number, initialValue?: number): number; + reduceRight(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: Int8Array) => number): number; + reduceRight(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: Int8Array) => number, initialValue: number): number; /** * Calls the specified callback function for all the elements in an array, in descending order. @@ -1914,7 +1920,8 @@ interface Uint8Array { * the accumulation. The first call to the callbackfn function provides this value as an argument * instead of an array value. */ - reduce(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: Uint8Array) => number, initialValue?: number): number; + reduce(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: Uint8Array) => number): number; + reduce(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: Uint8Array) => number, initialValue: number): number; /** * Calls the specified callback function for all the elements in an array. The return value of @@ -1938,7 +1945,8 @@ interface Uint8Array { * the accumulation. The first call to the callbackfn function provides this value as an * argument instead of an array value. */ - reduceRight(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: Uint8Array) => number, initialValue?: number): number; + reduceRight(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: Uint8Array) => number): number; + reduceRight(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: Uint8Array) => number, initialValue: number): number; /** * Calls the specified callback function for all the elements in an array, in descending order. @@ -2181,7 +2189,8 @@ interface Uint8ClampedArray { * the accumulation. The first call to the callbackfn function provides this value as an argument * instead of an array value. */ - reduce(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: Uint8ClampedArray) => number, initialValue?: number): number; + reduce(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: Uint8ClampedArray) => number): number; + reduce(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: Uint8ClampedArray) => number, initialValue: number): number; /** * Calls the specified callback function for all the elements in an array. The return value of @@ -2205,7 +2214,8 @@ interface Uint8ClampedArray { * the accumulation. The first call to the callbackfn function provides this value as an * argument instead of an array value. */ - reduceRight(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: Uint8ClampedArray) => number, initialValue?: number): number; + reduceRight(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: Uint8ClampedArray) => number): number; + reduceRight(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: Uint8ClampedArray) => number, initialValue: number): number; /** * Calls the specified callback function for all the elements in an array, in descending order. @@ -2446,7 +2456,8 @@ interface Int16Array { * the accumulation. The first call to the callbackfn function provides this value as an argument * instead of an array value. */ - reduce(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: Int16Array) => number, initialValue?: number): number; + reduce(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: Int16Array) => number): number; + reduce(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: Int16Array) => number, initialValue: number): number; /** * Calls the specified callback function for all the elements in an array. The return value of @@ -2470,7 +2481,8 @@ interface Int16Array { * the accumulation. The first call to the callbackfn function provides this value as an * argument instead of an array value. */ - reduceRight(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: Int16Array) => number, initialValue?: number): number; + reduceRight(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: Int16Array) => number): number; + reduceRight(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: Int16Array) => number, initialValue: number): number; /** * Calls the specified callback function for all the elements in an array, in descending order. @@ -2714,7 +2726,8 @@ interface Uint16Array { * the accumulation. The first call to the callbackfn function provides this value as an argument * instead of an array value. */ - reduce(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: Uint16Array) => number, initialValue?: number): number; + reduce(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: Uint16Array) => number): number; + reduce(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: Uint16Array) => number, initialValue: number): number; /** * Calls the specified callback function for all the elements in an array. The return value of @@ -2738,7 +2751,8 @@ interface Uint16Array { * the accumulation. The first call to the callbackfn function provides this value as an * argument instead of an array value. */ - reduceRight(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: Uint16Array) => number, initialValue?: number): number; + reduceRight(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: Uint16Array) => number): number; + reduceRight(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: Uint16Array) => number, initialValue: number): number; /** * Calls the specified callback function for all the elements in an array, in descending order. @@ -2981,7 +2995,8 @@ interface Int32Array { * the accumulation. The first call to the callbackfn function provides this value as an argument * instead of an array value. */ - reduce(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: Int32Array) => number, initialValue?: number): number; + reduce(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: Int32Array) => number): number; + reduce(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: Int32Array) => number, initialValue: number): number; /** * Calls the specified callback function for all the elements in an array. The return value of @@ -3005,7 +3020,8 @@ interface Int32Array { * the accumulation. The first call to the callbackfn function provides this value as an * argument instead of an array value. */ - reduceRight(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: Int32Array) => number, initialValue?: number): number; + reduceRight(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: Int32Array) => number): number; + reduceRight(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: Int32Array) => number, initialValue: number): number; /** * Calls the specified callback function for all the elements in an array, in descending order. @@ -3247,7 +3263,8 @@ interface Uint32Array { * the accumulation. The first call to the callbackfn function provides this value as an argument * instead of an array value. */ - reduce(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: Uint32Array) => number, initialValue?: number): number; + reduce(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: Uint32Array) => number): number; + reduce(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: Uint32Array) => number, initialValue: number): number; /** * Calls the specified callback function for all the elements in an array. The return value of @@ -3271,7 +3288,8 @@ interface Uint32Array { * the accumulation. The first call to the callbackfn function provides this value as an * argument instead of an array value. */ - reduceRight(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: Uint32Array) => number, initialValue?: number): number; + reduceRight(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: Uint32Array) => number): number; + reduceRight(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: Uint32Array) => number, initialValue: number): number; /** * Calls the specified callback function for all the elements in an array, in descending order. @@ -3514,7 +3532,8 @@ interface Float32Array { * the accumulation. The first call to the callbackfn function provides this value as an argument * instead of an array value. */ - reduce(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: Float32Array) => number, initialValue?: number): number; + reduce(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: Float32Array) => number): number; + reduce(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: Float32Array) => number, initialValue: number): number; /** * Calls the specified callback function for all the elements in an array. The return value of @@ -3538,7 +3557,8 @@ interface Float32Array { * the accumulation. The first call to the callbackfn function provides this value as an * argument instead of an array value. */ - reduceRight(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: Float32Array) => number, initialValue?: number): number; + reduceRight(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: Float32Array) => number): number; + reduceRight(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: Float32Array) => number, initialValue: number): number; /** * Calls the specified callback function for all the elements in an array, in descending order. @@ -3782,7 +3802,8 @@ interface Float64Array { * the accumulation. The first call to the callbackfn function provides this value as an argument * instead of an array value. */ - reduce(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: Float64Array) => number, initialValue?: number): number; + reduce(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: Float64Array) => number): number; + reduce(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: Float64Array) => number, initialValue: number): number; /** * Calls the specified callback function for all the elements in an array. The return value of @@ -3806,7 +3827,8 @@ interface Float64Array { * the accumulation. The first call to the callbackfn function provides this value as an * argument instead of an array value. */ - reduceRight(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: Float64Array) => number, initialValue?: number): number; + reduceRight(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: Float64Array) => number): number; + reduceRight(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: Float64Array) => number, initialValue: number): number; /** * Calls the specified callback function for all the elements in an array, in descending order. diff --git a/src/server/editorServices.ts b/src/server/editorServices.ts index 32358ba3c4c..fd229747390 100644 --- a/src/server/editorServices.ts +++ b/src/server/editorServices.ts @@ -403,7 +403,7 @@ namespace ts.server { this.globalPlugins = opts.globalPlugins || emptyArray; this.pluginProbeLocations = opts.pluginProbeLocations || emptyArray; this.allowLocalPluginLoads = !!opts.allowLocalPluginLoads; - this.typesMapLocation = (opts.typesMapLocation === undefined) ? combinePaths(this.host.getExecutingFilePath(), "../typesMap.json") : opts.typesMapLocation; + this.typesMapLocation = (opts.typesMapLocation === undefined) ? combinePaths(this.getExecutingFilePath(), "../typesMap.json") : opts.typesMapLocation; Debug.assert(!!this.host.createHash, "'ServerHost.createHash' is required for ProjectService"); @@ -431,6 +431,11 @@ namespace ts.server { this.watchFilePath = (host, file, cb, path, watchType, project) => ts.addFilePathWatcherWithLogging(host, file, cb, path, this.createWatcherLog(watchType, project)); this.watchDirectory = (host, dir, cb, flags, watchType, project) => ts.addDirectoryWatcherWithLogging(host, dir, cb, flags, this.createWatcherLog(watchType, project)); } + else if (this.logger.loggingEnabled()) { + this.watchFile = (host, file, cb, watchType, project) => ts.addFileWatcherWithOnlyTriggerLogging(host, file, cb, this.createWatcherLog(watchType, project)); + this.watchFilePath = (host, file, cb, path, watchType, project) => ts.addFilePathWatcherWithOnlyTriggerLogging(host, file, cb, path, this.createWatcherLog(watchType, project)); + this.watchDirectory = (host, dir, cb, flags, watchType, project) => ts.addDirectoryWatcherWithOnlyTriggerLogging(host, dir, cb, flags, this.createWatcherLog(watchType, project)); + } else { this.watchFile = ts.addFileWatcher; this.watchFilePath = ts.addFilePathWatcher; @@ -447,6 +452,16 @@ namespace ts.server { return toPath(fileName, this.currentDirectory, this.toCanonicalFileName); } + /*@internal*/ + getExecutingFilePath() { + return this.getNormalizedAbsolutePath(this.host.getExecutingFilePath()); + } + + /*@internal*/ + getNormalizedAbsolutePath(fileName: string) { + return getNormalizedAbsolutePath(fileName, this.host.getCurrentDirectory()); + } + /* @internal */ getChangedFiles_TestOnly() { return this.changedFiles; @@ -1624,12 +1639,13 @@ namespace ts.server { return this.inferredProjects[0]; } - return this.createInferredProject(/*rootDirectoryForResolution*/ undefined, /*isSingleInferredProject*/ true); + // Single inferred project does not have a project root and hence no current directory + return this.createInferredProject(/*currentDirectory*/ undefined, /*isSingleInferredProject*/ true); } - private createInferredProject(rootDirectoryForResolution: string | undefined, isSingleInferredProject?: boolean, projectRootPath?: string): InferredProject { + private createInferredProject(currentDirectory: string | undefined, isSingleInferredProject?: boolean, projectRootPath?: string): InferredProject { const compilerOptions = projectRootPath && this.compilerOptionsForInferredProjectsPerProjectRoot.get(projectRootPath) || this.compilerOptionsForInferredProjects; - const project = new InferredProject(this, this.documentRegistry, compilerOptions, projectRootPath, rootDirectoryForResolution); + const project = new InferredProject(this, this.documentRegistry, compilerOptions, projectRootPath, currentDirectory); if (isSingleInferredProject) { this.inferredProjects.unshift(project); } diff --git a/src/server/project.ts b/src/server/project.ts index 203355ad9db..c2a799d0845 100644 --- a/src/server/project.ts +++ b/src/server/project.ts @@ -195,6 +195,9 @@ namespace ts.server { return result.module; } + /*@internal*/ + readonly currentDirectory: string; + /*@internal*/ constructor( /*@internal*/readonly projectName: string, @@ -206,7 +209,8 @@ namespace ts.server { private compilerOptions: CompilerOptions, public compileOnSaveEnabled: boolean, /*@internal*/public directoryStructureHost: DirectoryStructureHost, - rootDirectoryForResolution: string | undefined) { + currentDirectory: string | undefined) { + this.currentDirectory = this.projectService.getNormalizedAbsolutePath(currentDirectory || ""); this.cancellationToken = new ThrottledCancellationToken(this.projectService.cancellationToken, this.projectService.throttleWaitMilliseconds); if (!this.compilerOptions) { @@ -230,7 +234,8 @@ namespace ts.server { } this.languageService = createLanguageService(this, this.documentRegistry); - this.resolutionCache = createResolutionCache(this, rootDirectoryForResolution); + // Use the current directory as resolution root only if the project created using current directory string + this.resolutionCache = createResolutionCache(this, currentDirectory && this.currentDirectory); if (!languageServiceEnabled) { this.disableLanguageService(); } @@ -296,16 +301,16 @@ namespace ts.server { } } - getCancellationToken() { + getCancellationToken(): HostCancellationToken { return this.cancellationToken; } getCurrentDirectory(): string { - return this.directoryStructureHost.getCurrentDirectory(); + return this.currentDirectory; } getDefaultLibFileName() { - const nodeModuleBinDir = getDirectoryPath(normalizePath(this.projectService.host.getExecutingFilePath())); + const nodeModuleBinDir = getDirectoryPath(normalizePath(this.projectService.getExecutingFilePath())); return combinePaths(nodeModuleBinDir, getDefaultLibFileName(this.compilerOptions)); } @@ -448,9 +453,8 @@ namespace ts.server { this.ensureBuilder(); const { emitSkipped, outputFiles } = this.builder.emitFile(this.program, scriptInfo.path); if (!emitSkipped) { - const projectRootPath = this.getProjectRootPath(); for (const outputFile of outputFiles) { - const outputFileAbsoluteFileName = getNormalizedAbsolutePath(outputFile.name, projectRootPath ? projectRootPath : getDirectoryPath(scriptInfo.fileName)); + const outputFileAbsoluteFileName = getNormalizedAbsolutePath(outputFile.name, this.currentDirectory); writeFile(outputFileAbsoluteFileName, outputFile.text, outputFile.writeByteOrderMark); } } @@ -479,7 +483,6 @@ namespace ts.server { getProjectName() { return this.projectName; } - abstract getProjectRootPath(): string | undefined; abstract getTypeAcquisition(): TypeAcquisition; getExternalFiles(): SortedReadonlyArray { @@ -561,7 +564,7 @@ namespace ts.server { return map(this.program.getSourceFiles(), sourceFile => { const scriptInfo = this.projectService.getScriptInfoForPath(sourceFile.path); if (!scriptInfo) { - Debug.fail(`scriptInfo for a file '${sourceFile.fileName}' is missing.`); + Debug.fail(`scriptInfo for a file '${sourceFile.fileName}' Path: '${sourceFile.path}' is missing.`); } return scriptInfo; }); @@ -1042,8 +1045,8 @@ namespace ts.server { projectService: ProjectService, documentRegistry: DocumentRegistry, compilerOptions: CompilerOptions, - public readonly projectRootPath: string | undefined, - rootDirectoryForResolution: string | undefined) { + readonly projectRootPath: string | undefined, + currentDirectory: string | undefined) { super(InferredProject.newName(), ProjectKind.Inferred, projectService, @@ -1053,7 +1056,7 @@ namespace ts.server { compilerOptions, /*compileOnSaveEnabled*/ false, projectService.host, - rootDirectoryForResolution); + currentDirectory); } addRoot(info: ScriptInfo) { @@ -1082,12 +1085,6 @@ namespace ts.server { this.getRootScriptInfos().length === 1; } - getProjectRootPath() { - return this.projectRootPath || - // Single inferred project does not have a project root. - !this.projectService.useSingleInferredProject && getDirectoryPath(this.getRootFiles()[0]); - } - close() { forEach(this.getRootScriptInfos(), info => this.projectService.stopWatchingConfigFilesForInferredProjectRoot(info)); super.close(); @@ -1183,7 +1180,7 @@ namespace ts.server { // Search our peer node_modules, then any globally-specified probe paths // ../../.. to walk from X/node_modules/typescript/lib/tsserver.js to X/node_modules/ - const searchPaths = [combinePaths(host.getExecutingFilePath(), "../../.."), ...this.projectService.pluginProbeLocations]; + const searchPaths = [combinePaths(this.projectService.getExecutingFilePath(), "../../.."), ...this.projectService.pluginProbeLocations]; if (this.projectService.allowLocalPluginLoads) { const local = getDirectoryPath(this.canonicalConfigFilePath); @@ -1263,10 +1260,6 @@ namespace ts.server { } } - getProjectRootPath() { - return getDirectoryPath(this.getConfigFilePath()); - } - /** * Get the errors that dont have any file name associated */ @@ -1381,13 +1374,14 @@ namespace ts.server { compilerOptions: CompilerOptions, languageServiceEnabled: boolean, public compileOnSaveEnabled: boolean, - private readonly projectFilePath?: string) { + projectFilePath?: string) { super(externalProjectName, ProjectKind.External, projectService, documentRegistry, /*hasExplicitListOfFiles*/ true, - languageServiceEnabled, compilerOptions, + languageServiceEnabled, + compilerOptions, compileOnSaveEnabled, projectService.host, getDirectoryPath(projectFilePath || normalizeSlashes(externalProjectName))); @@ -1397,16 +1391,6 @@ namespace ts.server { return this.excludedFiles; } - getProjectRootPath() { - if (this.projectFilePath) { - return getDirectoryPath(this.projectFilePath); - } - // if the projectFilePath is not given, we make the assumption that the project name - // is the path of the project file. AS the project name is provided by VS, we need to - // normalize slashes before using it as a file name. - return getDirectoryPath(normalizeSlashes(this.getProjectName())); - } - getTypeAcquisition() { return this.typeAcquisition; } diff --git a/src/services/codefixes/addMissingInvocationForDecorator.ts b/src/services/codefixes/addMissingInvocationForDecorator.ts new file mode 100644 index 00000000000..7f17aab6db2 --- /dev/null +++ b/src/services/codefixes/addMissingInvocationForDecorator.ts @@ -0,0 +1,20 @@ +/* @internal */ +namespace ts.codefix { + registerCodeFix({ + errorCodes: [Diagnostics._0_accepts_too_few_arguments_to_be_used_as_a_decorator_here_Did_you_mean_to_call_it_first_and_write_0.code], + getCodeActions: (context: CodeFixContext) => { + const sourceFile = context.sourceFile; + const token = getTokenAtPosition(sourceFile, context.span.start, /*includeJsDocComment*/ false); + const decorator = getAncestor(token, SyntaxKind.Decorator) as Decorator; + Debug.assert(!!decorator, "Expected position to be owned by a decorator."); + const replacement = createCall(decorator.expression, /*typeArguments*/ undefined, /*argumentsArray*/ undefined); + const changeTracker = textChanges.ChangeTracker.fromContext(context); + changeTracker.replaceNode(sourceFile, decorator.expression, replacement); + + return [{ + description: getLocaleSpecificMessage(Diagnostics.Call_decorator_expression), + changes: changeTracker.getChanges() + }]; + } + }); +} diff --git a/src/services/codefixes/fixes.ts b/src/services/codefixes/fixes.ts index 9bc80cad691..b024dfae7cd 100644 --- a/src/services/codefixes/fixes.ts +++ b/src/services/codefixes/fixes.ts @@ -1,3 +1,4 @@ +/// /// /// /// diff --git a/src/services/codefixes/importFixes.ts b/src/services/codefixes/importFixes.ts index f516bc15de3..9b54543231d 100644 --- a/src/services/codefixes/importFixes.ts +++ b/src/services/codefixes/importFixes.ts @@ -16,7 +16,7 @@ namespace ts.codefix { moduleSpecifier?: string; } - enum ModuleSpecifierComparison { + const enum ModuleSpecifierComparison { Better, Equal, Worse @@ -26,10 +26,6 @@ namespace ts.codefix { private symbolIdToActionMap: ImportCodeAction[][] = []; addAction(symbolId: number, newAction: ImportCodeAction) { - if (!newAction) { - return; - } - const actions = this.symbolIdToActionMap[symbolId]; if (!actions) { this.symbolIdToActionMap[symbolId] = [newAction]; diff --git a/src/services/findAllReferences.ts b/src/services/findAllReferences.ts index d4e660295a0..e43a2cbfd8e 100644 --- a/src/services/findAllReferences.ts +++ b/src/services/findAllReferences.ts @@ -482,7 +482,10 @@ namespace ts.FindAllReferences.Core { /** @param allSearchSymbols set of additinal symbols for use by `includes`. */ createSearch(location: Node, symbol: Symbol, comingFrom: ImportExport | undefined, searchOptions: { text?: string, allSearchSymbols?: Symbol[] } = {}): Search { // Note: if this is an external module symbol, the name doesn't include quotes. - const { text = stripQuotes(getDeclaredName(this.checker, symbol, location)), allSearchSymbols = undefined } = searchOptions; + const { + text = stripQuotes(unescapeLeadingUnderscores((getLocalSymbolForExportDefault(symbol) || symbol).escapedName)), + allSearchSymbols = undefined, + } = searchOptions; const escapedText = escapeLeadingUnderscores(text); const parents = this.options.implementations && getParentSymbolsOfPropertyAccess(location, symbol, this.checker); return { diff --git a/src/services/importTracker.ts b/src/services/importTracker.ts index a6152230218..f12df4613c0 100644 --- a/src/services/importTracker.ts +++ b/src/services/importTracker.ts @@ -609,9 +609,6 @@ namespace ts.FindAllReferences { } return forEach(symbol.declarations, decl => { - if (isExportAssignment(decl)) { - return isIdentifier(decl.expression) ? decl.expression.escapedText : undefined; - } const name = getNameOfDeclaration(decl); return name && name.kind === SyntaxKind.Identifier && name.escapedText; }); diff --git a/src/services/shims.ts b/src/services/shims.ts index 737db44b83f..9d4baccc3c4 100644 --- a/src/services/shims.ts +++ b/src/services/shims.ts @@ -16,7 +16,7 @@ /// /* @internal */ -let debugObjectHost = (function (this: any) { return this; })(); +let debugObjectHost: { CollectGarbage(): void } = (function (this: any) { return this; })(); // We need to use 'null' to interface with the managed side. /* tslint:disable:no-null-keyword */ @@ -119,13 +119,13 @@ namespace ts { } export interface Shim { - dispose(_dummy: any): void; + dispose(_dummy: {}): void; } export interface LanguageServiceShim extends Shim { languageService: LanguageService; - dispose(_dummy: any): void; + dispose(_dummy: {}): void; refresh(throwOnError: boolean): void; @@ -417,7 +417,7 @@ namespace ts { return this.shimHost.getScriptVersion(fileName); } - public getLocalizedDiagnosticMessages(): any { + public getLocalizedDiagnosticMessages() { const diagnosticMessagesJson = this.shimHost.getLocalizedDiagnosticMessages(); if (diagnosticMessagesJson === null || diagnosticMessagesJson === "") { return null; @@ -515,7 +515,7 @@ namespace ts { } } - function simpleForwardCall(logger: Logger, actionDescription: string, action: () => any, logPerformance: boolean): any { + function simpleForwardCall(logger: Logger, actionDescription: string, action: () => {}, logPerformance: boolean): {} { let start: number; if (logPerformance) { logger.log(actionDescription); @@ -539,14 +539,14 @@ namespace ts { return result; } - function forwardJSONCall(logger: Logger, actionDescription: string, action: () => any, logPerformance: boolean): string { + function forwardJSONCall(logger: Logger, actionDescription: string, action: () => {}, logPerformance: boolean): string { return forwardCall(logger, actionDescription, /*returnJson*/ true, action, logPerformance); } function forwardCall(logger: Logger, actionDescription: string, returnJson: boolean, action: () => T, logPerformance: boolean): T | string { try { const result = simpleForwardCall(logger, actionDescription, action, logPerformance); - return returnJson ? JSON.stringify({ result }) : result; + return returnJson ? JSON.stringify({ result }) : result as T; } catch (err) { if (err instanceof OperationCanceledException) { @@ -563,7 +563,7 @@ namespace ts { constructor(private factory: ShimFactory) { factory.registerShim(this); } - public dispose(_dummy: any): void { + public dispose(_dummy: {}): void { this.factory.unregisterShim(this); } } @@ -601,7 +601,7 @@ namespace ts { this.logger = this.host; } - public forwardJSONCall(actionDescription: string, action: () => any): string { + public forwardJSONCall(actionDescription: string, action: () => {}): string { return forwardJSONCall(this.logger, actionDescription, action, this.logPerformance); } @@ -611,7 +611,7 @@ namespace ts { * Ensure (almost) deterministic release of internal Javascript resources when * some external native objects holds onto us (e.g. Com/Interop). */ - public dispose(dummy: any): void { + public dispose(dummy: {}): void { this.logger.log("dispose()"); this.languageService.dispose(); this.languageService = null; @@ -635,7 +635,7 @@ namespace ts { public refresh(throwOnError: boolean): void { this.forwardJSONCall( `refresh(${throwOnError})`, - () => null + () => null ); } @@ -644,7 +644,7 @@ namespace ts { "cleanupSemanticCache()", () => { this.languageService.cleanupSemanticCache(); - return null; + return null; }); } @@ -980,13 +980,13 @@ namespace ts { ); } - public getEmitOutputObject(fileName: string): any { + public getEmitOutputObject(fileName: string): EmitOutput { return forwardCall( this.logger, `getEmitOutput('${fileName}')`, /*returnJson*/ false, () => this.languageService.getEmitOutput(fileName), - this.logPerformance); + this.logPerformance) as EmitOutput; } } @@ -1030,7 +1030,7 @@ namespace ts { super(factory); } - private forwardJSONCall(actionDescription: string, action: () => any): any { + private forwardJSONCall(actionDescription: string, action: () => {}): string { return forwardJSONCall(this.logger, actionDescription, action, this.logPerformance); } @@ -1221,7 +1221,7 @@ namespace ts { // Here we expose the TypeScript services as an external module // so that it may be consumed easily like a node module. - declare const module: any; + declare const module: { exports: {} }; if (typeof module !== "undefined" && module.exports) { module.exports = ts; } diff --git a/src/services/symbolDisplay.ts b/src/services/symbolDisplay.ts index a399610d823..d38d21f1092 100644 --- a/src/services/symbolDisplay.ts +++ b/src/services/symbolDisplay.ts @@ -341,13 +341,19 @@ namespace ts.SymbolDisplay { } if (symbolFlags & SymbolFlags.Alias) { addNewLineIfDisplayPartsExist(); - if (symbol.declarations[0].kind === SyntaxKind.NamespaceExportDeclaration) { - displayParts.push(keywordPart(SyntaxKind.ExportKeyword)); - displayParts.push(spacePart()); - displayParts.push(keywordPart(SyntaxKind.NamespaceKeyword)); - } - else { - displayParts.push(keywordPart(SyntaxKind.ImportKeyword)); + switch (symbol.declarations[0].kind) { + case SyntaxKind.NamespaceExportDeclaration: + displayParts.push(keywordPart(SyntaxKind.ExportKeyword)); + displayParts.push(spacePart()); + displayParts.push(keywordPart(SyntaxKind.NamespaceKeyword)); + break; + case SyntaxKind.ExportAssignment: + displayParts.push(keywordPart(SyntaxKind.ExportKeyword)); + displayParts.push(spacePart()); + displayParts.push(keywordPart((symbol.declarations[0] as ExportAssignment).isExportEquals ? SyntaxKind.EqualsToken : SyntaxKind.DefaultKeyword)); + break; + default: + displayParts.push(keywordPart(SyntaxKind.ImportKeyword)); } displayParts.push(spacePart()); addFullSymbolName(symbol); diff --git a/tests/baselines/reference/abstractPropertyInConstructor.errors.txt b/tests/baselines/reference/abstractPropertyInConstructor.errors.txt new file mode 100644 index 00000000000..461dd713d3b --- /dev/null +++ b/tests/baselines/reference/abstractPropertyInConstructor.errors.txt @@ -0,0 +1,37 @@ +tests/cases/compiler/abstractPropertyInConstructor.ts(4,24): error TS2715: Abstract property 'prop' in class 'AbstractClass' cannot be accessed in the constructor. +tests/cases/compiler/abstractPropertyInConstructor.ts(7,18): error TS2715: Abstract property 'prop' in class 'AbstractClass' cannot be accessed in the constructor. +tests/cases/compiler/abstractPropertyInConstructor.ts(9,14): error TS2715: Abstract property 'cb' in class 'AbstractClass' cannot be accessed in the constructor. + + +==== tests/cases/compiler/abstractPropertyInConstructor.ts (3 errors) ==== + abstract class AbstractClass { + constructor(str: string) { + this.method(parseInt(str)); + let val = this.prop.toLowerCase(); + ~~~~ +!!! error TS2715: Abstract property 'prop' in class 'AbstractClass' cannot be accessed in the constructor. + + if (!str) { + this.prop = "Hello World"; + ~~~~ +!!! error TS2715: Abstract property 'prop' in class 'AbstractClass' cannot be accessed in the constructor. + } + this.cb(str); + ~~ +!!! error TS2715: Abstract property 'cb' in class 'AbstractClass' cannot be accessed in the constructor. + + const innerFunction = () => { + return this.prop; + } + } + + abstract prop: string; + abstract cb: (s: string) => void; + + abstract method(num: number): void; + + method2() { + this.prop = this.prop + "!"; + } + } + \ No newline at end of file diff --git a/tests/baselines/reference/abstractPropertyInConstructor.js b/tests/baselines/reference/abstractPropertyInConstructor.js new file mode 100644 index 00000000000..18a2937a191 --- /dev/null +++ b/tests/baselines/reference/abstractPropertyInConstructor.js @@ -0,0 +1,46 @@ +//// [abstractPropertyInConstructor.ts] +abstract class AbstractClass { + constructor(str: string) { + this.method(parseInt(str)); + let val = this.prop.toLowerCase(); + + if (!str) { + this.prop = "Hello World"; + } + this.cb(str); + + const innerFunction = () => { + return this.prop; + } + } + + abstract prop: string; + abstract cb: (s: string) => void; + + abstract method(num: number): void; + + method2() { + this.prop = this.prop + "!"; + } +} + + +//// [abstractPropertyInConstructor.js] +var AbstractClass = /** @class */ (function () { + function AbstractClass(str) { + var _this = this; + this.method(parseInt(str)); + var val = this.prop.toLowerCase(); + if (!str) { + this.prop = "Hello World"; + } + this.cb(str); + var innerFunction = function () { + return _this.prop; + }; + } + AbstractClass.prototype.method2 = function () { + this.prop = this.prop + "!"; + }; + return AbstractClass; +}()); diff --git a/tests/baselines/reference/abstractPropertyInConstructor.symbols b/tests/baselines/reference/abstractPropertyInConstructor.symbols new file mode 100644 index 00000000000..0d542ffb0a8 --- /dev/null +++ b/tests/baselines/reference/abstractPropertyInConstructor.symbols @@ -0,0 +1,70 @@ +=== tests/cases/compiler/abstractPropertyInConstructor.ts === +abstract class AbstractClass { +>AbstractClass : Symbol(AbstractClass, Decl(abstractPropertyInConstructor.ts, 0, 0)) + + constructor(str: string) { +>str : Symbol(str, Decl(abstractPropertyInConstructor.ts, 1, 16)) + + this.method(parseInt(str)); +>this.method : Symbol(AbstractClass.method, Decl(abstractPropertyInConstructor.ts, 16, 37)) +>this : Symbol(AbstractClass, Decl(abstractPropertyInConstructor.ts, 0, 0)) +>method : Symbol(AbstractClass.method, Decl(abstractPropertyInConstructor.ts, 16, 37)) +>parseInt : Symbol(parseInt, Decl(lib.d.ts, --, --)) +>str : Symbol(str, Decl(abstractPropertyInConstructor.ts, 1, 16)) + + let val = this.prop.toLowerCase(); +>val : Symbol(val, Decl(abstractPropertyInConstructor.ts, 3, 11)) +>this.prop.toLowerCase : Symbol(String.toLowerCase, Decl(lib.d.ts, --, --)) +>this.prop : Symbol(AbstractClass.prop, Decl(abstractPropertyInConstructor.ts, 13, 5)) +>this : Symbol(AbstractClass, Decl(abstractPropertyInConstructor.ts, 0, 0)) +>prop : Symbol(AbstractClass.prop, Decl(abstractPropertyInConstructor.ts, 13, 5)) +>toLowerCase : Symbol(String.toLowerCase, Decl(lib.d.ts, --, --)) + + if (!str) { +>str : Symbol(str, Decl(abstractPropertyInConstructor.ts, 1, 16)) + + this.prop = "Hello World"; +>this.prop : Symbol(AbstractClass.prop, Decl(abstractPropertyInConstructor.ts, 13, 5)) +>this : Symbol(AbstractClass, Decl(abstractPropertyInConstructor.ts, 0, 0)) +>prop : Symbol(AbstractClass.prop, Decl(abstractPropertyInConstructor.ts, 13, 5)) + } + this.cb(str); +>this.cb : Symbol(AbstractClass.cb, Decl(abstractPropertyInConstructor.ts, 15, 26)) +>this : Symbol(AbstractClass, Decl(abstractPropertyInConstructor.ts, 0, 0)) +>cb : Symbol(AbstractClass.cb, Decl(abstractPropertyInConstructor.ts, 15, 26)) +>str : Symbol(str, Decl(abstractPropertyInConstructor.ts, 1, 16)) + + const innerFunction = () => { +>innerFunction : Symbol(innerFunction, Decl(abstractPropertyInConstructor.ts, 10, 13)) + + return this.prop; +>this.prop : Symbol(AbstractClass.prop, Decl(abstractPropertyInConstructor.ts, 13, 5)) +>this : Symbol(AbstractClass, Decl(abstractPropertyInConstructor.ts, 0, 0)) +>prop : Symbol(AbstractClass.prop, Decl(abstractPropertyInConstructor.ts, 13, 5)) + } + } + + abstract prop: string; +>prop : Symbol(AbstractClass.prop, Decl(abstractPropertyInConstructor.ts, 13, 5)) + + abstract cb: (s: string) => void; +>cb : Symbol(AbstractClass.cb, Decl(abstractPropertyInConstructor.ts, 15, 26)) +>s : Symbol(s, Decl(abstractPropertyInConstructor.ts, 16, 18)) + + abstract method(num: number): void; +>method : Symbol(AbstractClass.method, Decl(abstractPropertyInConstructor.ts, 16, 37)) +>num : Symbol(num, Decl(abstractPropertyInConstructor.ts, 18, 20)) + + method2() { +>method2 : Symbol(AbstractClass.method2, Decl(abstractPropertyInConstructor.ts, 18, 39)) + + this.prop = this.prop + "!"; +>this.prop : Symbol(AbstractClass.prop, Decl(abstractPropertyInConstructor.ts, 13, 5)) +>this : Symbol(AbstractClass, Decl(abstractPropertyInConstructor.ts, 0, 0)) +>prop : Symbol(AbstractClass.prop, Decl(abstractPropertyInConstructor.ts, 13, 5)) +>this.prop : Symbol(AbstractClass.prop, Decl(abstractPropertyInConstructor.ts, 13, 5)) +>this : Symbol(AbstractClass, Decl(abstractPropertyInConstructor.ts, 0, 0)) +>prop : Symbol(AbstractClass.prop, Decl(abstractPropertyInConstructor.ts, 13, 5)) + } +} + diff --git a/tests/baselines/reference/abstractPropertyInConstructor.types b/tests/baselines/reference/abstractPropertyInConstructor.types new file mode 100644 index 00000000000..0ffb5f1bdfd --- /dev/null +++ b/tests/baselines/reference/abstractPropertyInConstructor.types @@ -0,0 +1,81 @@ +=== tests/cases/compiler/abstractPropertyInConstructor.ts === +abstract class AbstractClass { +>AbstractClass : AbstractClass + + constructor(str: string) { +>str : string + + this.method(parseInt(str)); +>this.method(parseInt(str)) : void +>this.method : (num: number) => void +>this : this +>method : (num: number) => void +>parseInt(str) : number +>parseInt : (s: string, radix?: number) => number +>str : string + + let val = this.prop.toLowerCase(); +>val : string +>this.prop.toLowerCase() : string +>this.prop.toLowerCase : () => string +>this.prop : string +>this : this +>prop : string +>toLowerCase : () => string + + if (!str) { +>!str : boolean +>str : string + + this.prop = "Hello World"; +>this.prop = "Hello World" : "Hello World" +>this.prop : string +>this : this +>prop : string +>"Hello World" : "Hello World" + } + this.cb(str); +>this.cb(str) : void +>this.cb : (s: string) => void +>this : this +>cb : (s: string) => void +>str : string + + const innerFunction = () => { +>innerFunction : () => string +>() => { return this.prop; } : () => string + + return this.prop; +>this.prop : string +>this : this +>prop : string + } + } + + abstract prop: string; +>prop : string + + abstract cb: (s: string) => void; +>cb : (s: string) => void +>s : string + + abstract method(num: number): void; +>method : (num: number) => void +>num : number + + method2() { +>method2 : () => void + + this.prop = this.prop + "!"; +>this.prop = this.prop + "!" : string +>this.prop : string +>this : this +>prop : string +>this.prop + "!" : string +>this.prop : string +>this : this +>prop : string +>"!" : "!" + } +} + diff --git a/tests/baselines/reference/anyInferenceAnonymousFunctions.symbols b/tests/baselines/reference/anyInferenceAnonymousFunctions.symbols index c1b5df88fb0..4aad165f40a 100644 --- a/tests/baselines/reference/anyInferenceAnonymousFunctions.symbols +++ b/tests/baselines/reference/anyInferenceAnonymousFunctions.symbols @@ -3,9 +3,9 @@ var paired: any[]; >paired : Symbol(paired, Decl(anyInferenceAnonymousFunctions.ts, 0, 3)) paired.reduce(function (a1, a2) { ->paired.reduce : Symbol(Array.reduce, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>paired.reduce : Symbol(Array.reduce, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) >paired : Symbol(paired, Decl(anyInferenceAnonymousFunctions.ts, 0, 3)) ->reduce : Symbol(Array.reduce, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>reduce : Symbol(Array.reduce, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) >a1 : Symbol(a1, Decl(anyInferenceAnonymousFunctions.ts, 2, 24)) >a2 : Symbol(a2, Decl(anyInferenceAnonymousFunctions.ts, 2, 27)) @@ -15,9 +15,9 @@ paired.reduce(function (a1, a2) { } , []); paired.reduce((b1, b2) => { ->paired.reduce : Symbol(Array.reduce, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>paired.reduce : Symbol(Array.reduce, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) >paired : Symbol(paired, Decl(anyInferenceAnonymousFunctions.ts, 0, 3)) ->reduce : Symbol(Array.reduce, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>reduce : Symbol(Array.reduce, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) >b1 : Symbol(b1, Decl(anyInferenceAnonymousFunctions.ts, 8, 15)) >b2 : Symbol(b2, Decl(anyInferenceAnonymousFunctions.ts, 8, 18)) @@ -27,9 +27,9 @@ paired.reduce((b1, b2) => { } , []); paired.reduce((b3, b4) => b3.concat({}), []); ->paired.reduce : Symbol(Array.reduce, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>paired.reduce : Symbol(Array.reduce, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) >paired : Symbol(paired, Decl(anyInferenceAnonymousFunctions.ts, 0, 3)) ->reduce : Symbol(Array.reduce, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>reduce : Symbol(Array.reduce, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) >b3 : Symbol(b3, Decl(anyInferenceAnonymousFunctions.ts, 13, 15)) >b4 : Symbol(b4, Decl(anyInferenceAnonymousFunctions.ts, 13, 18)) >b3 : Symbol(b3, Decl(anyInferenceAnonymousFunctions.ts, 13, 15)) diff --git a/tests/baselines/reference/anyInferenceAnonymousFunctions.types b/tests/baselines/reference/anyInferenceAnonymousFunctions.types index 8dc7fdcb90f..d5f693b5453 100644 --- a/tests/baselines/reference/anyInferenceAnonymousFunctions.types +++ b/tests/baselines/reference/anyInferenceAnonymousFunctions.types @@ -4,9 +4,9 @@ var paired: any[]; paired.reduce(function (a1, a2) { >paired.reduce(function (a1, a2) { return a1.concat({});} , []) : any ->paired.reduce : { (callbackfn: (previousValue: any, currentValue: any, currentIndex: number, array: any[]) => any, initialValue?: any): any; (callbackfn: (previousValue: U, currentValue: any, currentIndex: number, array: any[]) => U, initialValue: U): U; } +>paired.reduce : { (callbackfn: (previousValue: any, currentValue: any, currentIndex: number, array: any[]) => any): any; (callbackfn: (previousValue: any, currentValue: any, currentIndex: number, array: any[]) => any, initialValue: any): any; (callbackfn: (previousValue: U, currentValue: any, currentIndex: number, array: any[]) => U, initialValue: U): U; } >paired : any[] ->reduce : { (callbackfn: (previousValue: any, currentValue: any, currentIndex: number, array: any[]) => any, initialValue?: any): any; (callbackfn: (previousValue: U, currentValue: any, currentIndex: number, array: any[]) => U, initialValue: U): U; } +>reduce : { (callbackfn: (previousValue: any, currentValue: any, currentIndex: number, array: any[]) => any): any; (callbackfn: (previousValue: any, currentValue: any, currentIndex: number, array: any[]) => any, initialValue: any): any; (callbackfn: (previousValue: U, currentValue: any, currentIndex: number, array: any[]) => U, initialValue: U): U; } >function (a1, a2) { return a1.concat({});} : (a1: any, a2: any) => any >a1 : any >a2 : any @@ -23,9 +23,9 @@ paired.reduce(function (a1, a2) { paired.reduce((b1, b2) => { >paired.reduce((b1, b2) => { return b1.concat({});} , []) : any ->paired.reduce : { (callbackfn: (previousValue: any, currentValue: any, currentIndex: number, array: any[]) => any, initialValue?: any): any; (callbackfn: (previousValue: U, currentValue: any, currentIndex: number, array: any[]) => U, initialValue: U): U; } +>paired.reduce : { (callbackfn: (previousValue: any, currentValue: any, currentIndex: number, array: any[]) => any): any; (callbackfn: (previousValue: any, currentValue: any, currentIndex: number, array: any[]) => any, initialValue: any): any; (callbackfn: (previousValue: U, currentValue: any, currentIndex: number, array: any[]) => U, initialValue: U): U; } >paired : any[] ->reduce : { (callbackfn: (previousValue: any, currentValue: any, currentIndex: number, array: any[]) => any, initialValue?: any): any; (callbackfn: (previousValue: U, currentValue: any, currentIndex: number, array: any[]) => U, initialValue: U): U; } +>reduce : { (callbackfn: (previousValue: any, currentValue: any, currentIndex: number, array: any[]) => any): any; (callbackfn: (previousValue: any, currentValue: any, currentIndex: number, array: any[]) => any, initialValue: any): any; (callbackfn: (previousValue: U, currentValue: any, currentIndex: number, array: any[]) => U, initialValue: U): U; } >(b1, b2) => { return b1.concat({});} : (b1: any, b2: any) => any >b1 : any >b2 : any @@ -42,9 +42,9 @@ paired.reduce((b1, b2) => { paired.reduce((b3, b4) => b3.concat({}), []); >paired.reduce((b3, b4) => b3.concat({}), []) : any ->paired.reduce : { (callbackfn: (previousValue: any, currentValue: any, currentIndex: number, array: any[]) => any, initialValue?: any): any; (callbackfn: (previousValue: U, currentValue: any, currentIndex: number, array: any[]) => U, initialValue: U): U; } +>paired.reduce : { (callbackfn: (previousValue: any, currentValue: any, currentIndex: number, array: any[]) => any): any; (callbackfn: (previousValue: any, currentValue: any, currentIndex: number, array: any[]) => any, initialValue: any): any; (callbackfn: (previousValue: U, currentValue: any, currentIndex: number, array: any[]) => U, initialValue: U): U; } >paired : any[] ->reduce : { (callbackfn: (previousValue: any, currentValue: any, currentIndex: number, array: any[]) => any, initialValue?: any): any; (callbackfn: (previousValue: U, currentValue: any, currentIndex: number, array: any[]) => U, initialValue: U): U; } +>reduce : { (callbackfn: (previousValue: any, currentValue: any, currentIndex: number, array: any[]) => any): any; (callbackfn: (previousValue: any, currentValue: any, currentIndex: number, array: any[]) => any, initialValue: any): any; (callbackfn: (previousValue: U, currentValue: any, currentIndex: number, array: any[]) => U, initialValue: U): U; } >(b3, b4) => b3.concat({}) : (b3: any, b4: any) => any >b3 : any >b4 : any diff --git a/tests/baselines/reference/api/tsserverlibrary.d.ts b/tests/baselines/reference/api/tsserverlibrary.d.ts index b9b72dec922..5991eb85c70 100644 --- a/tests/baselines/reference/api/tsserverlibrary.d.ts +++ b/tests/baselines/reference/api/tsserverlibrary.d.ts @@ -1442,6 +1442,10 @@ declare namespace ts { interface JSDocUnknownTag extends JSDocTag { kind: SyntaxKind.JSDocTag; } + /** + * Note that `@extends` is a synonym of `@augments`. + * Both tags are represented by this interface. + */ interface JSDocAugmentsTag extends JSDocTag { kind: SyntaxKind.JSDocAugmentsTag; class: ExpressionWithTypeArguments & { @@ -1473,7 +1477,7 @@ declare namespace ts { interface JSDocPropertyLikeTag extends JSDocTag, Declaration { parent: JSDoc; name: EntityName; - typeExpression: JSDocTypeExpression; + typeExpression?: JSDocTypeExpression; /** Whether the property name came before the type -- non-standard for JSDoc, but Typescript-like */ isNameFirst: boolean; isBracketed: boolean; @@ -1727,6 +1731,10 @@ declare namespace ts { signatureToString(signature: Signature, enclosingDeclaration?: Node, flags?: TypeFormatFlags, kind?: SignatureKind): string; typeToString(type: Type, enclosingDeclaration?: Node, flags?: TypeFormatFlags): string; symbolToString(symbol: Symbol, enclosingDeclaration?: Node, meaning?: SymbolFlags): string; + /** + * @deprecated Use the createX factory functions or XToY typechecker methods and `createPrinter` or the `xToString` methods instead + * This will be removed in a future version. + */ getSymbolDisplayBuilder(): SymbolDisplayBuilder; getFullyQualifiedName(symbol: Symbol): string; getAugmentedPropertiesOfType(type: Type): Symbol[]; @@ -2866,6 +2874,8 @@ declare namespace ts { function getJSDocReturnType(node: Node): TypeNode | undefined; /** Get all JSDoc tags related to a node, including those on parent nodes. */ function getJSDocTags(node: Node): ReadonlyArray | undefined; + /** Gets all JSDoc tags of a specified kind, or undefined if not present. */ + function getAllJSDocTagsOfKind(node: Node, kind: SyntaxKind): ReadonlyArray | undefined; } declare namespace ts { function isNumericLiteral(node: Node): node is NumericLiteral; @@ -7104,7 +7114,7 @@ declare namespace ts.server { getScriptKind(fileName: string): ScriptKind; getScriptVersion(filename: string): string; getScriptSnapshot(filename: string): IScriptSnapshot; - getCancellationToken(): ThrottledCancellationToken; + getCancellationToken(): HostCancellationToken; getCurrentDirectory(): string; getDefaultLibFileName(): string; useCaseSensitiveFileNames(): boolean; @@ -7131,7 +7141,6 @@ declare namespace ts.server { enableLanguageService(): void; disableLanguageService(): void; getProjectName(): string; - abstract getProjectRootPath(): string | undefined; abstract getTypeAcquisition(): TypeAcquisition; getExternalFiles(): SortedReadonlyArray; getSourceFile(path: Path): SourceFile; @@ -7184,7 +7193,6 @@ declare namespace ts.server { addRoot(info: ScriptInfo): void; removeRoot(info: ScriptInfo): void; isProjectWithSingleRoot(): boolean; - getProjectRootPath(): string; close(): void; getTypeAcquisition(): TypeAcquisition; } @@ -7211,7 +7219,6 @@ declare namespace ts.server { enablePlugins(): void; private enablePlugin(pluginConfigEntry, searchPaths); private enableProxy(pluginModuleFactory, configEntry); - getProjectRootPath(): string; /** * Get the errors that dont have any file name associated */ @@ -7237,11 +7244,9 @@ declare namespace ts.server { class ExternalProject extends Project { externalProjectName: string; compileOnSaveEnabled: boolean; - private readonly projectFilePath; excludedFiles: ReadonlyArray; private typeAcquisition; getExcludedFiles(): ReadonlyArray; - getProjectRootPath(): string; getTypeAcquisition(): TypeAcquisition; setTypeAcquisition(newTypeAcquisition: TypeAcquisition): void; } @@ -7520,7 +7525,7 @@ declare namespace ts.server { private sendConfigFileDiagEvent(project, triggerFile); private getOrCreateInferredProjectForProjectRootPathIfEnabled(info, projectRootPath); private getOrCreateSingleInferredProjectIfEnabled(); - private createInferredProject(rootDirectoryForResolution, isSingleInferredProject?, projectRootPath?); + private createInferredProject(currentDirectory, isSingleInferredProject?, projectRootPath?); getScriptInfo(uncheckedFileName: string): ScriptInfo; private watchClosedScriptInfo(info); private stopWatchingScriptInfo(info); diff --git a/tests/baselines/reference/api/typescript.d.ts b/tests/baselines/reference/api/typescript.d.ts index d41db2eb413..0c74f74c741 100644 --- a/tests/baselines/reference/api/typescript.d.ts +++ b/tests/baselines/reference/api/typescript.d.ts @@ -1442,6 +1442,10 @@ declare namespace ts { interface JSDocUnknownTag extends JSDocTag { kind: SyntaxKind.JSDocTag; } + /** + * Note that `@extends` is a synonym of `@augments`. + * Both tags are represented by this interface. + */ interface JSDocAugmentsTag extends JSDocTag { kind: SyntaxKind.JSDocAugmentsTag; class: ExpressionWithTypeArguments & { @@ -1473,7 +1477,7 @@ declare namespace ts { interface JSDocPropertyLikeTag extends JSDocTag, Declaration { parent: JSDoc; name: EntityName; - typeExpression: JSDocTypeExpression; + typeExpression?: JSDocTypeExpression; /** Whether the property name came before the type -- non-standard for JSDoc, but Typescript-like */ isNameFirst: boolean; isBracketed: boolean; @@ -1727,6 +1731,10 @@ declare namespace ts { signatureToString(signature: Signature, enclosingDeclaration?: Node, flags?: TypeFormatFlags, kind?: SignatureKind): string; typeToString(type: Type, enclosingDeclaration?: Node, flags?: TypeFormatFlags): string; symbolToString(symbol: Symbol, enclosingDeclaration?: Node, meaning?: SymbolFlags): string; + /** + * @deprecated Use the createX factory functions or XToY typechecker methods and `createPrinter` or the `xToString` methods instead + * This will be removed in a future version. + */ getSymbolDisplayBuilder(): SymbolDisplayBuilder; getFullyQualifiedName(symbol: Symbol): string; getAugmentedPropertiesOfType(type: Type): Symbol[]; @@ -2921,6 +2929,8 @@ declare namespace ts { function getJSDocReturnType(node: Node): TypeNode | undefined; /** Get all JSDoc tags related to a node, including those on parent nodes. */ function getJSDocTags(node: Node): ReadonlyArray | undefined; + /** Gets all JSDoc tags of a specified kind, or undefined if not present. */ + function getAllJSDocTagsOfKind(node: Node, kind: SyntaxKind): ReadonlyArray | undefined; } declare namespace ts { function isNumericLiteral(node: Node): node is NumericLiteral; diff --git a/tests/baselines/reference/arrayFind.js b/tests/baselines/reference/arrayFind.js new file mode 100644 index 00000000000..1926c3a8dcc --- /dev/null +++ b/tests/baselines/reference/arrayFind.js @@ -0,0 +1,22 @@ +//// [arrayFind.ts] +// test fix for #18112, type guard predicates should narrow returned element +function isNumber(x: any): x is number { + return typeof x === "number"; +} + +const arrayOfStringsNumbersAndBooleans = ["string", false, 0, "strung", 1, true]; +const foundNumber: number | undefined = arrayOfStringsNumbersAndBooleans.find(isNumber); + +const readonlyArrayOfStringsNumbersAndBooleans = arrayOfStringsNumbersAndBooleans as ReadonlyArray; +const readonlyFoundNumber: number | undefined = readonlyArrayOfStringsNumbersAndBooleans.find(isNumber); + + +//// [arrayFind.js] +// test fix for #18112, type guard predicates should narrow returned element +function isNumber(x) { + return typeof x === "number"; +} +var arrayOfStringsNumbersAndBooleans = ["string", false, 0, "strung", 1, true]; +var foundNumber = arrayOfStringsNumbersAndBooleans.find(isNumber); +var readonlyArrayOfStringsNumbersAndBooleans = arrayOfStringsNumbersAndBooleans; +var readonlyFoundNumber = readonlyArrayOfStringsNumbersAndBooleans.find(isNumber); diff --git a/tests/baselines/reference/arrayFind.symbols b/tests/baselines/reference/arrayFind.symbols new file mode 100644 index 00000000000..163d5d818ba --- /dev/null +++ b/tests/baselines/reference/arrayFind.symbols @@ -0,0 +1,33 @@ +=== tests/cases/compiler/arrayFind.ts === +// test fix for #18112, type guard predicates should narrow returned element +function isNumber(x: any): x is number { +>isNumber : Symbol(isNumber, Decl(arrayFind.ts, 0, 0)) +>x : Symbol(x, Decl(arrayFind.ts, 1, 18)) +>x : Symbol(x, Decl(arrayFind.ts, 1, 18)) + + return typeof x === "number"; +>x : Symbol(x, Decl(arrayFind.ts, 1, 18)) +} + +const arrayOfStringsNumbersAndBooleans = ["string", false, 0, "strung", 1, true]; +>arrayOfStringsNumbersAndBooleans : Symbol(arrayOfStringsNumbersAndBooleans, Decl(arrayFind.ts, 5, 5)) + +const foundNumber: number | undefined = arrayOfStringsNumbersAndBooleans.find(isNumber); +>foundNumber : Symbol(foundNumber, Decl(arrayFind.ts, 6, 5)) +>arrayOfStringsNumbersAndBooleans.find : Symbol(Array.find, Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --)) +>arrayOfStringsNumbersAndBooleans : Symbol(arrayOfStringsNumbersAndBooleans, Decl(arrayFind.ts, 5, 5)) +>find : Symbol(Array.find, Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --)) +>isNumber : Symbol(isNumber, Decl(arrayFind.ts, 0, 0)) + +const readonlyArrayOfStringsNumbersAndBooleans = arrayOfStringsNumbersAndBooleans as ReadonlyArray; +>readonlyArrayOfStringsNumbersAndBooleans : Symbol(readonlyArrayOfStringsNumbersAndBooleans, Decl(arrayFind.ts, 8, 5)) +>arrayOfStringsNumbersAndBooleans : Symbol(arrayOfStringsNumbersAndBooleans, Decl(arrayFind.ts, 5, 5)) +>ReadonlyArray : Symbol(ReadonlyArray, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --)) + +const readonlyFoundNumber: number | undefined = readonlyArrayOfStringsNumbersAndBooleans.find(isNumber); +>readonlyFoundNumber : Symbol(readonlyFoundNumber, Decl(arrayFind.ts, 9, 5)) +>readonlyArrayOfStringsNumbersAndBooleans.find : Symbol(ReadonlyArray.find, Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --)) +>readonlyArrayOfStringsNumbersAndBooleans : Symbol(readonlyArrayOfStringsNumbersAndBooleans, Decl(arrayFind.ts, 8, 5)) +>find : Symbol(ReadonlyArray.find, Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --)) +>isNumber : Symbol(isNumber, Decl(arrayFind.ts, 0, 0)) + diff --git a/tests/baselines/reference/arrayFind.types b/tests/baselines/reference/arrayFind.types new file mode 100644 index 00000000000..5c0769cb606 --- /dev/null +++ b/tests/baselines/reference/arrayFind.types @@ -0,0 +1,46 @@ +=== tests/cases/compiler/arrayFind.ts === +// test fix for #18112, type guard predicates should narrow returned element +function isNumber(x: any): x is number { +>isNumber : (x: any) => x is number +>x : any +>x : any + + return typeof x === "number"; +>typeof x === "number" : boolean +>typeof x : "string" | "number" | "boolean" | "symbol" | "undefined" | "object" | "function" +>x : any +>"number" : "number" +} + +const arrayOfStringsNumbersAndBooleans = ["string", false, 0, "strung", 1, true]; +>arrayOfStringsNumbersAndBooleans : (string | number | boolean)[] +>["string", false, 0, "strung", 1, true] : (string | number | boolean)[] +>"string" : "string" +>false : false +>0 : 0 +>"strung" : "strung" +>1 : 1 +>true : true + +const foundNumber: number | undefined = arrayOfStringsNumbersAndBooleans.find(isNumber); +>foundNumber : number +>arrayOfStringsNumbersAndBooleans.find(isNumber) : number +>arrayOfStringsNumbersAndBooleans.find : { (predicate: (this: void, value: string | number | boolean, index: number, obj: (string | number | boolean)[]) => value is S, thisArg?: any): S; (predicate: (value: string | number | boolean, index: number, obj: (string | number | boolean)[]) => boolean, thisArg?: any): string | number | boolean; } +>arrayOfStringsNumbersAndBooleans : (string | number | boolean)[] +>find : { (predicate: (this: void, value: string | number | boolean, index: number, obj: (string | number | boolean)[]) => value is S, thisArg?: any): S; (predicate: (value: string | number | boolean, index: number, obj: (string | number | boolean)[]) => boolean, thisArg?: any): string | number | boolean; } +>isNumber : (x: any) => x is number + +const readonlyArrayOfStringsNumbersAndBooleans = arrayOfStringsNumbersAndBooleans as ReadonlyArray; +>readonlyArrayOfStringsNumbersAndBooleans : ReadonlyArray +>arrayOfStringsNumbersAndBooleans as ReadonlyArray : ReadonlyArray +>arrayOfStringsNumbersAndBooleans : (string | number | boolean)[] +>ReadonlyArray : ReadonlyArray + +const readonlyFoundNumber: number | undefined = readonlyArrayOfStringsNumbersAndBooleans.find(isNumber); +>readonlyFoundNumber : number +>readonlyArrayOfStringsNumbersAndBooleans.find(isNumber) : number +>readonlyArrayOfStringsNumbersAndBooleans.find : { (predicate: (this: void, value: string | number | boolean, index: number, obj: ReadonlyArray) => value is S, thisArg?: any): S; (predicate: (value: string | number | boolean, index: number, obj: ReadonlyArray) => boolean, thisArg?: any): string | number | boolean; } +>readonlyArrayOfStringsNumbersAndBooleans : ReadonlyArray +>find : { (predicate: (this: void, value: string | number | boolean, index: number, obj: ReadonlyArray) => value is S, thisArg?: any): S; (predicate: (value: string | number | boolean, index: number, obj: ReadonlyArray) => boolean, thisArg?: any): string | number | boolean; } +>isNumber : (x: any) => x is number + diff --git a/tests/baselines/reference/decoratorOnClassMethod6.errors.txt b/tests/baselines/reference/decoratorOnClassMethod6.errors.txt index 530e86117ee..b863a9db72c 100644 --- a/tests/baselines/reference/decoratorOnClassMethod6.errors.txt +++ b/tests/baselines/reference/decoratorOnClassMethod6.errors.txt @@ -1,4 +1,4 @@ -tests/cases/conformance/decorators/class/method/decoratorOnClassMethod6.ts(4,5): error TS1241: Unable to resolve signature of method decorator when called as an expression. +tests/cases/conformance/decorators/class/method/decoratorOnClassMethod6.ts(4,5): error TS1329: 'dec' accepts too few arguments to be used as a decorator here. Did you mean to call it first and write '@dec()'? ==== tests/cases/conformance/decorators/class/method/decoratorOnClassMethod6.ts (1 errors) ==== @@ -7,5 +7,5 @@ tests/cases/conformance/decorators/class/method/decoratorOnClassMethod6.ts(4,5): class C { @dec ["method"]() {} ~~~~ -!!! error TS1241: Unable to resolve signature of method decorator when called as an expression. +!!! error TS1329: 'dec' accepts too few arguments to be used as a decorator here. Did you mean to call it first and write '@dec()'? } \ No newline at end of file diff --git a/tests/baselines/reference/decoratorOnClassProperty11.errors.txt b/tests/baselines/reference/decoratorOnClassProperty11.errors.txt index 2a72fefa53e..537daaf44ea 100644 --- a/tests/baselines/reference/decoratorOnClassProperty11.errors.txt +++ b/tests/baselines/reference/decoratorOnClassProperty11.errors.txt @@ -1,4 +1,4 @@ -tests/cases/conformance/decorators/class/property/decoratorOnClassProperty11.ts(4,5): error TS1240: Unable to resolve signature of property decorator when called as an expression. +tests/cases/conformance/decorators/class/property/decoratorOnClassProperty11.ts(4,5): error TS1329: 'dec' accepts too few arguments to be used as a decorator here. Did you mean to call it first and write '@dec()'? ==== tests/cases/conformance/decorators/class/property/decoratorOnClassProperty11.ts (1 errors) ==== @@ -7,5 +7,5 @@ tests/cases/conformance/decorators/class/property/decoratorOnClassProperty11.ts( class C { @dec prop; ~~~~ -!!! error TS1240: Unable to resolve signature of property decorator when called as an expression. +!!! error TS1329: 'dec' accepts too few arguments to be used as a decorator here. Did you mean to call it first and write '@dec()'? } \ No newline at end of file diff --git a/tests/baselines/reference/discriminatedUnionErrorMessage.errors.txt b/tests/baselines/reference/discriminatedUnionErrorMessage.errors.txt index 6f1eb511d37..e54727befd0 100644 --- a/tests/baselines/reference/discriminatedUnionErrorMessage.errors.txt +++ b/tests/baselines/reference/discriminatedUnionErrorMessage.errors.txt @@ -1,6 +1,5 @@ -tests/cases/compiler/discriminatedUnionErrorMessage.ts(8,5): error TS2322: Type '{ kind: "sq"; x: number; y: number; }' is not assignable to type 'Shape'. - Type '{ kind: "sq"; x: number; y: number; }' is not assignable to type 'Square'. - Property 'size' is missing in type '{ kind: "sq"; x: number; y: number; }'. +tests/cases/compiler/discriminatedUnionErrorMessage.ts(10,5): error TS2322: Type '{ kind: "sq"; x: number; y: number; }' is not assignable to type 'Shape'. + Object literal may only specify known properties, and 'x' does not exist in type 'Square'. ==== tests/cases/compiler/discriminatedUnionErrorMessage.ts (1 errors) ==== @@ -12,12 +11,11 @@ tests/cases/compiler/discriminatedUnionErrorMessage.ts(8,5): error TS2322: Type | Rectangle | Circle; let shape: Shape = { - ~~~~~ -!!! error TS2322: Type '{ kind: "sq"; x: number; y: number; }' is not assignable to type 'Shape'. -!!! error TS2322: Type '{ kind: "sq"; x: number; y: number; }' is not assignable to type 'Square'. -!!! error TS2322: Property 'size' is missing in type '{ kind: "sq"; x: number; y: number; }'. kind: "sq", x: 12, + ~~~~~ +!!! error TS2322: Type '{ kind: "sq"; x: number; y: number; }' is not assignable to type 'Shape'. +!!! error TS2322: Object literal may only specify known properties, and 'x' does not exist in type 'Square'. y: 13, } \ No newline at end of file diff --git a/tests/baselines/reference/duplicateExportAssignments.errors.txt b/tests/baselines/reference/duplicateExportAssignments.errors.txt index 17ad0a39847..0ad9507c9a6 100644 --- a/tests/baselines/reference/duplicateExportAssignments.errors.txt +++ b/tests/baselines/reference/duplicateExportAssignments.errors.txt @@ -1,34 +1,34 @@ -tests/cases/conformance/externalModules/foo1.ts(3,1): error TS2300: Duplicate identifier 'export='. -tests/cases/conformance/externalModules/foo1.ts(4,1): error TS2300: Duplicate identifier 'export='. -tests/cases/conformance/externalModules/foo2.ts(3,1): error TS2300: Duplicate identifier 'export='. -tests/cases/conformance/externalModules/foo2.ts(4,1): error TS2300: Duplicate identifier 'export='. -tests/cases/conformance/externalModules/foo3.ts(7,1): error TS2300: Duplicate identifier 'export='. -tests/cases/conformance/externalModules/foo3.ts(8,1): error TS2300: Duplicate identifier 'export='. -tests/cases/conformance/externalModules/foo4.ts(1,1): error TS2300: Duplicate identifier 'export='. -tests/cases/conformance/externalModules/foo4.ts(8,1): error TS2300: Duplicate identifier 'export='. -tests/cases/conformance/externalModules/foo5.ts(4,1): error TS2300: Duplicate identifier 'export='. -tests/cases/conformance/externalModules/foo5.ts(5,1): error TS2300: Duplicate identifier 'export='. -tests/cases/conformance/externalModules/foo5.ts(6,1): error TS2300: Duplicate identifier 'export='. +tests/cases/conformance/externalModules/foo1.ts(3,10): error TS2300: Duplicate identifier 'export='. +tests/cases/conformance/externalModules/foo1.ts(4,10): error TS2300: Duplicate identifier 'export='. +tests/cases/conformance/externalModules/foo2.ts(3,10): error TS2300: Duplicate identifier 'export='. +tests/cases/conformance/externalModules/foo2.ts(4,10): error TS2300: Duplicate identifier 'export='. +tests/cases/conformance/externalModules/foo3.ts(7,10): error TS2300: Duplicate identifier 'export='. +tests/cases/conformance/externalModules/foo3.ts(8,10): error TS2300: Duplicate identifier 'export='. +tests/cases/conformance/externalModules/foo4.ts(1,10): error TS2300: Duplicate identifier 'export='. +tests/cases/conformance/externalModules/foo4.ts(8,10): error TS2300: Duplicate identifier 'export='. +tests/cases/conformance/externalModules/foo5.ts(4,10): error TS2300: Duplicate identifier 'export='. +tests/cases/conformance/externalModules/foo5.ts(5,10): error TS2300: Duplicate identifier 'export='. +tests/cases/conformance/externalModules/foo5.ts(6,10): error TS2300: Duplicate identifier 'export='. ==== tests/cases/conformance/externalModules/foo1.ts (2 errors) ==== var x = 10; var y = 20; export = x; - ~~~~~~~~~~~ + ~ !!! error TS2300: Duplicate identifier 'export='. export = y; - ~~~~~~~~~~~ + ~ !!! error TS2300: Duplicate identifier 'export='. ==== tests/cases/conformance/externalModules/foo2.ts (2 errors) ==== var x = 10; class y {}; export = x; - ~~~~~~~~~~~ + ~ !!! error TS2300: Duplicate identifier 'export='. export = y; - ~~~~~~~~~~~ + ~ !!! error TS2300: Duplicate identifier 'export='. ==== tests/cases/conformance/externalModules/foo3.ts (2 errors) ==== @@ -39,15 +39,15 @@ tests/cases/conformance/externalModules/foo5.ts(6,1): error TS2300: Duplicate id y: number; } export = x; - ~~~~~~~~~~~ + ~ !!! error TS2300: Duplicate identifier 'export='. export = y; - ~~~~~~~~~~~ + ~ !!! error TS2300: Duplicate identifier 'export='. ==== tests/cases/conformance/externalModules/foo4.ts (2 errors) ==== export = x; - ~~~~~~~~~~~ + ~ !!! error TS2300: Duplicate identifier 'export='. function x(){ return 42; @@ -56,7 +56,7 @@ tests/cases/conformance/externalModules/foo5.ts(6,1): error TS2300: Duplicate id return 42; } export = y; - ~~~~~~~~~~~ + ~ !!! error TS2300: Duplicate identifier 'export='. ==== tests/cases/conformance/externalModules/foo5.ts (3 errors) ==== @@ -64,12 +64,12 @@ tests/cases/conformance/externalModules/foo5.ts(6,1): error TS2300: Duplicate id var y = "test"; var z = {}; export = x; - ~~~~~~~~~~~ + ~ !!! error TS2300: Duplicate identifier 'export='. export = y; - ~~~~~~~~~~~ + ~ !!! error TS2300: Duplicate identifier 'export='. export = z; - ~~~~~~~~~~~ + ~ !!! error TS2300: Duplicate identifier 'export='. \ No newline at end of file diff --git a/tests/baselines/reference/duplicateOverloadInTypeAugmentation1.symbols b/tests/baselines/reference/duplicateOverloadInTypeAugmentation1.symbols index 02589e011c4..31efb739e4c 100644 --- a/tests/baselines/reference/duplicateOverloadInTypeAugmentation1.symbols +++ b/tests/baselines/reference/duplicateOverloadInTypeAugmentation1.symbols @@ -4,7 +4,7 @@ interface Array { >T : Symbol(T, Decl(lib.d.ts, --, --), Decl(duplicateOverloadInTypeAugmentation1.ts, 0, 16)) reduce(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T, ->reduce : Symbol(Array.reduce, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(duplicateOverloadInTypeAugmentation1.ts, 0, 20), Decl(duplicateOverloadInTypeAugmentation1.ts, 2, 29)) +>reduce : Symbol(Array.reduce, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(duplicateOverloadInTypeAugmentation1.ts, 0, 20), Decl(duplicateOverloadInTypeAugmentation1.ts, 2, 29)) >callbackfn : Symbol(callbackfn, Decl(duplicateOverloadInTypeAugmentation1.ts, 1, 11)) >previousValue : Symbol(previousValue, Decl(duplicateOverloadInTypeAugmentation1.ts, 1, 24)) >T : Symbol(T, Decl(lib.d.ts, --, --), Decl(duplicateOverloadInTypeAugmentation1.ts, 0, 16)) @@ -21,7 +21,7 @@ interface Array { >T : Symbol(T, Decl(lib.d.ts, --, --), Decl(duplicateOverloadInTypeAugmentation1.ts, 0, 16)) reduce(callbackfn: (previousValue: U, currentValue: T, currentIndex: number, array: T[]) => U, ->reduce : Symbol(Array.reduce, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(duplicateOverloadInTypeAugmentation1.ts, 0, 20), Decl(duplicateOverloadInTypeAugmentation1.ts, 2, 29)) +>reduce : Symbol(Array.reduce, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(duplicateOverloadInTypeAugmentation1.ts, 0, 20), Decl(duplicateOverloadInTypeAugmentation1.ts, 2, 29)) >U : Symbol(U, Decl(duplicateOverloadInTypeAugmentation1.ts, 3, 11)) >callbackfn : Symbol(callbackfn, Decl(duplicateOverloadInTypeAugmentation1.ts, 3, 14)) >previousValue : Symbol(previousValue, Decl(duplicateOverloadInTypeAugmentation1.ts, 3, 27)) @@ -44,9 +44,9 @@ var a: Array; var r5 = a.reduce((x, y) => x + y); >r5 : Symbol(r5, Decl(duplicateOverloadInTypeAugmentation1.ts, 7, 3)) ->a.reduce : Symbol(Array.reduce, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(duplicateOverloadInTypeAugmentation1.ts, 0, 20), Decl(duplicateOverloadInTypeAugmentation1.ts, 2, 29)) +>a.reduce : Symbol(Array.reduce, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(duplicateOverloadInTypeAugmentation1.ts, 0, 20), Decl(duplicateOverloadInTypeAugmentation1.ts, 2, 29)) >a : Symbol(a, Decl(duplicateOverloadInTypeAugmentation1.ts, 6, 3)) ->reduce : Symbol(Array.reduce, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(duplicateOverloadInTypeAugmentation1.ts, 0, 20), Decl(duplicateOverloadInTypeAugmentation1.ts, 2, 29)) +>reduce : Symbol(Array.reduce, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(duplicateOverloadInTypeAugmentation1.ts, 0, 20), Decl(duplicateOverloadInTypeAugmentation1.ts, 2, 29)) >x : Symbol(x, Decl(duplicateOverloadInTypeAugmentation1.ts, 7, 19)) >y : Symbol(y, Decl(duplicateOverloadInTypeAugmentation1.ts, 7, 21)) >x : Symbol(x, Decl(duplicateOverloadInTypeAugmentation1.ts, 7, 19)) diff --git a/tests/baselines/reference/duplicateOverloadInTypeAugmentation1.types b/tests/baselines/reference/duplicateOverloadInTypeAugmentation1.types index bc7214eb6b9..ea07ece4314 100644 --- a/tests/baselines/reference/duplicateOverloadInTypeAugmentation1.types +++ b/tests/baselines/reference/duplicateOverloadInTypeAugmentation1.types @@ -4,7 +4,7 @@ interface Array { >T : T reduce(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T, ->reduce : { (callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T, initialValue?: T): T; (callbackfn: (previousValue: U, currentValue: T, currentIndex: number, array: T[]) => U, initialValue: U): U; (callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T, initialValue?: T): T; (callbackfn: (previousValue: U, currentValue: T, currentIndex: number, array: T[]) => U, initialValue: U): U; } +>reduce : { (callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T): T; (callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T, initialValue: T): T; (callbackfn: (previousValue: U, currentValue: T, currentIndex: number, array: T[]) => U, initialValue: U): U; (callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T, initialValue?: T): T; (callbackfn: (previousValue: U, currentValue: T, currentIndex: number, array: T[]) => U, initialValue: U): U; } >callbackfn : (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T >previousValue : T >T : T @@ -21,7 +21,7 @@ interface Array { >T : T reduce(callbackfn: (previousValue: U, currentValue: T, currentIndex: number, array: T[]) => U, ->reduce : { (callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T, initialValue?: T): T; (callbackfn: (previousValue: U, currentValue: T, currentIndex: number, array: T[]) => U, initialValue: U): U; (callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T, initialValue?: T): T; (callbackfn: (previousValue: U, currentValue: T, currentIndex: number, array: T[]) => U, initialValue: U): U; } +>reduce : { (callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T): T; (callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T, initialValue: T): T; (callbackfn: (previousValue: U, currentValue: T, currentIndex: number, array: T[]) => U, initialValue: U): U; (callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T, initialValue?: T): T; (callbackfn: (previousValue: U, currentValue: T, currentIndex: number, array: T[]) => U, initialValue: U): U; } >U : U >callbackfn : (previousValue: U, currentValue: T, currentIndex: number, array: T[]) => U >previousValue : U @@ -45,9 +45,9 @@ var a: Array; var r5 = a.reduce((x, y) => x + y); >r5 : string >a.reduce((x, y) => x + y) : string ->a.reduce : { (callbackfn: (previousValue: string, currentValue: string, currentIndex: number, array: string[]) => string, initialValue?: string): string; (callbackfn: (previousValue: U, currentValue: string, currentIndex: number, array: string[]) => U, initialValue: U): U; (callbackfn: (previousValue: string, currentValue: string, currentIndex: number, array: string[]) => string, initialValue?: string): string; (callbackfn: (previousValue: U, currentValue: string, currentIndex: number, array: string[]) => U, initialValue: U): U; } +>a.reduce : { (callbackfn: (previousValue: string, currentValue: string, currentIndex: number, array: string[]) => string): string; (callbackfn: (previousValue: string, currentValue: string, currentIndex: number, array: string[]) => string, initialValue: string): string; (callbackfn: (previousValue: U, currentValue: string, currentIndex: number, array: string[]) => U, initialValue: U): U; (callbackfn: (previousValue: string, currentValue: string, currentIndex: number, array: string[]) => string, initialValue?: string): string; (callbackfn: (previousValue: U, currentValue: string, currentIndex: number, array: string[]) => U, initialValue: U): U; } >a : string[] ->reduce : { (callbackfn: (previousValue: string, currentValue: string, currentIndex: number, array: string[]) => string, initialValue?: string): string; (callbackfn: (previousValue: U, currentValue: string, currentIndex: number, array: string[]) => U, initialValue: U): U; (callbackfn: (previousValue: string, currentValue: string, currentIndex: number, array: string[]) => string, initialValue?: string): string; (callbackfn: (previousValue: U, currentValue: string, currentIndex: number, array: string[]) => U, initialValue: U): U; } +>reduce : { (callbackfn: (previousValue: string, currentValue: string, currentIndex: number, array: string[]) => string): string; (callbackfn: (previousValue: string, currentValue: string, currentIndex: number, array: string[]) => string, initialValue: string): string; (callbackfn: (previousValue: U, currentValue: string, currentIndex: number, array: string[]) => U, initialValue: U): U; (callbackfn: (previousValue: string, currentValue: string, currentIndex: number, array: string[]) => string, initialValue?: string): string; (callbackfn: (previousValue: U, currentValue: string, currentIndex: number, array: string[]) => U, initialValue: U): U; } >(x, y) => x + y : (x: string, y: string) => string >x : string >y : string diff --git a/tests/baselines/reference/dynamicImportInDefaultExportExpression.errors.txt b/tests/baselines/reference/dynamicImportInDefaultExportExpression.errors.txt new file mode 100644 index 00000000000..8bf6704b743 --- /dev/null +++ b/tests/baselines/reference/dynamicImportInDefaultExportExpression.errors.txt @@ -0,0 +1,11 @@ +tests/cases/compiler/dynamicImportInDefaultExportExpression.ts(3,23): error TS2307: Cannot find module './foo2'. + + +==== tests/cases/compiler/dynamicImportInDefaultExportExpression.ts (1 errors) ==== + export default { + getInstance: function () { + return import('./foo2'); + ~~~~~~~~ +!!! error TS2307: Cannot find module './foo2'. + } + } \ No newline at end of file diff --git a/tests/baselines/reference/dynamicImportInDefaultExportExpression.js b/tests/baselines/reference/dynamicImportInDefaultExportExpression.js new file mode 100644 index 00000000000..75e5e0d57a2 --- /dev/null +++ b/tests/baselines/reference/dynamicImportInDefaultExportExpression.js @@ -0,0 +1,15 @@ +//// [dynamicImportInDefaultExportExpression.ts] +export default { + getInstance: function () { + return import('./foo2'); + } +} + +//// [dynamicImportInDefaultExportExpression.js] +"use strict"; +exports.__esModule = true; +exports["default"] = { + getInstance: function () { + return Promise.resolve().then(function () { return require('./foo2'); }); + } +}; diff --git a/tests/baselines/reference/dynamicImportInDefaultExportExpression.symbols b/tests/baselines/reference/dynamicImportInDefaultExportExpression.symbols new file mode 100644 index 00000000000..d16b5f0a374 --- /dev/null +++ b/tests/baselines/reference/dynamicImportInDefaultExportExpression.symbols @@ -0,0 +1,8 @@ +=== tests/cases/compiler/dynamicImportInDefaultExportExpression.ts === +export default { + getInstance: function () { +>getInstance : Symbol(getInstance, Decl(dynamicImportInDefaultExportExpression.ts, 0, 16)) + + return import('./foo2'); + } +} diff --git a/tests/baselines/reference/dynamicImportInDefaultExportExpression.types b/tests/baselines/reference/dynamicImportInDefaultExportExpression.types new file mode 100644 index 00000000000..c75894a17ff --- /dev/null +++ b/tests/baselines/reference/dynamicImportInDefaultExportExpression.types @@ -0,0 +1,13 @@ +=== tests/cases/compiler/dynamicImportInDefaultExportExpression.ts === +export default { +>{ getInstance: function () { return import('./foo2'); }} : { getInstance: () => Promise; } + + getInstance: function () { +>getInstance : () => Promise +>function () { return import('./foo2'); } : () => Promise + + return import('./foo2'); +>import('./foo2') : Promise +>'./foo2' : "./foo2" + } +} diff --git a/tests/baselines/reference/dynamicImportWithNestedThis_es2015.js b/tests/baselines/reference/dynamicImportWithNestedThis_es2015.js new file mode 100644 index 00000000000..86fba0c0b5d --- /dev/null +++ b/tests/baselines/reference/dynamicImportWithNestedThis_es2015.js @@ -0,0 +1,37 @@ +//// [dynamicImportWithNestedThis_es2015.ts] +// https://github.com/Microsoft/TypeScript/issues/17564 +class C { + private _path = './other'; + + dynamic() { + return import(this._path); + } +} + +const c = new C(); +c.dynamic(); + +//// [dynamicImportWithNestedThis_es2015.js] +(function (factory) { + if (typeof module === "object" && typeof module.exports === "object") { + var v = factory(require, exports); + if (v !== undefined) module.exports = v; + } + else if (typeof define === "function" && define.amd) { + define(["require", "exports"], factory); + } +})(function (require, exports) { + "use strict"; + var __syncRequire = typeof module === "object" && typeof module.exports === "object"; + // https://github.com/Microsoft/TypeScript/issues/17564 + class C { + constructor() { + this._path = './other'; + } + dynamic() { + return __syncRequire ? Promise.resolve().then(() => require(this._path)) : new Promise((resolve_1, reject_1) => { require([this._path], resolve_1, reject_1); }); + } + } + const c = new C(); + c.dynamic(); +}); diff --git a/tests/baselines/reference/dynamicImportWithNestedThis_es2015.symbols b/tests/baselines/reference/dynamicImportWithNestedThis_es2015.symbols new file mode 100644 index 00000000000..7043a071124 --- /dev/null +++ b/tests/baselines/reference/dynamicImportWithNestedThis_es2015.symbols @@ -0,0 +1,27 @@ +=== tests/cases/compiler/dynamicImportWithNestedThis_es2015.ts === +// https://github.com/Microsoft/TypeScript/issues/17564 +class C { +>C : Symbol(C, Decl(dynamicImportWithNestedThis_es2015.ts, 0, 0)) + + private _path = './other'; +>_path : Symbol(C._path, Decl(dynamicImportWithNestedThis_es2015.ts, 1, 9)) + + dynamic() { +>dynamic : Symbol(C.dynamic, Decl(dynamicImportWithNestedThis_es2015.ts, 2, 27)) + + return import(this._path); +>this._path : Symbol(C._path, Decl(dynamicImportWithNestedThis_es2015.ts, 1, 9)) +>this : Symbol(C, Decl(dynamicImportWithNestedThis_es2015.ts, 0, 0)) +>_path : Symbol(C._path, Decl(dynamicImportWithNestedThis_es2015.ts, 1, 9)) + } +} + +const c = new C(); +>c : Symbol(c, Decl(dynamicImportWithNestedThis_es2015.ts, 9, 5)) +>C : Symbol(C, Decl(dynamicImportWithNestedThis_es2015.ts, 0, 0)) + +c.dynamic(); +>c.dynamic : Symbol(C.dynamic, Decl(dynamicImportWithNestedThis_es2015.ts, 2, 27)) +>c : Symbol(c, Decl(dynamicImportWithNestedThis_es2015.ts, 9, 5)) +>dynamic : Symbol(C.dynamic, Decl(dynamicImportWithNestedThis_es2015.ts, 2, 27)) + diff --git a/tests/baselines/reference/dynamicImportWithNestedThis_es2015.types b/tests/baselines/reference/dynamicImportWithNestedThis_es2015.types new file mode 100644 index 00000000000..165929a43cf --- /dev/null +++ b/tests/baselines/reference/dynamicImportWithNestedThis_es2015.types @@ -0,0 +1,31 @@ +=== tests/cases/compiler/dynamicImportWithNestedThis_es2015.ts === +// https://github.com/Microsoft/TypeScript/issues/17564 +class C { +>C : C + + private _path = './other'; +>_path : string +>'./other' : "./other" + + dynamic() { +>dynamic : () => Promise + + return import(this._path); +>import(this._path) : Promise +>this._path : string +>this : this +>_path : string + } +} + +const c = new C(); +>c : C +>new C() : C +>C : typeof C + +c.dynamic(); +>c.dynamic() : Promise +>c.dynamic : () => Promise +>c : C +>dynamic : () => Promise + diff --git a/tests/baselines/reference/dynamicImportWithNestedThis_es5.js b/tests/baselines/reference/dynamicImportWithNestedThis_es5.js new file mode 100644 index 00000000000..cde1979b25b --- /dev/null +++ b/tests/baselines/reference/dynamicImportWithNestedThis_es5.js @@ -0,0 +1,39 @@ +//// [dynamicImportWithNestedThis_es5.ts] +// https://github.com/Microsoft/TypeScript/issues/17564 +class C { + private _path = './other'; + + dynamic() { + return import(this._path); + } +} + +const c = new C(); +c.dynamic(); + +//// [dynamicImportWithNestedThis_es5.js] +(function (factory) { + if (typeof module === "object" && typeof module.exports === "object") { + var v = factory(require, exports); + if (v !== undefined) module.exports = v; + } + else if (typeof define === "function" && define.amd) { + define(["require", "exports"], factory); + } +})(function (require, exports) { + "use strict"; + var __syncRequire = typeof module === "object" && typeof module.exports === "object"; + // https://github.com/Microsoft/TypeScript/issues/17564 + var C = /** @class */ (function () { + function C() { + this._path = './other'; + } + C.prototype.dynamic = function () { + var _this = this; + return __syncRequire ? Promise.resolve().then(function () { return require(_this._path); }) : new Promise(function (resolve_1, reject_1) { require([_this._path], resolve_1, reject_1); }); + }; + return C; + }()); + var c = new C(); + c.dynamic(); +}); diff --git a/tests/baselines/reference/dynamicImportWithNestedThis_es5.symbols b/tests/baselines/reference/dynamicImportWithNestedThis_es5.symbols new file mode 100644 index 00000000000..6a127548030 --- /dev/null +++ b/tests/baselines/reference/dynamicImportWithNestedThis_es5.symbols @@ -0,0 +1,27 @@ +=== tests/cases/compiler/dynamicImportWithNestedThis_es5.ts === +// https://github.com/Microsoft/TypeScript/issues/17564 +class C { +>C : Symbol(C, Decl(dynamicImportWithNestedThis_es5.ts, 0, 0)) + + private _path = './other'; +>_path : Symbol(C._path, Decl(dynamicImportWithNestedThis_es5.ts, 1, 9)) + + dynamic() { +>dynamic : Symbol(C.dynamic, Decl(dynamicImportWithNestedThis_es5.ts, 2, 27)) + + return import(this._path); +>this._path : Symbol(C._path, Decl(dynamicImportWithNestedThis_es5.ts, 1, 9)) +>this : Symbol(C, Decl(dynamicImportWithNestedThis_es5.ts, 0, 0)) +>_path : Symbol(C._path, Decl(dynamicImportWithNestedThis_es5.ts, 1, 9)) + } +} + +const c = new C(); +>c : Symbol(c, Decl(dynamicImportWithNestedThis_es5.ts, 9, 5)) +>C : Symbol(C, Decl(dynamicImportWithNestedThis_es5.ts, 0, 0)) + +c.dynamic(); +>c.dynamic : Symbol(C.dynamic, Decl(dynamicImportWithNestedThis_es5.ts, 2, 27)) +>c : Symbol(c, Decl(dynamicImportWithNestedThis_es5.ts, 9, 5)) +>dynamic : Symbol(C.dynamic, Decl(dynamicImportWithNestedThis_es5.ts, 2, 27)) + diff --git a/tests/baselines/reference/dynamicImportWithNestedThis_es5.types b/tests/baselines/reference/dynamicImportWithNestedThis_es5.types new file mode 100644 index 00000000000..78b0f472971 --- /dev/null +++ b/tests/baselines/reference/dynamicImportWithNestedThis_es5.types @@ -0,0 +1,31 @@ +=== tests/cases/compiler/dynamicImportWithNestedThis_es5.ts === +// https://github.com/Microsoft/TypeScript/issues/17564 +class C { +>C : C + + private _path = './other'; +>_path : string +>'./other' : "./other" + + dynamic() { +>dynamic : () => Promise + + return import(this._path); +>import(this._path) : Promise +>this._path : string +>this : this +>_path : string + } +} + +const c = new C(); +>c : C +>new C() : C +>C : typeof C + +c.dynamic(); +>c.dynamic() : Promise +>c.dynamic : () => Promise +>c : C +>dynamic : () => Promise + diff --git a/tests/baselines/reference/es5-commonjs7.symbols b/tests/baselines/reference/es5-commonjs7.symbols index ed8247a6878..eb6dc062573 100644 --- a/tests/baselines/reference/es5-commonjs7.symbols +++ b/tests/baselines/reference/es5-commonjs7.symbols @@ -1,6 +1,6 @@ === tests/cases/compiler/test.d.ts === export default undefined; ->undefined : Symbol(default) +>undefined : Symbol(undefined) export var __esModule; >__esModule : Symbol(__esModule, Decl(test.d.ts, 1, 10)) diff --git a/tests/baselines/reference/excessPropertyCheckWithUnions.errors.txt b/tests/baselines/reference/excessPropertyCheckWithUnions.errors.txt new file mode 100644 index 00000000000..3b7e5a787d2 --- /dev/null +++ b/tests/baselines/reference/excessPropertyCheckWithUnions.errors.txt @@ -0,0 +1,99 @@ +tests/cases/compiler/excessPropertyCheckWithUnions.ts(10,30): error TS2322: Type '{ tag: "T"; a1: string; }' is not assignable to type 'ADT'. + Object literal may only specify known properties, and 'a1' does not exist in type '{ tag: "T"; }'. +tests/cases/compiler/excessPropertyCheckWithUnions.ts(11,21): error TS2322: Type '{ tag: "A"; d20: 12; }' is not assignable to type 'ADT'. + Object literal may only specify known properties, and 'd20' does not exist in type '{ tag: "A"; a1: string; }'. +tests/cases/compiler/excessPropertyCheckWithUnions.ts(12,1): error TS2322: Type '{ tag: "D"; }' is not assignable to type 'ADT'. + Type '{ tag: "D"; }' is not assignable to type '{ tag: "D"; d20: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20; }'. + Property 'd20' is missing in type '{ tag: "D"; }'. +tests/cases/compiler/excessPropertyCheckWithUnions.ts(33,28): error TS2322: Type '{ tag: "A"; x: string; extra: number; }' is not assignable to type 'Ambiguous'. + Object literal may only specify known properties, and 'extra' does not exist in type 'Ambiguous'. +tests/cases/compiler/excessPropertyCheckWithUnions.ts(34,26): error TS2322: Type '{ tag: "A"; y: number; extra: number; }' is not assignable to type 'Ambiguous'. + Object literal may only specify known properties, and 'extra' does not exist in type 'Ambiguous'. +tests/cases/compiler/excessPropertyCheckWithUnions.ts(39,1): error TS2322: Type '{ tag: "A"; }' is not assignable to type 'Ambiguous'. + Type '{ tag: "A"; }' is not assignable to type '{ tag: "C"; }'. + Types of property 'tag' are incompatible. + Type '"A"' is not assignable to type '"C"'. +tests/cases/compiler/excessPropertyCheckWithUnions.ts(40,1): error TS2322: Type '{ tag: "A"; z: true; }' is not assignable to type 'Ambiguous'. + Type '{ tag: "A"; z: true; }' is not assignable to type '{ tag: "C"; }'. + Types of property 'tag' are incompatible. + Type '"A"' is not assignable to type '"C"'. + + +==== tests/cases/compiler/excessPropertyCheckWithUnions.ts (7 errors) ==== + type ADT = { + tag: "A", + a1: string + } | { + tag: "D", + d20: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 + } | { + tag: "T", + } + let wrong: ADT = { tag: "T", a1: "extra" } + ~~~~~~~~~~~ +!!! error TS2322: Type '{ tag: "T"; a1: string; }' is not assignable to type 'ADT'. +!!! error TS2322: Object literal may only specify known properties, and 'a1' does not exist in type '{ tag: "T"; }'. + wrong = { tag: "A", d20: 12 } + ~~~~~~~ +!!! error TS2322: Type '{ tag: "A"; d20: 12; }' is not assignable to type 'ADT'. +!!! error TS2322: Object literal may only specify known properties, and 'd20' does not exist in type '{ tag: "A"; a1: string; }'. + wrong = { tag: "D" } + ~~~~~ +!!! error TS2322: Type '{ tag: "D"; }' is not assignable to type 'ADT'. +!!! error TS2322: Type '{ tag: "D"; }' is not assignable to type '{ tag: "D"; d20: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20; }'. +!!! error TS2322: Property 'd20' is missing in type '{ tag: "D"; }'. + + type Ambiguous = { + tag: "A", + x: string + } | { + tag: "A", + y: number + } | { + tag: "B", + z: boolean + } | { + tag: "C" + } + let amb: Ambiguous + // no error for ambiguous tag, even when it could satisfy both constituents at once + amb = { tag: "A", x: "hi" } + amb = { tag: "A", y: 12 } + amb = { tag: "A", x: "hi", y: 12 } + + // correctly error on excess property 'extra', even when ambiguous + amb = { tag: "A", x: "hi", extra: 12 } + ~~~~~~~~~ +!!! error TS2322: Type '{ tag: "A"; x: string; extra: number; }' is not assignable to type 'Ambiguous'. +!!! error TS2322: Object literal may only specify known properties, and 'extra' does not exist in type 'Ambiguous'. + amb = { tag: "A", y: 12, extra: 12 } + ~~~~~~~~~ +!!! error TS2322: Type '{ tag: "A"; y: number; extra: number; }' is not assignable to type 'Ambiguous'. +!!! error TS2322: Object literal may only specify known properties, and 'extra' does not exist in type 'Ambiguous'. + + // assignability errors still work. + // But note that the error for `z: true` is the fallback one of reporting on + // the last constituent since assignability error reporting can't find a single best discriminant either. + amb = { tag: "A" } + ~~~ +!!! error TS2322: Type '{ tag: "A"; }' is not assignable to type 'Ambiguous'. +!!! error TS2322: Type '{ tag: "A"; }' is not assignable to type '{ tag: "C"; }'. +!!! error TS2322: Types of property 'tag' are incompatible. +!!! error TS2322: Type '"A"' is not assignable to type '"C"'. + amb = { tag: "A", z: true } + ~~~ +!!! error TS2322: Type '{ tag: "A"; z: true; }' is not assignable to type 'Ambiguous'. +!!! error TS2322: Type '{ tag: "A"; z: true; }' is not assignable to type '{ tag: "C"; }'. +!!! error TS2322: Types of property 'tag' are incompatible. +!!! error TS2322: Type '"A"' is not assignable to type '"C"'. + + type Overlapping = + | { a: 1, b: 1, first: string } + | { a: 2, second: string } + | { b: 3, third: string } + let over: Overlapping + + // these two are not reported because there are two discriminant properties + over = { a: 1, b: 1, first: "ok", second: "error" } + over = { a: 1, b: 1, first: "ok", third: "error" } + \ No newline at end of file diff --git a/tests/baselines/reference/excessPropertyCheckWithUnions.js b/tests/baselines/reference/excessPropertyCheckWithUnions.js new file mode 100644 index 00000000000..c6da660b52d --- /dev/null +++ b/tests/baselines/reference/excessPropertyCheckWithUnions.js @@ -0,0 +1,74 @@ +//// [excessPropertyCheckWithUnions.ts] +type ADT = { + tag: "A", + a1: string +} | { + tag: "D", + d20: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 +} | { + tag: "T", +} +let wrong: ADT = { tag: "T", a1: "extra" } +wrong = { tag: "A", d20: 12 } +wrong = { tag: "D" } + +type Ambiguous = { + tag: "A", + x: string +} | { + tag: "A", + y: number +} | { + tag: "B", + z: boolean +} | { + tag: "C" +} +let amb: Ambiguous +// no error for ambiguous tag, even when it could satisfy both constituents at once +amb = { tag: "A", x: "hi" } +amb = { tag: "A", y: 12 } +amb = { tag: "A", x: "hi", y: 12 } + +// correctly error on excess property 'extra', even when ambiguous +amb = { tag: "A", x: "hi", extra: 12 } +amb = { tag: "A", y: 12, extra: 12 } + +// assignability errors still work. +// But note that the error for `z: true` is the fallback one of reporting on +// the last constituent since assignability error reporting can't find a single best discriminant either. +amb = { tag: "A" } +amb = { tag: "A", z: true } + +type Overlapping = + | { a: 1, b: 1, first: string } + | { a: 2, second: string } + | { b: 3, third: string } +let over: Overlapping + +// these two are not reported because there are two discriminant properties +over = { a: 1, b: 1, first: "ok", second: "error" } +over = { a: 1, b: 1, first: "ok", third: "error" } + + +//// [excessPropertyCheckWithUnions.js] +var wrong = { tag: "T", a1: "extra" }; +wrong = { tag: "A", d20: 12 }; +wrong = { tag: "D" }; +var amb; +// no error for ambiguous tag, even when it could satisfy both constituents at once +amb = { tag: "A", x: "hi" }; +amb = { tag: "A", y: 12 }; +amb = { tag: "A", x: "hi", y: 12 }; +// correctly error on excess property 'extra', even when ambiguous +amb = { tag: "A", x: "hi", extra: 12 }; +amb = { tag: "A", y: 12, extra: 12 }; +// assignability errors still work. +// But note that the error for `z: true` is the fallback one of reporting on +// the last constituent since assignability error reporting can't find a single best discriminant either. +amb = { tag: "A" }; +amb = { tag: "A", z: true }; +var over; +// these two are not reported because there are two discriminant properties +over = { a: 1, b: 1, first: "ok", second: "error" }; +over = { a: 1, b: 1, first: "ok", third: "error" }; diff --git a/tests/baselines/reference/excessPropertyCheckWithUnions.symbols b/tests/baselines/reference/excessPropertyCheckWithUnions.symbols new file mode 100644 index 00000000000..332166e396c --- /dev/null +++ b/tests/baselines/reference/excessPropertyCheckWithUnions.symbols @@ -0,0 +1,144 @@ +=== tests/cases/compiler/excessPropertyCheckWithUnions.ts === +type ADT = { +>ADT : Symbol(ADT, Decl(excessPropertyCheckWithUnions.ts, 0, 0)) + + tag: "A", +>tag : Symbol(tag, Decl(excessPropertyCheckWithUnions.ts, 0, 12)) + + a1: string +>a1 : Symbol(a1, Decl(excessPropertyCheckWithUnions.ts, 1, 13)) + +} | { + tag: "D", +>tag : Symbol(tag, Decl(excessPropertyCheckWithUnions.ts, 3, 5)) + + d20: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 +>d20 : Symbol(d20, Decl(excessPropertyCheckWithUnions.ts, 4, 13)) + +} | { + tag: "T", +>tag : Symbol(tag, Decl(excessPropertyCheckWithUnions.ts, 6, 5)) +} +let wrong: ADT = { tag: "T", a1: "extra" } +>wrong : Symbol(wrong, Decl(excessPropertyCheckWithUnions.ts, 9, 3)) +>ADT : Symbol(ADT, Decl(excessPropertyCheckWithUnions.ts, 0, 0)) +>tag : Symbol(tag, Decl(excessPropertyCheckWithUnions.ts, 9, 18)) +>a1 : Symbol(a1, Decl(excessPropertyCheckWithUnions.ts, 9, 28)) + +wrong = { tag: "A", d20: 12 } +>wrong : Symbol(wrong, Decl(excessPropertyCheckWithUnions.ts, 9, 3)) +>tag : Symbol(tag, Decl(excessPropertyCheckWithUnions.ts, 10, 9)) +>d20 : Symbol(d20, Decl(excessPropertyCheckWithUnions.ts, 10, 19)) + +wrong = { tag: "D" } +>wrong : Symbol(wrong, Decl(excessPropertyCheckWithUnions.ts, 9, 3)) +>tag : Symbol(tag, Decl(excessPropertyCheckWithUnions.ts, 11, 9)) + +type Ambiguous = { +>Ambiguous : Symbol(Ambiguous, Decl(excessPropertyCheckWithUnions.ts, 11, 20)) + + tag: "A", +>tag : Symbol(tag, Decl(excessPropertyCheckWithUnions.ts, 13, 18)) + + x: string +>x : Symbol(x, Decl(excessPropertyCheckWithUnions.ts, 14, 13)) + +} | { + tag: "A", +>tag : Symbol(tag, Decl(excessPropertyCheckWithUnions.ts, 16, 5)) + + y: number +>y : Symbol(y, Decl(excessPropertyCheckWithUnions.ts, 17, 13)) + +} | { + tag: "B", +>tag : Symbol(tag, Decl(excessPropertyCheckWithUnions.ts, 19, 5)) + + z: boolean +>z : Symbol(z, Decl(excessPropertyCheckWithUnions.ts, 20, 13)) + +} | { + tag: "C" +>tag : Symbol(tag, Decl(excessPropertyCheckWithUnions.ts, 22, 5)) +} +let amb: Ambiguous +>amb : Symbol(amb, Decl(excessPropertyCheckWithUnions.ts, 25, 3)) +>Ambiguous : Symbol(Ambiguous, Decl(excessPropertyCheckWithUnions.ts, 11, 20)) + +// no error for ambiguous tag, even when it could satisfy both constituents at once +amb = { tag: "A", x: "hi" } +>amb : Symbol(amb, Decl(excessPropertyCheckWithUnions.ts, 25, 3)) +>tag : Symbol(tag, Decl(excessPropertyCheckWithUnions.ts, 27, 7)) +>x : Symbol(x, Decl(excessPropertyCheckWithUnions.ts, 27, 17)) + +amb = { tag: "A", y: 12 } +>amb : Symbol(amb, Decl(excessPropertyCheckWithUnions.ts, 25, 3)) +>tag : Symbol(tag, Decl(excessPropertyCheckWithUnions.ts, 28, 7)) +>y : Symbol(y, Decl(excessPropertyCheckWithUnions.ts, 28, 17)) + +amb = { tag: "A", x: "hi", y: 12 } +>amb : Symbol(amb, Decl(excessPropertyCheckWithUnions.ts, 25, 3)) +>tag : Symbol(tag, Decl(excessPropertyCheckWithUnions.ts, 29, 7)) +>x : Symbol(x, Decl(excessPropertyCheckWithUnions.ts, 29, 17)) +>y : Symbol(y, Decl(excessPropertyCheckWithUnions.ts, 29, 26)) + +// correctly error on excess property 'extra', even when ambiguous +amb = { tag: "A", x: "hi", extra: 12 } +>amb : Symbol(amb, Decl(excessPropertyCheckWithUnions.ts, 25, 3)) +>tag : Symbol(tag, Decl(excessPropertyCheckWithUnions.ts, 32, 7)) +>x : Symbol(x, Decl(excessPropertyCheckWithUnions.ts, 32, 17)) +>extra : Symbol(extra, Decl(excessPropertyCheckWithUnions.ts, 32, 26)) + +amb = { tag: "A", y: 12, extra: 12 } +>amb : Symbol(amb, Decl(excessPropertyCheckWithUnions.ts, 25, 3)) +>tag : Symbol(tag, Decl(excessPropertyCheckWithUnions.ts, 33, 7)) +>y : Symbol(y, Decl(excessPropertyCheckWithUnions.ts, 33, 17)) +>extra : Symbol(extra, Decl(excessPropertyCheckWithUnions.ts, 33, 24)) + +// assignability errors still work. +// But note that the error for `z: true` is the fallback one of reporting on +// the last constituent since assignability error reporting can't find a single best discriminant either. +amb = { tag: "A" } +>amb : Symbol(amb, Decl(excessPropertyCheckWithUnions.ts, 25, 3)) +>tag : Symbol(tag, Decl(excessPropertyCheckWithUnions.ts, 38, 7)) + +amb = { tag: "A", z: true } +>amb : Symbol(amb, Decl(excessPropertyCheckWithUnions.ts, 25, 3)) +>tag : Symbol(tag, Decl(excessPropertyCheckWithUnions.ts, 39, 7)) +>z : Symbol(z, Decl(excessPropertyCheckWithUnions.ts, 39, 17)) + +type Overlapping = +>Overlapping : Symbol(Overlapping, Decl(excessPropertyCheckWithUnions.ts, 39, 27)) + + | { a: 1, b: 1, first: string } +>a : Symbol(a, Decl(excessPropertyCheckWithUnions.ts, 42, 7)) +>b : Symbol(b, Decl(excessPropertyCheckWithUnions.ts, 42, 13)) +>first : Symbol(first, Decl(excessPropertyCheckWithUnions.ts, 42, 19)) + + | { a: 2, second: string } +>a : Symbol(a, Decl(excessPropertyCheckWithUnions.ts, 43, 7)) +>second : Symbol(second, Decl(excessPropertyCheckWithUnions.ts, 43, 13)) + + | { b: 3, third: string } +>b : Symbol(b, Decl(excessPropertyCheckWithUnions.ts, 44, 7)) +>third : Symbol(third, Decl(excessPropertyCheckWithUnions.ts, 44, 13)) + +let over: Overlapping +>over : Symbol(over, Decl(excessPropertyCheckWithUnions.ts, 45, 3)) +>Overlapping : Symbol(Overlapping, Decl(excessPropertyCheckWithUnions.ts, 39, 27)) + +// these two are not reported because there are two discriminant properties +over = { a: 1, b: 1, first: "ok", second: "error" } +>over : Symbol(over, Decl(excessPropertyCheckWithUnions.ts, 45, 3)) +>a : Symbol(a, Decl(excessPropertyCheckWithUnions.ts, 48, 8)) +>b : Symbol(b, Decl(excessPropertyCheckWithUnions.ts, 48, 14)) +>first : Symbol(first, Decl(excessPropertyCheckWithUnions.ts, 48, 20)) +>second : Symbol(second, Decl(excessPropertyCheckWithUnions.ts, 48, 33)) + +over = { a: 1, b: 1, first: "ok", third: "error" } +>over : Symbol(over, Decl(excessPropertyCheckWithUnions.ts, 45, 3)) +>a : Symbol(a, Decl(excessPropertyCheckWithUnions.ts, 49, 8)) +>b : Symbol(b, Decl(excessPropertyCheckWithUnions.ts, 49, 14)) +>first : Symbol(first, Decl(excessPropertyCheckWithUnions.ts, 49, 20)) +>third : Symbol(third, Decl(excessPropertyCheckWithUnions.ts, 49, 33)) + diff --git a/tests/baselines/reference/excessPropertyCheckWithUnions.types b/tests/baselines/reference/excessPropertyCheckWithUnions.types new file mode 100644 index 00000000000..1d6bdd32eb2 --- /dev/null +++ b/tests/baselines/reference/excessPropertyCheckWithUnions.types @@ -0,0 +1,196 @@ +=== tests/cases/compiler/excessPropertyCheckWithUnions.ts === +type ADT = { +>ADT : ADT + + tag: "A", +>tag : "A" + + a1: string +>a1 : string + +} | { + tag: "D", +>tag : "D" + + d20: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 +>d20 : 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 + +} | { + tag: "T", +>tag : "T" +} +let wrong: ADT = { tag: "T", a1: "extra" } +>wrong : ADT +>ADT : ADT +>{ tag: "T", a1: "extra" } : { tag: "T"; a1: string; } +>tag : string +>"T" : "T" +>a1 : string +>"extra" : "extra" + +wrong = { tag: "A", d20: 12 } +>wrong = { tag: "A", d20: 12 } : { tag: "A"; d20: 12; } +>wrong : ADT +>{ tag: "A", d20: 12 } : { tag: "A"; d20: 12; } +>tag : string +>"A" : "A" +>d20 : number +>12 : 12 + +wrong = { tag: "D" } +>wrong = { tag: "D" } : { tag: "D"; } +>wrong : ADT +>{ tag: "D" } : { tag: "D"; } +>tag : string +>"D" : "D" + +type Ambiguous = { +>Ambiguous : Ambiguous + + tag: "A", +>tag : "A" + + x: string +>x : string + +} | { + tag: "A", +>tag : "A" + + y: number +>y : number + +} | { + tag: "B", +>tag : "B" + + z: boolean +>z : boolean + +} | { + tag: "C" +>tag : "C" +} +let amb: Ambiguous +>amb : Ambiguous +>Ambiguous : Ambiguous + +// no error for ambiguous tag, even when it could satisfy both constituents at once +amb = { tag: "A", x: "hi" } +>amb = { tag: "A", x: "hi" } : { tag: "A"; x: string; } +>amb : Ambiguous +>{ tag: "A", x: "hi" } : { tag: "A"; x: string; } +>tag : string +>"A" : "A" +>x : string +>"hi" : "hi" + +amb = { tag: "A", y: 12 } +>amb = { tag: "A", y: 12 } : { tag: "A"; y: number; } +>amb : Ambiguous +>{ tag: "A", y: 12 } : { tag: "A"; y: number; } +>tag : string +>"A" : "A" +>y : number +>12 : 12 + +amb = { tag: "A", x: "hi", y: 12 } +>amb = { tag: "A", x: "hi", y: 12 } : { tag: "A"; x: string; y: number; } +>amb : Ambiguous +>{ tag: "A", x: "hi", y: 12 } : { tag: "A"; x: string; y: number; } +>tag : string +>"A" : "A" +>x : string +>"hi" : "hi" +>y : number +>12 : 12 + +// correctly error on excess property 'extra', even when ambiguous +amb = { tag: "A", x: "hi", extra: 12 } +>amb = { tag: "A", x: "hi", extra: 12 } : { tag: "A"; x: string; extra: number; } +>amb : Ambiguous +>{ tag: "A", x: "hi", extra: 12 } : { tag: "A"; x: string; extra: number; } +>tag : string +>"A" : "A" +>x : string +>"hi" : "hi" +>extra : number +>12 : 12 + +amb = { tag: "A", y: 12, extra: 12 } +>amb = { tag: "A", y: 12, extra: 12 } : { tag: "A"; y: number; extra: number; } +>amb : Ambiguous +>{ tag: "A", y: 12, extra: 12 } : { tag: "A"; y: number; extra: number; } +>tag : string +>"A" : "A" +>y : number +>12 : 12 +>extra : number +>12 : 12 + +// assignability errors still work. +// But note that the error for `z: true` is the fallback one of reporting on +// the last constituent since assignability error reporting can't find a single best discriminant either. +amb = { tag: "A" } +>amb = { tag: "A" } : { tag: "A"; } +>amb : Ambiguous +>{ tag: "A" } : { tag: "A"; } +>tag : string +>"A" : "A" + +amb = { tag: "A", z: true } +>amb = { tag: "A", z: true } : { tag: "A"; z: true; } +>amb : Ambiguous +>{ tag: "A", z: true } : { tag: "A"; z: true; } +>tag : string +>"A" : "A" +>z : boolean +>true : true + +type Overlapping = +>Overlapping : Overlapping + + | { a: 1, b: 1, first: string } +>a : 1 +>b : 1 +>first : string + + | { a: 2, second: string } +>a : 2 +>second : string + + | { b: 3, third: string } +>b : 3 +>third : string + +let over: Overlapping +>over : Overlapping +>Overlapping : Overlapping + +// these two are not reported because there are two discriminant properties +over = { a: 1, b: 1, first: "ok", second: "error" } +>over = { a: 1, b: 1, first: "ok", second: "error" } : { a: 1; b: 1; first: string; second: string; } +>over : Overlapping +>{ a: 1, b: 1, first: "ok", second: "error" } : { a: 1; b: 1; first: string; second: string; } +>a : number +>1 : 1 +>b : number +>1 : 1 +>first : string +>"ok" : "ok" +>second : string +>"error" : "error" + +over = { a: 1, b: 1, first: "ok", third: "error" } +>over = { a: 1, b: 1, first: "ok", third: "error" } : { a: 1; b: 1; first: string; third: string; } +>over : Overlapping +>{ a: 1, b: 1, first: "ok", third: "error" } : { a: 1; b: 1; first: string; third: string; } +>a : number +>1 : 1 +>b : number +>1 : 1 +>first : string +>"ok" : "ok" +>third : string +>"error" : "error" + diff --git a/tests/baselines/reference/exportDefaultVariable.symbols b/tests/baselines/reference/exportDefaultVariable.symbols index cd7ebed926c..9c924c32f4e 100644 --- a/tests/baselines/reference/exportDefaultVariable.symbols +++ b/tests/baselines/reference/exportDefaultVariable.symbols @@ -6,6 +6,6 @@ declare var io: any; declare module 'module' { export default io; ->io : Symbol(default, Decl(exportDefaultVariable.ts, 2, 11)) +>io : Symbol(io, Decl(exportDefaultVariable.ts, 2, 11)) } diff --git a/tests/baselines/reference/genericContextualTypingSpecialization.symbols b/tests/baselines/reference/genericContextualTypingSpecialization.symbols index b244ab496be..0dcc8cb5899 100644 --- a/tests/baselines/reference/genericContextualTypingSpecialization.symbols +++ b/tests/baselines/reference/genericContextualTypingSpecialization.symbols @@ -3,9 +3,9 @@ var b: number[]; >b : Symbol(b, Decl(genericContextualTypingSpecialization.ts, 0, 3)) b.reduce((c, d) => c + d, 0); // should not error on '+' ->b.reduce : Symbol(Array.reduce, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>b.reduce : Symbol(Array.reduce, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) >b : Symbol(b, Decl(genericContextualTypingSpecialization.ts, 0, 3)) ->reduce : Symbol(Array.reduce, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>reduce : Symbol(Array.reduce, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) >c : Symbol(c, Decl(genericContextualTypingSpecialization.ts, 1, 18)) >d : Symbol(d, Decl(genericContextualTypingSpecialization.ts, 1, 20)) >c : Symbol(c, Decl(genericContextualTypingSpecialization.ts, 1, 18)) diff --git a/tests/baselines/reference/genericContextualTypingSpecialization.types b/tests/baselines/reference/genericContextualTypingSpecialization.types index 82255020347..d7d61010507 100644 --- a/tests/baselines/reference/genericContextualTypingSpecialization.types +++ b/tests/baselines/reference/genericContextualTypingSpecialization.types @@ -4,9 +4,9 @@ var b: number[]; b.reduce((c, d) => c + d, 0); // should not error on '+' >b.reduce((c, d) => c + d, 0) : number ->b.reduce : { (callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: number[]) => number, initialValue?: number): number; (callbackfn: (previousValue: U, currentValue: number, currentIndex: number, array: number[]) => U, initialValue: U): U; } +>b.reduce : { (callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: number[]) => number): number; (callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: number[]) => number, initialValue: number): number; (callbackfn: (previousValue: U, currentValue: number, currentIndex: number, array: number[]) => U, initialValue: U): U; } >b : number[] ->reduce : { (callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: number[]) => number, initialValue?: number): number; (callbackfn: (previousValue: U, currentValue: number, currentIndex: number, array: number[]) => U, initialValue: U): U; } +>reduce : { (callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: number[]) => number): number; (callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: number[]) => number, initialValue: number): number; (callbackfn: (previousValue: U, currentValue: number, currentIndex: number, array: number[]) => U, initialValue: U): U; } >(c, d) => c + d : (c: number, d: number) => number >c : number >d : number diff --git a/tests/baselines/reference/genericReduce.symbols b/tests/baselines/reference/genericReduce.symbols index f220972a350..a939c5cf92d 100644 --- a/tests/baselines/reference/genericReduce.symbols +++ b/tests/baselines/reference/genericReduce.symbols @@ -14,9 +14,9 @@ var b = a.map(s => s.length); var n1 = b.reduce((x, y) => x + y); >n1 : Symbol(n1, Decl(genericReduce.ts, 2, 3)) ->b.reduce : Symbol(Array.reduce, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>b.reduce : Symbol(Array.reduce, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) >b : Symbol(b, Decl(genericReduce.ts, 1, 3)) ->reduce : Symbol(Array.reduce, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>reduce : Symbol(Array.reduce, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) >x : Symbol(x, Decl(genericReduce.ts, 2, 19)) >y : Symbol(y, Decl(genericReduce.ts, 2, 21)) >x : Symbol(x, Decl(genericReduce.ts, 2, 19)) @@ -24,9 +24,9 @@ var n1 = b.reduce((x, y) => x + y); var n2 = b.reduceRight((x, y) => x + y); >n2 : Symbol(n2, Decl(genericReduce.ts, 3, 3)) ->b.reduceRight : Symbol(Array.reduceRight, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>b.reduceRight : Symbol(Array.reduceRight, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) >b : Symbol(b, Decl(genericReduce.ts, 1, 3)) ->reduceRight : Symbol(Array.reduceRight, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>reduceRight : Symbol(Array.reduceRight, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) >x : Symbol(x, Decl(genericReduce.ts, 3, 24)) >y : Symbol(y, Decl(genericReduce.ts, 3, 26)) >x : Symbol(x, Decl(genericReduce.ts, 3, 24)) @@ -50,9 +50,9 @@ n2.toExponential(2); // should not error if 'n2' is correctly number. var n3 = b.reduce( (x, y) => x + y, ""); // Initial value is of type string >n3 : Symbol(n3, Decl(genericReduce.ts, 10, 3)) ->b.reduce : Symbol(Array.reduce, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>b.reduce : Symbol(Array.reduce, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) >b : Symbol(b, Decl(genericReduce.ts, 1, 3)) ->reduce : Symbol(Array.reduce, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>reduce : Symbol(Array.reduce, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) >x : Symbol(x, Decl(genericReduce.ts, 10, 28)) >y : Symbol(y, Decl(genericReduce.ts, 10, 30)) >x : Symbol(x, Decl(genericReduce.ts, 10, 28)) diff --git a/tests/baselines/reference/genericReduce.types b/tests/baselines/reference/genericReduce.types index 628398f86fd..65a069426a7 100644 --- a/tests/baselines/reference/genericReduce.types +++ b/tests/baselines/reference/genericReduce.types @@ -22,9 +22,9 @@ var b = a.map(s => s.length); var n1 = b.reduce((x, y) => x + y); >n1 : number >b.reduce((x, y) => x + y) : number ->b.reduce : { (callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: number[]) => number, initialValue?: number): number; (callbackfn: (previousValue: U, currentValue: number, currentIndex: number, array: number[]) => U, initialValue: U): U; } +>b.reduce : { (callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: number[]) => number): number; (callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: number[]) => number, initialValue: number): number; (callbackfn: (previousValue: U, currentValue: number, currentIndex: number, array: number[]) => U, initialValue: U): U; } >b : number[] ->reduce : { (callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: number[]) => number, initialValue?: number): number; (callbackfn: (previousValue: U, currentValue: number, currentIndex: number, array: number[]) => U, initialValue: U): U; } +>reduce : { (callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: number[]) => number): number; (callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: number[]) => number, initialValue: number): number; (callbackfn: (previousValue: U, currentValue: number, currentIndex: number, array: number[]) => U, initialValue: U): U; } >(x, y) => x + y : (x: number, y: number) => number >x : number >y : number @@ -35,9 +35,9 @@ var n1 = b.reduce((x, y) => x + y); var n2 = b.reduceRight((x, y) => x + y); >n2 : number >b.reduceRight((x, y) => x + y) : number ->b.reduceRight : { (callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: number[]) => number, initialValue?: number): number; (callbackfn: (previousValue: U, currentValue: number, currentIndex: number, array: number[]) => U, initialValue: U): U; } +>b.reduceRight : { (callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: number[]) => number): number; (callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: number[]) => number, initialValue: number): number; (callbackfn: (previousValue: U, currentValue: number, currentIndex: number, array: number[]) => U, initialValue: U): U; } >b : number[] ->reduceRight : { (callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: number[]) => number, initialValue?: number): number; (callbackfn: (previousValue: U, currentValue: number, currentIndex: number, array: number[]) => U, initialValue: U): U; } +>reduceRight : { (callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: number[]) => number): number; (callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: number[]) => number, initialValue: number): number; (callbackfn: (previousValue: U, currentValue: number, currentIndex: number, array: number[]) => U, initialValue: U): U; } >(x, y) => x + y : (x: number, y: number) => number >x : number >y : number @@ -76,9 +76,9 @@ n2.toExponential(2); // should not error if 'n2' is correctly number. var n3 = b.reduce( (x, y) => x + y, ""); // Initial value is of type string >n3 : string >b.reduce( (x, y) => x + y, "") : string ->b.reduce : { (callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: number[]) => number, initialValue?: number): number; (callbackfn: (previousValue: U, currentValue: number, currentIndex: number, array: number[]) => U, initialValue: U): U; } +>b.reduce : { (callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: number[]) => number): number; (callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: number[]) => number, initialValue: number): number; (callbackfn: (previousValue: U, currentValue: number, currentIndex: number, array: number[]) => U, initialValue: U): U; } >b : number[] ->reduce : { (callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: number[]) => number, initialValue?: number): number; (callbackfn: (previousValue: U, currentValue: number, currentIndex: number, array: number[]) => U, initialValue: U): U; } +>reduce : { (callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: number[]) => number): number; (callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: number[]) => number, initialValue: number): number; (callbackfn: (previousValue: U, currentValue: number, currentIndex: number, array: number[]) => U, initialValue: U): U; } >(x, y) => x + y : (x: string, y: number) => string >x : string >y : number diff --git a/tests/baselines/reference/importCallExpressionAsyncES6AMD.js b/tests/baselines/reference/importCallExpressionAsyncES6AMD.js index 9819da8369b..7f86625bbfc 100644 --- a/tests/baselines/reference/importCallExpressionAsyncES6AMD.js +++ b/tests/baselines/reference/importCallExpressionAsyncES6AMD.js @@ -42,34 +42,34 @@ define(["require", "exports"], function (require, exports) { Object.defineProperty(exports, "__esModule", { value: true }); function fn() { return __awaiter(this, void 0, void 0, function* () { - const req = yield new Promise(function (resolve_1, reject_1) { require(['./test'], resolve_1, reject_1); }); // ONE + const req = yield new Promise((resolve_1, reject_1) => { require(['./test'], resolve_1, reject_1); }); // ONE }); } exports.fn = fn; class cl1 { m() { return __awaiter(this, void 0, void 0, function* () { - const req = yield new Promise(function (resolve_2, reject_2) { require(['./test'], resolve_2, reject_2); }); // TWO + const req = yield new Promise((resolve_2, reject_2) => { require(['./test'], resolve_2, reject_2); }); // TWO }); } } exports.cl1 = cl1; exports.obj = { m: () => __awaiter(this, void 0, void 0, function* () { - const req = yield new Promise(function (resolve_3, reject_3) { require(['./test'], resolve_3, reject_3); }); // THREE + const req = yield new Promise((resolve_3, reject_3) => { require(['./test'], resolve_3, reject_3); }); // THREE }) }; class cl2 { constructor() { this.p = { m: () => __awaiter(this, void 0, void 0, function* () { - const req = yield new Promise(function (resolve_4, reject_4) { require(['./test'], resolve_4, reject_4); }); // FOUR + const req = yield new Promise((resolve_4, reject_4) => { require(['./test'], resolve_4, reject_4); }); // FOUR }) }; } } exports.cl2 = cl2; exports.l = () => __awaiter(this, void 0, void 0, function* () { - const req = yield new Promise(function (resolve_5, reject_5) { require(['./test'], resolve_5, reject_5); }); // FIVE + const req = yield new Promise((resolve_5, reject_5) => { require(['./test'], resolve_5, reject_5); }); // FIVE }); }); diff --git a/tests/baselines/reference/importCallExpressionAsyncES6CJS.js b/tests/baselines/reference/importCallExpressionAsyncES6CJS.js index b512ae94b48..20961f96330 100644 --- a/tests/baselines/reference/importCallExpressionAsyncES6CJS.js +++ b/tests/baselines/reference/importCallExpressionAsyncES6CJS.js @@ -41,33 +41,33 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge Object.defineProperty(exports, "__esModule", { value: true }); function fn() { return __awaiter(this, void 0, void 0, function* () { - const req = yield Promise.resolve().then(function () { return require('./test'); }); // ONE + const req = yield Promise.resolve().then(() => require('./test')); // ONE }); } exports.fn = fn; class cl1 { m() { return __awaiter(this, void 0, void 0, function* () { - const req = yield Promise.resolve().then(function () { return require('./test'); }); // TWO + const req = yield Promise.resolve().then(() => require('./test')); // TWO }); } } exports.cl1 = cl1; exports.obj = { m: () => __awaiter(this, void 0, void 0, function* () { - const req = yield Promise.resolve().then(function () { return require('./test'); }); // THREE + const req = yield Promise.resolve().then(() => require('./test')); // THREE }) }; class cl2 { constructor() { this.p = { m: () => __awaiter(this, void 0, void 0, function* () { - const req = yield Promise.resolve().then(function () { return require('./test'); }); // FOUR + const req = yield Promise.resolve().then(() => require('./test')); // FOUR }) }; } } exports.cl2 = cl2; exports.l = () => __awaiter(this, void 0, void 0, function* () { - const req = yield Promise.resolve().then(function () { return require('./test'); }); // FIVE + const req = yield Promise.resolve().then(() => require('./test')); // FIVE }); diff --git a/tests/baselines/reference/importCallExpressionAsyncES6UMD.js b/tests/baselines/reference/importCallExpressionAsyncES6UMD.js index f77d5150118..1d4aff02670 100644 --- a/tests/baselines/reference/importCallExpressionAsyncES6UMD.js +++ b/tests/baselines/reference/importCallExpressionAsyncES6UMD.js @@ -51,34 +51,34 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge Object.defineProperty(exports, "__esModule", { value: true }); function fn() { return __awaiter(this, void 0, void 0, function* () { - const req = yield __syncRequire ? Promise.resolve().then(function () { return require('./test'); }) : new Promise(function (resolve_1, reject_1) { require(['./test'], resolve_1, reject_1); }); // ONE + const req = yield __syncRequire ? Promise.resolve().then(() => require('./test')) : new Promise((resolve_1, reject_1) => { require(['./test'], resolve_1, reject_1); }); // ONE }); } exports.fn = fn; class cl1 { m() { return __awaiter(this, void 0, void 0, function* () { - const req = yield __syncRequire ? Promise.resolve().then(function () { return require('./test'); }) : new Promise(function (resolve_2, reject_2) { require(['./test'], resolve_2, reject_2); }); // TWO + const req = yield __syncRequire ? Promise.resolve().then(() => require('./test')) : new Promise((resolve_2, reject_2) => { require(['./test'], resolve_2, reject_2); }); // TWO }); } } exports.cl1 = cl1; exports.obj = { m: () => __awaiter(this, void 0, void 0, function* () { - const req = yield __syncRequire ? Promise.resolve().then(function () { return require('./test'); }) : new Promise(function (resolve_3, reject_3) { require(['./test'], resolve_3, reject_3); }); // THREE + const req = yield __syncRequire ? Promise.resolve().then(() => require('./test')) : new Promise((resolve_3, reject_3) => { require(['./test'], resolve_3, reject_3); }); // THREE }) }; class cl2 { constructor() { this.p = { m: () => __awaiter(this, void 0, void 0, function* () { - const req = yield __syncRequire ? Promise.resolve().then(function () { return require('./test'); }) : new Promise(function (resolve_4, reject_4) { require(['./test'], resolve_4, reject_4); }); // FOUR + const req = yield __syncRequire ? Promise.resolve().then(() => require('./test')) : new Promise((resolve_4, reject_4) => { require(['./test'], resolve_4, reject_4); }); // FOUR }) }; } } exports.cl2 = cl2; exports.l = () => __awaiter(this, void 0, void 0, function* () { - const req = yield __syncRequire ? Promise.resolve().then(function () { return require('./test'); }) : new Promise(function (resolve_5, reject_5) { require(['./test'], resolve_5, reject_5); }); // FIVE + const req = yield __syncRequire ? Promise.resolve().then(() => require('./test')) : new Promise((resolve_5, reject_5) => { require(['./test'], resolve_5, reject_5); }); // FIVE }); }); diff --git a/tests/baselines/reference/importCallExpressionCheckReturntype1.js b/tests/baselines/reference/importCallExpressionCheckReturntype1.js index facb6913388..3cc4893ff67 100644 --- a/tests/baselines/reference/importCallExpressionCheckReturntype1.js +++ b/tests/baselines/reference/importCallExpressionCheckReturntype1.js @@ -30,6 +30,6 @@ exports.C = C; //// [1.js] "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); -let p1 = Promise.resolve().then(function () { return require("./defaultPath"); }); -let p2 = Promise.resolve().then(function () { return require("./defaultPath"); }); -let p3 = Promise.resolve().then(function () { return require("./defaultPath"); }); +let p1 = Promise.resolve().then(() => require("./defaultPath")); +let p2 = Promise.resolve().then(() => require("./defaultPath")); +let p3 = Promise.resolve().then(() => require("./defaultPath")); diff --git a/tests/baselines/reference/importCallExpressionDeclarationEmit1.js b/tests/baselines/reference/importCallExpressionDeclarationEmit1.js index 07f95d3b3b2..721d85abe71 100644 --- a/tests/baselines/reference/importCallExpressionDeclarationEmit1.js +++ b/tests/baselines/reference/importCallExpressionDeclarationEmit1.js @@ -15,12 +15,12 @@ function returnDynamicLoad(path: string) { } //// [importCallExpressionDeclarationEmit1.js] -Promise.resolve().then(function () { return require(getSpecifier()); }); -var p0 = Promise.resolve().then(function () { return require(`${directory}\${moduleFile}`); }); -var p1 = Promise.resolve().then(function () { return require(getSpecifier()); }); -const p2 = Promise.resolve().then(function () { return require(whatToLoad ? getSpecifier() : "defaulPath"); }); +Promise.resolve().then(() => require(getSpecifier())); +var p0 = Promise.resolve().then(() => require(`${directory}\${moduleFile}`)); +var p1 = Promise.resolve().then(() => require(getSpecifier())); +const p2 = Promise.resolve().then(() => require(whatToLoad ? getSpecifier() : "defaulPath")); function returnDynamicLoad(path) { - return Promise.resolve().then(function () { return require(path); }); + return Promise.resolve().then(() => require(path)); } diff --git a/tests/baselines/reference/importCallExpressionES6AMD.js b/tests/baselines/reference/importCallExpressionES6AMD.js index 08fec3b27fd..1c5430c9f04 100644 --- a/tests/baselines/reference/importCallExpressionES6AMD.js +++ b/tests/baselines/reference/importCallExpressionES6AMD.js @@ -39,23 +39,23 @@ define(["require", "exports"], function (require, exports) { define(["require", "exports"], function (require, exports) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); - new Promise(function (resolve_1, reject_1) { require(["./0"], resolve_1, reject_1); }); - var p1 = new Promise(function (resolve_2, reject_2) { require(["./0"], resolve_2, reject_2); }); + new Promise((resolve_1, reject_1) => { require(["./0"], resolve_1, reject_1); }); + var p1 = new Promise((resolve_2, reject_2) => { require(["./0"], resolve_2, reject_2); }); p1.then(zero => { return zero.foo(); }); - exports.p2 = new Promise(function (resolve_3, reject_3) { require(["./0"], resolve_3, reject_3); }); + exports.p2 = new Promise((resolve_3, reject_3) => { require(["./0"], resolve_3, reject_3); }); function foo() { - const p2 = new Promise(function (resolve_4, reject_4) { require(["./0"], resolve_4, reject_4); }); + const p2 = new Promise((resolve_4, reject_4) => { require(["./0"], resolve_4, reject_4); }); } class C { method() { - const loadAsync = new Promise(function (resolve_5, reject_5) { require(["./0"], resolve_5, reject_5); }); + const loadAsync = new Promise((resolve_5, reject_5) => { require(["./0"], resolve_5, reject_5); }); } } class D { method() { - const loadAsync = new Promise(function (resolve_6, reject_6) { require(["./0"], resolve_6, reject_6); }); + const loadAsync = new Promise((resolve_6, reject_6) => { require(["./0"], resolve_6, reject_6); }); } } exports.D = D; diff --git a/tests/baselines/reference/importCallExpressionES6CJS.js b/tests/baselines/reference/importCallExpressionES6CJS.js index 28833e17479..a1d8108bdea 100644 --- a/tests/baselines/reference/importCallExpressionES6CJS.js +++ b/tests/baselines/reference/importCallExpressionES6CJS.js @@ -36,23 +36,23 @@ exports.foo = foo; //// [1.js] "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); -Promise.resolve().then(function () { return require("./0"); }); -var p1 = Promise.resolve().then(function () { return require("./0"); }); +Promise.resolve().then(() => require("./0")); +var p1 = Promise.resolve().then(() => require("./0")); p1.then(zero => { return zero.foo(); }); -exports.p2 = Promise.resolve().then(function () { return require("./0"); }); +exports.p2 = Promise.resolve().then(() => require("./0")); function foo() { - const p2 = Promise.resolve().then(function () { return require("./0"); }); + const p2 = Promise.resolve().then(() => require("./0")); } class C { method() { - const loadAsync = Promise.resolve().then(function () { return require("./0"); }); + const loadAsync = Promise.resolve().then(() => require("./0")); } } class D { method() { - const loadAsync = Promise.resolve().then(function () { return require("./0"); }); + const loadAsync = Promise.resolve().then(() => require("./0")); } } exports.D = D; diff --git a/tests/baselines/reference/importCallExpressionES6UMD.js b/tests/baselines/reference/importCallExpressionES6UMD.js index cc7dfef0074..750a1a7cc0c 100644 --- a/tests/baselines/reference/importCallExpressionES6UMD.js +++ b/tests/baselines/reference/importCallExpressionES6UMD.js @@ -56,23 +56,23 @@ export class D { "use strict"; var __syncRequire = typeof module === "object" && typeof module.exports === "object"; Object.defineProperty(exports, "__esModule", { value: true }); - __syncRequire ? Promise.resolve().then(function () { return require("./0"); }) : new Promise(function (resolve_1, reject_1) { require(["./0"], resolve_1, reject_1); }); - var p1 = __syncRequire ? Promise.resolve().then(function () { return require("./0"); }) : new Promise(function (resolve_2, reject_2) { require(["./0"], resolve_2, reject_2); }); + __syncRequire ? Promise.resolve().then(() => require("./0")) : new Promise((resolve_1, reject_1) => { require(["./0"], resolve_1, reject_1); }); + var p1 = __syncRequire ? Promise.resolve().then(() => require("./0")) : new Promise((resolve_2, reject_2) => { require(["./0"], resolve_2, reject_2); }); p1.then(zero => { return zero.foo(); }); - exports.p2 = __syncRequire ? Promise.resolve().then(function () { return require("./0"); }) : new Promise(function (resolve_3, reject_3) { require(["./0"], resolve_3, reject_3); }); + exports.p2 = __syncRequire ? Promise.resolve().then(() => require("./0")) : new Promise((resolve_3, reject_3) => { require(["./0"], resolve_3, reject_3); }); function foo() { - const p2 = __syncRequire ? Promise.resolve().then(function () { return require("./0"); }) : new Promise(function (resolve_4, reject_4) { require(["./0"], resolve_4, reject_4); }); + const p2 = __syncRequire ? Promise.resolve().then(() => require("./0")) : new Promise((resolve_4, reject_4) => { require(["./0"], resolve_4, reject_4); }); } class C { method() { - const loadAsync = __syncRequire ? Promise.resolve().then(function () { return require("./0"); }) : new Promise(function (resolve_5, reject_5) { require(["./0"], resolve_5, reject_5); }); + const loadAsync = __syncRequire ? Promise.resolve().then(() => require("./0")) : new Promise((resolve_5, reject_5) => { require(["./0"], resolve_5, reject_5); }); } } class D { method() { - const loadAsync = __syncRequire ? Promise.resolve().then(function () { return require("./0"); }) : new Promise(function (resolve_6, reject_6) { require(["./0"], resolve_6, reject_6); }); + const loadAsync = __syncRequire ? Promise.resolve().then(() => require("./0")) : new Promise((resolve_6, reject_6) => { require(["./0"], resolve_6, reject_6); }); } } exports.D = D; diff --git a/tests/baselines/reference/importCallExpressionGrammarError.js b/tests/baselines/reference/importCallExpressionGrammarError.js index b30b0c9ddd5..e2ffc55577d 100644 --- a/tests/baselines/reference/importCallExpressionGrammarError.js +++ b/tests/baselines/reference/importCallExpressionGrammarError.js @@ -12,8 +12,8 @@ const p4 = import("pathToModule", "secondModule"); //// [importCallExpressionGrammarError.js] var a = ["./0"]; -Promise.resolve().then(function () { return require(...["PathModule"]); }); -var p1 = Promise.resolve().then(function () { return require(...a); }); -const p2 = Promise.resolve().then(function () { return require(); }); -const p3 = Promise.resolve().then(function () { return require(); }); -const p4 = Promise.resolve().then(function () { return require("pathToModule", "secondModule"); }); +Promise.resolve().then(() => require(...["PathModule"])); +var p1 = Promise.resolve().then(() => require(...a)); +const p2 = Promise.resolve().then(() => require()); +const p3 = Promise.resolve().then(() => require()); +const p4 = Promise.resolve().then(() => require("pathToModule", "secondModule")); diff --git a/tests/baselines/reference/importCallExpressionInAMD1.js b/tests/baselines/reference/importCallExpressionInAMD1.js index 5c858160353..64e5aee2dda 100644 --- a/tests/baselines/reference/importCallExpressionInAMD1.js +++ b/tests/baselines/reference/importCallExpressionInAMD1.js @@ -27,13 +27,13 @@ define(["require", "exports"], function (require, exports) { define(["require", "exports"], function (require, exports) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); - new Promise(function (resolve_1, reject_1) { require(["./0"], resolve_1, reject_1); }); - var p1 = new Promise(function (resolve_2, reject_2) { require(["./0"], resolve_2, reject_2); }); + new Promise((resolve_1, reject_1) => { require(["./0"], resolve_1, reject_1); }); + var p1 = new Promise((resolve_2, reject_2) => { require(["./0"], resolve_2, reject_2); }); p1.then(zero => { return zero.foo(); }); - exports.p2 = new Promise(function (resolve_3, reject_3) { require(["./0"], resolve_3, reject_3); }); + exports.p2 = new Promise((resolve_3, reject_3) => { require(["./0"], resolve_3, reject_3); }); function foo() { - const p2 = new Promise(function (resolve_4, reject_4) { require(["./0"], resolve_4, reject_4); }); + const p2 = new Promise((resolve_4, reject_4) => { require(["./0"], resolve_4, reject_4); }); } }); diff --git a/tests/baselines/reference/importCallExpressionInAMD2.js b/tests/baselines/reference/importCallExpressionInAMD2.js index 7347e2f8105..0d3f0e08d21 100644 --- a/tests/baselines/reference/importCallExpressionInAMD2.js +++ b/tests/baselines/reference/importCallExpressionInAMD2.js @@ -35,5 +35,5 @@ define(["require", "exports"], function (require, exports) { b.print(); }); } - foo(new Promise(function (resolve_1, reject_1) { require(["./0"], resolve_1, reject_1); })); + foo(new Promise((resolve_1, reject_1) => { require(["./0"], resolve_1, reject_1); })); }); diff --git a/tests/baselines/reference/importCallExpressionInAMD3.js b/tests/baselines/reference/importCallExpressionInAMD3.js index 471f35a6415..07e7e922541 100644 --- a/tests/baselines/reference/importCallExpressionInAMD3.js +++ b/tests/baselines/reference/importCallExpressionInAMD3.js @@ -26,7 +26,7 @@ define(["require", "exports"], function (require, exports) { define(["require", "exports"], function (require, exports) { "use strict"; async function foo() { - class C extends (await new Promise(function (resolve_1, reject_1) { require(["./0"], resolve_1, reject_1); })).B { + class C extends (await new Promise((resolve_1, reject_1) => { require(["./0"], resolve_1, reject_1); })).B { } var c = new C(); c.print(); diff --git a/tests/baselines/reference/importCallExpressionInAMD4.js b/tests/baselines/reference/importCallExpressionInAMD4.js index 43ba5afcd30..2fe29e5ae06 100644 --- a/tests/baselines/reference/importCallExpressionInAMD4.js +++ b/tests/baselines/reference/importCallExpressionInAMD4.js @@ -64,30 +64,30 @@ define(["require", "exports"], function (require, exports) { Object.defineProperty(exports, "__esModule", { value: true }); class C { constructor() { - this.myModule = new Promise(function (resolve_1, reject_1) { require(["./0"], resolve_1, reject_1); }); + this.myModule = new Promise((resolve_1, reject_1) => { require(["./0"], resolve_1, reject_1); }); } method() { - const loadAsync = new Promise(function (resolve_2, reject_2) { require(["./0"], resolve_2, reject_2); }); + const loadAsync = new Promise((resolve_2, reject_2) => { require(["./0"], resolve_2, reject_2); }); this.myModule.then(Zero => { console.log(Zero.foo()); }, async (err) => { console.log(err); - let one = await new Promise(function (resolve_3, reject_3) { require(["./1"], resolve_3, reject_3); }); + let one = await new Promise((resolve_3, reject_3) => { require(["./1"], resolve_3, reject_3); }); console.log(one.backup()); }); } } class D { constructor() { - this.myModule = new Promise(function (resolve_4, reject_4) { require(["./0"], resolve_4, reject_4); }); + this.myModule = new Promise((resolve_4, reject_4) => { require(["./0"], resolve_4, reject_4); }); } method() { - const loadAsync = new Promise(function (resolve_5, reject_5) { require(["./0"], resolve_5, reject_5); }); + const loadAsync = new Promise((resolve_5, reject_5) => { require(["./0"], resolve_5, reject_5); }); this.myModule.then(Zero => { console.log(Zero.foo()); }, async (err) => { console.log(err); - let one = await new Promise(function (resolve_6, reject_6) { require(["./1"], resolve_6, reject_6); }); + let one = await new Promise((resolve_6, reject_6) => { require(["./1"], resolve_6, reject_6); }); console.log(one.backup()); }); } diff --git a/tests/baselines/reference/importCallExpressionInCJS1.js b/tests/baselines/reference/importCallExpressionInCJS1.js index 359e743144b..c814f5e5671 100644 --- a/tests/baselines/reference/importCallExpressionInCJS1.js +++ b/tests/baselines/reference/importCallExpressionInCJS1.js @@ -24,12 +24,12 @@ exports.foo = foo; //// [1.js] "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); -Promise.resolve().then(function () { return require("./0"); }); -var p1 = Promise.resolve().then(function () { return require("./0"); }); +Promise.resolve().then(() => require("./0")); +var p1 = Promise.resolve().then(() => require("./0")); p1.then(zero => { return zero.foo(); }); -exports.p2 = Promise.resolve().then(function () { return require("./0"); }); +exports.p2 = Promise.resolve().then(() => require("./0")); function foo() { - const p2 = Promise.resolve().then(function () { return require("./0"); }); + const p2 = Promise.resolve().then(() => require("./0")); } diff --git a/tests/baselines/reference/importCallExpressionInCJS2.js b/tests/baselines/reference/importCallExpressionInCJS2.js index aa983a7a2fe..fb559cb1193 100644 --- a/tests/baselines/reference/importCallExpressionInCJS2.js +++ b/tests/baselines/reference/importCallExpressionInCJS2.js @@ -32,9 +32,9 @@ exports.backup = backup; async function compute(promise) { let j = await promise; if (!j) { - j = await Promise.resolve().then(function () { return require("./1"); }); + j = await Promise.resolve().then(() => require("./1")); return j.backup(); } return j.foo(); } -compute(Promise.resolve().then(function () { return require("./0"); })); +compute(Promise.resolve().then(() => require("./0"))); diff --git a/tests/baselines/reference/importCallExpressionInCJS3.js b/tests/baselines/reference/importCallExpressionInCJS3.js index 2f956d9ac3a..616fbc9c3f9 100644 --- a/tests/baselines/reference/importCallExpressionInCJS3.js +++ b/tests/baselines/reference/importCallExpressionInCJS3.js @@ -31,4 +31,4 @@ function foo(x) { b.print(); }); } -foo(Promise.resolve().then(function () { return require("./0"); })); +foo(Promise.resolve().then(() => require("./0"))); diff --git a/tests/baselines/reference/importCallExpressionInCJS4.js b/tests/baselines/reference/importCallExpressionInCJS4.js index 554a0b222ab..b88295110b8 100644 --- a/tests/baselines/reference/importCallExpressionInCJS4.js +++ b/tests/baselines/reference/importCallExpressionInCJS4.js @@ -22,7 +22,7 @@ class B { exports.B = B; //// [2.js] async function foo() { - class C extends (await Promise.resolve().then(function () { return require("./0"); })).B { + class C extends (await Promise.resolve().then(() => require("./0"))).B { } var c = new C(); c.print(); diff --git a/tests/baselines/reference/importCallExpressionInCJS5.js b/tests/baselines/reference/importCallExpressionInCJS5.js index eeb4db275fa..b32b0e52c50 100644 --- a/tests/baselines/reference/importCallExpressionInCJS5.js +++ b/tests/baselines/reference/importCallExpressionInCJS5.js @@ -59,30 +59,30 @@ exports.backup = backup; Object.defineProperty(exports, "__esModule", { value: true }); class C { constructor() { - this.myModule = Promise.resolve().then(function () { return require("./0"); }); + this.myModule = Promise.resolve().then(() => require("./0")); } method() { - const loadAsync = Promise.resolve().then(function () { return require("./0"); }); + const loadAsync = Promise.resolve().then(() => require("./0")); this.myModule.then(Zero => { console.log(Zero.foo()); }, async (err) => { console.log(err); - let one = await Promise.resolve().then(function () { return require("./1"); }); + let one = await Promise.resolve().then(() => require("./1")); console.log(one.backup()); }); } } class D { constructor() { - this.myModule = Promise.resolve().then(function () { return require("./0"); }); + this.myModule = Promise.resolve().then(() => require("./0")); } method() { - const loadAsync = Promise.resolve().then(function () { return require("./0"); }); + const loadAsync = Promise.resolve().then(() => require("./0")); this.myModule.then(Zero => { console.log(Zero.foo()); }, async (err) => { console.log(err); - let one = await Promise.resolve().then(function () { return require("./1"); }); + let one = await Promise.resolve().then(() => require("./1")); console.log(one.backup()); }); } diff --git a/tests/baselines/reference/importCallExpressionInExportEqualsAMD.js b/tests/baselines/reference/importCallExpressionInExportEqualsAMD.js index f2fda1fadd7..1fcef2bde39 100644 --- a/tests/baselines/reference/importCallExpressionInExportEqualsAMD.js +++ b/tests/baselines/reference/importCallExpressionInExportEqualsAMD.js @@ -17,6 +17,6 @@ define(["require", "exports"], function (require, exports) { define(["require", "exports"], function (require, exports) { "use strict"; return async function () { - const something = await new Promise(function (resolve_1, reject_1) { require(["./something"], resolve_1, reject_1); }); + const something = await new Promise((resolve_1, reject_1) => { require(["./something"], resolve_1, reject_1); }); }; }); diff --git a/tests/baselines/reference/importCallExpressionInExportEqualsCJS.js b/tests/baselines/reference/importCallExpressionInExportEqualsCJS.js index 5d7e2816116..72e3a0ec0af 100644 --- a/tests/baselines/reference/importCallExpressionInExportEqualsCJS.js +++ b/tests/baselines/reference/importCallExpressionInExportEqualsCJS.js @@ -14,5 +14,5 @@ module.exports = 42; //// [index.js] "use strict"; module.exports = async function () { - const something = await Promise.resolve().then(function () { return require("./something"); }); + const something = await Promise.resolve().then(() => require("./something")); }; diff --git a/tests/baselines/reference/importCallExpressionInExportEqualsUMD.js b/tests/baselines/reference/importCallExpressionInExportEqualsUMD.js index e0c6e2a925f..5f70891b09e 100644 --- a/tests/baselines/reference/importCallExpressionInExportEqualsUMD.js +++ b/tests/baselines/reference/importCallExpressionInExportEqualsUMD.js @@ -34,6 +34,6 @@ export = async function() { "use strict"; var __syncRequire = typeof module === "object" && typeof module.exports === "object"; return async function () { - const something = await (__syncRequire ? Promise.resolve().then(function () { return require("./something"); }) : new Promise(function (resolve_1, reject_1) { require(["./something"], resolve_1, reject_1); })); + const something = await (__syncRequire ? Promise.resolve().then(() => require("./something")) : new Promise((resolve_1, reject_1) => { require(["./something"], resolve_1, reject_1); })); }; }); diff --git a/tests/baselines/reference/importCallExpressionInScriptContext1.js b/tests/baselines/reference/importCallExpressionInScriptContext1.js index 2c2d2f904d5..53c6118f61b 100644 --- a/tests/baselines/reference/importCallExpressionInScriptContext1.js +++ b/tests/baselines/reference/importCallExpressionInScriptContext1.js @@ -13,5 +13,5 @@ Object.defineProperty(exports, "__esModule", { value: true }); function foo() { return "foo"; } exports.foo = foo; //// [1.js] -var p1 = Promise.resolve().then(function () { return require("./0"); }); +var p1 = Promise.resolve().then(() => require("./0")); function arguments() { } // this is allow as the file doesn't have implicit "use strict" diff --git a/tests/baselines/reference/importCallExpressionInScriptContext2.js b/tests/baselines/reference/importCallExpressionInScriptContext2.js index 6b6e0109fda..4a0d4a1bf5a 100644 --- a/tests/baselines/reference/importCallExpressionInScriptContext2.js +++ b/tests/baselines/reference/importCallExpressionInScriptContext2.js @@ -15,5 +15,5 @@ function foo() { return "foo"; } exports.foo = foo; //// [1.js] "use strict"; -var p1 = Promise.resolve().then(function () { return require("./0"); }); +var p1 = Promise.resolve().then(() => require("./0")); function arguments() { } diff --git a/tests/baselines/reference/importCallExpressionInUMD1.js b/tests/baselines/reference/importCallExpressionInUMD1.js index ee99468f7f3..597e68e2d6f 100644 --- a/tests/baselines/reference/importCallExpressionInUMD1.js +++ b/tests/baselines/reference/importCallExpressionInUMD1.js @@ -44,13 +44,13 @@ function foo() { "use strict"; var __syncRequire = typeof module === "object" && typeof module.exports === "object"; Object.defineProperty(exports, "__esModule", { value: true }); - __syncRequire ? Promise.resolve().then(function () { return require("./0"); }) : new Promise(function (resolve_1, reject_1) { require(["./0"], resolve_1, reject_1); }); - var p1 = __syncRequire ? Promise.resolve().then(function () { return require("./0"); }) : new Promise(function (resolve_2, reject_2) { require(["./0"], resolve_2, reject_2); }); + __syncRequire ? Promise.resolve().then(() => require("./0")) : new Promise((resolve_1, reject_1) => { require(["./0"], resolve_1, reject_1); }); + var p1 = __syncRequire ? Promise.resolve().then(() => require("./0")) : new Promise((resolve_2, reject_2) => { require(["./0"], resolve_2, reject_2); }); p1.then(zero => { return zero.foo(); }); - exports.p2 = __syncRequire ? Promise.resolve().then(function () { return require("./0"); }) : new Promise(function (resolve_3, reject_3) { require(["./0"], resolve_3, reject_3); }); + exports.p2 = __syncRequire ? Promise.resolve().then(() => require("./0")) : new Promise((resolve_3, reject_3) => { require(["./0"], resolve_3, reject_3); }); function foo() { - const p2 = __syncRequire ? Promise.resolve().then(function () { return require("./0"); }) : new Promise(function (resolve_4, reject_4) { require(["./0"], resolve_4, reject_4); }); + const p2 = __syncRequire ? Promise.resolve().then(() => require("./0")) : new Promise((resolve_4, reject_4) => { require(["./0"], resolve_4, reject_4); }); } }); diff --git a/tests/baselines/reference/importCallExpressionInUMD2.js b/tests/baselines/reference/importCallExpressionInUMD2.js index db8b87a2f79..516800968c1 100644 --- a/tests/baselines/reference/importCallExpressionInUMD2.js +++ b/tests/baselines/reference/importCallExpressionInUMD2.js @@ -52,5 +52,5 @@ foo(import("./0")); b.print(); }); } - foo(__syncRequire ? Promise.resolve().then(function () { return require("./0"); }) : new Promise(function (resolve_1, reject_1) { require(["./0"], resolve_1, reject_1); })); + foo(__syncRequire ? Promise.resolve().then(() => require("./0")) : new Promise((resolve_1, reject_1) => { require(["./0"], resolve_1, reject_1); })); }); diff --git a/tests/baselines/reference/importCallExpressionInUMD3.js b/tests/baselines/reference/importCallExpressionInUMD3.js index 41106e3ab78..57d200ca70c 100644 --- a/tests/baselines/reference/importCallExpressionInUMD3.js +++ b/tests/baselines/reference/importCallExpressionInUMD3.js @@ -43,7 +43,7 @@ foo(); "use strict"; var __syncRequire = typeof module === "object" && typeof module.exports === "object"; async function foo() { - class C extends (await (__syncRequire ? Promise.resolve().then(function () { return require("./0"); }) : new Promise(function (resolve_1, reject_1) { require(["./0"], resolve_1, reject_1); }))).B { + class C extends (await (__syncRequire ? Promise.resolve().then(() => require("./0")) : new Promise((resolve_1, reject_1) => { require(["./0"], resolve_1, reject_1); }))).B { } var c = new C(); c.print(); diff --git a/tests/baselines/reference/importCallExpressionInUMD4.js b/tests/baselines/reference/importCallExpressionInUMD4.js index 477a7826bc0..70a574f0302 100644 --- a/tests/baselines/reference/importCallExpressionInUMD4.js +++ b/tests/baselines/reference/importCallExpressionInUMD4.js @@ -89,30 +89,30 @@ export class D { Object.defineProperty(exports, "__esModule", { value: true }); class C { constructor() { - this.myModule = __syncRequire ? Promise.resolve().then(function () { return require("./0"); }) : new Promise(function (resolve_1, reject_1) { require(["./0"], resolve_1, reject_1); }); + this.myModule = __syncRequire ? Promise.resolve().then(() => require("./0")) : new Promise((resolve_1, reject_1) => { require(["./0"], resolve_1, reject_1); }); } method() { - const loadAsync = __syncRequire ? Promise.resolve().then(function () { return require("./0"); }) : new Promise(function (resolve_2, reject_2) { require(["./0"], resolve_2, reject_2); }); + const loadAsync = __syncRequire ? Promise.resolve().then(() => require("./0")) : new Promise((resolve_2, reject_2) => { require(["./0"], resolve_2, reject_2); }); this.myModule.then(Zero => { console.log(Zero.foo()); }, async (err) => { console.log(err); - let one = await (__syncRequire ? Promise.resolve().then(function () { return require("./1"); }) : new Promise(function (resolve_3, reject_3) { require(["./1"], resolve_3, reject_3); })); + let one = await (__syncRequire ? Promise.resolve().then(() => require("./1")) : new Promise((resolve_3, reject_3) => { require(["./1"], resolve_3, reject_3); })); console.log(one.backup()); }); } } class D { constructor() { - this.myModule = __syncRequire ? Promise.resolve().then(function () { return require("./0"); }) : new Promise(function (resolve_4, reject_4) { require(["./0"], resolve_4, reject_4); }); + this.myModule = __syncRequire ? Promise.resolve().then(() => require("./0")) : new Promise((resolve_4, reject_4) => { require(["./0"], resolve_4, reject_4); }); } method() { - const loadAsync = __syncRequire ? Promise.resolve().then(function () { return require("./0"); }) : new Promise(function (resolve_5, reject_5) { require(["./0"], resolve_5, reject_5); }); + const loadAsync = __syncRequire ? Promise.resolve().then(() => require("./0")) : new Promise((resolve_5, reject_5) => { require(["./0"], resolve_5, reject_5); }); this.myModule.then(Zero => { console.log(Zero.foo()); }, async (err) => { console.log(err); - let one = await (__syncRequire ? Promise.resolve().then(function () { return require("./1"); }) : new Promise(function (resolve_6, reject_6) { require(["./1"], resolve_6, reject_6); })); + let one = await (__syncRequire ? Promise.resolve().then(() => require("./1")) : new Promise((resolve_6, reject_6) => { require(["./1"], resolve_6, reject_6); })); console.log(one.backup()); }); } diff --git a/tests/baselines/reference/importCallExpressionReturnPromiseOfAny.js b/tests/baselines/reference/importCallExpressionReturnPromiseOfAny.js index 728d6636953..8c94510b609 100644 --- a/tests/baselines/reference/importCallExpressionReturnPromiseOfAny.js +++ b/tests/baselines/reference/importCallExpressionReturnPromiseOfAny.js @@ -42,20 +42,20 @@ exports.C = C; //// [1.js] "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); -Promise.resolve().then(function () { return require(`${directory}\${moduleFile}`); }); -Promise.resolve().then(function () { return require(getSpecifier()); }); -var p1 = Promise.resolve().then(function () { return require(ValidSomeCondition() ? "./0" : "externalModule"); }); -var p1 = Promise.resolve().then(function () { return require(getSpecifier()); }); -var p11 = Promise.resolve().then(function () { return require(getSpecifier()); }); -const p2 = Promise.resolve().then(function () { return require(whatToLoad ? getSpecifier() : "defaulPath"); }); +Promise.resolve().then(() => require(`${directory}\${moduleFile}`)); +Promise.resolve().then(() => require(getSpecifier())); +var p1 = Promise.resolve().then(() => require(ValidSomeCondition() ? "./0" : "externalModule")); +var p1 = Promise.resolve().then(() => require(getSpecifier())); +var p11 = Promise.resolve().then(() => require(getSpecifier())); +const p2 = Promise.resolve().then(() => require(whatToLoad ? getSpecifier() : "defaulPath")); p1.then(zero => { return zero.foo(); // ok, zero is any }); let j; -var p3 = Promise.resolve().then(function () { return require(j = getSpecifier()); }); +var p3 = Promise.resolve().then(() => require(j = getSpecifier())); function* loadModule(directories) { for (const directory of directories) { const path = `${directory}\moduleFile`; - Promise.resolve().then(function () { return require(yield path); }); + Promise.resolve().then(() => require(yield path)); } } diff --git a/tests/baselines/reference/importCallExpressionSpecifierNotStringTypeError.js b/tests/baselines/reference/importCallExpressionSpecifierNotStringTypeError.js index dde35d8048b..5e2ace1c401 100644 --- a/tests/baselines/reference/importCallExpressionSpecifierNotStringTypeError.js +++ b/tests/baselines/reference/importCallExpressionSpecifierNotStringTypeError.js @@ -15,11 +15,11 @@ var p4 = import(()=>"PathToModule"); //// [importCallExpressionSpecifierNotStringTypeError.js] // Error specifier is not assignable to string -Promise.resolve().then(function () { return require(getSpecifier()); }); -var p1 = Promise.resolve().then(function () { return require(getSpecifier()); }); -const p2 = Promise.resolve().then(function () { return require(whatToLoad ? getSpecifier() : "defaulPath"); }); +Promise.resolve().then(() => require(getSpecifier())); +var p1 = Promise.resolve().then(() => require(getSpecifier())); +const p2 = Promise.resolve().then(() => require(whatToLoad ? getSpecifier() : "defaulPath")); p1.then(zero => { return zero.foo(); // ok, zero is any }); -var p3 = Promise.resolve().then(function () { return require(["path1", "path2"]); }); -var p4 = Promise.resolve().then(function () { return require(() => "PathToModule"); }); +var p3 = Promise.resolve().then(() => require(["path1", "path2"])); +var p4 = Promise.resolve().then(() => require(() => "PathToModule")); diff --git a/tests/baselines/reference/importCallExpressionWithTypeArgument.js b/tests/baselines/reference/importCallExpressionWithTypeArgument.js index 2915669eae5..885992a798b 100644 --- a/tests/baselines/reference/importCallExpressionWithTypeArgument.js +++ b/tests/baselines/reference/importCallExpressionWithTypeArgument.js @@ -15,5 +15,5 @@ function foo() { return "foo"; } exports.foo = foo; //// [1.js] "use strict"; -var p1 = Promise.resolve().then(function () { return require("./0"); }); // error -var p2 = Promise.resolve().then(function () { return require("./0"); }); // error +var p1 = Promise.resolve().then(() => require("./0")); // error +var p2 = Promise.resolve().then(() => require("./0")); // error diff --git a/tests/baselines/reference/inferFromGenericFunctionReturnTypes1.symbols b/tests/baselines/reference/inferFromGenericFunctionReturnTypes1.symbols index e18c80afcde..3060f44009b 100644 --- a/tests/baselines/reference/inferFromGenericFunctionReturnTypes1.symbols +++ b/tests/baselines/reference/inferFromGenericFunctionReturnTypes1.symbols @@ -124,9 +124,9 @@ function compose(...fns: ((x: T) => T)[]): (x: T) => T { return (x: T) => fns.reduce((prev, fn) => fn(prev), x); >x : Symbol(x, Decl(inferFromGenericFunctionReturnTypes1.ts, 27, 10)) >T : Symbol(T, Decl(inferFromGenericFunctionReturnTypes1.ts, 26, 17)) ->fns.reduce : Symbol(Array.reduce, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>fns.reduce : Symbol(Array.reduce, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) >fns : Symbol(fns, Decl(inferFromGenericFunctionReturnTypes1.ts, 26, 20)) ->reduce : Symbol(Array.reduce, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>reduce : Symbol(Array.reduce, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) >prev : Symbol(prev, Decl(inferFromGenericFunctionReturnTypes1.ts, 27, 31)) >fn : Symbol(fn, Decl(inferFromGenericFunctionReturnTypes1.ts, 27, 36)) >fn : Symbol(fn, Decl(inferFromGenericFunctionReturnTypes1.ts, 27, 36)) diff --git a/tests/baselines/reference/inferFromGenericFunctionReturnTypes1.types b/tests/baselines/reference/inferFromGenericFunctionReturnTypes1.types index dfbe6c2f2b6..9484b3aaa19 100644 --- a/tests/baselines/reference/inferFromGenericFunctionReturnTypes1.types +++ b/tests/baselines/reference/inferFromGenericFunctionReturnTypes1.types @@ -131,9 +131,9 @@ function compose(...fns: ((x: T) => T)[]): (x: T) => T { >x : T >T : T >fns.reduce((prev, fn) => fn(prev), x) : T ->fns.reduce : { (callbackfn: (previousValue: (x: T) => T, currentValue: (x: T) => T, currentIndex: number, array: ((x: T) => T)[]) => (x: T) => T, initialValue?: (x: T) => T): (x: T) => T; (callbackfn: (previousValue: U, currentValue: (x: T) => T, currentIndex: number, array: ((x: T) => T)[]) => U, initialValue: U): U; } +>fns.reduce : { (callbackfn: (previousValue: (x: T) => T, currentValue: (x: T) => T, currentIndex: number, array: ((x: T) => T)[]) => (x: T) => T): (x: T) => T; (callbackfn: (previousValue: (x: T) => T, currentValue: (x: T) => T, currentIndex: number, array: ((x: T) => T)[]) => (x: T) => T, initialValue: (x: T) => T): (x: T) => T; (callbackfn: (previousValue: U, currentValue: (x: T) => T, currentIndex: number, array: ((x: T) => T)[]) => U, initialValue: U): U; } >fns : ((x: T) => T)[] ->reduce : { (callbackfn: (previousValue: (x: T) => T, currentValue: (x: T) => T, currentIndex: number, array: ((x: T) => T)[]) => (x: T) => T, initialValue?: (x: T) => T): (x: T) => T; (callbackfn: (previousValue: U, currentValue: (x: T) => T, currentIndex: number, array: ((x: T) => T)[]) => U, initialValue: U): U; } +>reduce : { (callbackfn: (previousValue: (x: T) => T, currentValue: (x: T) => T, currentIndex: number, array: ((x: T) => T)[]) => (x: T) => T): (x: T) => T; (callbackfn: (previousValue: (x: T) => T, currentValue: (x: T) => T, currentIndex: number, array: ((x: T) => T)[]) => (x: T) => T, initialValue: (x: T) => T): (x: T) => T; (callbackfn: (previousValue: U, currentValue: (x: T) => T, currentIndex: number, array: ((x: T) => T)[]) => U, initialValue: U): U; } >(prev, fn) => fn(prev) : (prev: T, fn: (x: T) => T) => T >prev : T >fn : (x: T) => T diff --git a/tests/baselines/reference/inferFromGenericFunctionReturnTypes2.symbols b/tests/baselines/reference/inferFromGenericFunctionReturnTypes2.symbols index 7e4fe043b93..f7189682273 100644 --- a/tests/baselines/reference/inferFromGenericFunctionReturnTypes2.symbols +++ b/tests/baselines/reference/inferFromGenericFunctionReturnTypes2.symbols @@ -292,9 +292,9 @@ function compose(...fns: ((x: T) => T)[]): (x: T) => T { return (x: T) => fns.reduce((prev, fn) => fn(prev), x); >x : Symbol(x, Decl(inferFromGenericFunctionReturnTypes2.ts, 49, 10)) >T : Symbol(T, Decl(inferFromGenericFunctionReturnTypes2.ts, 48, 17)) ->fns.reduce : Symbol(Array.reduce, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>fns.reduce : Symbol(Array.reduce, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) >fns : Symbol(fns, Decl(inferFromGenericFunctionReturnTypes2.ts, 48, 20)) ->reduce : Symbol(Array.reduce, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>reduce : Symbol(Array.reduce, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) >prev : Symbol(prev, Decl(inferFromGenericFunctionReturnTypes2.ts, 49, 31)) >fn : Symbol(fn, Decl(inferFromGenericFunctionReturnTypes2.ts, 49, 36)) >fn : Symbol(fn, Decl(inferFromGenericFunctionReturnTypes2.ts, 49, 36)) diff --git a/tests/baselines/reference/inferFromGenericFunctionReturnTypes2.types b/tests/baselines/reference/inferFromGenericFunctionReturnTypes2.types index cf7752e237e..a36b7ed35be 100644 --- a/tests/baselines/reference/inferFromGenericFunctionReturnTypes2.types +++ b/tests/baselines/reference/inferFromGenericFunctionReturnTypes2.types @@ -358,9 +358,9 @@ function compose(...fns: ((x: T) => T)[]): (x: T) => T { >x : T >T : T >fns.reduce((prev, fn) => fn(prev), x) : T ->fns.reduce : { (callbackfn: (previousValue: (x: T) => T, currentValue: (x: T) => T, currentIndex: number, array: ((x: T) => T)[]) => (x: T) => T, initialValue?: (x: T) => T): (x: T) => T; (callbackfn: (previousValue: U, currentValue: (x: T) => T, currentIndex: number, array: ((x: T) => T)[]) => U, initialValue: U): U; } +>fns.reduce : { (callbackfn: (previousValue: (x: T) => T, currentValue: (x: T) => T, currentIndex: number, array: ((x: T) => T)[]) => (x: T) => T): (x: T) => T; (callbackfn: (previousValue: (x: T) => T, currentValue: (x: T) => T, currentIndex: number, array: ((x: T) => T)[]) => (x: T) => T, initialValue: (x: T) => T): (x: T) => T; (callbackfn: (previousValue: U, currentValue: (x: T) => T, currentIndex: number, array: ((x: T) => T)[]) => U, initialValue: U): U; } >fns : ((x: T) => T)[] ->reduce : { (callbackfn: (previousValue: (x: T) => T, currentValue: (x: T) => T, currentIndex: number, array: ((x: T) => T)[]) => (x: T) => T, initialValue?: (x: T) => T): (x: T) => T; (callbackfn: (previousValue: U, currentValue: (x: T) => T, currentIndex: number, array: ((x: T) => T)[]) => U, initialValue: U): U; } +>reduce : { (callbackfn: (previousValue: (x: T) => T, currentValue: (x: T) => T, currentIndex: number, array: ((x: T) => T)[]) => (x: T) => T): (x: T) => T; (callbackfn: (previousValue: (x: T) => T, currentValue: (x: T) => T, currentIndex: number, array: ((x: T) => T)[]) => (x: T) => T, initialValue: (x: T) => T): (x: T) => T; (callbackfn: (previousValue: U, currentValue: (x: T) => T, currentIndex: number, array: ((x: T) => T)[]) => U, initialValue: U): U; } >(prev, fn) => fn(prev) : (prev: T, fn: (x: T) => T) => T >prev : T >fn : (x: T) => T diff --git a/tests/baselines/reference/jsFileCompilationBindMultipleDefaultExports.errors.txt b/tests/baselines/reference/jsFileCompilationBindMultipleDefaultExports.errors.txt index 9a9a7a12db9..246b8f20cac 100644 --- a/tests/baselines/reference/jsFileCompilationBindMultipleDefaultExports.errors.txt +++ b/tests/baselines/reference/jsFileCompilationBindMultipleDefaultExports.errors.txt @@ -1,6 +1,6 @@ tests/cases/compiler/a.js(1,22): error TS2528: A module cannot have multiple default exports. tests/cases/compiler/a.js(1,22): error TS2652: Merged declaration 'a' cannot include a default export declaration. Consider adding a separate 'export default a' declaration instead. -tests/cases/compiler/a.js(3,1): error TS2528: A module cannot have multiple default exports. +tests/cases/compiler/a.js(3,15): error TS2528: A module cannot have multiple default exports. tests/cases/compiler/a.js(3,16): error TS1109: Expression expected. tests/cases/compiler/a.js(3,20): error TS2652: Merged declaration 'a' cannot include a default export declaration. Consider adding a separate 'export default a' declaration instead. @@ -13,7 +13,7 @@ tests/cases/compiler/a.js(3,20): error TS2652: Merged declaration 'a' cannot inc !!! error TS2652: Merged declaration 'a' cannot include a default export declaration. Consider adding a separate 'export default a' declaration instead. } export default var a = 10; - ~~~~~~~~~~~~~~ + !!! error TS2528: A module cannot have multiple default exports. ~~~ !!! error TS1109: Expression expected. diff --git a/tests/baselines/reference/jsFileCompilationRestParamJsDocFunction.types b/tests/baselines/reference/jsFileCompilationRestParamJsDocFunction.types index 54bc7938689..72c3388f226 100644 --- a/tests/baselines/reference/jsFileCompilationRestParamJsDocFunction.types +++ b/tests/baselines/reference/jsFileCompilationRestParamJsDocFunction.types @@ -10,7 +10,7 @@ * @returns {*} Returns the result of `func`. */ function apply(func, thisArg, args) { ->apply : (func: Function, thisArg: any, ...args: any[]) => any +>apply : (func: Function, thisArg: any, args: any[]) => any >func : Function >thisArg : any >args : any[] @@ -84,5 +84,5 @@ function apply(func, thisArg, args) { } export default apply; ->apply : (func: Function, thisArg: any, ...args: any[]) => any +>apply : (func: Function, thisArg: any, args: any[]) => any diff --git a/tests/baselines/reference/jsdocPrefixPostfixParsing.types b/tests/baselines/reference/jsdocPrefixPostfixParsing.types index b5ddec68cba..9961af48e27 100644 --- a/tests/baselines/reference/jsdocPrefixPostfixParsing.types +++ b/tests/baselines/reference/jsdocPrefixPostfixParsing.types @@ -16,7 +16,7 @@ * @param {...number?[]!} k - (number[] | null)[] */ function f(x, y, z, a, b, c, d, e, f, g, h, i, j, k) { ->f : (x: number[], y: number[], z: number[], a: (number | null)[], b: number[] | null, c: number[] | null, d: number[] | null, ...e: (number | null)[], f: number[] | null, g: number[] | null, h: number[] | null, i: number[][], j: number[][] | null, k: (number[] | null)[]) => void +>f : (x: number[], y: number[], z: number[], a: (number | null)[], b: number[] | null, c: number[] | null, d: number[] | null, e: (number | null)[], f: number[] | null, g: number[] | null, h: number[] | null, i: number[][], j: number[][] | null, k: (number[] | null)[]) => void >x : number[] >y : number[] >z : number[] diff --git a/tests/baselines/reference/jsdocTypedef_propertyWithNoType.symbols b/tests/baselines/reference/jsdocTypedef_propertyWithNoType.symbols new file mode 100644 index 00000000000..0bac06e2e61 --- /dev/null +++ b/tests/baselines/reference/jsdocTypedef_propertyWithNoType.symbols @@ -0,0 +1,11 @@ +=== /a.js === +/** + * @typedef Foo + * @property foo + */ + +/** @type {Foo} */ +const x = { foo: 0 }; +>x : Symbol(x, Decl(a.js, 6, 5)) +>foo : Symbol(foo, Decl(a.js, 6, 11)) + diff --git a/tests/baselines/reference/jsdocTypedef_propertyWithNoType.types b/tests/baselines/reference/jsdocTypedef_propertyWithNoType.types new file mode 100644 index 00000000000..7d7326fc80c --- /dev/null +++ b/tests/baselines/reference/jsdocTypedef_propertyWithNoType.types @@ -0,0 +1,13 @@ +=== /a.js === +/** + * @typedef Foo + * @property foo + */ + +/** @type {Foo} */ +const x = { foo: 0 }; +>x : { foo: any; } +>{ foo: 0 } : { foo: number; } +>foo : number +>0 : 0 + diff --git a/tests/baselines/reference/multipleDefaultExports01.errors.txt b/tests/baselines/reference/multipleDefaultExports01.errors.txt index b53d4113ded..eff0203387c 100644 --- a/tests/baselines/reference/multipleDefaultExports01.errors.txt +++ b/tests/baselines/reference/multipleDefaultExports01.errors.txt @@ -1,6 +1,6 @@ tests/cases/conformance/es6/modules/m1.ts(1,22): error TS2528: A module cannot have multiple default exports. tests/cases/conformance/es6/modules/m1.ts(5,25): error TS2528: A module cannot have multiple default exports. -tests/cases/conformance/es6/modules/m1.ts(10,1): error TS2528: A module cannot have multiple default exports. +tests/cases/conformance/es6/modules/m1.ts(10,16): error TS2528: A module cannot have multiple default exports. tests/cases/conformance/es6/modules/m2.ts(3,1): error TS2348: Value of type 'typeof foo' is not callable. Did you mean to include 'new'? @@ -19,7 +19,7 @@ tests/cases/conformance/es6/modules/m2.ts(3,1): error TS2348: Value of type 'typ var x = 10; export default x; - ~~~~~~~~~~~~~~~~~ + ~ !!! error TS2528: A module cannot have multiple default exports. ==== tests/cases/conformance/es6/modules/m2.ts (1 errors) ==== diff --git a/tests/baselines/reference/multipleExportAssignments.errors.txt b/tests/baselines/reference/multipleExportAssignments.errors.txt index 5fbabc2b4db..c9f5eb7cf79 100644 --- a/tests/baselines/reference/multipleExportAssignments.errors.txt +++ b/tests/baselines/reference/multipleExportAssignments.errors.txt @@ -1,5 +1,5 @@ -tests/cases/compiler/multipleExportAssignments.ts(13,1): error TS2300: Duplicate identifier 'export='. -tests/cases/compiler/multipleExportAssignments.ts(14,1): error TS2300: Duplicate identifier 'export='. +tests/cases/compiler/multipleExportAssignments.ts(13,10): error TS2300: Duplicate identifier 'export='. +tests/cases/compiler/multipleExportAssignments.ts(14,10): error TS2300: Duplicate identifier 'export='. ==== tests/cases/compiler/multipleExportAssignments.ts (2 errors) ==== @@ -16,10 +16,10 @@ tests/cases/compiler/multipleExportAssignments.ts(14,1): error TS2300: Duplicate test2(): connectModule; }; export = server; - ~~~~~~~~~~~~~~~~ + ~~~~~~ !!! error TS2300: Duplicate identifier 'export='. export = connectExport; - ~~~~~~~~~~~~~~~~~~~~~~~ + ~~~~~~~~~~~~~ !!! error TS2300: Duplicate identifier 'export='. \ No newline at end of file diff --git a/tests/baselines/reference/multipleExportAssignmentsInAmbientDeclaration.errors.txt b/tests/baselines/reference/multipleExportAssignmentsInAmbientDeclaration.errors.txt index c6427a5cc28..792e2dd5968 100644 --- a/tests/baselines/reference/multipleExportAssignmentsInAmbientDeclaration.errors.txt +++ b/tests/baselines/reference/multipleExportAssignmentsInAmbientDeclaration.errors.txt @@ -1,5 +1,5 @@ -tests/cases/compiler/multipleExportAssignmentsInAmbientDeclaration.ts(4,5): error TS2300: Duplicate identifier 'export='. -tests/cases/compiler/multipleExportAssignmentsInAmbientDeclaration.ts(5,5): error TS2300: Duplicate identifier 'export='. +tests/cases/compiler/multipleExportAssignmentsInAmbientDeclaration.ts(4,14): error TS2300: Duplicate identifier 'export='. +tests/cases/compiler/multipleExportAssignmentsInAmbientDeclaration.ts(5,14): error TS2300: Duplicate identifier 'export='. ==== tests/cases/compiler/multipleExportAssignmentsInAmbientDeclaration.ts (2 errors) ==== @@ -7,9 +7,9 @@ tests/cases/compiler/multipleExportAssignmentsInAmbientDeclaration.ts(5,5): erro var a: number var b: number; export = a; - ~~~~~~~~~~~ + ~ !!! error TS2300: Duplicate identifier 'export='. export = b; - ~~~~~~~~~~~ + ~ !!! error TS2300: Duplicate identifier 'export='. } \ No newline at end of file diff --git a/tests/baselines/reference/noUnusedLocals_selfReference.errors.txt b/tests/baselines/reference/noUnusedLocals_selfReference.errors.txt index e4a0d478cb4..603bc54d448 100644 --- a/tests/baselines/reference/noUnusedLocals_selfReference.errors.txt +++ b/tests/baselines/reference/noUnusedLocals_selfReference.errors.txt @@ -1,14 +1,22 @@ tests/cases/compiler/noUnusedLocals_selfReference.ts(3,10): error TS6133: 'f' is declared but its value is never read. -tests/cases/compiler/noUnusedLocals_selfReference.ts(4,7): error TS6133: 'C' is declared but its value is never read. -tests/cases/compiler/noUnusedLocals_selfReference.ts(7,6): error TS6133: 'E' is declared but its value is never read. +tests/cases/compiler/noUnusedLocals_selfReference.ts(5,14): error TS6133: 'g' is declared but its value is never read. +tests/cases/compiler/noUnusedLocals_selfReference.ts(9,7): error TS6133: 'C' is declared but its value is never read. +tests/cases/compiler/noUnusedLocals_selfReference.ts(12,6): error TS6133: 'E' is declared but its value is never read. -==== tests/cases/compiler/noUnusedLocals_selfReference.ts (3 errors) ==== +==== tests/cases/compiler/noUnusedLocals_selfReference.ts (4 errors) ==== export {}; // Make this a module scope, so these are local variables. - function f() { f; } + function f() { ~ !!! error TS6133: 'f' is declared but its value is never read. + f; + function g() { + ~ +!!! error TS6133: 'g' is declared but its value is never read. + g; + } + } class C { ~ !!! error TS6133: 'C' is declared but its value is never read. diff --git a/tests/baselines/reference/noUnusedLocals_selfReference.js b/tests/baselines/reference/noUnusedLocals_selfReference.js index 5f206fbc3dc..a8f3d6a8aed 100644 --- a/tests/baselines/reference/noUnusedLocals_selfReference.js +++ b/tests/baselines/reference/noUnusedLocals_selfReference.js @@ -1,7 +1,12 @@ //// [noUnusedLocals_selfReference.ts] export {}; // Make this a module scope, so these are local variables. -function f() { f; } +function f() { + f; + function g() { + g; + } +} class C { m() { C; } } @@ -19,7 +24,12 @@ P; //// [noUnusedLocals_selfReference.js] "use strict"; exports.__esModule = true; -function f() { f; } +function f() { + f; + function g() { + g; + } +} var C = /** @class */ (function () { function C() { } diff --git a/tests/baselines/reference/noUnusedLocals_selfReference.symbols b/tests/baselines/reference/noUnusedLocals_selfReference.symbols index dcd815b2619..015a78d87d3 100644 --- a/tests/baselines/reference/noUnusedLocals_selfReference.symbols +++ b/tests/baselines/reference/noUnusedLocals_selfReference.symbols @@ -1,43 +1,52 @@ === tests/cases/compiler/noUnusedLocals_selfReference.ts === export {}; // Make this a module scope, so these are local variables. -function f() { f; } ->f : Symbol(f, Decl(noUnusedLocals_selfReference.ts, 0, 10)) +function f() { >f : Symbol(f, Decl(noUnusedLocals_selfReference.ts, 0, 10)) + f; +>f : Symbol(f, Decl(noUnusedLocals_selfReference.ts, 0, 10)) + + function g() { +>g : Symbol(g, Decl(noUnusedLocals_selfReference.ts, 3, 6)) + + g; +>g : Symbol(g, Decl(noUnusedLocals_selfReference.ts, 3, 6)) + } +} class C { ->C : Symbol(C, Decl(noUnusedLocals_selfReference.ts, 2, 19)) +>C : Symbol(C, Decl(noUnusedLocals_selfReference.ts, 7, 1)) m() { C; } ->m : Symbol(C.m, Decl(noUnusedLocals_selfReference.ts, 3, 9)) ->C : Symbol(C, Decl(noUnusedLocals_selfReference.ts, 2, 19)) +>m : Symbol(C.m, Decl(noUnusedLocals_selfReference.ts, 8, 9)) +>C : Symbol(C, Decl(noUnusedLocals_selfReference.ts, 7, 1)) } enum E { A = 0, B = E.A } ->E : Symbol(E, Decl(noUnusedLocals_selfReference.ts, 5, 1)) ->A : Symbol(E.A, Decl(noUnusedLocals_selfReference.ts, 6, 8)) ->B : Symbol(E.B, Decl(noUnusedLocals_selfReference.ts, 6, 15)) ->E.A : Symbol(E.A, Decl(noUnusedLocals_selfReference.ts, 6, 8)) ->E : Symbol(E, Decl(noUnusedLocals_selfReference.ts, 5, 1)) ->A : Symbol(E.A, Decl(noUnusedLocals_selfReference.ts, 6, 8)) +>E : Symbol(E, Decl(noUnusedLocals_selfReference.ts, 10, 1)) +>A : Symbol(E.A, Decl(noUnusedLocals_selfReference.ts, 11, 8)) +>B : Symbol(E.B, Decl(noUnusedLocals_selfReference.ts, 11, 15)) +>E.A : Symbol(E.A, Decl(noUnusedLocals_selfReference.ts, 11, 8)) +>E : Symbol(E, Decl(noUnusedLocals_selfReference.ts, 10, 1)) +>A : Symbol(E.A, Decl(noUnusedLocals_selfReference.ts, 11, 8)) // Does not detect mutual recursion. function g() { D; } ->g : Symbol(g, Decl(noUnusedLocals_selfReference.ts, 6, 25)) ->D : Symbol(D, Decl(noUnusedLocals_selfReference.ts, 9, 19)) +>g : Symbol(g, Decl(noUnusedLocals_selfReference.ts, 11, 25)) +>D : Symbol(D, Decl(noUnusedLocals_selfReference.ts, 14, 19)) class D { m() { g; } } ->D : Symbol(D, Decl(noUnusedLocals_selfReference.ts, 9, 19)) ->m : Symbol(D.m, Decl(noUnusedLocals_selfReference.ts, 10, 9)) ->g : Symbol(g, Decl(noUnusedLocals_selfReference.ts, 6, 25)) +>D : Symbol(D, Decl(noUnusedLocals_selfReference.ts, 14, 19)) +>m : Symbol(D.m, Decl(noUnusedLocals_selfReference.ts, 15, 9)) +>g : Symbol(g, Decl(noUnusedLocals_selfReference.ts, 11, 25)) // Does not work on private methods. class P { private m() { this.m; } } ->P : Symbol(P, Decl(noUnusedLocals_selfReference.ts, 10, 22)) ->m : Symbol(P.m, Decl(noUnusedLocals_selfReference.ts, 13, 9)) ->this.m : Symbol(P.m, Decl(noUnusedLocals_selfReference.ts, 13, 9)) ->this : Symbol(P, Decl(noUnusedLocals_selfReference.ts, 10, 22)) ->m : Symbol(P.m, Decl(noUnusedLocals_selfReference.ts, 13, 9)) +>P : Symbol(P, Decl(noUnusedLocals_selfReference.ts, 15, 22)) +>m : Symbol(P.m, Decl(noUnusedLocals_selfReference.ts, 18, 9)) +>this.m : Symbol(P.m, Decl(noUnusedLocals_selfReference.ts, 18, 9)) +>this : Symbol(P, Decl(noUnusedLocals_selfReference.ts, 15, 22)) +>m : Symbol(P.m, Decl(noUnusedLocals_selfReference.ts, 18, 9)) P; ->P : Symbol(P, Decl(noUnusedLocals_selfReference.ts, 10, 22)) +>P : Symbol(P, Decl(noUnusedLocals_selfReference.ts, 15, 22)) diff --git a/tests/baselines/reference/noUnusedLocals_selfReference.types b/tests/baselines/reference/noUnusedLocals_selfReference.types index 7d2741c5681..7e75062db34 100644 --- a/tests/baselines/reference/noUnusedLocals_selfReference.types +++ b/tests/baselines/reference/noUnusedLocals_selfReference.types @@ -1,10 +1,19 @@ === tests/cases/compiler/noUnusedLocals_selfReference.ts === export {}; // Make this a module scope, so these are local variables. -function f() { f; } ->f : () => void +function f() { >f : () => void + f; +>f : () => void + + function g() { +>g : () => void + + g; +>g : () => void + } +} class C { >C : C diff --git a/tests/baselines/reference/parserharness.symbols b/tests/baselines/reference/parserharness.symbols index 94ae5c87901..8382d6ab41a 100644 --- a/tests/baselines/reference/parserharness.symbols +++ b/tests/baselines/reference/parserharness.symbols @@ -4692,7 +4692,7 @@ module Harness { var minDistFromStart = entries.map(x => x.editRange.minChar).reduce((prev, current) => Math.min(prev, current)); >minDistFromStart : Symbol(minDistFromStart, Decl(parserharness.ts, 1595, 15)) ->entries.map(x => x.editRange.minChar).reduce : Symbol(Array.reduce, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>entries.map(x => x.editRange.minChar).reduce : Symbol(Array.reduce, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) >entries.map : Symbol(Array.map, Decl(lib.d.ts, --, --)) >entries : Symbol(entries, Decl(parserharness.ts, 1593, 15)) >map : Symbol(Array.map, Decl(lib.d.ts, --, --)) @@ -4700,7 +4700,7 @@ module Harness { >x.editRange : Symbol(editRange, Decl(parserharness.ts, 1547, 44)) >x : Symbol(x, Decl(parserharness.ts, 1595, 47)) >editRange : Symbol(editRange, Decl(parserharness.ts, 1547, 44)) ->reduce : Symbol(Array.reduce, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>reduce : Symbol(Array.reduce, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) >prev : Symbol(prev, Decl(parserharness.ts, 1595, 81)) >current : Symbol(current, Decl(parserharness.ts, 1595, 86)) >Math.min : Symbol(Math.min, Decl(lib.d.ts, --, --)) @@ -4711,7 +4711,7 @@ module Harness { var minDistFromEnd = entries.map(x => x.length - x.editRange.limChar).reduce((prev, current) => Math.min(prev, current)); >minDistFromEnd : Symbol(minDistFromEnd, Decl(parserharness.ts, 1596, 15)) ->entries.map(x => x.length - x.editRange.limChar).reduce : Symbol(Array.reduce, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>entries.map(x => x.length - x.editRange.limChar).reduce : Symbol(Array.reduce, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) >entries.map : Symbol(Array.map, Decl(lib.d.ts, --, --)) >entries : Symbol(entries, Decl(parserharness.ts, 1593, 15)) >map : Symbol(Array.map, Decl(lib.d.ts, --, --)) @@ -4722,7 +4722,7 @@ module Harness { >x.editRange : Symbol(editRange, Decl(parserharness.ts, 1547, 44)) >x : Symbol(x, Decl(parserharness.ts, 1596, 45)) >editRange : Symbol(editRange, Decl(parserharness.ts, 1547, 44)) ->reduce : Symbol(Array.reduce, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>reduce : Symbol(Array.reduce, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) >prev : Symbol(prev, Decl(parserharness.ts, 1596, 90)) >current : Symbol(current, Decl(parserharness.ts, 1596, 95)) >Math.min : Symbol(Math.min, Decl(lib.d.ts, --, --)) @@ -4733,7 +4733,7 @@ module Harness { var aggDelta = entries.map(x => x.editRange.delta).reduce((prev, current) => prev + current); >aggDelta : Symbol(aggDelta, Decl(parserharness.ts, 1597, 15)) ->entries.map(x => x.editRange.delta).reduce : Symbol(Array.reduce, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>entries.map(x => x.editRange.delta).reduce : Symbol(Array.reduce, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) >entries.map : Symbol(Array.map, Decl(lib.d.ts, --, --)) >entries : Symbol(entries, Decl(parserharness.ts, 1593, 15)) >map : Symbol(Array.map, Decl(lib.d.ts, --, --)) @@ -4741,7 +4741,7 @@ module Harness { >x.editRange : Symbol(editRange, Decl(parserharness.ts, 1547, 44)) >x : Symbol(x, Decl(parserharness.ts, 1597, 39)) >editRange : Symbol(editRange, Decl(parserharness.ts, 1547, 44)) ->reduce : Symbol(Array.reduce, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>reduce : Symbol(Array.reduce, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) >prev : Symbol(prev, Decl(parserharness.ts, 1597, 71)) >current : Symbol(current, Decl(parserharness.ts, 1597, 76)) >prev : Symbol(prev, Decl(parserharness.ts, 1597, 71)) diff --git a/tests/baselines/reference/parserharness.types b/tests/baselines/reference/parserharness.types index 2fd260f5d2b..6ea78e22f2f 100644 --- a/tests/baselines/reference/parserharness.types +++ b/tests/baselines/reference/parserharness.types @@ -6604,7 +6604,7 @@ module Harness { var minDistFromStart = entries.map(x => x.editRange.minChar).reduce((prev, current) => Math.min(prev, current)); >minDistFromStart : any >entries.map(x => x.editRange.minChar).reduce((prev, current) => Math.min(prev, current)) : any ->entries.map(x => x.editRange.minChar).reduce : { (callbackfn: (previousValue: any, currentValue: any, currentIndex: number, array: any[]) => any, initialValue?: any): any; (callbackfn: (previousValue: U, currentValue: any, currentIndex: number, array: any[]) => U, initialValue: U): U; } +>entries.map(x => x.editRange.minChar).reduce : { (callbackfn: (previousValue: any, currentValue: any, currentIndex: number, array: any[]) => any): any; (callbackfn: (previousValue: any, currentValue: any, currentIndex: number, array: any[]) => any, initialValue: any): any; (callbackfn: (previousValue: U, currentValue: any, currentIndex: number, array: any[]) => U, initialValue: U): U; } >entries.map(x => x.editRange.minChar) : any[] >entries.map : (callbackfn: (value: { length: number; editRange: any; }, index: number, array: { length: number; editRange: any; }[]) => U, thisArg?: any) => U[] >entries : { length: number; editRange: any; }[] @@ -6616,7 +6616,7 @@ module Harness { >x : { length: number; editRange: any; } >editRange : any >minChar : any ->reduce : { (callbackfn: (previousValue: any, currentValue: any, currentIndex: number, array: any[]) => any, initialValue?: any): any; (callbackfn: (previousValue: U, currentValue: any, currentIndex: number, array: any[]) => U, initialValue: U): U; } +>reduce : { (callbackfn: (previousValue: any, currentValue: any, currentIndex: number, array: any[]) => any): any; (callbackfn: (previousValue: any, currentValue: any, currentIndex: number, array: any[]) => any, initialValue: any): any; (callbackfn: (previousValue: U, currentValue: any, currentIndex: number, array: any[]) => U, initialValue: U): U; } >(prev, current) => Math.min(prev, current) : (prev: any, current: any) => number >prev : any >current : any @@ -6630,7 +6630,7 @@ module Harness { var minDistFromEnd = entries.map(x => x.length - x.editRange.limChar).reduce((prev, current) => Math.min(prev, current)); >minDistFromEnd : number >entries.map(x => x.length - x.editRange.limChar).reduce((prev, current) => Math.min(prev, current)) : number ->entries.map(x => x.length - x.editRange.limChar).reduce : { (callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: number[]) => number, initialValue?: number): number; (callbackfn: (previousValue: U, currentValue: number, currentIndex: number, array: number[]) => U, initialValue: U): U; } +>entries.map(x => x.length - x.editRange.limChar).reduce : { (callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: number[]) => number): number; (callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: number[]) => number, initialValue: number): number; (callbackfn: (previousValue: U, currentValue: number, currentIndex: number, array: number[]) => U, initialValue: U): U; } >entries.map(x => x.length - x.editRange.limChar) : number[] >entries.map : (callbackfn: (value: { length: number; editRange: any; }, index: number, array: { length: number; editRange: any; }[]) => U, thisArg?: any) => U[] >entries : { length: number; editRange: any; }[] @@ -6646,7 +6646,7 @@ module Harness { >x : { length: number; editRange: any; } >editRange : any >limChar : any ->reduce : { (callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: number[]) => number, initialValue?: number): number; (callbackfn: (previousValue: U, currentValue: number, currentIndex: number, array: number[]) => U, initialValue: U): U; } +>reduce : { (callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: number[]) => number): number; (callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: number[]) => number, initialValue: number): number; (callbackfn: (previousValue: U, currentValue: number, currentIndex: number, array: number[]) => U, initialValue: U): U; } >(prev, current) => Math.min(prev, current) : (prev: number, current: number) => number >prev : number >current : number @@ -6660,7 +6660,7 @@ module Harness { var aggDelta = entries.map(x => x.editRange.delta).reduce((prev, current) => prev + current); >aggDelta : any >entries.map(x => x.editRange.delta).reduce((prev, current) => prev + current) : any ->entries.map(x => x.editRange.delta).reduce : { (callbackfn: (previousValue: any, currentValue: any, currentIndex: number, array: any[]) => any, initialValue?: any): any; (callbackfn: (previousValue: U, currentValue: any, currentIndex: number, array: any[]) => U, initialValue: U): U; } +>entries.map(x => x.editRange.delta).reduce : { (callbackfn: (previousValue: any, currentValue: any, currentIndex: number, array: any[]) => any): any; (callbackfn: (previousValue: any, currentValue: any, currentIndex: number, array: any[]) => any, initialValue: any): any; (callbackfn: (previousValue: U, currentValue: any, currentIndex: number, array: any[]) => U, initialValue: U): U; } >entries.map(x => x.editRange.delta) : any[] >entries.map : (callbackfn: (value: { length: number; editRange: any; }, index: number, array: { length: number; editRange: any; }[]) => U, thisArg?: any) => U[] >entries : { length: number; editRange: any; }[] @@ -6672,7 +6672,7 @@ module Harness { >x : { length: number; editRange: any; } >editRange : any >delta : any ->reduce : { (callbackfn: (previousValue: any, currentValue: any, currentIndex: number, array: any[]) => any, initialValue?: any): any; (callbackfn: (previousValue: U, currentValue: any, currentIndex: number, array: any[]) => U, initialValue: U): U; } +>reduce : { (callbackfn: (previousValue: any, currentValue: any, currentIndex: number, array: any[]) => any): any; (callbackfn: (previousValue: any, currentValue: any, currentIndex: number, array: any[]) => any, initialValue: any): any; (callbackfn: (previousValue: U, currentValue: any, currentIndex: number, array: any[]) => U, initialValue: U): U; } >(prev, current) => prev + current : (prev: any, current: any) => any >prev : any >current : any diff --git a/tests/baselines/reference/potentiallyUncalledDecorators.errors.txt b/tests/baselines/reference/potentiallyUncalledDecorators.errors.txt new file mode 100644 index 00000000000..9028ebe0377 --- /dev/null +++ b/tests/baselines/reference/potentiallyUncalledDecorators.errors.txt @@ -0,0 +1,174 @@ +tests/cases/compiler/potentiallyUncalledDecorators.ts(4,5): error TS1329: 'Input' accepts too few arguments to be used as a decorator here. Did you mean to call it first and write '@Input()'? +tests/cases/compiler/potentiallyUncalledDecorators.ts(35,1): error TS1329: 'noArgs' accepts too few arguments to be used as a decorator here. Did you mean to call it first and write '@noArgs()'? +tests/cases/compiler/potentiallyUncalledDecorators.ts(37,5): error TS1329: 'noArgs' accepts too few arguments to be used as a decorator here. Did you mean to call it first and write '@noArgs()'? +tests/cases/compiler/potentiallyUncalledDecorators.ts(38,5): error TS1329: 'noArgs' accepts too few arguments to be used as a decorator here. Did you mean to call it first and write '@noArgs()'? +tests/cases/compiler/potentiallyUncalledDecorators.ts(41,1): error TS1238: Unable to resolve signature of class decorator when called as an expression. + Type 'OmniDecorator' is not assignable to type 'typeof B'. + Type 'OmniDecorator' provides no match for the signature 'new (): B'. +tests/cases/compiler/potentiallyUncalledDecorators.ts(43,5): error TS1236: The return type of a property decorator function must be either 'void' or 'any'. + Unable to resolve signature of property decorator when called as an expression. +tests/cases/compiler/potentiallyUncalledDecorators.ts(44,5): error TS1241: Unable to resolve signature of method decorator when called as an expression. + Type 'OmniDecorator' has no properties in common with type 'TypedPropertyDescriptor<() => void>'. +tests/cases/compiler/potentiallyUncalledDecorators.ts(47,1): error TS1238: Unable to resolve signature of class decorator when called as an expression. + Type 'OmniDecorator' is not assignable to type 'typeof C'. + Type 'OmniDecorator' provides no match for the signature 'new (): C'. +tests/cases/compiler/potentiallyUncalledDecorators.ts(49,5): error TS1329: 'oneOptional' accepts too few arguments to be used as a decorator here. Did you mean to call it first and write '@oneOptional()'? +tests/cases/compiler/potentiallyUncalledDecorators.ts(50,5): error TS1329: 'oneOptional' accepts too few arguments to be used as a decorator here. Did you mean to call it first and write '@oneOptional()'? +tests/cases/compiler/potentiallyUncalledDecorators.ts(53,1): error TS1238: Unable to resolve signature of class decorator when called as an expression. + Type 'OmniDecorator' is not assignable to type 'typeof D'. + Type 'OmniDecorator' provides no match for the signature 'new (): D'. +tests/cases/compiler/potentiallyUncalledDecorators.ts(55,5): error TS1236: The return type of a property decorator function must be either 'void' or 'any'. + Unable to resolve signature of property decorator when called as an expression. +tests/cases/compiler/potentiallyUncalledDecorators.ts(56,5): error TS1241: Unable to resolve signature of method decorator when called as an expression. + Type 'OmniDecorator' has no properties in common with type 'TypedPropertyDescriptor<() => void>'. +tests/cases/compiler/potentiallyUncalledDecorators.ts(59,1): error TS1238: Unable to resolve signature of class decorator when called as an expression. + Type 'OmniDecorator' is not assignable to type 'typeof E'. + Type 'OmniDecorator' provides no match for the signature 'new (): E'. +tests/cases/compiler/potentiallyUncalledDecorators.ts(61,5): error TS1236: The return type of a property decorator function must be either 'void' or 'any'. + Unable to resolve signature of property decorator when called as an expression. +tests/cases/compiler/potentiallyUncalledDecorators.ts(62,5): error TS1241: Unable to resolve signature of method decorator when called as an expression. + Type 'OmniDecorator' has no properties in common with type 'TypedPropertyDescriptor<() => void>'. +tests/cases/compiler/potentiallyUncalledDecorators.ts(65,1): error TS1238: Unable to resolve signature of class decorator when called as an expression. + Type 'OmniDecorator' is not assignable to type 'typeof F'. + Type 'OmniDecorator' provides no match for the signature 'new (): F'. +tests/cases/compiler/potentiallyUncalledDecorators.ts(67,5): error TS1236: The return type of a property decorator function must be either 'void' or 'any'. + Unable to resolve signature of property decorator when called as an expression. +tests/cases/compiler/potentiallyUncalledDecorators.ts(68,5): error TS1241: Unable to resolve signature of method decorator when called as an expression. + Type 'OmniDecorator' has no properties in common with type 'TypedPropertyDescriptor<() => void>'. + + +==== tests/cases/compiler/potentiallyUncalledDecorators.ts (19 errors) ==== + // Angular-style Input/Output API: + declare function Input(bindingPropertyName?: string): any; + class FooComponent { + @Input foo: string; + ~~~~~~ +!!! error TS1329: 'Input' accepts too few arguments to be used as a decorator here. Did you mean to call it first and write '@Input()'? + } + + // Glimmer-style tracked API: + declare const tracked: PropertyDecorator & { (...watchedProperties: string[]): any; } + + class Person { + @tracked person; any; + } + + class MultiplyByTwo { + args: any; + @tracked('args') + get multiplied() { + return this.args.number * 2; + } + } + + // Other fun stuff. + + interface OmniDecorator extends MethodDecorator, ClassDecorator, PropertyDecorator { + } + + declare function noArgs(): OmniDecorator; + declare function allRest(...args: any[]): OmniDecorator; + declare function oneOptional(x?: any): OmniDecorator; + declare function twoOptional(x?: any, y?: any): OmniDecorator; + declare function threeOptional(x?: any, y?: any, z?: any): OmniDecorator; + declare function oneOptionalWithRest(x?: any, ...args: any[]): OmniDecorator; + declare const anyDec: any; + + @noArgs + ~~~~~~~ +!!! error TS1329: 'noArgs' accepts too few arguments to be used as a decorator here. Did you mean to call it first and write '@noArgs()'? + class A { + @noArgs foo: any; + ~~~~~~~ +!!! error TS1329: 'noArgs' accepts too few arguments to be used as a decorator here. Did you mean to call it first and write '@noArgs()'? + @noArgs bar() { } + ~~~~~~~ +!!! error TS1329: 'noArgs' accepts too few arguments to be used as a decorator here. Did you mean to call it first and write '@noArgs()'? + } + + @allRest + ~~~~~~~~ +!!! error TS1238: Unable to resolve signature of class decorator when called as an expression. +!!! error TS1238: Type 'OmniDecorator' is not assignable to type 'typeof B'. +!!! error TS1238: Type 'OmniDecorator' provides no match for the signature 'new (): B'. + class B { + @allRest foo: any; + ~~~~~~~~ +!!! error TS1236: The return type of a property decorator function must be either 'void' or 'any'. +!!! error TS1236: Unable to resolve signature of property decorator when called as an expression. + @allRest bar() { } + ~~~~~~~~ +!!! error TS1241: Unable to resolve signature of method decorator when called as an expression. +!!! error TS1241: Type 'OmniDecorator' has no properties in common with type 'TypedPropertyDescriptor<() => void>'. + } + + @oneOptional + ~~~~~~~~~~~~ +!!! error TS1238: Unable to resolve signature of class decorator when called as an expression. +!!! error TS1238: Type 'OmniDecorator' is not assignable to type 'typeof C'. +!!! error TS1238: Type 'OmniDecorator' provides no match for the signature 'new (): C'. + class C { + @oneOptional foo: any; + ~~~~~~~~~~~~ +!!! error TS1329: 'oneOptional' accepts too few arguments to be used as a decorator here. Did you mean to call it first and write '@oneOptional()'? + @oneOptional bar() { } + ~~~~~~~~~~~~ +!!! error TS1329: 'oneOptional' accepts too few arguments to be used as a decorator here. Did you mean to call it first and write '@oneOptional()'? + } + + @twoOptional + ~~~~~~~~~~~~ +!!! error TS1238: Unable to resolve signature of class decorator when called as an expression. +!!! error TS1238: Type 'OmniDecorator' is not assignable to type 'typeof D'. +!!! error TS1238: Type 'OmniDecorator' provides no match for the signature 'new (): D'. + class D { + @twoOptional foo: any; + ~~~~~~~~~~~~ +!!! error TS1236: The return type of a property decorator function must be either 'void' or 'any'. +!!! error TS1236: Unable to resolve signature of property decorator when called as an expression. + @twoOptional bar() { } + ~~~~~~~~~~~~ +!!! error TS1241: Unable to resolve signature of method decorator when called as an expression. +!!! error TS1241: Type 'OmniDecorator' has no properties in common with type 'TypedPropertyDescriptor<() => void>'. + } + + @threeOptional + ~~~~~~~~~~~~~~ +!!! error TS1238: Unable to resolve signature of class decorator when called as an expression. +!!! error TS1238: Type 'OmniDecorator' is not assignable to type 'typeof E'. +!!! error TS1238: Type 'OmniDecorator' provides no match for the signature 'new (): E'. + class E { + @threeOptional foo: any; + ~~~~~~~~~~~~~~ +!!! error TS1236: The return type of a property decorator function must be either 'void' or 'any'. +!!! error TS1236: Unable to resolve signature of property decorator when called as an expression. + @threeOptional bar() { } + ~~~~~~~~~~~~~~ +!!! error TS1241: Unable to resolve signature of method decorator when called as an expression. +!!! error TS1241: Type 'OmniDecorator' has no properties in common with type 'TypedPropertyDescriptor<() => void>'. + } + + @oneOptionalWithRest + ~~~~~~~~~~~~~~~~~~~~ +!!! error TS1238: Unable to resolve signature of class decorator when called as an expression. +!!! error TS1238: Type 'OmniDecorator' is not assignable to type 'typeof F'. +!!! error TS1238: Type 'OmniDecorator' provides no match for the signature 'new (): F'. + class F { + @oneOptionalWithRest foo: any; + ~~~~~~~~~~~~~~~~~~~~ +!!! error TS1236: The return type of a property decorator function must be either 'void' or 'any'. +!!! error TS1236: Unable to resolve signature of property decorator when called as an expression. + @oneOptionalWithRest bar() { } + ~~~~~~~~~~~~~~~~~~~~ +!!! error TS1241: Unable to resolve signature of method decorator when called as an expression. +!!! error TS1241: Type 'OmniDecorator' has no properties in common with type 'TypedPropertyDescriptor<() => void>'. + } + + @anyDec + class G { + @anyDec foo: any; + @anyDec bar() { } + } + + export { }; + \ No newline at end of file diff --git a/tests/baselines/reference/potentiallyUncalledDecorators.js b/tests/baselines/reference/potentiallyUncalledDecorators.js new file mode 100644 index 00000000000..b69f848a8c9 --- /dev/null +++ b/tests/baselines/reference/potentiallyUncalledDecorators.js @@ -0,0 +1,189 @@ +//// [potentiallyUncalledDecorators.ts] +// Angular-style Input/Output API: +declare function Input(bindingPropertyName?: string): any; +class FooComponent { + @Input foo: string; +} + +// Glimmer-style tracked API: +declare const tracked: PropertyDecorator & { (...watchedProperties: string[]): any; } + +class Person { + @tracked person; any; +} + +class MultiplyByTwo { + args: any; + @tracked('args') + get multiplied() { + return this.args.number * 2; + } +} + +// Other fun stuff. + +interface OmniDecorator extends MethodDecorator, ClassDecorator, PropertyDecorator { +} + +declare function noArgs(): OmniDecorator; +declare function allRest(...args: any[]): OmniDecorator; +declare function oneOptional(x?: any): OmniDecorator; +declare function twoOptional(x?: any, y?: any): OmniDecorator; +declare function threeOptional(x?: any, y?: any, z?: any): OmniDecorator; +declare function oneOptionalWithRest(x?: any, ...args: any[]): OmniDecorator; +declare const anyDec: any; + +@noArgs +class A { + @noArgs foo: any; + @noArgs bar() { } +} + +@allRest +class B { + @allRest foo: any; + @allRest bar() { } +} + +@oneOptional +class C { + @oneOptional foo: any; + @oneOptional bar() { } +} + +@twoOptional +class D { + @twoOptional foo: any; + @twoOptional bar() { } +} + +@threeOptional +class E { + @threeOptional foo: any; + @threeOptional bar() { } +} + +@oneOptionalWithRest +class F { + @oneOptionalWithRest foo: any; + @oneOptionalWithRest bar() { } +} + +@anyDec +class G { + @anyDec foo: any; + @anyDec bar() { } +} + +export { }; + + +//// [potentiallyUncalledDecorators.js] +var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { + var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); + else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; + return c > 3 && r && Object.defineProperty(target, key, r), r; +}; +class FooComponent { +} +__decorate([ + Input +], FooComponent.prototype, "foo", void 0); +class Person { +} +__decorate([ + tracked +], Person.prototype, "person", void 0); +class MultiplyByTwo { + get multiplied() { + return this.args.number * 2; + } +} +__decorate([ + tracked('args') +], MultiplyByTwo.prototype, "multiplied", null); +let A = class A { + bar() { } +}; +__decorate([ + noArgs +], A.prototype, "foo", void 0); +__decorate([ + noArgs +], A.prototype, "bar", null); +A = __decorate([ + noArgs +], A); +let B = class B { + bar() { } +}; +__decorate([ + allRest +], B.prototype, "foo", void 0); +__decorate([ + allRest +], B.prototype, "bar", null); +B = __decorate([ + allRest +], B); +let C = class C { + bar() { } +}; +__decorate([ + oneOptional +], C.prototype, "foo", void 0); +__decorate([ + oneOptional +], C.prototype, "bar", null); +C = __decorate([ + oneOptional +], C); +let D = class D { + bar() { } +}; +__decorate([ + twoOptional +], D.prototype, "foo", void 0); +__decorate([ + twoOptional +], D.prototype, "bar", null); +D = __decorate([ + twoOptional +], D); +let E = class E { + bar() { } +}; +__decorate([ + threeOptional +], E.prototype, "foo", void 0); +__decorate([ + threeOptional +], E.prototype, "bar", null); +E = __decorate([ + threeOptional +], E); +let F = class F { + bar() { } +}; +__decorate([ + oneOptionalWithRest +], F.prototype, "foo", void 0); +__decorate([ + oneOptionalWithRest +], F.prototype, "bar", null); +F = __decorate([ + oneOptionalWithRest +], F); +let G = class G { + bar() { } +}; +__decorate([ + anyDec +], G.prototype, "foo", void 0); +__decorate([ + anyDec +], G.prototype, "bar", null); +G = __decorate([ + anyDec +], G); diff --git a/tests/baselines/reference/potentiallyUncalledDecorators.symbols b/tests/baselines/reference/potentiallyUncalledDecorators.symbols new file mode 100644 index 00000000000..38fe3f3dc52 --- /dev/null +++ b/tests/baselines/reference/potentiallyUncalledDecorators.symbols @@ -0,0 +1,200 @@ +=== tests/cases/compiler/potentiallyUncalledDecorators.ts === +// Angular-style Input/Output API: +declare function Input(bindingPropertyName?: string): any; +>Input : Symbol(Input, Decl(potentiallyUncalledDecorators.ts, 0, 0)) +>bindingPropertyName : Symbol(bindingPropertyName, Decl(potentiallyUncalledDecorators.ts, 1, 23)) + +class FooComponent { +>FooComponent : Symbol(FooComponent, Decl(potentiallyUncalledDecorators.ts, 1, 58)) + + @Input foo: string; +>Input : Symbol(Input, Decl(potentiallyUncalledDecorators.ts, 0, 0)) +>foo : Symbol(FooComponent.foo, Decl(potentiallyUncalledDecorators.ts, 2, 20)) +} + +// Glimmer-style tracked API: +declare const tracked: PropertyDecorator & { (...watchedProperties: string[]): any; } +>tracked : Symbol(tracked, Decl(potentiallyUncalledDecorators.ts, 7, 13)) +>PropertyDecorator : Symbol(PropertyDecorator, Decl(lib.es5.d.ts, --, --)) +>watchedProperties : Symbol(watchedProperties, Decl(potentiallyUncalledDecorators.ts, 7, 46)) + +class Person { +>Person : Symbol(Person, Decl(potentiallyUncalledDecorators.ts, 7, 85)) + + @tracked person; any; +>tracked : Symbol(tracked, Decl(potentiallyUncalledDecorators.ts, 7, 13)) +>person : Symbol(Person.person, Decl(potentiallyUncalledDecorators.ts, 9, 14)) +>any : Symbol(Person.any, Decl(potentiallyUncalledDecorators.ts, 10, 20)) +} + +class MultiplyByTwo { +>MultiplyByTwo : Symbol(MultiplyByTwo, Decl(potentiallyUncalledDecorators.ts, 11, 1)) + + args: any; +>args : Symbol(MultiplyByTwo.args, Decl(potentiallyUncalledDecorators.ts, 13, 21)) + + @tracked('args') +>tracked : Symbol(tracked, Decl(potentiallyUncalledDecorators.ts, 7, 13)) + + get multiplied() { +>multiplied : Symbol(MultiplyByTwo.multiplied, Decl(potentiallyUncalledDecorators.ts, 14, 14)) + + return this.args.number * 2; +>this.args : Symbol(MultiplyByTwo.args, Decl(potentiallyUncalledDecorators.ts, 13, 21)) +>this : Symbol(MultiplyByTwo, Decl(potentiallyUncalledDecorators.ts, 11, 1)) +>args : Symbol(MultiplyByTwo.args, Decl(potentiallyUncalledDecorators.ts, 13, 21)) + } +} + +// Other fun stuff. + +interface OmniDecorator extends MethodDecorator, ClassDecorator, PropertyDecorator { +>OmniDecorator : Symbol(OmniDecorator, Decl(potentiallyUncalledDecorators.ts, 19, 1)) +>MethodDecorator : Symbol(MethodDecorator, Decl(lib.es5.d.ts, --, --)) +>ClassDecorator : Symbol(ClassDecorator, Decl(lib.es5.d.ts, --, --)) +>PropertyDecorator : Symbol(PropertyDecorator, Decl(lib.es5.d.ts, --, --)) +} + +declare function noArgs(): OmniDecorator; +>noArgs : Symbol(noArgs, Decl(potentiallyUncalledDecorators.ts, 24, 1)) +>OmniDecorator : Symbol(OmniDecorator, Decl(potentiallyUncalledDecorators.ts, 19, 1)) + +declare function allRest(...args: any[]): OmniDecorator; +>allRest : Symbol(allRest, Decl(potentiallyUncalledDecorators.ts, 26, 41)) +>args : Symbol(args, Decl(potentiallyUncalledDecorators.ts, 27, 25)) +>OmniDecorator : Symbol(OmniDecorator, Decl(potentiallyUncalledDecorators.ts, 19, 1)) + +declare function oneOptional(x?: any): OmniDecorator; +>oneOptional : Symbol(oneOptional, Decl(potentiallyUncalledDecorators.ts, 27, 56)) +>x : Symbol(x, Decl(potentiallyUncalledDecorators.ts, 28, 29)) +>OmniDecorator : Symbol(OmniDecorator, Decl(potentiallyUncalledDecorators.ts, 19, 1)) + +declare function twoOptional(x?: any, y?: any): OmniDecorator; +>twoOptional : Symbol(twoOptional, Decl(potentiallyUncalledDecorators.ts, 28, 53)) +>x : Symbol(x, Decl(potentiallyUncalledDecorators.ts, 29, 29)) +>y : Symbol(y, Decl(potentiallyUncalledDecorators.ts, 29, 37)) +>OmniDecorator : Symbol(OmniDecorator, Decl(potentiallyUncalledDecorators.ts, 19, 1)) + +declare function threeOptional(x?: any, y?: any, z?: any): OmniDecorator; +>threeOptional : Symbol(threeOptional, Decl(potentiallyUncalledDecorators.ts, 29, 62)) +>x : Symbol(x, Decl(potentiallyUncalledDecorators.ts, 30, 31)) +>y : Symbol(y, Decl(potentiallyUncalledDecorators.ts, 30, 39)) +>z : Symbol(z, Decl(potentiallyUncalledDecorators.ts, 30, 48)) +>OmniDecorator : Symbol(OmniDecorator, Decl(potentiallyUncalledDecorators.ts, 19, 1)) + +declare function oneOptionalWithRest(x?: any, ...args: any[]): OmniDecorator; +>oneOptionalWithRest : Symbol(oneOptionalWithRest, Decl(potentiallyUncalledDecorators.ts, 30, 73)) +>x : Symbol(x, Decl(potentiallyUncalledDecorators.ts, 31, 37)) +>args : Symbol(args, Decl(potentiallyUncalledDecorators.ts, 31, 45)) +>OmniDecorator : Symbol(OmniDecorator, Decl(potentiallyUncalledDecorators.ts, 19, 1)) + +declare const anyDec: any; +>anyDec : Symbol(anyDec, Decl(potentiallyUncalledDecorators.ts, 32, 13)) + +@noArgs +>noArgs : Symbol(noArgs, Decl(potentiallyUncalledDecorators.ts, 24, 1)) + +class A { +>A : Symbol(A, Decl(potentiallyUncalledDecorators.ts, 32, 26)) + + @noArgs foo: any; +>noArgs : Symbol(noArgs, Decl(potentiallyUncalledDecorators.ts, 24, 1)) +>foo : Symbol(A.foo, Decl(potentiallyUncalledDecorators.ts, 35, 9)) + + @noArgs bar() { } +>noArgs : Symbol(noArgs, Decl(potentiallyUncalledDecorators.ts, 24, 1)) +>bar : Symbol(A.bar, Decl(potentiallyUncalledDecorators.ts, 36, 21)) +} + +@allRest +>allRest : Symbol(allRest, Decl(potentiallyUncalledDecorators.ts, 26, 41)) + +class B { +>B : Symbol(B, Decl(potentiallyUncalledDecorators.ts, 38, 1)) + + @allRest foo: any; +>allRest : Symbol(allRest, Decl(potentiallyUncalledDecorators.ts, 26, 41)) +>foo : Symbol(B.foo, Decl(potentiallyUncalledDecorators.ts, 41, 9)) + + @allRest bar() { } +>allRest : Symbol(allRest, Decl(potentiallyUncalledDecorators.ts, 26, 41)) +>bar : Symbol(B.bar, Decl(potentiallyUncalledDecorators.ts, 42, 22)) +} + +@oneOptional +>oneOptional : Symbol(oneOptional, Decl(potentiallyUncalledDecorators.ts, 27, 56)) + +class C { +>C : Symbol(C, Decl(potentiallyUncalledDecorators.ts, 44, 1)) + + @oneOptional foo: any; +>oneOptional : Symbol(oneOptional, Decl(potentiallyUncalledDecorators.ts, 27, 56)) +>foo : Symbol(C.foo, Decl(potentiallyUncalledDecorators.ts, 47, 9)) + + @oneOptional bar() { } +>oneOptional : Symbol(oneOptional, Decl(potentiallyUncalledDecorators.ts, 27, 56)) +>bar : Symbol(C.bar, Decl(potentiallyUncalledDecorators.ts, 48, 26)) +} + +@twoOptional +>twoOptional : Symbol(twoOptional, Decl(potentiallyUncalledDecorators.ts, 28, 53)) + +class D { +>D : Symbol(D, Decl(potentiallyUncalledDecorators.ts, 50, 1)) + + @twoOptional foo: any; +>twoOptional : Symbol(twoOptional, Decl(potentiallyUncalledDecorators.ts, 28, 53)) +>foo : Symbol(D.foo, Decl(potentiallyUncalledDecorators.ts, 53, 9)) + + @twoOptional bar() { } +>twoOptional : Symbol(twoOptional, Decl(potentiallyUncalledDecorators.ts, 28, 53)) +>bar : Symbol(D.bar, Decl(potentiallyUncalledDecorators.ts, 54, 26)) +} + +@threeOptional +>threeOptional : Symbol(threeOptional, Decl(potentiallyUncalledDecorators.ts, 29, 62)) + +class E { +>E : Symbol(E, Decl(potentiallyUncalledDecorators.ts, 56, 1)) + + @threeOptional foo: any; +>threeOptional : Symbol(threeOptional, Decl(potentiallyUncalledDecorators.ts, 29, 62)) +>foo : Symbol(E.foo, Decl(potentiallyUncalledDecorators.ts, 59, 9)) + + @threeOptional bar() { } +>threeOptional : Symbol(threeOptional, Decl(potentiallyUncalledDecorators.ts, 29, 62)) +>bar : Symbol(E.bar, Decl(potentiallyUncalledDecorators.ts, 60, 28)) +} + +@oneOptionalWithRest +>oneOptionalWithRest : Symbol(oneOptionalWithRest, Decl(potentiallyUncalledDecorators.ts, 30, 73)) + +class F { +>F : Symbol(F, Decl(potentiallyUncalledDecorators.ts, 62, 1)) + + @oneOptionalWithRest foo: any; +>oneOptionalWithRest : Symbol(oneOptionalWithRest, Decl(potentiallyUncalledDecorators.ts, 30, 73)) +>foo : Symbol(F.foo, Decl(potentiallyUncalledDecorators.ts, 65, 9)) + + @oneOptionalWithRest bar() { } +>oneOptionalWithRest : Symbol(oneOptionalWithRest, Decl(potentiallyUncalledDecorators.ts, 30, 73)) +>bar : Symbol(F.bar, Decl(potentiallyUncalledDecorators.ts, 66, 34)) +} + +@anyDec +>anyDec : Symbol(anyDec, Decl(potentiallyUncalledDecorators.ts, 32, 13)) + +class G { +>G : Symbol(G, Decl(potentiallyUncalledDecorators.ts, 68, 1)) + + @anyDec foo: any; +>anyDec : Symbol(anyDec, Decl(potentiallyUncalledDecorators.ts, 32, 13)) +>foo : Symbol(G.foo, Decl(potentiallyUncalledDecorators.ts, 71, 9)) + + @anyDec bar() { } +>anyDec : Symbol(anyDec, Decl(potentiallyUncalledDecorators.ts, 32, 13)) +>bar : Symbol(G.bar, Decl(potentiallyUncalledDecorators.ts, 72, 21)) +} + +export { }; + diff --git a/tests/baselines/reference/potentiallyUncalledDecorators.types b/tests/baselines/reference/potentiallyUncalledDecorators.types new file mode 100644 index 00000000000..cad861fc7b4 --- /dev/null +++ b/tests/baselines/reference/potentiallyUncalledDecorators.types @@ -0,0 +1,206 @@ +=== tests/cases/compiler/potentiallyUncalledDecorators.ts === +// Angular-style Input/Output API: +declare function Input(bindingPropertyName?: string): any; +>Input : (bindingPropertyName?: string) => any +>bindingPropertyName : string + +class FooComponent { +>FooComponent : FooComponent + + @Input foo: string; +>Input : (bindingPropertyName?: string) => any +>foo : string +} + +// Glimmer-style tracked API: +declare const tracked: PropertyDecorator & { (...watchedProperties: string[]): any; } +>tracked : PropertyDecorator & ((...watchedProperties: string[]) => any) +>PropertyDecorator : PropertyDecorator +>watchedProperties : string[] + +class Person { +>Person : Person + + @tracked person; any; +>tracked : PropertyDecorator & ((...watchedProperties: string[]) => any) +>person : any +>any : any +} + +class MultiplyByTwo { +>MultiplyByTwo : MultiplyByTwo + + args: any; +>args : any + + @tracked('args') +>tracked('args') : any +>tracked : PropertyDecorator & ((...watchedProperties: string[]) => any) +>'args' : "args" + + get multiplied() { +>multiplied : number + + return this.args.number * 2; +>this.args.number * 2 : number +>this.args.number : any +>this.args : any +>this : this +>args : any +>number : any +>2 : 2 + } +} + +// Other fun stuff. + +interface OmniDecorator extends MethodDecorator, ClassDecorator, PropertyDecorator { +>OmniDecorator : OmniDecorator +>MethodDecorator : MethodDecorator +>ClassDecorator : ClassDecorator +>PropertyDecorator : PropertyDecorator +} + +declare function noArgs(): OmniDecorator; +>noArgs : () => OmniDecorator +>OmniDecorator : OmniDecorator + +declare function allRest(...args: any[]): OmniDecorator; +>allRest : (...args: any[]) => OmniDecorator +>args : any[] +>OmniDecorator : OmniDecorator + +declare function oneOptional(x?: any): OmniDecorator; +>oneOptional : (x?: any) => OmniDecorator +>x : any +>OmniDecorator : OmniDecorator + +declare function twoOptional(x?: any, y?: any): OmniDecorator; +>twoOptional : (x?: any, y?: any) => OmniDecorator +>x : any +>y : any +>OmniDecorator : OmniDecorator + +declare function threeOptional(x?: any, y?: any, z?: any): OmniDecorator; +>threeOptional : (x?: any, y?: any, z?: any) => OmniDecorator +>x : any +>y : any +>z : any +>OmniDecorator : OmniDecorator + +declare function oneOptionalWithRest(x?: any, ...args: any[]): OmniDecorator; +>oneOptionalWithRest : (x?: any, ...args: any[]) => OmniDecorator +>x : any +>args : any[] +>OmniDecorator : OmniDecorator + +declare const anyDec: any; +>anyDec : any + +@noArgs +>noArgs : () => OmniDecorator + +class A { +>A : A + + @noArgs foo: any; +>noArgs : () => OmniDecorator +>foo : any + + @noArgs bar() { } +>noArgs : () => OmniDecorator +>bar : () => void +} + +@allRest +>allRest : (...args: any[]) => OmniDecorator + +class B { +>B : B + + @allRest foo: any; +>allRest : (...args: any[]) => OmniDecorator +>foo : any + + @allRest bar() { } +>allRest : (...args: any[]) => OmniDecorator +>bar : () => void +} + +@oneOptional +>oneOptional : (x?: any) => OmniDecorator + +class C { +>C : C + + @oneOptional foo: any; +>oneOptional : (x?: any) => OmniDecorator +>foo : any + + @oneOptional bar() { } +>oneOptional : (x?: any) => OmniDecorator +>bar : () => void +} + +@twoOptional +>twoOptional : (x?: any, y?: any) => OmniDecorator + +class D { +>D : D + + @twoOptional foo: any; +>twoOptional : (x?: any, y?: any) => OmniDecorator +>foo : any + + @twoOptional bar() { } +>twoOptional : (x?: any, y?: any) => OmniDecorator +>bar : () => void +} + +@threeOptional +>threeOptional : (x?: any, y?: any, z?: any) => OmniDecorator + +class E { +>E : E + + @threeOptional foo: any; +>threeOptional : (x?: any, y?: any, z?: any) => OmniDecorator +>foo : any + + @threeOptional bar() { } +>threeOptional : (x?: any, y?: any, z?: any) => OmniDecorator +>bar : () => void +} + +@oneOptionalWithRest +>oneOptionalWithRest : (x?: any, ...args: any[]) => OmniDecorator + +class F { +>F : F + + @oneOptionalWithRest foo: any; +>oneOptionalWithRest : (x?: any, ...args: any[]) => OmniDecorator +>foo : any + + @oneOptionalWithRest bar() { } +>oneOptionalWithRest : (x?: any, ...args: any[]) => OmniDecorator +>bar : () => void +} + +@anyDec +>anyDec : any + +class G { +>G : G + + @anyDec foo: any; +>anyDec : any +>foo : any + + @anyDec bar() { } +>anyDec : any +>bar : () => void +} + +export { }; + diff --git a/tests/baselines/reference/recursiveTypeRelations.symbols b/tests/baselines/reference/recursiveTypeRelations.symbols index 9f656a789ed..2c940df2487 100644 --- a/tests/baselines/reference/recursiveTypeRelations.symbols +++ b/tests/baselines/reference/recursiveTypeRelations.symbols @@ -89,12 +89,12 @@ export function css(styles: S, ...classNam >arg : Symbol(arg, Decl(recursiveTypeRelations.ts, 18, 30)) return Object.keys(arg).reduce((obj: ClassNameObject, key: keyof S) => { ->Object.keys(arg).reduce : Symbol(Array.reduce, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>Object.keys(arg).reduce : Symbol(Array.reduce, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) >Object.keys : Symbol(ObjectConstructor.keys, Decl(lib.d.ts, --, --)) >Object : Symbol(Object, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) >keys : Symbol(ObjectConstructor.keys, Decl(lib.d.ts, --, --)) >arg : Symbol(arg, Decl(recursiveTypeRelations.ts, 18, 30)) ->reduce : Symbol(Array.reduce, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>reduce : Symbol(Array.reduce, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) >obj : Symbol(obj, Decl(recursiveTypeRelations.ts, 26, 55)) >key : Symbol(key, Decl(recursiveTypeRelations.ts, 26, 76)) >S : Symbol(S, Decl(recursiveTypeRelations.ts, 17, 20)) diff --git a/tests/baselines/reference/recursiveTypeRelations.types b/tests/baselines/reference/recursiveTypeRelations.types index 6def28d4461..110ff8175c4 100644 --- a/tests/baselines/reference/recursiveTypeRelations.types +++ b/tests/baselines/reference/recursiveTypeRelations.types @@ -102,13 +102,13 @@ export function css(styles: S, ...classNam return Object.keys(arg).reduce((obj: ClassNameObject, key: keyof S) => { >Object.keys(arg).reduce((obj: ClassNameObject, key: keyof S) => { const exportedClassName = styles[key]; obj[exportedClassName] = (arg as ClassNameMap)[key]; return obj; }, {}) : any ->Object.keys(arg).reduce : { (callbackfn: (previousValue: string, currentValue: string, currentIndex: number, array: string[]) => string, initialValue?: string): string; (callbackfn: (previousValue: U, currentValue: string, currentIndex: number, array: string[]) => U, initialValue: U): U; } +>Object.keys(arg).reduce : { (callbackfn: (previousValue: string, currentValue: string, currentIndex: number, array: string[]) => string): string; (callbackfn: (previousValue: string, currentValue: string, currentIndex: number, array: string[]) => string, initialValue: string): string; (callbackfn: (previousValue: U, currentValue: string, currentIndex: number, array: string[]) => U, initialValue: U): U; } >Object.keys(arg) : string[] >Object.keys : (o: {}) => string[] >Object : ObjectConstructor >keys : (o: {}) => string[] >arg : keyof S | (object & { [K in keyof S]?: boolean; }) ->reduce : { (callbackfn: (previousValue: string, currentValue: string, currentIndex: number, array: string[]) => string, initialValue?: string): string; (callbackfn: (previousValue: U, currentValue: string, currentIndex: number, array: string[]) => U, initialValue: U): U; } +>reduce : { (callbackfn: (previousValue: string, currentValue: string, currentIndex: number, array: string[]) => string): string; (callbackfn: (previousValue: string, currentValue: string, currentIndex: number, array: string[]) => string, initialValue: string): string; (callbackfn: (previousValue: U, currentValue: string, currentIndex: number, array: string[]) => U, initialValue: U): U; } >ClassNameObject : No type information available! >(obj: ClassNameObject, key: keyof S) => { const exportedClassName = styles[key]; obj[exportedClassName] = (arg as ClassNameMap)[key]; return obj; } : (obj: any, key: keyof S) => any >obj : any diff --git a/tests/baselines/reference/restInvalidArgumentType.types b/tests/baselines/reference/restInvalidArgumentType.types index 28162bcc7cc..39495008877 100644 --- a/tests/baselines/reference/restInvalidArgumentType.types +++ b/tests/baselines/reference/restInvalidArgumentType.types @@ -87,7 +87,7 @@ function f(p1: T, p2: T[]) { >p1 : T var {...r2} = p2; // OK ->r2 : { [n: number]: T; length: number; toString(): string; toLocaleString(): string; push(...items: T[]): number; pop(): T; concat(...items: ReadonlyArray[]): T[]; concat(...items: (T | ReadonlyArray)[]): T[]; join(separator?: string): string; reverse(): T[]; shift(): T; slice(start?: number, end?: number): T[]; sort(compareFn?: (a: T, b: T) => number): T[]; splice(start: number, deleteCount?: number): T[]; splice(start: number, deleteCount: number, ...items: T[]): T[]; unshift(...items: T[]): number; indexOf(searchElement: T, fromIndex?: number): number; lastIndexOf(searchElement: T, fromIndex?: number): number; every(callbackfn: (value: T, index: number, array: T[]) => boolean, thisArg?: any): boolean; some(callbackfn: (value: T, index: number, array: T[]) => boolean, thisArg?: any): boolean; forEach(callbackfn: (value: T, index: number, array: T[]) => void, thisArg?: any): void; map(callbackfn: (value: T, index: number, array: T[]) => U, thisArg?: any): U[]; filter(callbackfn: (value: T, index: number, array: T[]) => value is S, thisArg?: any): S[]; filter(callbackfn: (value: T, index: number, array: T[]) => any, thisArg?: any): T[]; reduce(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T, initialValue?: T): T; reduce(callbackfn: (previousValue: U, currentValue: T, currentIndex: number, array: T[]) => U, initialValue: U): U; reduceRight(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T, initialValue?: T): T; reduceRight(callbackfn: (previousValue: U, currentValue: T, currentIndex: number, array: T[]) => U, initialValue: U): U; } +>r2 : { [n: number]: T; length: number; toString(): string; toLocaleString(): string; push(...items: T[]): number; pop(): T; concat(...items: ReadonlyArray[]): T[]; concat(...items: (T | ReadonlyArray)[]): T[]; join(separator?: string): string; reverse(): T[]; shift(): T; slice(start?: number, end?: number): T[]; sort(compareFn?: (a: T, b: T) => number): T[]; splice(start: number, deleteCount?: number): T[]; splice(start: number, deleteCount: number, ...items: T[]): T[]; unshift(...items: T[]): number; indexOf(searchElement: T, fromIndex?: number): number; lastIndexOf(searchElement: T, fromIndex?: number): number; every(callbackfn: (value: T, index: number, array: T[]) => boolean, thisArg?: any): boolean; some(callbackfn: (value: T, index: number, array: T[]) => boolean, thisArg?: any): boolean; forEach(callbackfn: (value: T, index: number, array: T[]) => void, thisArg?: any): void; map(callbackfn: (value: T, index: number, array: T[]) => U, thisArg?: any): U[]; filter(callbackfn: (value: T, index: number, array: T[]) => value is S, thisArg?: any): S[]; filter(callbackfn: (value: T, index: number, array: T[]) => any, thisArg?: any): T[]; reduce(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T): T; reduce(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T, initialValue: T): T; reduce(callbackfn: (previousValue: U, currentValue: T, currentIndex: number, array: T[]) => U, initialValue: U): U; reduceRight(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T): T; reduceRight(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T, initialValue: T): T; reduceRight(callbackfn: (previousValue: U, currentValue: T, currentIndex: number, array: T[]) => U, initialValue: U): U; } >p2 : T[] var {...r3} = t; // Error, generic type paramter diff --git a/tests/baselines/reference/returnTypeParameterWithModules.symbols b/tests/baselines/reference/returnTypeParameterWithModules.symbols index 7f8fab382a3..eb56940b604 100644 --- a/tests/baselines/reference/returnTypeParameterWithModules.symbols +++ b/tests/baselines/reference/returnTypeParameterWithModules.symbols @@ -13,11 +13,11 @@ module M1 { return Array.prototype.reduce.apply(ar, e ? [f, e] : [f]); >Array.prototype.reduce.apply : Symbol(Function.apply, Decl(lib.d.ts, --, --)) ->Array.prototype.reduce : Symbol(Array.reduce, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>Array.prototype.reduce : Symbol(Array.reduce, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) >Array.prototype : Symbol(ArrayConstructor.prototype, Decl(lib.d.ts, --, --)) >Array : Symbol(Array, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) >prototype : Symbol(ArrayConstructor.prototype, Decl(lib.d.ts, --, --)) ->reduce : Symbol(Array.reduce, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>reduce : Symbol(Array.reduce, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) >apply : Symbol(Function.apply, Decl(lib.d.ts, --, --)) >ar : Symbol(ar, Decl(returnTypeParameterWithModules.ts, 1, 30)) >e : Symbol(e, Decl(returnTypeParameterWithModules.ts, 1, 36)) diff --git a/tests/baselines/reference/returnTypeParameterWithModules.types b/tests/baselines/reference/returnTypeParameterWithModules.types index 584c962a170..3aec0f14fcf 100644 --- a/tests/baselines/reference/returnTypeParameterWithModules.types +++ b/tests/baselines/reference/returnTypeParameterWithModules.types @@ -14,11 +14,11 @@ module M1 { return Array.prototype.reduce.apply(ar, e ? [f, e] : [f]); >Array.prototype.reduce.apply(ar, e ? [f, e] : [f]) : any >Array.prototype.reduce.apply : (this: Function, thisArg: any, argArray?: any) => any ->Array.prototype.reduce : { (callbackfn: (previousValue: any, currentValue: any, currentIndex: number, array: any[]) => any, initialValue?: any): any; (callbackfn: (previousValue: U, currentValue: any, currentIndex: number, array: any[]) => U, initialValue: U): U; } +>Array.prototype.reduce : { (callbackfn: (previousValue: any, currentValue: any, currentIndex: number, array: any[]) => any): any; (callbackfn: (previousValue: any, currentValue: any, currentIndex: number, array: any[]) => any, initialValue: any): any; (callbackfn: (previousValue: U, currentValue: any, currentIndex: number, array: any[]) => U, initialValue: U): U; } >Array.prototype : any[] >Array : ArrayConstructor >prototype : any[] ->reduce : { (callbackfn: (previousValue: any, currentValue: any, currentIndex: number, array: any[]) => any, initialValue?: any): any; (callbackfn: (previousValue: U, currentValue: any, currentIndex: number, array: any[]) => U, initialValue: U): U; } +>reduce : { (callbackfn: (previousValue: any, currentValue: any, currentIndex: number, array: any[]) => any): any; (callbackfn: (previousValue: any, currentValue: any, currentIndex: number, array: any[]) => any, initialValue: any): any; (callbackfn: (previousValue: U, currentValue: any, currentIndex: number, array: any[]) => U, initialValue: U): U; } >apply : (this: Function, thisArg: any, argArray?: any) => any >ar : any >e ? [f, e] : [f] : any[] diff --git a/tests/baselines/reference/spreadInvalidArgumentType.types b/tests/baselines/reference/spreadInvalidArgumentType.types index 1eebc00850f..244d8515893 100644 --- a/tests/baselines/reference/spreadInvalidArgumentType.types +++ b/tests/baselines/reference/spreadInvalidArgumentType.types @@ -89,8 +89,8 @@ function f(p1: T, p2: T[]) { >p1 : T var o2 = { ...p2 }; // OK ->o2 : { [n: number]: T; length: number; toString(): string; toLocaleString(): string; push(...items: T[]): number; pop(): T; concat(...items: ReadonlyArray[]): T[]; concat(...items: (T | ReadonlyArray)[]): T[]; join(separator?: string): string; reverse(): T[]; shift(): T; slice(start?: number, end?: number): T[]; sort(compareFn?: (a: T, b: T) => number): T[]; splice(start: number, deleteCount?: number): T[]; splice(start: number, deleteCount: number, ...items: T[]): T[]; unshift(...items: T[]): number; indexOf(searchElement: T, fromIndex?: number): number; lastIndexOf(searchElement: T, fromIndex?: number): number; every(callbackfn: (value: T, index: number, array: T[]) => boolean, thisArg?: any): boolean; some(callbackfn: (value: T, index: number, array: T[]) => boolean, thisArg?: any): boolean; forEach(callbackfn: (value: T, index: number, array: T[]) => void, thisArg?: any): void; map(callbackfn: (value: T, index: number, array: T[]) => U, thisArg?: any): U[]; filter(callbackfn: (value: T, index: number, array: T[]) => value is S, thisArg?: any): S[]; filter(callbackfn: (value: T, index: number, array: T[]) => any, thisArg?: any): T[]; reduce(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T, initialValue?: T): T; reduce(callbackfn: (previousValue: U, currentValue: T, currentIndex: number, array: T[]) => U, initialValue: U): U; reduceRight(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T, initialValue?: T): T; reduceRight(callbackfn: (previousValue: U, currentValue: T, currentIndex: number, array: T[]) => U, initialValue: U): U; } ->{ ...p2 } : { [n: number]: T; length: number; toString(): string; toLocaleString(): string; push(...items: T[]): number; pop(): T; concat(...items: ReadonlyArray[]): T[]; concat(...items: (T | ReadonlyArray)[]): T[]; join(separator?: string): string; reverse(): T[]; shift(): T; slice(start?: number, end?: number): T[]; sort(compareFn?: (a: T, b: T) => number): T[]; splice(start: number, deleteCount?: number): T[]; splice(start: number, deleteCount: number, ...items: T[]): T[]; unshift(...items: T[]): number; indexOf(searchElement: T, fromIndex?: number): number; lastIndexOf(searchElement: T, fromIndex?: number): number; every(callbackfn: (value: T, index: number, array: T[]) => boolean, thisArg?: any): boolean; some(callbackfn: (value: T, index: number, array: T[]) => boolean, thisArg?: any): boolean; forEach(callbackfn: (value: T, index: number, array: T[]) => void, thisArg?: any): void; map(callbackfn: (value: T, index: number, array: T[]) => U, thisArg?: any): U[]; filter(callbackfn: (value: T, index: number, array: T[]) => value is S, thisArg?: any): S[]; filter(callbackfn: (value: T, index: number, array: T[]) => any, thisArg?: any): T[]; reduce(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T, initialValue?: T): T; reduce(callbackfn: (previousValue: U, currentValue: T, currentIndex: number, array: T[]) => U, initialValue: U): U; reduceRight(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T, initialValue?: T): T; reduceRight(callbackfn: (previousValue: U, currentValue: T, currentIndex: number, array: T[]) => U, initialValue: U): U; } +>o2 : { [n: number]: T; length: number; toString(): string; toLocaleString(): string; push(...items: T[]): number; pop(): T; concat(...items: ReadonlyArray[]): T[]; concat(...items: (T | ReadonlyArray)[]): T[]; join(separator?: string): string; reverse(): T[]; shift(): T; slice(start?: number, end?: number): T[]; sort(compareFn?: (a: T, b: T) => number): T[]; splice(start: number, deleteCount?: number): T[]; splice(start: number, deleteCount: number, ...items: T[]): T[]; unshift(...items: T[]): number; indexOf(searchElement: T, fromIndex?: number): number; lastIndexOf(searchElement: T, fromIndex?: number): number; every(callbackfn: (value: T, index: number, array: T[]) => boolean, thisArg?: any): boolean; some(callbackfn: (value: T, index: number, array: T[]) => boolean, thisArg?: any): boolean; forEach(callbackfn: (value: T, index: number, array: T[]) => void, thisArg?: any): void; map(callbackfn: (value: T, index: number, array: T[]) => U, thisArg?: any): U[]; filter(callbackfn: (value: T, index: number, array: T[]) => value is S, thisArg?: any): S[]; filter(callbackfn: (value: T, index: number, array: T[]) => any, thisArg?: any): T[]; reduce(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T): T; reduce(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T, initialValue: T): T; reduce(callbackfn: (previousValue: U, currentValue: T, currentIndex: number, array: T[]) => U, initialValue: U): U; reduceRight(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T): T; reduceRight(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T, initialValue: T): T; reduceRight(callbackfn: (previousValue: U, currentValue: T, currentIndex: number, array: T[]) => U, initialValue: U): U; } +>{ ...p2 } : { [n: number]: T; length: number; toString(): string; toLocaleString(): string; push(...items: T[]): number; pop(): T; concat(...items: ReadonlyArray[]): T[]; concat(...items: (T | ReadonlyArray)[]): T[]; join(separator?: string): string; reverse(): T[]; shift(): T; slice(start?: number, end?: number): T[]; sort(compareFn?: (a: T, b: T) => number): T[]; splice(start: number, deleteCount?: number): T[]; splice(start: number, deleteCount: number, ...items: T[]): T[]; unshift(...items: T[]): number; indexOf(searchElement: T, fromIndex?: number): number; lastIndexOf(searchElement: T, fromIndex?: number): number; every(callbackfn: (value: T, index: number, array: T[]) => boolean, thisArg?: any): boolean; some(callbackfn: (value: T, index: number, array: T[]) => boolean, thisArg?: any): boolean; forEach(callbackfn: (value: T, index: number, array: T[]) => void, thisArg?: any): void; map(callbackfn: (value: T, index: number, array: T[]) => U, thisArg?: any): U[]; filter(callbackfn: (value: T, index: number, array: T[]) => value is S, thisArg?: any): S[]; filter(callbackfn: (value: T, index: number, array: T[]) => any, thisArg?: any): T[]; reduce(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T): T; reduce(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T, initialValue: T): T; reduce(callbackfn: (previousValue: U, currentValue: T, currentIndex: number, array: T[]) => U, initialValue: U): U; reduceRight(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T): T; reduceRight(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T, initialValue: T): T; reduceRight(callbackfn: (previousValue: U, currentValue: T, currentIndex: number, array: T[]) => U, initialValue: U): U; } >p2 : T[] var o3 = { ...t }; // Error, generic type paramter diff --git a/tests/baselines/reference/strictFunctionTypesErrors.errors.txt b/tests/baselines/reference/strictFunctionTypesErrors.errors.txt index 2827983bd5a..d8e36e43060 100644 --- a/tests/baselines/reference/strictFunctionTypesErrors.errors.txt +++ b/tests/baselines/reference/strictFunctionTypesErrors.errors.txt @@ -87,9 +87,24 @@ tests/cases/compiler/strictFunctionTypesErrors.ts(126,1): error TS2322: Type 'Cr tests/cases/compiler/strictFunctionTypesErrors.ts(127,1): error TS2322: Type 'Crate' is not assignable to type 'Crate'. Types of property 'item' are incompatible. Type 'Animal' is not assignable to type 'Dog'. +tests/cases/compiler/strictFunctionTypesErrors.ts(133,1): error TS2322: Type '(f: (x: Dog) => Dog) => void' is not assignable to type '(f: (x: Animal) => Animal) => void'. + Types of parameters 'f' and 'f' are incompatible. + Type 'Animal' is not assignable to type 'Dog'. +tests/cases/compiler/strictFunctionTypesErrors.ts(134,1): error TS2322: Type '(f: (x: Animal) => Animal) => void' is not assignable to type '(f: (x: Dog) => Dog) => void'. + Types of parameters 'f' and 'f' are incompatible. + Types of parameters 'x' and 'x' are incompatible. + Type 'Animal' is not assignable to type 'Dog'. +tests/cases/compiler/strictFunctionTypesErrors.ts(147,5): error TS2322: Type '(cb: (x: Animal) => Animal) => void' is not assignable to type '(cb: (x: Dog) => Animal) => void'. + Types of parameters 'cb' and 'cb' are incompatible. + Types of parameters 'x' and 'x' are incompatible. + Type 'Animal' is not assignable to type 'Dog'. +tests/cases/compiler/strictFunctionTypesErrors.ts(155,5): error TS2322: Type '(cb: (x: Animal) => Animal) => void' is not assignable to type '(cb: (x: Dog) => Animal) => void'. + Types of parameters 'cb' and 'cb' are incompatible. + Types of parameters 'x' and 'x' are incompatible. + Type 'Animal' is not assignable to type 'Dog'. -==== tests/cases/compiler/strictFunctionTypesErrors.ts (31 errors) ==== +==== tests/cases/compiler/strictFunctionTypesErrors.ts (35 errors) ==== export {} @@ -337,4 +352,51 @@ tests/cases/compiler/strictFunctionTypesErrors.ts(127,1): error TS2322: Type 'Cr !!! error TS2322: Type 'Crate' is not assignable to type 'Crate'. !!! error TS2322: Types of property 'item' are incompatible. !!! error TS2322: Type 'Animal' is not assignable to type 'Dog'. - \ No newline at end of file + + // Verify that callback parameters are strictly checked + + declare let fc1: (f: (x: Animal) => Animal) => void; + declare let fc2: (f: (x: Dog) => Dog) => void; + fc1 = fc2; // Error + ~~~ +!!! error TS2322: Type '(f: (x: Dog) => Dog) => void' is not assignable to type '(f: (x: Animal) => Animal) => void'. +!!! error TS2322: Types of parameters 'f' and 'f' are incompatible. +!!! error TS2322: Type 'Animal' is not assignable to type 'Dog'. + fc2 = fc1; // Error + ~~~ +!!! error TS2322: Type '(f: (x: Animal) => Animal) => void' is not assignable to type '(f: (x: Dog) => Dog) => void'. +!!! error TS2322: Types of parameters 'f' and 'f' are incompatible. +!!! error TS2322: Types of parameters 'x' and 'x' are incompatible. +!!! error TS2322: Type 'Animal' is not assignable to type 'Dog'. + + // Verify that callback parameters aren't loosely checked when types + // originate in method declarations + + namespace n1 { + class Foo { + static f1(x: Animal): Animal { throw "wat"; } + static f2(x: Dog): Animal { throw "wat"; }; + } + declare let f1: (cb: typeof Foo.f1) => void; + declare let f2: (cb: typeof Foo.f2) => void; + f1 = f2; + f2 = f1; // Error + ~~ +!!! error TS2322: Type '(cb: (x: Animal) => Animal) => void' is not assignable to type '(cb: (x: Dog) => Animal) => void'. +!!! error TS2322: Types of parameters 'cb' and 'cb' are incompatible. +!!! error TS2322: Types of parameters 'x' and 'x' are incompatible. +!!! error TS2322: Type 'Animal' is not assignable to type 'Dog'. + } + + namespace n2 { + type BivariantHack = { foo(x: Input): Output }["foo"]; + declare let f1: (cb: BivariantHack) => void; + declare let f2: (cb: BivariantHack) => void; + f1 = f2; + f2 = f1; // Error + ~~ +!!! error TS2322: Type '(cb: (x: Animal) => Animal) => void' is not assignable to type '(cb: (x: Dog) => Animal) => void'. +!!! error TS2322: Types of parameters 'cb' and 'cb' are incompatible. +!!! error TS2322: Types of parameters 'x' and 'x' are incompatible. +!!! error TS2322: Type 'Animal' is not assignable to type 'Dog'. + } \ No newline at end of file diff --git a/tests/baselines/reference/strictFunctionTypesErrors.js b/tests/baselines/reference/strictFunctionTypesErrors.js index 2be598f0ef9..d0608f6c1ac 100644 --- a/tests/baselines/reference/strictFunctionTypesErrors.js +++ b/tests/baselines/reference/strictFunctionTypesErrors.js @@ -126,7 +126,35 @@ declare let dogCrate: Crate; animalCrate = dogCrate; // Error dogCrate = animalCrate; // Error - + +// Verify that callback parameters are strictly checked + +declare let fc1: (f: (x: Animal) => Animal) => void; +declare let fc2: (f: (x: Dog) => Dog) => void; +fc1 = fc2; // Error +fc2 = fc1; // Error + +// Verify that callback parameters aren't loosely checked when types +// originate in method declarations + +namespace n1 { + class Foo { + static f1(x: Animal): Animal { throw "wat"; } + static f2(x: Dog): Animal { throw "wat"; }; + } + declare let f1: (cb: typeof Foo.f1) => void; + declare let f2: (cb: typeof Foo.f2) => void; + f1 = f2; + f2 = f1; // Error +} + +namespace n2 { + type BivariantHack = { foo(x: Input): Output }["foo"]; + declare let f1: (cb: BivariantHack) => void; + declare let f2: (cb: BivariantHack) => void; + f1 = f2; + f2 = f1; // Error +} //// [strictFunctionTypesErrors.js] "use strict"; @@ -186,3 +214,25 @@ dogComparer2 = animalComparer2; // Ok // Errors below should elaborate the reason for invariance animalCrate = dogCrate; // Error dogCrate = animalCrate; // Error +fc1 = fc2; // Error +fc2 = fc1; // Error +// Verify that callback parameters aren't loosely checked when types +// originate in method declarations +var n1; +(function (n1) { + var Foo = /** @class */ (function () { + function Foo() { + } + Foo.f1 = function (x) { throw "wat"; }; + Foo.f2 = function (x) { throw "wat"; }; + ; + return Foo; + }()); + f1 = f2; + f2 = f1; // Error +})(n1 || (n1 = {})); +var n2; +(function (n2) { + f1 = f2; + f2 = f1; // Error +})(n2 || (n2 = {})); diff --git a/tests/baselines/reference/strictFunctionTypesErrors.symbols b/tests/baselines/reference/strictFunctionTypesErrors.symbols index 30faf83d87e..c85c337ca44 100644 --- a/tests/baselines/reference/strictFunctionTypesErrors.symbols +++ b/tests/baselines/reference/strictFunctionTypesErrors.symbols @@ -400,3 +400,105 @@ dogCrate = animalCrate; // Error >dogCrate : Symbol(dogCrate, Decl(strictFunctionTypesErrors.ts, 121, 11)) >animalCrate : Symbol(animalCrate, Decl(strictFunctionTypesErrors.ts, 120, 11)) +// Verify that callback parameters are strictly checked + +declare let fc1: (f: (x: Animal) => Animal) => void; +>fc1 : Symbol(fc1, Decl(strictFunctionTypesErrors.ts, 130, 11)) +>f : Symbol(f, Decl(strictFunctionTypesErrors.ts, 130, 18)) +>x : Symbol(x, Decl(strictFunctionTypesErrors.ts, 130, 22)) +>Animal : Symbol(Animal, Decl(strictFunctionTypesErrors.ts, 87, 8)) +>Animal : Symbol(Animal, Decl(strictFunctionTypesErrors.ts, 87, 8)) + +declare let fc2: (f: (x: Dog) => Dog) => void; +>fc2 : Symbol(fc2, Decl(strictFunctionTypesErrors.ts, 131, 11)) +>f : Symbol(f, Decl(strictFunctionTypesErrors.ts, 131, 18)) +>x : Symbol(x, Decl(strictFunctionTypesErrors.ts, 131, 22)) +>Dog : Symbol(Dog, Decl(strictFunctionTypesErrors.ts, 89, 33)) +>Dog : Symbol(Dog, Decl(strictFunctionTypesErrors.ts, 89, 33)) + +fc1 = fc2; // Error +>fc1 : Symbol(fc1, Decl(strictFunctionTypesErrors.ts, 130, 11)) +>fc2 : Symbol(fc2, Decl(strictFunctionTypesErrors.ts, 131, 11)) + +fc2 = fc1; // Error +>fc2 : Symbol(fc2, Decl(strictFunctionTypesErrors.ts, 131, 11)) +>fc1 : Symbol(fc1, Decl(strictFunctionTypesErrors.ts, 130, 11)) + +// Verify that callback parameters aren't loosely checked when types +// originate in method declarations + +namespace n1 { +>n1 : Symbol(n1, Decl(strictFunctionTypesErrors.ts, 133, 10)) + + class Foo { +>Foo : Symbol(Foo, Decl(strictFunctionTypesErrors.ts, 138, 14)) + + static f1(x: Animal): Animal { throw "wat"; } +>f1 : Symbol(Foo.f1, Decl(strictFunctionTypesErrors.ts, 139, 15)) +>x : Symbol(x, Decl(strictFunctionTypesErrors.ts, 140, 18)) +>Animal : Symbol(Animal, Decl(strictFunctionTypesErrors.ts, 87, 8)) +>Animal : Symbol(Animal, Decl(strictFunctionTypesErrors.ts, 87, 8)) + + static f2(x: Dog): Animal { throw "wat"; }; +>f2 : Symbol(Foo.f2, Decl(strictFunctionTypesErrors.ts, 140, 53)) +>x : Symbol(x, Decl(strictFunctionTypesErrors.ts, 141, 18)) +>Dog : Symbol(Dog, Decl(strictFunctionTypesErrors.ts, 89, 33)) +>Animal : Symbol(Animal, Decl(strictFunctionTypesErrors.ts, 87, 8)) + } + declare let f1: (cb: typeof Foo.f1) => void; +>f1 : Symbol(f1, Decl(strictFunctionTypesErrors.ts, 143, 15)) +>cb : Symbol(cb, Decl(strictFunctionTypesErrors.ts, 143, 21)) +>Foo.f1 : Symbol(Foo.f1, Decl(strictFunctionTypesErrors.ts, 139, 15)) +>Foo : Symbol(Foo, Decl(strictFunctionTypesErrors.ts, 138, 14)) +>f1 : Symbol(Foo.f1, Decl(strictFunctionTypesErrors.ts, 139, 15)) + + declare let f2: (cb: typeof Foo.f2) => void; +>f2 : Symbol(f2, Decl(strictFunctionTypesErrors.ts, 144, 15)) +>cb : Symbol(cb, Decl(strictFunctionTypesErrors.ts, 144, 21)) +>Foo.f2 : Symbol(Foo.f2, Decl(strictFunctionTypesErrors.ts, 140, 53)) +>Foo : Symbol(Foo, Decl(strictFunctionTypesErrors.ts, 138, 14)) +>f2 : Symbol(Foo.f2, Decl(strictFunctionTypesErrors.ts, 140, 53)) + + f1 = f2; +>f1 : Symbol(f1, Decl(strictFunctionTypesErrors.ts, 143, 15)) +>f2 : Symbol(f2, Decl(strictFunctionTypesErrors.ts, 144, 15)) + + f2 = f1; // Error +>f2 : Symbol(f2, Decl(strictFunctionTypesErrors.ts, 144, 15)) +>f1 : Symbol(f1, Decl(strictFunctionTypesErrors.ts, 143, 15)) +} + +namespace n2 { +>n2 : Symbol(n2, Decl(strictFunctionTypesErrors.ts, 147, 1)) + + type BivariantHack = { foo(x: Input): Output }["foo"]; +>BivariantHack : Symbol(BivariantHack, Decl(strictFunctionTypesErrors.ts, 149, 14)) +>Input : Symbol(Input, Decl(strictFunctionTypesErrors.ts, 150, 23)) +>Output : Symbol(Output, Decl(strictFunctionTypesErrors.ts, 150, 29)) +>foo : Symbol(foo, Decl(strictFunctionTypesErrors.ts, 150, 41)) +>x : Symbol(x, Decl(strictFunctionTypesErrors.ts, 150, 46)) +>Input : Symbol(Input, Decl(strictFunctionTypesErrors.ts, 150, 23)) +>Output : Symbol(Output, Decl(strictFunctionTypesErrors.ts, 150, 29)) + + declare let f1: (cb: BivariantHack) => void; +>f1 : Symbol(f1, Decl(strictFunctionTypesErrors.ts, 151, 15)) +>cb : Symbol(cb, Decl(strictFunctionTypesErrors.ts, 151, 21)) +>BivariantHack : Symbol(BivariantHack, Decl(strictFunctionTypesErrors.ts, 149, 14)) +>Animal : Symbol(Animal, Decl(strictFunctionTypesErrors.ts, 87, 8)) +>Animal : Symbol(Animal, Decl(strictFunctionTypesErrors.ts, 87, 8)) + + declare let f2: (cb: BivariantHack) => void; +>f2 : Symbol(f2, Decl(strictFunctionTypesErrors.ts, 152, 15)) +>cb : Symbol(cb, Decl(strictFunctionTypesErrors.ts, 152, 21)) +>BivariantHack : Symbol(BivariantHack, Decl(strictFunctionTypesErrors.ts, 149, 14)) +>Dog : Symbol(Dog, Decl(strictFunctionTypesErrors.ts, 89, 33)) +>Animal : Symbol(Animal, Decl(strictFunctionTypesErrors.ts, 87, 8)) + + f1 = f2; +>f1 : Symbol(f1, Decl(strictFunctionTypesErrors.ts, 151, 15)) +>f2 : Symbol(f2, Decl(strictFunctionTypesErrors.ts, 152, 15)) + + f2 = f1; // Error +>f2 : Symbol(f2, Decl(strictFunctionTypesErrors.ts, 152, 15)) +>f1 : Symbol(f1, Decl(strictFunctionTypesErrors.ts, 151, 15)) +} diff --git a/tests/baselines/reference/strictFunctionTypesErrors.types b/tests/baselines/reference/strictFunctionTypesErrors.types index e4372d4b8fa..1890279258c 100644 --- a/tests/baselines/reference/strictFunctionTypesErrors.types +++ b/tests/baselines/reference/strictFunctionTypesErrors.types @@ -454,3 +454,113 @@ dogCrate = animalCrate; // Error >dogCrate : Crate >animalCrate : Crate +// Verify that callback parameters are strictly checked + +declare let fc1: (f: (x: Animal) => Animal) => void; +>fc1 : (f: (x: Animal) => Animal) => void +>f : (x: Animal) => Animal +>x : Animal +>Animal : Animal +>Animal : Animal + +declare let fc2: (f: (x: Dog) => Dog) => void; +>fc2 : (f: (x: Dog) => Dog) => void +>f : (x: Dog) => Dog +>x : Dog +>Dog : Dog +>Dog : Dog + +fc1 = fc2; // Error +>fc1 = fc2 : (f: (x: Dog) => Dog) => void +>fc1 : (f: (x: Animal) => Animal) => void +>fc2 : (f: (x: Dog) => Dog) => void + +fc2 = fc1; // Error +>fc2 = fc1 : (f: (x: Animal) => Animal) => void +>fc2 : (f: (x: Dog) => Dog) => void +>fc1 : (f: (x: Animal) => Animal) => void + +// Verify that callback parameters aren't loosely checked when types +// originate in method declarations + +namespace n1 { +>n1 : typeof n1 + + class Foo { +>Foo : Foo + + static f1(x: Animal): Animal { throw "wat"; } +>f1 : (x: Animal) => Animal +>x : Animal +>Animal : Animal +>Animal : Animal +>"wat" : "wat" + + static f2(x: Dog): Animal { throw "wat"; }; +>f2 : (x: Dog) => Animal +>x : Dog +>Dog : Dog +>Animal : Animal +>"wat" : "wat" + } + declare let f1: (cb: typeof Foo.f1) => void; +>f1 : (cb: (x: Animal) => Animal) => void +>cb : (x: Animal) => Animal +>Foo.f1 : (x: Animal) => Animal +>Foo : typeof Foo +>f1 : (x: Animal) => Animal + + declare let f2: (cb: typeof Foo.f2) => void; +>f2 : (cb: (x: Dog) => Animal) => void +>cb : (x: Dog) => Animal +>Foo.f2 : (x: Dog) => Animal +>Foo : typeof Foo +>f2 : (x: Dog) => Animal + + f1 = f2; +>f1 = f2 : (cb: (x: Dog) => Animal) => void +>f1 : (cb: (x: Animal) => Animal) => void +>f2 : (cb: (x: Dog) => Animal) => void + + f2 = f1; // Error +>f2 = f1 : (cb: (x: Animal) => Animal) => void +>f2 : (cb: (x: Dog) => Animal) => void +>f1 : (cb: (x: Animal) => Animal) => void +} + +namespace n2 { +>n2 : typeof n2 + + type BivariantHack = { foo(x: Input): Output }["foo"]; +>BivariantHack : (x: Input) => Output +>Input : Input +>Output : Output +>foo : (x: Input) => Output +>x : Input +>Input : Input +>Output : Output + + declare let f1: (cb: BivariantHack) => void; +>f1 : (cb: (x: Animal) => Animal) => void +>cb : (x: Animal) => Animal +>BivariantHack : (x: Input) => Output +>Animal : Animal +>Animal : Animal + + declare let f2: (cb: BivariantHack) => void; +>f2 : (cb: (x: Dog) => Animal) => void +>cb : (x: Dog) => Animal +>BivariantHack : (x: Input) => Output +>Dog : Dog +>Animal : Animal + + f1 = f2; +>f1 = f2 : (cb: (x: Dog) => Animal) => void +>f1 : (cb: (x: Animal) => Animal) => void +>f2 : (cb: (x: Dog) => Animal) => void + + f2 = f1; // Error +>f2 = f1 : (cb: (x: Animal) => Animal) => void +>f2 : (cb: (x: Dog) => Animal) => void +>f1 : (cb: (x: Animal) => Animal) => void +} diff --git a/tests/baselines/reference/typeAliasExport.symbols b/tests/baselines/reference/typeAliasExport.symbols index e019ca7a10b..5ffe181ca70 100644 --- a/tests/baselines/reference/typeAliasExport.symbols +++ b/tests/baselines/reference/typeAliasExport.symbols @@ -1,7 +1,7 @@ === tests/cases/compiler/typeAliasExport.ts === declare module "a" { export default undefined ->undefined : Symbol(default) +>undefined : Symbol(undefined) export var a; >a : Symbol(a, Decl(typeAliasExport.ts, 2, 12), Decl(typeAliasExport.ts, 2, 15)) diff --git a/tests/baselines/reference/unknownSymbolOffContextualType1.symbols b/tests/baselines/reference/unknownSymbolOffContextualType1.symbols index 1e19afeb6a0..3acf34ec9bf 100644 --- a/tests/baselines/reference/unknownSymbolOffContextualType1.symbols +++ b/tests/baselines/reference/unknownSymbolOffContextualType1.symbols @@ -61,9 +61,9 @@ function getMaxWidth(elementNames: string[]) { }); var maxWidth = widths.reduce(function (a, b) { >maxWidth : Symbol(maxWidth, Decl(unknownSymbolOffContextualType1.ts, 17, 7)) ->widths.reduce : Symbol(Array.reduce, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>widths.reduce : Symbol(Array.reduce, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) >widths : Symbol(widths, Decl(unknownSymbolOffContextualType1.ts, 14, 7)) ->reduce : Symbol(Array.reduce, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>reduce : Symbol(Array.reduce, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) >a : Symbol(a, Decl(unknownSymbolOffContextualType1.ts, 17, 43)) >b : Symbol(b, Decl(unknownSymbolOffContextualType1.ts, 17, 45)) diff --git a/tests/baselines/reference/unknownSymbolOffContextualType1.types b/tests/baselines/reference/unknownSymbolOffContextualType1.types index c6f05b69b74..7df3bd52cc9 100644 --- a/tests/baselines/reference/unknownSymbolOffContextualType1.types +++ b/tests/baselines/reference/unknownSymbolOffContextualType1.types @@ -72,9 +72,9 @@ function getMaxWidth(elementNames: string[]) { var maxWidth = widths.reduce(function (a, b) { >maxWidth : any >widths.reduce(function (a, b) { return a > b ? a : b; }) : any ->widths.reduce : { (callbackfn: (previousValue: any, currentValue: any, currentIndex: number, array: any[]) => any, initialValue?: any): any; (callbackfn: (previousValue: U, currentValue: any, currentIndex: number, array: any[]) => U, initialValue: U): U; } +>widths.reduce : { (callbackfn: (previousValue: any, currentValue: any, currentIndex: number, array: any[]) => any): any; (callbackfn: (previousValue: any, currentValue: any, currentIndex: number, array: any[]) => any, initialValue: any): any; (callbackfn: (previousValue: U, currentValue: any, currentIndex: number, array: any[]) => U, initialValue: U): U; } >widths : any[] ->reduce : { (callbackfn: (previousValue: any, currentValue: any, currentIndex: number, array: any[]) => any, initialValue?: any): any; (callbackfn: (previousValue: U, currentValue: any, currentIndex: number, array: any[]) => U, initialValue: U): U; } +>reduce : { (callbackfn: (previousValue: any, currentValue: any, currentIndex: number, array: any[]) => any): any; (callbackfn: (previousValue: any, currentValue: any, currentIndex: number, array: any[]) => any, initialValue: any): any; (callbackfn: (previousValue: U, currentValue: any, currentIndex: number, array: any[]) => U, initialValue: U): U; } >function (a, b) { return a > b ? a : b; } : (a: any, b: any) => any >a : any >b : any diff --git a/tests/baselines/reference/useObjectValuesAndEntries1.types b/tests/baselines/reference/useObjectValuesAndEntries1.types index 1b537ed063d..6ea45385bbc 100644 --- a/tests/baselines/reference/useObjectValuesAndEntries1.types +++ b/tests/baselines/reference/useObjectValuesAndEntries1.types @@ -10,9 +10,9 @@ var o = { a: 1, b: 2 }; for (var x of Object.values(o)) { >x : number >Object.values(o) : number[] ->Object.values : { (o: { [s: string]: T; }): T[]; (o: any): any[]; } +>Object.values : { (o: { [s: string]: T; } | { [n: number]: T; }): T[]; (o: any): any[]; } >Object : ObjectConstructor ->values : { (o: { [s: string]: T; }): T[]; (o: any): any[]; } +>values : { (o: { [s: string]: T; } | { [n: number]: T; }): T[]; (o: any): any[]; } >o : { a: number; b: number; } let y = x; @@ -23,25 +23,25 @@ for (var x of Object.values(o)) { var entries = Object.entries(o); // <-- entries: ['a' | 'b', number][] >entries : [string, number][] >Object.entries(o) : [string, number][] ->Object.entries : { (o: { [s: string]: T; }): [string, T][]; (o: any): [string, any][]; } +>Object.entries : { (o: { [s: string]: T; } | { [n: number]: T; }): [string, T][]; (o: any): [string, any][]; } >Object : ObjectConstructor ->entries : { (o: { [s: string]: T; }): [string, T][]; (o: any): [string, any][]; } +>entries : { (o: { [s: string]: T; } | { [n: number]: T; }): [string, T][]; (o: any): [string, any][]; } >o : { a: number; b: number; } var entries1 = Object.entries(1); // <-- entries: [string, any][] >entries1 : [string, any][] >Object.entries(1) : [string, any][] ->Object.entries : { (o: { [s: string]: T; }): [string, T][]; (o: any): [string, any][]; } +>Object.entries : { (o: { [s: string]: T; } | { [n: number]: T; }): [string, T][]; (o: any): [string, any][]; } >Object : ObjectConstructor ->entries : { (o: { [s: string]: T; }): [string, T][]; (o: any): [string, any][]; } +>entries : { (o: { [s: string]: T; } | { [n: number]: T; }): [string, T][]; (o: any): [string, any][]; } >1 : 1 var entries2 = Object.entries({a: true, b: 2}) // ['a' | 'b', number | boolean][] >entries2 : [string, number | boolean][] >Object.entries({a: true, b: 2}) : [string, number | boolean][] ->Object.entries : { (o: { [s: string]: T; }): [string, T][]; (o: any): [string, any][]; } +>Object.entries : { (o: { [s: string]: T; } | { [n: number]: T; }): [string, T][]; (o: any): [string, any][]; } >Object : ObjectConstructor ->entries : { (o: { [s: string]: T; }): [string, T][]; (o: any): [string, any][]; } +>entries : { (o: { [s: string]: T; } | { [n: number]: T; }): [string, T][]; (o: any): [string, any][]; } >{a: true, b: 2} : { a: true; b: 2; } >a : boolean >true : true @@ -51,8 +51,8 @@ var entries2 = Object.entries({a: true, b: 2}) // ['a' | 'b', number | boolean][ var entries3 = Object.entries({}) // [never, any][] >entries3 : [string, {}][] >Object.entries({}) : [string, {}][] ->Object.entries : { (o: { [s: string]: T; }): [string, T][]; (o: any): [string, any][]; } +>Object.entries : { (o: { [s: string]: T; } | { [n: number]: T; }): [string, T][]; (o: any): [string, any][]; } >Object : ObjectConstructor ->entries : { (o: { [s: string]: T; }): [string, T][]; (o: any): [string, any][]; } +>entries : { (o: { [s: string]: T; } | { [n: number]: T; }): [string, T][]; (o: any): [string, any][]; } >{} : {} diff --git a/tests/baselines/reference/useObjectValuesAndEntries4.types b/tests/baselines/reference/useObjectValuesAndEntries4.types index 85810bccd26..245803a24d4 100644 --- a/tests/baselines/reference/useObjectValuesAndEntries4.types +++ b/tests/baselines/reference/useObjectValuesAndEntries4.types @@ -10,9 +10,9 @@ var o = { a: 1, b: 2 }; for (var x of Object.values(o)) { >x : number >Object.values(o) : number[] ->Object.values : { (o: { [s: string]: T; }): T[]; (o: any): any[]; } +>Object.values : { (o: { [s: string]: T; } | { [n: number]: T; }): T[]; (o: any): any[]; } >Object : ObjectConstructor ->values : { (o: { [s: string]: T; }): T[]; (o: any): any[]; } +>values : { (o: { [s: string]: T; } | { [n: number]: T; }): T[]; (o: any): any[]; } >o : { a: number; b: number; } let y = x; @@ -23,8 +23,8 @@ for (var x of Object.values(o)) { var entries = Object.entries(o); >entries : [string, number][] >Object.entries(o) : [string, number][] ->Object.entries : { (o: { [s: string]: T; }): [string, T][]; (o: any): [string, any][]; } +>Object.entries : { (o: { [s: string]: T; } | { [n: number]: T; }): [string, T][]; (o: any): [string, any][]; } >Object : ObjectConstructor ->entries : { (o: { [s: string]: T; }): [string, T][]; (o: any): [string, any][]; } +>entries : { (o: { [s: string]: T; } | { [n: number]: T; }): [string, T][]; (o: any): [string, any][]; } >o : { a: number; b: number; } diff --git a/tests/cases/compiler/abstractPropertyInConstructor.ts b/tests/cases/compiler/abstractPropertyInConstructor.ts new file mode 100644 index 00000000000..457fdb473b1 --- /dev/null +++ b/tests/cases/compiler/abstractPropertyInConstructor.ts @@ -0,0 +1,24 @@ +abstract class AbstractClass { + constructor(str: string) { + this.method(parseInt(str)); + let val = this.prop.toLowerCase(); + + if (!str) { + this.prop = "Hello World"; + } + this.cb(str); + + const innerFunction = () => { + return this.prop; + } + } + + abstract prop: string; + abstract cb: (s: string) => void; + + abstract method(num: number): void; + + method2() { + this.prop = this.prop + "!"; + } +} diff --git a/tests/cases/compiler/arrayFind.ts b/tests/cases/compiler/arrayFind.ts new file mode 100644 index 00000000000..90883974766 --- /dev/null +++ b/tests/cases/compiler/arrayFind.ts @@ -0,0 +1,12 @@ +// @lib: es2015 + +// test fix for #18112, type guard predicates should narrow returned element +function isNumber(x: any): x is number { + return typeof x === "number"; +} + +const arrayOfStringsNumbersAndBooleans = ["string", false, 0, "strung", 1, true]; +const foundNumber: number | undefined = arrayOfStringsNumbersAndBooleans.find(isNumber); + +const readonlyArrayOfStringsNumbersAndBooleans = arrayOfStringsNumbersAndBooleans as ReadonlyArray; +const readonlyFoundNumber: number | undefined = readonlyArrayOfStringsNumbersAndBooleans.find(isNumber); diff --git a/tests/cases/compiler/dynamicImportInDefaultExportExpression.ts b/tests/cases/compiler/dynamicImportInDefaultExportExpression.ts new file mode 100644 index 00000000000..0e6ad95886b --- /dev/null +++ b/tests/cases/compiler/dynamicImportInDefaultExportExpression.ts @@ -0,0 +1,7 @@ +// @skipLibCheck: true +// @lib: es6 +export default { + getInstance: function () { + return import('./foo2'); + } +} \ No newline at end of file diff --git a/tests/cases/compiler/dynamicImportWithNestedThis_es2015.ts b/tests/cases/compiler/dynamicImportWithNestedThis_es2015.ts new file mode 100644 index 00000000000..3c7f2936931 --- /dev/null +++ b/tests/cases/compiler/dynamicImportWithNestedThis_es2015.ts @@ -0,0 +1,14 @@ +// @lib: es2015 +// @target: es2015 +// @module: umd +// https://github.com/Microsoft/TypeScript/issues/17564 +class C { + private _path = './other'; + + dynamic() { + return import(this._path); + } +} + +const c = new C(); +c.dynamic(); \ No newline at end of file diff --git a/tests/cases/compiler/dynamicImportWithNestedThis_es5.ts b/tests/cases/compiler/dynamicImportWithNestedThis_es5.ts new file mode 100644 index 00000000000..5740c3f6694 --- /dev/null +++ b/tests/cases/compiler/dynamicImportWithNestedThis_es5.ts @@ -0,0 +1,14 @@ +// @lib: es2015 +// @target: es5 +// @module: umd +// https://github.com/Microsoft/TypeScript/issues/17564 +class C { + private _path = './other'; + + dynamic() { + return import(this._path); + } +} + +const c = new C(); +c.dynamic(); \ No newline at end of file diff --git a/tests/cases/compiler/excessPropertyCheckWithUnions.ts b/tests/cases/compiler/excessPropertyCheckWithUnions.ts new file mode 100644 index 00000000000..9a7968fe511 --- /dev/null +++ b/tests/cases/compiler/excessPropertyCheckWithUnions.ts @@ -0,0 +1,50 @@ +type ADT = { + tag: "A", + a1: string +} | { + tag: "D", + d20: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 +} | { + tag: "T", +} +let wrong: ADT = { tag: "T", a1: "extra" } +wrong = { tag: "A", d20: 12 } +wrong = { tag: "D" } + +type Ambiguous = { + tag: "A", + x: string +} | { + tag: "A", + y: number +} | { + tag: "B", + z: boolean +} | { + tag: "C" +} +let amb: Ambiguous +// no error for ambiguous tag, even when it could satisfy both constituents at once +amb = { tag: "A", x: "hi" } +amb = { tag: "A", y: 12 } +amb = { tag: "A", x: "hi", y: 12 } + +// correctly error on excess property 'extra', even when ambiguous +amb = { tag: "A", x: "hi", extra: 12 } +amb = { tag: "A", y: 12, extra: 12 } + +// assignability errors still work. +// But note that the error for `z: true` is the fallback one of reporting on +// the last constituent since assignability error reporting can't find a single best discriminant either. +amb = { tag: "A" } +amb = { tag: "A", z: true } + +type Overlapping = + | { a: 1, b: 1, first: string } + | { a: 2, second: string } + | { b: 3, third: string } +let over: Overlapping + +// these two are not reported because there are two discriminant properties +over = { a: 1, b: 1, first: "ok", second: "error" } +over = { a: 1, b: 1, first: "ok", third: "error" } diff --git a/tests/cases/compiler/jsdocTypedef_propertyWithNoType.ts b/tests/cases/compiler/jsdocTypedef_propertyWithNoType.ts new file mode 100644 index 00000000000..bcabe980915 --- /dev/null +++ b/tests/cases/compiler/jsdocTypedef_propertyWithNoType.ts @@ -0,0 +1,12 @@ +// @allowJs: true +// @checkJs: true +// @noEmit: true + +// @Filename: /a.js +/** + * @typedef Foo + * @property foo + */ + +/** @type {Foo} */ +const x = { foo: 0 }; diff --git a/tests/cases/compiler/noUnusedLocals_selfReference.ts b/tests/cases/compiler/noUnusedLocals_selfReference.ts index 8eb528743c0..fc6b02b6006 100644 --- a/tests/cases/compiler/noUnusedLocals_selfReference.ts +++ b/tests/cases/compiler/noUnusedLocals_selfReference.ts @@ -2,7 +2,12 @@ export {}; // Make this a module scope, so these are local variables. -function f() { f; } +function f() { + f; + function g() { + g; + } +} class C { m() { C; } } diff --git a/tests/cases/compiler/potentiallyUncalledDecorators.ts b/tests/cases/compiler/potentiallyUncalledDecorators.ts new file mode 100644 index 00000000000..6e537686d0f --- /dev/null +++ b/tests/cases/compiler/potentiallyUncalledDecorators.ts @@ -0,0 +1,81 @@ +// @target: esnext +// @module: esnext +// @experimentalDecorators: true + +// Angular-style Input/Output API: +declare function Input(bindingPropertyName?: string): any; +class FooComponent { + @Input foo: string; +} + +// Glimmer-style tracked API: +declare const tracked: PropertyDecorator & { (...watchedProperties: string[]): any; } + +class Person { + @tracked person; any; +} + +class MultiplyByTwo { + args: any; + @tracked('args') + get multiplied() { + return this.args.number * 2; + } +} + +// Other fun stuff. + +interface OmniDecorator extends MethodDecorator, ClassDecorator, PropertyDecorator { +} + +declare function noArgs(): OmniDecorator; +declare function allRest(...args: any[]): OmniDecorator; +declare function oneOptional(x?: any): OmniDecorator; +declare function twoOptional(x?: any, y?: any): OmniDecorator; +declare function threeOptional(x?: any, y?: any, z?: any): OmniDecorator; +declare function oneOptionalWithRest(x?: any, ...args: any[]): OmniDecorator; +declare const anyDec: any; + +@noArgs +class A { + @noArgs foo: any; + @noArgs bar() { } +} + +@allRest +class B { + @allRest foo: any; + @allRest bar() { } +} + +@oneOptional +class C { + @oneOptional foo: any; + @oneOptional bar() { } +} + +@twoOptional +class D { + @twoOptional foo: any; + @twoOptional bar() { } +} + +@threeOptional +class E { + @threeOptional foo: any; + @threeOptional bar() { } +} + +@oneOptionalWithRest +class F { + @oneOptionalWithRest foo: any; + @oneOptionalWithRest bar() { } +} + +@anyDec +class G { + @anyDec foo: any; + @anyDec bar() { } +} + +export { }; diff --git a/tests/cases/compiler/strictFunctionTypesErrors.ts b/tests/cases/compiler/strictFunctionTypesErrors.ts index fbf1c0fa6da..3f86f2529c0 100644 --- a/tests/cases/compiler/strictFunctionTypesErrors.ts +++ b/tests/cases/compiler/strictFunctionTypesErrors.ts @@ -126,3 +126,32 @@ declare let dogCrate: Crate; animalCrate = dogCrate; // Error dogCrate = animalCrate; // Error + +// Verify that callback parameters are strictly checked + +declare let fc1: (f: (x: Animal) => Animal) => void; +declare let fc2: (f: (x: Dog) => Dog) => void; +fc1 = fc2; // Error +fc2 = fc1; // Error + +// Verify that callback parameters aren't loosely checked when types +// originate in method declarations + +namespace n1 { + class Foo { + static f1(x: Animal): Animal { throw "wat"; } + static f2(x: Dog): Animal { throw "wat"; }; + } + declare let f1: (cb: typeof Foo.f1) => void; + declare let f2: (cb: typeof Foo.f2) => void; + f1 = f2; + f2 = f1; // Error +} + +namespace n2 { + type BivariantHack = { foo(x: Input): Output }["foo"]; + declare let f1: (cb: BivariantHack) => void; + declare let f2: (cb: BivariantHack) => void; + f1 = f2; + f2 = f1; // Error +} \ No newline at end of file diff --git a/tests/cases/fourslash/codeFixAddForgottenDecoratorCall01.ts b/tests/cases/fourslash/codeFixAddForgottenDecoratorCall01.ts new file mode 100644 index 00000000000..17ae7f626f0 --- /dev/null +++ b/tests/cases/fourslash/codeFixAddForgottenDecoratorCall01.ts @@ -0,0 +1,14 @@ +/// + +////declare function foo(): (...args: any[]) => void; +////class C { +//// [|@foo|] +//// bar() { +//// +//// } +////} + +verify.codeFix({ + description: "Call decorator expression.", + newRangeContent: `@foo()` +}); diff --git a/tests/cases/fourslash/findAllRefsDefaultImportThroughNamespace.ts b/tests/cases/fourslash/findAllRefsDefaultImportThroughNamespace.ts index e5f77631324..1411a106c89 100644 --- a/tests/cases/fourslash/findAllRefsDefaultImportThroughNamespace.ts +++ b/tests/cases/fourslash/findAllRefsDefaultImportThroughNamespace.ts @@ -1,7 +1,7 @@ /// // @Filename: /a.ts -////export default function [|{| "isWriteAccess": true, "isDefinition": true |}f|]() {} +////export [|{| "isWriteAccess": true, "isDefinition": true |}default|] function [|{| "isWriteAccess": true, "isDefinition": true |}f|]() {} // @Filename: /b.ts ////export import a = require("./a"); @@ -13,16 +13,17 @@ ////declare const x: { [|{| "isWriteAccess": true, "isDefinition": true |}default|]: number }; ////x.[|default|]; -const [r0, r1, r2, r3] = test.ranges(); +const [r0, r1, r2, r3, r4] = test.ranges(); -verify.singleReferenceGroup("function f(): void", [r0, r1]); -verify.singleReferenceGroup("(property) default: number", [r2, r3]); +verify.referenceGroups([r0], [{ definition: "function f(): void", ranges: [r1, r2] }]); +verify.singleReferenceGroup("function f(): void", [r1, r2]); +verify.singleReferenceGroup("(property) default: number", [r3, r4]); -verify.rangesAreRenameLocations([r0]); +verify.rangesAreRenameLocations([r1]); // Can't rename a default import. -goTo.rangeStart(r1); +goTo.rangeStart(r2); verify.renameInfoFailed(); // Can rename a default property. -verify.rangesAreRenameLocations([r2, r3]); +verify.rangesAreRenameLocations([r3, r4]); diff --git a/tests/cases/fourslash/findAllRefsForDefaultExport04.ts b/tests/cases/fourslash/findAllRefsForDefaultExport04.ts index 1b5eb7a282d..093910d1cb5 100644 --- a/tests/cases/fourslash/findAllRefsForDefaultExport04.ts +++ b/tests/cases/fourslash/findAllRefsForDefaultExport04.ts @@ -14,12 +14,10 @@ verify.referenceGroups([r0, r2], [ { definition: "import a", ranges: [r3, r4] } ]); verify.referenceGroups(r1, [ - // TODO:GH#17990 - { definition: "import default", ranges: [r1] }, + { definition: "export default a", ranges: [r1] }, { definition: "import a", ranges: [r3, r4] }, ]); verify.referenceGroups([r3, r4], [ { definition: "import a", ranges: [r3, r4] }, - // TODO:GH#17990 - { definition: "import default", ranges: [r1] }, + { definition: "export default a", ranges: [r1] }, ]); diff --git a/tests/cases/fourslash/getOccurrencesIsDefinitionOfComputedProperty.ts b/tests/cases/fourslash/getOccurrencesIsDefinitionOfComputedProperty.ts index 7d6cb0a48af..329a72c30fd 100644 --- a/tests/cases/fourslash/getOccurrencesIsDefinitionOfComputedProperty.ts +++ b/tests/cases/fourslash/getOccurrencesIsDefinitionOfComputedProperty.ts @@ -6,4 +6,8 @@ const ranges = test.ranges(); const [r0, r1, r2] = ranges; verify.referenceGroups(r0, [{ definition: '(property) ["foo"]: number', ranges }]); -verify.referenceGroups([r1, r2], undefined); // TODO: fix +verify.referenceGroups([r1, r2], [ + // TODO: these are the same thing, should be in the same group. + { definition: "(property) [\"foo\"]: number", ranges: [r0] }, + { definition: "(property) [\"foo\"]: number", ranges: [r1, r2] }, +]); diff --git a/tests/cases/fourslash/jsDocAugments.ts b/tests/cases/fourslash/jsDocAugments.ts index 1938cd0e2aa..cd2190e5486 100644 --- a/tests/cases/fourslash/jsDocAugments.ts +++ b/tests/cases/fourslash/jsDocAugments.ts @@ -20,4 +20,3 @@ goTo.marker(); verify.quickInfoIs("(local var) x: string"); - diff --git a/tests/cases/fourslash/jsDocAugmentsAndExtends.ts b/tests/cases/fourslash/jsDocAugmentsAndExtends.ts new file mode 100644 index 00000000000..10f33260268 --- /dev/null +++ b/tests/cases/fourslash/jsDocAugmentsAndExtends.ts @@ -0,0 +1,37 @@ +/// + +// @allowJs: true +// @checkJs: true +// @Filename: dummy.js + +//// /** +//// * @augments {Thing} +//// * @extends {Thing} +//// */ +//// class MyStringThing extends Thing { +//// constructor() { +//// super(); +//// var x = this.mine; +//// x/**/; +//// } +//// } + +// @Filename: declarations.d.ts +//// declare class Thing { +//// mine: T; +//// } + +// if more than one tag is present, report an error and take the type of the first entry. + +goTo.marker(); +verify.quickInfoIs("(local var) x: number"); +verify.getSemanticDiagnostics( +`[ + { + "message": "Class declarations cannot have more than one \`@augments\` or \`@extends\` tag.", + "start": 36, + "length": 24, + "category": "error", + "code": 8025 + } +]`); \ No newline at end of file diff --git a/tests/cases/fourslash/jsDocExtends.ts b/tests/cases/fourslash/jsDocExtends.ts new file mode 100644 index 00000000000..6bce5569533 --- /dev/null +++ b/tests/cases/fourslash/jsDocExtends.ts @@ -0,0 +1,22 @@ +/// + +// @allowJs: true +// @Filename: dummy.js + +//// /** +//// * @extends {Thing} +//// */ +//// class MyStringThing extends Thing { +//// constructor() { +//// var x = this.mine; +//// x/**/; +//// } +//// } + +// @Filename: declarations.d.ts +//// declare class Thing { +//// mine: T; +//// } + +goTo.marker(); +verify.quickInfoIs("(local var) x: string"); diff --git a/tests/cases/fourslash/server/projectInfo01.ts b/tests/cases/fourslash/server/projectInfo01.ts index 0d8707bf8a1..036aa5f0d4d 100644 --- a/tests/cases/fourslash/server/projectInfo01.ts +++ b/tests/cases/fourslash/server/projectInfo01.ts @@ -14,11 +14,11 @@ ////console.log("nothing"); goTo.file("a.ts") -verify.ProjectInfo(["lib.d.ts", "a.ts"]) +verify.ProjectInfo(["/lib.d.ts", "a.ts"]) goTo.file("b.ts") -verify.ProjectInfo(["lib.d.ts", "a.ts", "b.ts"]) +verify.ProjectInfo(["/lib.d.ts", "a.ts", "b.ts"]) goTo.file("c.ts") -verify.ProjectInfo(["lib.d.ts", "a.ts", "b.ts", "c.ts"]) +verify.ProjectInfo(["/lib.d.ts", "a.ts", "b.ts", "c.ts"]) goTo.file("d.ts") -verify.ProjectInfo(["lib.d.ts", "d.ts"]) +verify.ProjectInfo(["/lib.d.ts", "d.ts"]) diff --git a/tests/cases/fourslash/server/projectInfo02.ts b/tests/cases/fourslash/server/projectInfo02.ts index 3077deb453c..fb7c9cf8257 100644 --- a/tests/cases/fourslash/server/projectInfo02.ts +++ b/tests/cases/fourslash/server/projectInfo02.ts @@ -10,4 +10,4 @@ ////{ "files": ["a.ts", "b.ts"] } goTo.file("a.ts") -verify.ProjectInfo(["lib.d.ts", "a.ts", "b.ts", "tsconfig.json"]) +verify.ProjectInfo(["/lib.d.ts", "a.ts", "b.ts", "tsconfig.json"]) diff --git a/tests/cases/fourslash/server/projectWithNonExistentFiles.ts b/tests/cases/fourslash/server/projectWithNonExistentFiles.ts index 0e263d9aca6..a52c5f8918f 100644 --- a/tests/cases/fourslash/server/projectWithNonExistentFiles.ts +++ b/tests/cases/fourslash/server/projectWithNonExistentFiles.ts @@ -10,4 +10,4 @@ ////{ "files": ["a.ts", "c.ts", "b.ts"] } goTo.file("a.ts"); -verify.ProjectInfo(["lib.d.ts", "a.ts", "b.ts", "tsconfig.json"]) +verify.ProjectInfo(["/lib.d.ts", "a.ts", "b.ts", "tsconfig.json"])