Merge branch 'master' into qualified-name-param-tag-error

This commit is contained in:
Gabriela Britto
2019-01-10 09:49:26 -08:00
40 changed files with 708 additions and 113 deletions
+5
View File
@@ -0,0 +1,5 @@
/// <reference path='fourslash.ts'/>
////namespace wwer./**/w
verify.completions({ marker: "", exact: [], isNewIdentifierLocation: true });
+2 -2
View File
@@ -12,7 +12,7 @@ function baselineAccept(subfolder = "") {
}
function baselineCopy(subfolder = "") {
return gulp.src([`${localBaseline}${subfolder ? `${subfolder}/` : ``}**`, `!${localBaseline}${subfolder}/**/*.delete`], { base: localBaseline, read: false })
return gulp.src([`${localBaseline}${subfolder ? `${subfolder}/` : ``}**`, `!${localBaseline}${subfolder}/**/*.delete`], { base: localBaseline })
.pipe(gulp.dest(refBaseline));
}
@@ -21,4 +21,4 @@ function baselineDelete(subfolder = "") {
.pipe(rm())
.pipe(rename({ extname: "" }))
.pipe(rm(refBaseline));
}
}
+82 -73
View File
@@ -444,10 +444,10 @@ namespace ts {
const circularConstraintType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined);
const resolvingDefaultType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined);
const markerSuperType = <TypeParameter>createType(TypeFlags.TypeParameter);
const markerSubType = <TypeParameter>createType(TypeFlags.TypeParameter);
const markerSuperType = createTypeParameter();
const markerSubType = createTypeParameter();
markerSubType.constraint = markerSuperType;
const markerOtherType = <TypeParameter>createType(TypeFlags.TypeParameter);
const markerOtherType = createTypeParameter();
const noTypePredicate = createIdentifierTypePredicate("<<unresolved>>", 0, anyType);
@@ -663,7 +663,6 @@ namespace ts {
const subtypeRelation = createMap<RelationComparisonResult>();
const assignableRelation = createMap<RelationComparisonResult>();
const definitelyAssignableRelation = createMap<RelationComparisonResult>();
const comparableRelation = createMap<RelationComparisonResult>();
const identityRelation = createMap<RelationComparisonResult>();
const enumRelation = createMap<RelationComparisonResult>();
@@ -2408,11 +2407,18 @@ namespace ts {
// combine other declarations with the module or variable (e.g. a class/module, function/module, interface/variable).
function resolveESModuleSymbol(moduleSymbol: Symbol | undefined, referencingLocation: Node, dontResolveAlias: boolean): Symbol | undefined {
const symbol = resolveExternalModuleSymbol(moduleSymbol, dontResolveAlias);
if (!dontResolveAlias && symbol) {
if (!(symbol.flags & (SymbolFlags.Module | SymbolFlags.Variable)) && !getDeclarationOfKind(symbol, SyntaxKind.SourceFile)) {
error(referencingLocation, Diagnostics.Module_0_resolves_to_a_non_module_entity_and_cannot_be_imported_using_this_construct, symbolToString(moduleSymbol!));
const compilerOptionName = moduleKind >= ModuleKind.ES2015
? "allowSyntheticDefaultImports"
: "esModuleInterop";
error(referencingLocation, Diagnostics.This_module_can_only_be_referenced_with_ECMAScript_imports_Slashexports_by_turning_on_the_0_flag_and_referencing_its_default_export, compilerOptionName);
return symbol;
}
if (compilerOptions.esModuleInterop) {
const referenceParent = referencingLocation.parent;
if (
@@ -2745,6 +2751,12 @@ namespace ts {
return getUnionType(arrayFrom(typeofEQFacts.keys(), getLiteralType));
}
function createTypeParameter(symbol?: Symbol) {
const type = <TypeParameter>createType(TypeFlags.TypeParameter);
if (symbol) type.symbol = symbol;
return type;
}
// A reserved member name starts with two underscores, but the third character cannot be an underscore
// or the @ symbol. A third underscore indicates an escaped form of an identifer that started
// with at least two underscores. The @ character indicates that the name is denoted by a well known ES
@@ -6085,9 +6097,8 @@ namespace ts {
(<GenericType>type).instantiations.set(getTypeListId(type.typeParameters), <GenericType>type);
(<GenericType>type).target = <GenericType>type;
(<GenericType>type).typeArguments = type.typeParameters;
type.thisType = <TypeParameter>createType(TypeFlags.TypeParameter);
type.thisType = createTypeParameter(symbol);
type.thisType.isThisType = true;
type.thisType.symbol = symbol;
type.thisType.constraint = type;
}
}
@@ -6228,20 +6239,12 @@ namespace ts {
function getDeclaredTypeOfTypeParameter(symbol: Symbol): TypeParameter {
const links = getSymbolLinks(symbol);
if (!links.declaredType) {
const type = <TypeParameter>createType(TypeFlags.TypeParameter);
type.symbol = symbol;
links.declaredType = type;
}
return <TypeParameter>links.declaredType;
return links.declaredType || (links.declaredType = createTypeParameter(symbol));
}
function getDeclaredTypeOfAlias(symbol: Symbol): Type {
const links = getSymbolLinks(symbol);
if (!links.declaredType) {
links.declaredType = getDeclaredTypeOfSymbol(resolveAlias(symbol));
}
return links.declaredType;
return links.declaredType || (links.declaredType = getDeclaredTypeOfSymbol(resolveAlias(symbol)));
}
function getDeclaredTypeOfSymbol(symbol: Symbol): Type {
@@ -6930,7 +6933,7 @@ namespace ts {
function resolveUnionTypeMembers(type: UnionType) {
// The members and properties collections are empty for union types. To get all properties of a union
// type use getPropertiesOfType (only the language service uses this).
const callSignatures = getUnionSignatures(map(type.types, t => getSignaturesOfType(t, SignatureKind.Call)));
const callSignatures = getUnionSignatures(map(type.types, t => t === globalFunctionType ? [unknownSignature] : getSignaturesOfType(t, SignatureKind.Call)));
const constructSignatures = getUnionSignatures(map(type.types, t => getSignaturesOfType(t, SignatureKind.Construct)));
const stringIndexInfo = getUnionIndexInfo(type.types, IndexKind.String);
const numberIndexInfo = getUnionIndexInfo(type.types, IndexKind.Number);
@@ -7413,7 +7416,7 @@ namespace ts {
if (type.root.isDistributive) {
const simplified = getSimplifiedType(type.checkType);
const constraint = simplified === type.checkType ? getConstraintOfType(simplified) : simplified;
if (constraint) {
if (constraint && constraint !== type.checkType) {
const mapper = makeUnaryTypeMapper(type.root.checkType, constraint);
const instantiated = getConditionalTypeInstantiation(type, combineTypeMappers(mapper, type.mapper));
if (!(instantiated.flags & TypeFlags.Never)) {
@@ -9049,7 +9052,7 @@ namespace ts {
if (arity) {
typeParameters = new Array(arity);
for (let i = 0; i < arity; i++) {
const typeParameter = typeParameters[i] = <TypeParameter>createType(TypeFlags.TypeParameter);
const typeParameter = typeParameters[i] = createTypeParameter();
if (i < maxLength) {
const property = createSymbol(SymbolFlags.Property | (i >= minLength ? SymbolFlags.Optional : 0), "" + i as __String);
property.type = typeParameter;
@@ -9070,7 +9073,7 @@ namespace ts {
type.instantiations.set(getTypeListId(type.typeParameters), <GenericType>type);
type.target = <GenericType>type;
type.typeArguments = type.typeParameters;
type.thisType = <TypeParameter>createType(TypeFlags.TypeParameter);
type.thisType = createTypeParameter();
type.thisType.isThisType = true;
type.thisType.constraint = type;
type.declaredProperties = properties;
@@ -9971,7 +9974,7 @@ namespace ts {
if (checkType === wildcardType || extendsType === wildcardType) {
return wildcardType;
}
const checkTypeInstantiable = maybeTypeOfKind(checkType, TypeFlags.Instantiable);
const checkTypeInstantiable = maybeTypeOfKind(checkType, TypeFlags.Instantiable | TypeFlags.GenericMappedType);
let combinedMapper: TypeMapper | undefined;
if (root.inferTypeParameters) {
const context = createInferenceContext(root.inferTypeParameters, /*signature*/ undefined, InferenceFlags.None);
@@ -9986,7 +9989,7 @@ namespace ts {
// Instantiate the extends type including inferences for 'infer T' type parameters
const inferredExtendsType = combinedMapper ? instantiateType(root.extendsType, combinedMapper) : extendsType;
// We attempt to resolve the conditional type only when the check and extends types are non-generic
if (!checkTypeInstantiable && !maybeTypeOfKind(inferredExtendsType, TypeFlags.Instantiable)) {
if (!checkTypeInstantiable && !maybeTypeOfKind(inferredExtendsType, TypeFlags.Instantiable | TypeFlags.GenericMappedType)) {
if (inferredExtendsType.flags & TypeFlags.AnyOrUnknown) {
return instantiateType(root.trueType, mapper);
}
@@ -9998,14 +10001,15 @@ namespace ts {
// types with type parameters mapped to the wildcard type, the most permissive instantiations
// possible (the wildcard type is assignable to and from all types). If those are not related,
// then no instatiations will be and we can just return the false branch type.
if (!isTypeAssignableTo(getWildcardInstantiation(checkType), getWildcardInstantiation(inferredExtendsType))) {
if (!isTypeAssignableTo(getPermissiveInstantiation(checkType), getPermissiveInstantiation(inferredExtendsType))) {
return instantiateType(root.falseType, mapper);
}
// Return trueType for a definitely true extends check. The definitely assignable relation excludes
// type variable constraints from consideration. Without the definitely assignable relation, the type
// Return trueType for a definitely true extends check. We check instantiations of the two
// types with type parameters mapped to their restrictive form, i.e. a form of the type parameter
// that has no constraint. This ensures that, for example, the type
// type Foo<T extends { x: any }> = T extends { x: string } ? string : number
// would immediately resolve to 'string' instead of being deferred.
if (checkTypeRelatedTo(checkType, inferredExtendsType, definitelyAssignableRelation, /*errorNode*/ undefined)) {
// doesn't immediately resolve to 'string' instead of being deferred.
if (isTypeAssignableTo(getRestrictiveInstantiation(checkType), getRestrictiveInstantiation(inferredExtendsType))) {
return instantiateType(root.trueType, combinedMapper || mapper);
}
}
@@ -10611,13 +10615,20 @@ namespace ts {
return t => t === source ? target : baseMapper(t);
}
function wildcardMapper(type: Type) {
function permissiveMapper(type: Type) {
return type.flags & TypeFlags.TypeParameter ? wildcardType : type;
}
function getRestrictiveTypeParameter(tp: TypeParameter) {
return !tp.constraint ? tp : tp.restrictiveInstantiation || (tp.restrictiveInstantiation = createTypeParameter(tp.symbol));
}
function restrictiveMapper(type: Type) {
return type.flags & TypeFlags.TypeParameter ? getRestrictiveTypeParameter(<TypeParameter>type) : type;
}
function cloneTypeParameter(typeParameter: TypeParameter): TypeParameter {
const result = <TypeParameter>createType(TypeFlags.TypeParameter);
result.symbol = typeParameter.symbol;
const result = createTypeParameter(typeParameter.symbol);
result.target = typeParameter;
return result;
}
@@ -10969,9 +10980,14 @@ namespace ts {
return type;
}
function getWildcardInstantiation(type: Type) {
function getPermissiveInstantiation(type: Type) {
return type.flags & (TypeFlags.Primitive | TypeFlags.AnyOrUnknown | TypeFlags.Never) ? type :
type.wildcardInstantiation || (type.wildcardInstantiation = instantiateType(type, wildcardMapper));
type.permissiveInstantiation || (type.permissiveInstantiation = instantiateType(type, permissiveMapper));
}
function getRestrictiveInstantiation(type: Type) {
return type.flags & (TypeFlags.Primitive | TypeFlags.AnyOrUnknown | TypeFlags.Never) ? type :
type.restrictiveInstantiation || (type.restrictiveInstantiation = instantiateType(type, restrictiveMapper));
}
function instantiateIndexInfo(info: IndexInfo | undefined, mapper: TypeMapper): IndexInfo | undefined {
@@ -11644,7 +11660,7 @@ namespace ts {
if (s & TypeFlags.Null && (!strictNullChecks || t & TypeFlags.Null)) return true;
if (s & TypeFlags.Object && t & TypeFlags.NonPrimitive) return true;
if (s & TypeFlags.UniqueESSymbol || t & TypeFlags.UniqueESSymbol) return false;
if (relation === assignableRelation || relation === definitelyAssignableRelation || relation === comparableRelation) {
if (relation === assignableRelation || relation === comparableRelation) {
if (s & TypeFlags.Any) return true;
// Type number or any numeric literal type is assignable to any numeric enum type or any
// numeric enum literal type. This rule exists for backwards compatibility reasons because
@@ -11836,7 +11852,7 @@ namespace ts {
target = (<FreshableType>target).regularType;
}
if (source.flags & TypeFlags.Substitution) {
source = relation === definitelyAssignableRelation ? (<SubstitutionType>source).typeVariable : (<SubstitutionType>source).substitute;
source = (<SubstitutionType>source).substitute;
}
if (target.flags & TypeFlags.Substitution) {
target = (<SubstitutionType>target).typeVariable;
@@ -12022,7 +12038,7 @@ namespace ts {
}
if (isExcessPropertyCheckTarget(target)) {
const isComparingJsxAttributes = !!(getObjectFlags(source) & ObjectFlags.JsxAttributes);
if ((relation === assignableRelation || relation === definitelyAssignableRelation || relation === comparableRelation) &&
if ((relation === assignableRelation || relation === comparableRelation) &&
(isTypeSubsetOf(globalObjectType, target) || (!isComparingJsxAttributes && isEmptyObjectType(target)))) {
return false;
}
@@ -12425,24 +12441,22 @@ namespace ts {
}
// A type S is assignable to keyof T if S is assignable to keyof C, where C is the
// simplified form of T or, if T doesn't simplify, the constraint of T.
if (relation !== definitelyAssignableRelation) {
const simplified = getSimplifiedType((<IndexType>target).type);
const constraint = simplified !== (<IndexType>target).type ? simplified : getConstraintOfType((<IndexType>target).type);
if (constraint) {
// We require Ternary.True here such that circular constraints don't cause
// false positives. For example, given 'T extends { [K in keyof T]: string }',
// 'keyof T' has itself as its constraint and produces a Ternary.Maybe when
// related to other types.
if (isRelatedTo(source, getIndexType(constraint, (target as IndexType).stringsOnly), reportErrors) === Ternary.True) {
return Ternary.True;
}
const simplified = getSimplifiedType((<IndexType>target).type);
const constraint = simplified !== (<IndexType>target).type ? simplified : getConstraintOfType((<IndexType>target).type);
if (constraint) {
// We require Ternary.True here such that circular constraints don't cause
// false positives. For example, given 'T extends { [K in keyof T]: string }',
// 'keyof T' has itself as its constraint and produces a Ternary.Maybe when
// related to other types.
if (isRelatedTo(source, getIndexType(constraint, (target as IndexType).stringsOnly), reportErrors) === Ternary.True) {
return Ternary.True;
}
}
}
else if (target.flags & TypeFlags.IndexedAccess) {
// A type S is related to a type T[K], where T and K aren't both type variables, if S is related to C,
// where C is the base constraint of T[K]
if (relation !== identityRelation && relation !== definitelyAssignableRelation &&
if (relation !== identityRelation &&
!(isGenericObjectType((<IndexedAccessType>target).objectType) && isGenericIndexType((<IndexedAccessType>target).indexType))) {
const constraint = getBaseConstraintOfType(target);
if (constraint && constraint !== target) {
@@ -12485,26 +12499,24 @@ namespace ts {
return result;
}
}
if (relation !== definitelyAssignableRelation) {
const constraint = getConstraintOfType(<TypeParameter>source);
if (!constraint || (source.flags & TypeFlags.TypeParameter && constraint.flags & TypeFlags.Any)) {
// A type variable with no constraint is not related to the non-primitive object type.
if (result = isRelatedTo(emptyObjectType, extractTypesOfKind(target, ~TypeFlags.NonPrimitive))) {
errorInfo = saveErrorInfo;
return result;
}
}
// hi-speed no-this-instantiation check (less accurate, but avoids costly `this`-instantiation when the constraint will suffice), see #28231 for report on why this is needed
else if (result = isRelatedTo(constraint, target, /*reportErrors*/ false, /*headMessage*/ undefined, isIntersectionConstituent)) {
errorInfo = saveErrorInfo;
return result;
}
// slower, fuller, this-instantiated check (necessary when comparing raw `this` types from base classes), see `subclassWithPolymorphicThisIsAssignable.ts` test for example
else if (result = isRelatedTo(getTypeWithThisArgument(constraint, source), target, reportErrors, /*headMessage*/ undefined, isIntersectionConstituent)) {
const constraint = getConstraintOfType(<TypeParameter>source);
if (!constraint || (source.flags & TypeFlags.TypeParameter && constraint.flags & TypeFlags.Any)) {
// A type variable with no constraint is not related to the non-primitive object type.
if (result = isRelatedTo(emptyObjectType, extractTypesOfKind(target, ~TypeFlags.NonPrimitive))) {
errorInfo = saveErrorInfo;
return result;
}
}
// hi-speed no-this-instantiation check (less accurate, but avoids costly `this`-instantiation when the constraint will suffice), see #28231 for report on why this is needed
else if (result = isRelatedTo(constraint, target, /*reportErrors*/ false, /*headMessage*/ undefined, isIntersectionConstituent)) {
errorInfo = saveErrorInfo;
return result;
}
// slower, fuller, this-instantiated check (necessary when comparing raw `this` types from base classes), see `subclassWithPolymorphicThisIsAssignable.ts` test for example
else if (result = isRelatedTo(getTypeWithThisArgument(constraint, source), target, reportErrors, /*headMessage*/ undefined, isIntersectionConstituent)) {
errorInfo = saveErrorInfo;
return result;
}
}
else if (source.flags & TypeFlags.Index) {
if (result = isRelatedTo(keyofConstraintType, target, reportErrors)) {
@@ -12528,7 +12540,7 @@ namespace ts {
}
}
}
else if (relation !== definitelyAssignableRelation) {
else {
const distributiveConstraint = getConstraintOfDistributiveConditionalType(<ConditionalType>source);
if (distributiveConstraint) {
if (result = isRelatedTo(distributiveConstraint, target, reportErrors)) {
@@ -12559,9 +12571,6 @@ namespace ts {
}
return Ternary.False;
}
if (relation === definitelyAssignableRelation && isGenericMappedType(source)) {
return Ternary.False;
}
const sourceIsPrimitive = !!(source.flags & TypeFlags.Primitive);
if (relation !== identityRelation) {
source = getApparentType(source);
@@ -16625,7 +16634,7 @@ namespace ts {
function checkThisBeforeSuper(node: Node, container: Node, diagnosticMessage: DiagnosticMessage) {
const containingClassDecl = <ClassDeclaration>container.parent;
const baseTypeNode = getEffectiveBaseTypeNode(containingClassDecl);
const baseTypeNode = getClassExtendsHeritageElement(containingClassDecl);
// If a containing class does not have extends clause or the class extends null
// skip checking whether super statement is called before "this" accessing.
@@ -16974,7 +16983,7 @@ namespace ts {
// at this point the only legal case for parent is ClassLikeDeclaration
const classLikeDeclaration = <ClassLikeDeclaration>container.parent;
if (!getEffectiveBaseTypeNode(classLikeDeclaration)) {
if (!getClassExtendsHeritageElement(classLikeDeclaration)) {
error(node, Diagnostics.super_can_only_be_referenced_in_a_derived_class);
return errorType;
}
@@ -20506,9 +20515,9 @@ namespace ts {
* If FuncExpr is of type Any, or of an object type that has no call or construct signatures
* but is a subtype of the Function interface, the call is an untyped function call.
*/
function isUntypedFunctionCall(funcType: Type, apparentFuncType: Type, numCallSignatures: number, numConstructSignatures: number) {
function isUntypedFunctionCall(funcType: Type, apparentFuncType: Type, numCallSignatures: number, numConstructSignatures: number): boolean {
// We exclude union types because we may have a union of function types that happen to have no common signatures.
return isTypeAny(funcType) || isTypeAny(apparentFuncType) && funcType.flags & TypeFlags.TypeParameter ||
return isTypeAny(funcType) || isTypeAny(apparentFuncType) && !!(funcType.flags & TypeFlags.TypeParameter) ||
!numCallSignatures && !numConstructSignatures && !(apparentFuncType.flags & (TypeFlags.Union | TypeFlags.Never)) && isTypeAssignableTo(funcType, globalFunctionType);
}
@@ -23575,7 +23584,7 @@ namespace ts {
// Constructors of classes with no extends clause may not contain super calls, whereas
// constructors of derived classes must contain at least one super call somewhere in their function body.
const containingClassDecl = <ClassDeclaration>node.parent;
if (getEffectiveBaseTypeNode(containingClassDecl)) {
if (getClassExtendsHeritageElement(containingClassDecl)) {
captureLexicalThis(node.parent, containingClassDecl);
const classExtendsNull = classDeclarationExtendsNull(containingClassDecl);
const superCall = getSuperCallInConstructor(node);
+1 -1
View File
@@ -1776,7 +1776,7 @@
"category": "Error",
"code": 2496
},
"Module '{0}' resolves to a non-module entity and cannot be imported using this construct.": {
"This module can only be referenced with ECMAScript imports/exports by turning on the '{0}' flag and referencing its default export.": {
"category": "Error",
"code": 2497
},
+1
View File
@@ -1898,6 +1898,7 @@ namespace ts {
case SyntaxKind.StringLiteral:
return createIdentifier("String");
case SyntaxKind.PrefixUnaryExpression:
case SyntaxKind.NumericLiteral:
return createIdentifier("Number");
+3 -1
View File
@@ -3916,7 +3916,9 @@ namespace ts {
aliasTypeArguments?: ReadonlyArray<Type>; // Alias type arguments (if any)
/* @internal */ aliasTypeArgumentsContainsMarker?: boolean; // Alias type arguments (if any)
/* @internal */
wildcardInstantiation?: Type; // Instantiation with type parameters mapped to wildcard type
permissiveInstantiation?: Type; // Instantiation with type parameters mapped to wildcard type
/* @internal */
restrictiveInstantiation?: Type; // Instantiation with type parameters mapped to unconstrained form
/* @internal */
immediateBaseConstraint?: Type; // Immediate base constraint cache
}
+1 -1
View File
@@ -2008,7 +2008,7 @@ namespace ts.server {
const path = toNormalizedPath(uncheckedFileName);
const info = this.getScriptInfoForNormalizedPath(path);
if (info) return info;
const configProject = this.configuredProjects.get(uncheckedFileName);
const configProject = this.configuredProjects.get(this.toPath(uncheckedFileName));
return configProject && configProject.getCompilerOptions().configFile;
}
+1 -1
View File
@@ -104,7 +104,7 @@ namespace ts.Completions {
getJSCompletionEntries(sourceFile, location!.pos, uniqueNames, compilerOptions.target!, entries); // TODO: GH#18217
}
else {
if ((!symbols || symbols.length === 0) && keywordFilters === KeywordCompletionFilters.None) {
if (!isNewIdentifierLocation && (!symbols || symbols.length === 0) && keywordFilters === KeywordCompletionFilters.None) {
return undefined;
}
+19 -12
View File
@@ -151,7 +151,7 @@ namespace ts {
const toImport = oldFromNew !== undefined
// If we're at the new location (file was already renamed), need to redo module resolution starting from the old location.
// TODO:GH#18217
? getSourceFileToImportFromResolved(resolveModuleName(importLiteral.text, oldImportFromPath, program.getCompilerOptions(), host as ModuleResolutionHost), oldToNew, host)
? getSourceFileToImportFromResolved(resolveModuleName(importLiteral.text, oldImportFromPath, program.getCompilerOptions(), host as ModuleResolutionHost), oldToNew)
: getSourceFileToImport(importedModuleSymbol, importLiteral, sourceFile, program, host, oldToNew);
// Need an update if the imported file moved, or the importing file moved and was using a relative path.
@@ -192,28 +192,35 @@ namespace ts {
const resolved = host.resolveModuleNames
? host.getResolvedModuleWithFailedLookupLocationsFromCache && host.getResolvedModuleWithFailedLookupLocationsFromCache(importLiteral.text, importingSourceFile.fileName)
: program.getResolvedModuleWithFailedLookupLocationsFromCache(importLiteral.text, importingSourceFile.fileName);
return getSourceFileToImportFromResolved(resolved, oldToNew, host);
return getSourceFileToImportFromResolved(resolved, oldToNew);
}
}
function getSourceFileToImportFromResolved(resolved: ResolvedModuleWithFailedLookupLocations | undefined, oldToNew: PathUpdater, host: LanguageServiceHost): ToImport | undefined {
function getSourceFileToImportFromResolved(resolved: ResolvedModuleWithFailedLookupLocations | undefined, oldToNew: PathUpdater): ToImport | undefined {
// Search through all locations looking for a moved file, and only then test already existing files.
// This is because if `a.ts` is compiled to `a.js` and `a.ts` is moved, we don't want to resolve anything to `a.js`, but to `a.ts`'s new location.
return tryEach(tryGetNewFile) || tryEach(tryGetOldFile);
if (!resolved) return undefined;
function tryEach(cb: (oldFileName: string) => ToImport | undefined): ToImport | undefined {
return resolved && (
(resolved.resolvedModule && cb(resolved.resolvedModule.resolvedFileName)) || firstDefined(resolved.failedLookupLocations, cb));
// First try resolved module
if (resolved.resolvedModule) {
const result = tryChange(resolved.resolvedModule.resolvedFileName);
if (result) return result;
}
function tryGetNewFile(oldFileName: string): ToImport | undefined {
const newFileName = oldToNew(oldFileName);
return newFileName !== undefined && host.fileExists!(newFileName) ? { newFileName, updated: true } : undefined; // TODO: GH#18217
// Then failed lookups except package.json since we dont want to touch them (only included ts/js files)
const result = forEach(resolved.failedLookupLocations, tryChangeWithIgnoringPackageJson);
if (result) return result;
// If nothing changed, then result is resolved module file thats not updated
return resolved.resolvedModule && { newFileName: resolved.resolvedModule.resolvedFileName, updated: false };
function tryChangeWithIgnoringPackageJson(oldFileName: string) {
return !endsWith(oldFileName, "/package.json") ? tryChange(oldFileName) : undefined;
}
function tryGetOldFile(oldFileName: string): ToImport | undefined {
function tryChange(oldFileName: string) {
const newFileName = oldToNew(oldFileName);
return host.fileExists!(oldFileName) ? newFileName !== undefined ? { newFileName, updated: true } : { newFileName: oldFileName, updated: false } : undefined; // TODO: GH#18217
return newFileName && { newFileName, updated: true };
}
}
@@ -116,5 +116,40 @@ namespace ts.projectSystem {
renameLocation: undefined,
});
});
it("handles canonicalization of tsconfig path", () => {
const aTs: File = { path: "/Foo/a.ts", content: "const x = 0;" };
const tsconfig: File = { path: "/Foo/tsconfig.json", content: '{ "files": ["./a.ts"] }' };
const session = createSession(createServerHost([aTs, tsconfig]));
openFilesForSession([aTs], session);
const result = executeSessionRequest<protocol.GetEditsForRefactorRequest, protocol.GetEditsForRefactorResponse>(session, protocol.CommandTypes.GetEditsForRefactor, {
file: aTs.path,
startLine: 1,
startOffset: 1,
endLine: 2,
endOffset: aTs.content.length,
refactor: "Move to a new file",
action: "Move to a new file",
});
assert.deepEqual<protocol.RefactorEditInfo | undefined>(result, {
edits: [
{
fileName: aTs.path,
textChanges: [{ start: { line: 1, offset: 1 }, end: { line: 1, offset: aTs.content.length + 1 }, newText: "" }],
},
{
fileName: tsconfig.path,
textChanges: [{ start: { line: 1, offset: 21 }, end: { line: 1, offset: 21 }, newText: ', "./x.ts"' }],
},
{
fileName: "/Foo/x.ts",
textChanges: [{ start: { line: 0, offset: 0 }, end: { line: 0, offset: 0 }, newText: "const x = 0;\n" }],
},
],
renameFilename: undefined,
renameLocation: undefined,
});
});
});
}
@@ -0,0 +1,22 @@
tests/cases/compiler/noSuperInJSDocExtends.js(14,9): error TS2335: 'super' can only be referenced in a derived class.
==== tests/cases/compiler/noSuperInJSDocExtends.js (1 errors) ====
class Based { }
/** @extends {Based} */
class Derived {
constructor() {
this;
this.x = 10;
var that = this;
}
}
/** @extends {Based} */
class Derived2 {
constructor() {
super();
~~~~~
!!! error TS2335: 'super' can only be referenced in a derived class.
}
}
@@ -0,0 +1,31 @@
=== tests/cases/compiler/noSuperInJSDocExtends.js ===
class Based { }
>Based : Symbol(Based, Decl(noSuperInJSDocExtends.js, 0, 0))
/** @extends {Based} */
class Derived {
>Derived : Symbol(Derived, Decl(noSuperInJSDocExtends.js, 0, 15))
constructor() {
this;
>this : Symbol(Derived, Decl(noSuperInJSDocExtends.js, 0, 15))
this.x = 10;
>this.x : Symbol(Derived.x, Decl(noSuperInJSDocExtends.js, 4, 13))
>this : Symbol(Derived, Decl(noSuperInJSDocExtends.js, 0, 15))
>x : Symbol(Derived.x, Decl(noSuperInJSDocExtends.js, 4, 13))
var that = this;
>that : Symbol(that, Decl(noSuperInJSDocExtends.js, 6, 11))
>this : Symbol(Derived, Decl(noSuperInJSDocExtends.js, 0, 15))
}
}
/** @extends {Based} */
class Derived2 {
>Derived2 : Symbol(Derived2, Decl(noSuperInJSDocExtends.js, 8, 1))
constructor() {
super();
}
}
@@ -0,0 +1,35 @@
=== tests/cases/compiler/noSuperInJSDocExtends.js ===
class Based { }
>Based : Based
/** @extends {Based} */
class Derived {
>Derived : Derived
constructor() {
this;
>this : this
this.x = 10;
>this.x = 10 : 10
>this.x : number
>this : this
>x : number
>10 : 10
var that = this;
>that : this
>this : this
}
}
/** @extends {Based} */
class Derived2 {
>Derived2 : Derived2
constructor() {
super();
>super() : void
>super : any
}
}
@@ -471,4 +471,12 @@ tests/cases/conformance/types/conditional/conditionalTypes1.ts(288,43): error TS
var a = {o: 1, b: 2, c: [{a: 1, c: '213'}]}
assign(a, {o: 2, c: {0: {a: 2, c: '213123'}}})
// Repros from #23843
type Weird1 = (<U extends boolean>(a: U) => never) extends
(<U extends true>(a: U) => never) ? never : never;
type Weird2 = (<U extends boolean>(a: U) => U) extends
(<U extends true>(a: U) => infer T) ? T : never;
@@ -351,6 +351,14 @@ declare function assign<T>(o: T, a: RecursivePartial<T>): void;
var a = {o: 1, b: 2, c: [{a: 1, c: '213'}]}
assign(a, {o: 2, c: {0: {a: 2, c: '213123'}}})
// Repros from #23843
type Weird1 = (<U extends boolean>(a: U) => never) extends
(<U extends true>(a: U) => never) ? never : never;
type Weird2 = (<U extends boolean>(a: U) => U) extends
(<U extends true>(a: U) => infer T) ? T : never;
//// [conditionalTypes1.js]
@@ -715,3 +723,5 @@ declare var a: {
c: string;
}[];
};
declare type Weird1 = (<U extends boolean>(a: U) => never) extends (<U extends true>(a: U) => never) ? never : never;
declare type Weird2 = (<U extends boolean>(a: U) => U) extends (<U extends true>(a: U) => infer T) ? T : never;
@@ -1371,3 +1371,30 @@ assign(a, {o: 2, c: {0: {a: 2, c: '213123'}}})
>a : Symbol(a, Decl(conditionalTypes1.ts, 351, 25))
>c : Symbol(c, Decl(conditionalTypes1.ts, 351, 30))
// Repros from #23843
type Weird1 = (<U extends boolean>(a: U) => never) extends
>Weird1 : Symbol(Weird1, Decl(conditionalTypes1.ts, 351, 46))
>U : Symbol(U, Decl(conditionalTypes1.ts, 355, 16))
>a : Symbol(a, Decl(conditionalTypes1.ts, 355, 35))
>U : Symbol(U, Decl(conditionalTypes1.ts, 355, 16))
(<U extends true>(a: U) => never) ? never : never;
>U : Symbol(U, Decl(conditionalTypes1.ts, 356, 6))
>a : Symbol(a, Decl(conditionalTypes1.ts, 356, 22))
>U : Symbol(U, Decl(conditionalTypes1.ts, 356, 6))
type Weird2 = (<U extends boolean>(a: U) => U) extends
>Weird2 : Symbol(Weird2, Decl(conditionalTypes1.ts, 356, 54))
>U : Symbol(U, Decl(conditionalTypes1.ts, 358, 16))
>a : Symbol(a, Decl(conditionalTypes1.ts, 358, 35))
>U : Symbol(U, Decl(conditionalTypes1.ts, 358, 16))
>U : Symbol(U, Decl(conditionalTypes1.ts, 358, 16))
(<U extends true>(a: U) => infer T) ? T : never;
>U : Symbol(U, Decl(conditionalTypes1.ts, 359, 6))
>a : Symbol(a, Decl(conditionalTypes1.ts, 359, 22))
>U : Symbol(U, Decl(conditionalTypes1.ts, 359, 6))
>T : Symbol(T, Decl(conditionalTypes1.ts, 359, 36))
>T : Symbol(T, Decl(conditionalTypes1.ts, 359, 36))
@@ -1054,3 +1054,21 @@ assign(a, {o: 2, c: {0: {a: 2, c: '213123'}}})
>c : string
>'213123' : "213123"
// Repros from #23843
type Weird1 = (<U extends boolean>(a: U) => never) extends
>Weird1 : never
>a : U
(<U extends true>(a: U) => never) ? never : never;
>true : true
>a : U
type Weird2 = (<U extends boolean>(a: U) => U) extends
>Weird2 : boolean
>a : U
(<U extends true>(a: U) => infer T) ? T : never;
>true : true
>a : U
@@ -0,0 +1,28 @@
//// [decoratorWithNegativeLiteralTypeNoCrash.ts]
class A {
@decorator
public field1: -1 = -1;
}
function decorator(target: any, field: any) {}
//// [decoratorWithNegativeLiteralTypeNoCrash.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;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
var A = /** @class */ (function () {
function A() {
this.field1 = -1;
}
__decorate([
decorator,
__metadata("design:type", Number)
], A.prototype, "field1", void 0);
return A;
}());
function decorator(target, field) { }
@@ -0,0 +1,15 @@
=== tests/cases/compiler/decoratorWithNegativeLiteralTypeNoCrash.ts ===
class A {
>A : Symbol(A, Decl(decoratorWithNegativeLiteralTypeNoCrash.ts, 0, 0))
@decorator
>decorator : Symbol(decorator, Decl(decoratorWithNegativeLiteralTypeNoCrash.ts, 3, 1))
public field1: -1 = -1;
>field1 : Symbol(A.field1, Decl(decoratorWithNegativeLiteralTypeNoCrash.ts, 0, 9))
}
function decorator(target: any, field: any) {}
>decorator : Symbol(decorator, Decl(decoratorWithNegativeLiteralTypeNoCrash.ts, 3, 1))
>target : Symbol(target, Decl(decoratorWithNegativeLiteralTypeNoCrash.ts, 4, 19))
>field : Symbol(field, Decl(decoratorWithNegativeLiteralTypeNoCrash.ts, 4, 31))
@@ -0,0 +1,19 @@
=== tests/cases/compiler/decoratorWithNegativeLiteralTypeNoCrash.ts ===
class A {
>A : A
@decorator
>decorator : (target: any, field: any) => void
public field1: -1 = -1;
>field1 : -1
>-1 : -1
>1 : 1
>-1 : -1
>1 : 1
}
function decorator(target: any, field: any) {}
>decorator : (target: any, field: any) => void
>target : any
>field : any
@@ -11,24 +11,24 @@ tests/cases/compiler/main.ts(33,8): error TS1192: Module '"function"' has no def
tests/cases/compiler/main.ts(34,8): error TS1192: Module '"function-module"' has no default export.
tests/cases/compiler/main.ts(35,8): error TS1192: Module '"class"' has no default export.
tests/cases/compiler/main.ts(36,8): error TS1192: Module '"class-module"' has no default export.
tests/cases/compiler/main.ts(39,21): error TS2497: Module '"interface"' resolves to a non-module entity and cannot be imported using this construct.
tests/cases/compiler/main.ts(45,21): error TS2497: Module '"function"' resolves to a non-module entity and cannot be imported using this construct.
tests/cases/compiler/main.ts(47,21): error TS2497: Module '"class"' resolves to a non-module entity and cannot be imported using this construct.
tests/cases/compiler/main.ts(39,21): error TS2497: This module can only be referenced with ECMAScript imports/exports by turning on the 'esModuleInterop' flag and referencing its default export.
tests/cases/compiler/main.ts(45,21): error TS2497: This module can only be referenced with ECMAScript imports/exports by turning on the 'esModuleInterop' flag and referencing its default export.
tests/cases/compiler/main.ts(47,21): error TS2497: This module can only be referenced with ECMAScript imports/exports by turning on the 'esModuleInterop' flag and referencing its default export.
tests/cases/compiler/main.ts(50,1): error TS2693: 'y1' only refers to a type, but is being used as a value here.
tests/cases/compiler/main.ts(56,4): error TS2339: Property 'a' does not exist on type '() => any'.
tests/cases/compiler/main.ts(58,4): error TS2339: Property 'a' does not exist on type 'typeof Foo'.
tests/cases/compiler/main.ts(62,10): error TS2305: Module '"interface"' has no exported member 'a'.
tests/cases/compiler/main.ts(62,25): error TS2497: Module '"interface"' resolves to a non-module entity and cannot be imported using this construct.
tests/cases/compiler/main.ts(62,25): error TS2497: This module can only be referenced with ECMAScript imports/exports by turning on the 'esModuleInterop' flag and referencing its default export.
tests/cases/compiler/main.ts(68,10): error TS2305: Module '"function"' has no exported member 'a'.
tests/cases/compiler/main.ts(68,25): error TS2497: Module '"function"' resolves to a non-module entity and cannot be imported using this construct.
tests/cases/compiler/main.ts(68,25): error TS2497: This module can only be referenced with ECMAScript imports/exports by turning on the 'esModuleInterop' flag and referencing its default export.
tests/cases/compiler/main.ts(70,10): error TS2305: Module '"class"' has no exported member 'a'.
tests/cases/compiler/main.ts(70,25): error TS2497: Module '"class"' resolves to a non-module entity and cannot be imported using this construct.
tests/cases/compiler/main.ts(70,25): error TS2497: This module can only be referenced with ECMAScript imports/exports by turning on the 'esModuleInterop' flag and referencing its default export.
tests/cases/compiler/main.ts(85,10): error TS2305: Module '"interface"' has no exported member 'a'.
tests/cases/compiler/main.ts(85,25): error TS2497: Module '"interface"' resolves to a non-module entity and cannot be imported using this construct.
tests/cases/compiler/main.ts(85,25): error TS2497: This module can only be referenced with ECMAScript imports/exports by turning on the 'esModuleInterop' flag and referencing its default export.
tests/cases/compiler/main.ts(91,10): error TS2305: Module '"function"' has no exported member 'a'.
tests/cases/compiler/main.ts(91,25): error TS2497: Module '"function"' resolves to a non-module entity and cannot be imported using this construct.
tests/cases/compiler/main.ts(91,25): error TS2497: This module can only be referenced with ECMAScript imports/exports by turning on the 'esModuleInterop' flag and referencing its default export.
tests/cases/compiler/main.ts(93,10): error TS2305: Module '"class"' has no exported member 'a'.
tests/cases/compiler/main.ts(93,25): error TS2497: Module '"class"' resolves to a non-module entity and cannot be imported using this construct.
tests/cases/compiler/main.ts(93,25): error TS2497: This module can only be referenced with ECMAScript imports/exports by turning on the 'esModuleInterop' flag and referencing its default export.
tests/cases/compiler/main.ts(97,15): error TS2498: Module '"interface"' uses 'export =' and cannot be used with 'export *'.
tests/cases/compiler/main.ts(98,15): error TS2498: Module '"variable"' uses 'export =' and cannot be used with 'export *'.
tests/cases/compiler/main.ts(99,15): error TS2498: Module '"interface-variable"' uses 'export =' and cannot be used with 'export *'.
@@ -108,7 +108,7 @@ tests/cases/compiler/main.ts(106,15): error TS2498: Module '"class-module"' uses
// namespace import
import * as y1 from "interface";
~~~~~~~~~~~
!!! error TS2497: Module '"interface"' resolves to a non-module entity and cannot be imported using this construct.
!!! error TS2497: This module can only be referenced with ECMAScript imports/exports by turning on the 'esModuleInterop' flag and referencing its default export.
import * as y2 from "variable";
import * as y3 from "interface-variable";
import * as y4 from "module";
@@ -116,11 +116,11 @@ tests/cases/compiler/main.ts(106,15): error TS2498: Module '"class-module"' uses
import * as y6 from "variable-module";
import * as y7 from "function";
~~~~~~~~~~
!!! error TS2497: Module '"function"' resolves to a non-module entity and cannot be imported using this construct.
!!! error TS2497: This module can only be referenced with ECMAScript imports/exports by turning on the 'esModuleInterop' flag and referencing its default export.
import * as y8 from "function-module";
import * as y9 from "class";
~~~~~~~
!!! error TS2497: Module '"class"' resolves to a non-module entity and cannot be imported using this construct.
!!! error TS2497: This module can only be referenced with ECMAScript imports/exports by turning on the 'esModuleInterop' flag and referencing its default export.
import * as y0 from "class-module";
y1.a;
@@ -145,7 +145,7 @@ tests/cases/compiler/main.ts(106,15): error TS2498: Module '"class-module"' uses
~
!!! error TS2305: Module '"interface"' has no exported member 'a'.
~~~~~~~~~~~
!!! error TS2497: Module '"interface"' resolves to a non-module entity and cannot be imported using this construct.
!!! error TS2497: This module can only be referenced with ECMAScript imports/exports by turning on the 'esModuleInterop' flag and referencing its default export.
import { a as a2 } from "variable";
import { a as a3 } from "interface-variable";
import { a as a4 } from "module";
@@ -155,13 +155,13 @@ tests/cases/compiler/main.ts(106,15): error TS2498: Module '"class-module"' uses
~
!!! error TS2305: Module '"function"' has no exported member 'a'.
~~~~~~~~~~
!!! error TS2497: Module '"function"' resolves to a non-module entity and cannot be imported using this construct.
!!! error TS2497: This module can only be referenced with ECMAScript imports/exports by turning on the 'esModuleInterop' flag and referencing its default export.
import { a as a8 } from "function-module";
import { a as a9 } from "class";
~
!!! error TS2305: Module '"class"' has no exported member 'a'.
~~~~~~~
!!! error TS2497: Module '"class"' resolves to a non-module entity and cannot be imported using this construct.
!!! error TS2497: This module can only be referenced with ECMAScript imports/exports by turning on the 'esModuleInterop' flag and referencing its default export.
import { a as a0 } from "class-module";
a1;
@@ -180,7 +180,7 @@ tests/cases/compiler/main.ts(106,15): error TS2498: Module '"class-module"' uses
~
!!! error TS2305: Module '"interface"' has no exported member 'a'.
~~~~~~~~~~~
!!! error TS2497: Module '"interface"' resolves to a non-module entity and cannot be imported using this construct.
!!! error TS2497: This module can only be referenced with ECMAScript imports/exports by turning on the 'esModuleInterop' flag and referencing its default export.
export { a as a2 } from "variable";
export { a as a3 } from "interface-variable";
export { a as a4 } from "module";
@@ -190,13 +190,13 @@ tests/cases/compiler/main.ts(106,15): error TS2498: Module '"class-module"' uses
~
!!! error TS2305: Module '"function"' has no exported member 'a'.
~~~~~~~~~~
!!! error TS2497: Module '"function"' resolves to a non-module entity and cannot be imported using this construct.
!!! error TS2497: This module can only be referenced with ECMAScript imports/exports by turning on the 'esModuleInterop' flag and referencing its default export.
export { a as a8 } from "function-module";
export { a as a9 } from "class";
~
!!! error TS2305: Module '"class"' has no exported member 'a'.
~~~~~~~
!!! error TS2497: Module '"class"' resolves to a non-module entity and cannot be imported using this construct.
!!! error TS2497: This module can only be referenced with ECMAScript imports/exports by turning on the 'esModuleInterop' flag and referencing its default export.
export { a as a0 } from "class-module";
// export-star
@@ -0,0 +1,15 @@
tests/cases/compiler/main.ts(1,20): error TS2497: This module can only be referenced with ECMAScript imports/exports by turning on the 'esModuleInterop' flag and referencing its default export.
==== tests/cases/compiler/a.ts (0 errors) ====
class a { }
export = a;
==== tests/cases/compiler/main.ts (1 errors) ====
import * as a from "./a";
~~~~~
!!! error TS2497: This module can only be referenced with ECMAScript imports/exports by turning on the 'esModuleInterop' flag and referencing its default export.
a;
@@ -0,0 +1,26 @@
//// [tests/cases/compiler/es6ImportEqualsExportModuleCommonJsError.ts] ////
//// [a.ts]
class a { }
export = a;
//// [main.ts]
import * as a from "./a";
a;
//// [a.js]
"use strict";
var a = /** @class */ (function () {
function a() {
}
return a;
}());
module.exports = a;
//// [main.js]
"use strict";
exports.__esModule = true;
var a = require("./a");
a;
@@ -0,0 +1,16 @@
=== tests/cases/compiler/a.ts ===
class a { }
>a : Symbol(a, Decl(a.ts, 0, 0))
export = a;
>a : Symbol(a, Decl(a.ts, 0, 0))
=== tests/cases/compiler/main.ts ===
import * as a from "./a";
>a : Symbol(a, Decl(main.ts, 0, 6))
a;
>a : Symbol(a, Decl(main.ts, 0, 6))
@@ -0,0 +1,16 @@
=== tests/cases/compiler/a.ts ===
class a { }
>a : a
export = a;
>a : a
=== tests/cases/compiler/main.ts ===
import * as a from "./a";
>a : typeof a
a;
>a : typeof a
@@ -0,0 +1,18 @@
tests/cases/compiler/a.ts(2,1): error TS1203: Export assignment cannot be used when targeting ECMAScript modules. Consider using 'export default' or another module format instead.
tests/cases/compiler/main.ts(1,20): error TS2497: This module can only be referenced with ECMAScript imports/exports by turning on the 'allowSyntheticDefaultImports' flag and referencing its default export.
==== tests/cases/compiler/a.ts (1 errors) ====
class a { }
export = a;
~~~~~~~~~~~
!!! error TS1203: Export assignment cannot be used when targeting ECMAScript modules. Consider using 'export default' or another module format instead.
==== tests/cases/compiler/main.ts (1 errors) ====
import * as a from "./a";
~~~~~
!!! error TS2497: This module can only be referenced with ECMAScript imports/exports by turning on the 'allowSyntheticDefaultImports' flag and referencing its default export.
a;
@@ -0,0 +1,22 @@
//// [tests/cases/compiler/es6ImportEqualsExportModuleEs2015Error.ts] ////
//// [a.ts]
class a { }
export = a;
//// [main.ts]
import * as a from "./a";
a;
//// [a.js]
var a = /** @class */ (function () {
function a() {
}
return a;
}());
//// [main.js]
import * as a from "./a";
a;
@@ -0,0 +1,16 @@
=== tests/cases/compiler/a.ts ===
class a { }
>a : Symbol(a, Decl(a.ts, 0, 0))
export = a;
>a : Symbol(a, Decl(a.ts, 0, 0))
=== tests/cases/compiler/main.ts ===
import * as a from "./a";
>a : Symbol(a, Decl(main.ts, 0, 6))
a;
>a : Symbol(a, Decl(main.ts, 0, 6))
@@ -0,0 +1,16 @@
=== tests/cases/compiler/a.ts ===
class a { }
>a : a
export = a;
>a : a
=== tests/cases/compiler/main.ts ===
import * as a from "./a";
>a : typeof a
a;
>a : typeof a
@@ -0,0 +1,25 @@
//// [unionOfFunctionAndSignatureIsCallable.ts]
function f1(c1: Function, c2: () => object, callable: typeof c1 | typeof c2) {
const a = c1();
const b = c2();
const c = callable();
}
function f2(fetcherParams: object | (() => object)) {
const data = typeof fetcherParams === 'function'
? fetcherParams()
: fetcherParams
}
//// [unionOfFunctionAndSignatureIsCallable.js]
function f1(c1, c2, callable) {
var a = c1();
var b = c2();
var c = callable();
}
function f2(fetcherParams) {
var data = typeof fetcherParams === 'function'
? fetcherParams()
: fetcherParams;
}
@@ -0,0 +1,38 @@
=== tests/cases/compiler/unionOfFunctionAndSignatureIsCallable.ts ===
function f1(c1: Function, c2: () => object, callable: typeof c1 | typeof c2) {
>f1 : Symbol(f1, Decl(unionOfFunctionAndSignatureIsCallable.ts, 0, 0))
>c1 : Symbol(c1, Decl(unionOfFunctionAndSignatureIsCallable.ts, 0, 12))
>Function : Symbol(Function, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
>c2 : Symbol(c2, Decl(unionOfFunctionAndSignatureIsCallable.ts, 0, 25))
>callable : Symbol(callable, Decl(unionOfFunctionAndSignatureIsCallable.ts, 0, 43))
>c1 : Symbol(c1, Decl(unionOfFunctionAndSignatureIsCallable.ts, 0, 12))
>c2 : Symbol(c2, Decl(unionOfFunctionAndSignatureIsCallable.ts, 0, 25))
const a = c1();
>a : Symbol(a, Decl(unionOfFunctionAndSignatureIsCallable.ts, 1, 9))
>c1 : Symbol(c1, Decl(unionOfFunctionAndSignatureIsCallable.ts, 0, 12))
const b = c2();
>b : Symbol(b, Decl(unionOfFunctionAndSignatureIsCallable.ts, 2, 9))
>c2 : Symbol(c2, Decl(unionOfFunctionAndSignatureIsCallable.ts, 0, 25))
const c = callable();
>c : Symbol(c, Decl(unionOfFunctionAndSignatureIsCallable.ts, 3, 9))
>callable : Symbol(callable, Decl(unionOfFunctionAndSignatureIsCallable.ts, 0, 43))
}
function f2(fetcherParams: object | (() => object)) {
>f2 : Symbol(f2, Decl(unionOfFunctionAndSignatureIsCallable.ts, 4, 1))
>fetcherParams : Symbol(fetcherParams, Decl(unionOfFunctionAndSignatureIsCallable.ts, 6, 12))
const data = typeof fetcherParams === 'function'
>data : Symbol(data, Decl(unionOfFunctionAndSignatureIsCallable.ts, 7, 9))
>fetcherParams : Symbol(fetcherParams, Decl(unionOfFunctionAndSignatureIsCallable.ts, 6, 12))
? fetcherParams()
>fetcherParams : Symbol(fetcherParams, Decl(unionOfFunctionAndSignatureIsCallable.ts, 6, 12))
: fetcherParams
>fetcherParams : Symbol(fetcherParams, Decl(unionOfFunctionAndSignatureIsCallable.ts, 6, 12))
}
@@ -0,0 +1,45 @@
=== tests/cases/compiler/unionOfFunctionAndSignatureIsCallable.ts ===
function f1(c1: Function, c2: () => object, callable: typeof c1 | typeof c2) {
>f1 : (c1: Function, c2: () => object, callable: Function | (() => object)) => void
>c1 : Function
>c2 : () => object
>callable : Function | (() => object)
>c1 : Function
>c2 : () => object
const a = c1();
>a : any
>c1() : any
>c1 : Function
const b = c2();
>b : object
>c2() : object
>c2 : () => object
const c = callable();
>c : any
>callable() : any
>callable : Function | (() => object)
}
function f2(fetcherParams: object | (() => object)) {
>f2 : (fetcherParams: object | (() => object)) => void
>fetcherParams : object | (() => object)
const data = typeof fetcherParams === 'function'
>data : any
>typeof fetcherParams === 'function' ? fetcherParams() : fetcherParams : any
>typeof fetcherParams === 'function' : boolean
>typeof fetcherParams : "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function"
>fetcherParams : object | (() => object)
>'function' : "function"
? fetcherParams()
>fetcherParams() : any
>fetcherParams : Function | (() => object)
: fetcherParams
>fetcherParams : object
}
+3 -3
View File
@@ -62,9 +62,9 @@ lib/Page.js(936,3): error TS2322: Type '{ width: number; height: number; }' is n
lib/Page.js(937,3): error TS2322: Type '{ width: number; height: number; }' is not assignable to type 'string'.
lib/Page.js(938,3): error TS2322: Type '{ width: number; height: number; }' is not assignable to type 'string'.
lib/TaskQueue.js(7,14): error TS7014: Function type, which lacks return-type annotation, implicitly has an 'any' return type.
lib/externs.d.ts(3,29): error TS2497: Module '"/puppeteer/puppeteer/lib/Target"' resolves to a non-module entity and cannot be imported using this construct.
lib/externs.d.ts(5,32): error TS2497: Module '"/puppeteer/puppeteer/lib/TaskQueue"' resolves to a non-module entity and cannot be imported using this construct.
lib/externs.d.ts(9,37): error TS2497: Module '"/puppeteer/puppeteer/lib/ElementHandle"' resolves to a non-module entity and cannot be imported using this construct.
lib/externs.d.ts(3,29): error TS2497: This module can only be referenced with ECMAScript imports/exports by turning on the 'allowSyntheticDefaultImports' flag and referencing its default export.
lib/externs.d.ts(5,32): error TS2497: This module can only be referenced with ECMAScript imports/exports by turning on the 'allowSyntheticDefaultImports' flag and referencing its default export.
lib/externs.d.ts(9,37): error TS2497: This module can only be referenced with ECMAScript imports/exports by turning on the 'allowSyntheticDefaultImports' flag and referencing its default export.
lib/externs.d.ts(16,26): error TS2503: Cannot find namespace 'Protocol'.
lib/externs.d.ts(16,69): error TS2503: Cannot find namespace 'Protocol'.
lib/externs.d.ts(17,28): error TS2503: Cannot find namespace 'Protocol'.
@@ -0,0 +1,21 @@
// @allowJs: true
// @checkJs: true
// @noEmit: true
// @filename: noSuperInJSDocExtends.js
class Based { }
/** @extends {Based} */
class Derived {
constructor() {
this;
this.x = 10;
var that = this;
}
}
/** @extends {Based} */
class Derived2 {
constructor() {
super();
}
}
@@ -0,0 +1,8 @@
// @target: es5
// @experimentalDecorators: true
// @emitDecoratorMetadata: true
class A {
@decorator
public field1: -1 = -1;
}
function decorator(target: any, field: any) {}
@@ -0,0 +1,11 @@
// @module: commonjs
// @filename: a.ts
class a { }
export = a;
// @filename: main.ts
import * as a from "./a";
a;
@@ -0,0 +1,11 @@
// @module: es2015
// @filename: a.ts
class a { }
export = a;
// @filename: main.ts
import * as a from "./a";
a;
@@ -0,0 +1,11 @@
function f1(c1: Function, c2: () => object, callable: typeof c1 | typeof c2) {
const a = c1();
const b = c2();
const c = callable();
}
function f2(fetcherParams: object | (() => object)) {
const data = typeof fetcherParams === 'function'
? fetcherParams()
: fetcherParams
}
@@ -353,3 +353,11 @@ declare function assign<T>(o: T, a: RecursivePartial<T>): void;
var a = {o: 1, b: 2, c: [{a: 1, c: '213'}]}
assign(a, {o: 2, c: {0: {a: 2, c: '213123'}}})
// Repros from #23843
type Weird1 = (<U extends boolean>(a: U) => never) extends
(<U extends true>(a: U) => never) ? never : never;
type Weird2 = (<U extends boolean>(a: U) => U) extends
(<U extends true>(a: U) => infer T) ? T : never;
@@ -7,5 +7,5 @@
verify.completions(
{ marker: "moduleName1", exact: completion.globals, isNewIdentifierLocation: true },
{ marker: "moduleName2", exact: undefined },
{ marker: "moduleName2", exact: [], isNewIdentifierLocation: true },
);