Merge branch 'main' into dump-variances

This commit is contained in:
Nathan Shively-Sanders 2021-10-26 08:06:24 -07:00
commit 416323d967
50 changed files with 934 additions and 95 deletions

12
package-lock.json generated
View file

@ -676,9 +676,9 @@
"dev": true
},
"@types/node": {
"version": "16.11.1",
"resolved": "https://registry.npmjs.org/@types/node/-/node-16.11.1.tgz",
"integrity": "sha512-PYGcJHL9mwl1Ek3PLiYgyEKtwTMmkMw4vbiyz/ps3pfdRYLVv+SN7qHVAImrjdAXxgluDEw6Ph4lyv+m9UpRmA==",
"version": "16.11.6",
"resolved": "https://registry.npmjs.org/@types/node/-/node-16.11.6.tgz",
"integrity": "sha512-ua7PgUoeQFjmWPcoo9khiPum3Pd60k4/2ZGXt18sm2Slk0W0xZTqt5Y0Ny1NyBiN1EVQ/+FaF9NcY4Qe6rwk5w==",
"dev": true
},
"@types/node-fetch": {
@ -6797,9 +6797,9 @@
}
},
"shell-quote": {
"version": "1.7.2",
"resolved": "https://registry.npmjs.org/shell-quote/-/shell-quote-1.7.2.tgz",
"integrity": "sha512-mRz/m/JVscCrkMyPqHc/bczi3OQHkLTqXHEFu0zDhK/qfv3UcOA4SVmRCLmos4bhjr9ekVQubj/R7waKapmiQg==",
"version": "1.7.3",
"resolved": "https://registry.npmjs.org/shell-quote/-/shell-quote-1.7.3.tgz",
"integrity": "sha512-Vpfqwm4EnqGdlsBFNmHhxhElJYrdfcxPThu+ryKS5J8L/fhAwLazFZtq+S+TWZ9ANj2piSQLGj6NQg+lKPmxrw==",
"dev": true
},
"side-channel": {

View file

@ -2947,6 +2947,7 @@ namespace ts {
case SyntaxKind.MethodDeclaration:
case SyntaxKind.GetAccessor:
case SyntaxKind.SetAccessor:
case SyntaxKind.ClassStaticBlockDeclaration:
// this.foo assignment in a JavaScript class
// Bind this property to the containing class
const containingClass = thisContainer.parent;

View file

@ -3276,21 +3276,40 @@ namespace ts {
const namespaceName = getFullyQualifiedName(namespace);
const declarationName = declarationNameToString(right);
const suggestionForNonexistentModule = getSuggestedSymbolForNonexistentModule(right, namespace);
const exportedTypeSymbol = getMergedSymbol(getSymbol(getExportsOfSymbol(namespace), right.escapedText, SymbolFlags.Type));
const containingQualifiedName = isQualifiedName(name) && getContainingQualifiedNameNode(name);
const canSuggestTypeof = containingQualifiedName && !isTypeOfExpression(containingQualifiedName.parent) && tryGetQualifiedNameAsValue(containingQualifiedName);
if (suggestionForNonexistentModule) {
error(right, Diagnostics._0_has_no_exported_member_named_1_Did_you_mean_2, namespaceName, declarationName, symbolToString(suggestionForNonexistentModule));
return undefined;
}
else if (canSuggestTypeof) {
error(containingQualifiedName, Diagnostics._0_refers_to_a_value_but_is_being_used_as_a_type_here_Did_you_mean_typeof_0, entityNameToString(containingQualifiedName));
const containingQualifiedName = isQualifiedName(name) && getContainingQualifiedNameNode(name);
const canSuggestTypeof = globalObjectType // <-- can't pull on types if global types aren't initialized yet
&& (meaning & SymbolFlags.Type)
&& containingQualifiedName
&& !isTypeOfExpression(containingQualifiedName.parent)
&& tryGetQualifiedNameAsValue(containingQualifiedName);
if (canSuggestTypeof) {
error(
containingQualifiedName,
Diagnostics._0_refers_to_a_value_but_is_being_used_as_a_type_here_Did_you_mean_typeof_0,
entityNameToString(containingQualifiedName)
);
return undefined;
}
else if (meaning & SymbolFlags.Namespace && exportedTypeSymbol && isQualifiedName(name.parent)) {
error(name.parent.right, Diagnostics.Cannot_access_0_1_because_0_is_a_type_but_not_a_namespace_Did_you_mean_to_retrieve_the_type_of_the_property_1_in_0_with_0_1, symbolToString(exportedTypeSymbol), unescapeLeadingUnderscores(name.parent.right.escapedText));
}
else {
error(right, Diagnostics.Namespace_0_has_no_exported_member_1, namespaceName, declarationName);
if (meaning & SymbolFlags.Namespace && isQualifiedName(name.parent)) {
const exportedTypeSymbol = getMergedSymbol(getSymbol(getExportsOfSymbol(namespace), right.escapedText, SymbolFlags.Type));
if (exportedTypeSymbol) {
error(
name.parent.right,
Diagnostics.Cannot_access_0_1_because_0_is_a_type_but_not_a_namespace_Did_you_mean_to_retrieve_the_type_of_the_property_1_in_0_with_0_1,
symbolToString(exportedTypeSymbol),
unescapeLeadingUnderscores(name.parent.right.escapedText)
);
return undefined;
}
}
error(right, Diagnostics.Namespace_0_has_no_exported_member_1, namespaceName, declarationName);
}
return undefined;
}
@ -3657,8 +3676,8 @@ namespace ts {
if (exportEquals !== moduleSymbol) {
const type = getTypeOfSymbol(exportEquals);
if (shouldTreatPropertiesOfExternalModuleAsExports(type)) {
getPropertiesOfType(type).forEach(symbol => {
cb(symbol, symbol.escapedName);
forEachPropertyOfType(type, (symbol, escapedName) => {
cb(symbol, escapedName);
});
}
}
@ -4034,13 +4053,17 @@ namespace ts {
function getNamedMembers(members: SymbolTable): Symbol[] {
let result: Symbol[] | undefined;
members.forEach((symbol, id) => {
if (!isReservedMemberName(id) && symbolIsValue(symbol)) {
if (isNamedMember(symbol, id)) {
(result || (result = [])).push(symbol);
}
});
return result || emptyArray;
}
function isNamedMember(member: Symbol, escapedName: __String) {
return !isReservedMemberName(escapedName) && symbolIsValue(member);
}
function getNamedOrIndexSignatureMembers(members: SymbolTable): Symbol[] {
const result = getNamedMembers(members);
const index = getIndexSymbolFromSymbolTable(members);
@ -11572,6 +11595,17 @@ namespace ts {
getPropertiesOfObjectType(type);
}
function forEachPropertyOfType(type: Type, action: (symbol: Symbol, escapedName: __String) => void): void {
type = getReducedApparentType(type);
if (type.flags & TypeFlags.StructuredType) {
resolveStructuredTypeMembers(type as StructuredType).members.forEach((symbol, escapedName) => {
if (isNamedMember(symbol, escapedName)) {
action(symbol, escapedName);
}
});
}
}
function isTypeInvalidDueToUnionDiscriminant(contextualType: Type, obj: ObjectLiteralExpression | JsxAttributes): boolean {
const list = obj.properties as NodeArray<ObjectLiteralElementLike | JsxAttributeLike>;
return list.some(property => {
@ -15316,13 +15350,6 @@ namespace ts {
return type[cache] = type;
}
function isConditionalTypeAlwaysTrueDisregardingInferTypes(type: ConditionalType) {
const extendsInferParamMapper = type.root.inferTypeParameters && createTypeMapper(type.root.inferTypeParameters, map(type.root.inferTypeParameters, () => wildcardType));
const checkType = type.checkType;
const extendsType = type.extendsType;
return isTypeAssignableTo(getRestrictiveInstantiation(checkType), getRestrictiveInstantiation(instantiateType(extendsType, extendsInferParamMapper)));
}
function getSimplifiedConditionalType(type: ConditionalType, writing: boolean) {
const checkType = type.checkType;
const extendsType = type.extendsType;
@ -15646,6 +15673,12 @@ namespace ts {
return result;
}
function isDistributionDependent(root: ConditionalRoot) {
return root.isDistributive && (
isTypeParameterPossiblyReferenced(root.checkType as TypeParameter, root.node.trueType) ||
isTypeParameterPossiblyReferenced(root.checkType as TypeParameter, root.node.falseType));
}
function getTypeFromConditionalTypeNode(node: ConditionalTypeNode): Type {
const links = getNodeLinks(node);
if (!links.resolvedType) {
@ -19032,34 +19065,22 @@ namespace ts {
return Ternary.Maybe;
}
const c = target as ConditionalType;
// Check if the conditional is always true or always false but still deferred for distribution purposes
const skipTrue = !isTypeAssignableTo(getPermissiveInstantiation(c.checkType), getPermissiveInstantiation(c.extendsType));
const skipFalse = !skipTrue && isConditionalTypeAlwaysTrueDisregardingInferTypes(c);
// Instantiate with a replacement mapper if the conditional is distributive, replacing the check type with a clone of itself,
// this way {x: string | number, y: string | number} -> (T extends T ? { x: T, y: T } : never) appropriately _fails_ when
// T = string | number (since that will end up distributing and producing `{x: string, y: string} | {x: number, y: number}`,
// to which `{x: string | number, y: string | number}` isn't assignable)
let distributionMapper: TypeMapper | undefined;
const checkVar = getActualTypeVariable(c.root.checkType);
if (c.root.isDistributive && checkVar.flags & TypeFlags.TypeParameter) {
const newParam = cloneTypeParameter(checkVar);
distributionMapper = prependTypeMapping(checkVar, newParam, c.mapper);
newParam.mapper = distributionMapper;
}
// TODO: Find a nice way to include potential conditional type breakdowns in error output, if they seem good (they usually don't)
const expanding = isDeeplyNestedType(target, targetStack, targetDepth);
let localResult: Ternary | undefined = expanding ? Ternary.Maybe : undefined;
if (skipTrue || expanding || (localResult = isRelatedTo(source, distributionMapper ? instantiateType(getTypeFromTypeNode(c.root.node.trueType), distributionMapper) : getTrueTypeFromConditionalType(c), RecursionFlags.Target, /*reportErrors*/ false))) {
if (!skipFalse && !expanding) {
localResult = (localResult || Ternary.Maybe) & isRelatedTo(source, distributionMapper ? instantiateType(getTypeFromTypeNode(c.root.node.falseType), distributionMapper) : getFalseTypeFromConditionalType(c), RecursionFlags.Target, /*reportErrors*/ false);
// We check for a relationship to a conditional type target only when the conditional type has no
// 'infer' positions and is not distributive or is distributive but doesn't reference the check type
// parameter in either of the result types.
if (!c.root.inferTypeParameters && !isDistributionDependent(c.root)) {
// Check if the conditional is always true or always false but still deferred for distribution purposes.
const skipTrue = !isTypeAssignableTo(getPermissiveInstantiation(c.checkType), getPermissiveInstantiation(c.extendsType));
const skipFalse = !skipTrue && isTypeAssignableTo(getRestrictiveInstantiation(c.checkType), getRestrictiveInstantiation(c.extendsType));
// TODO: Find a nice way to include potential conditional type breakdowns in error output, if they seem good (they usually don't)
if (result = skipTrue ? Ternary.True : isRelatedTo(source, getTrueTypeFromConditionalType(c), RecursionFlags.Target, /*reportErrors*/ false)) {
result &= skipFalse ? Ternary.True : isRelatedTo(source, getFalseTypeFromConditionalType(c), RecursionFlags.Target, /*reportErrors*/ false);
if (result) {
resetErrorInfo(saveErrorInfo);
return result;
}
}
}
if (localResult) {
resetErrorInfo(saveErrorInfo);
return localResult;
}
}
else if (target.flags & TypeFlags.TemplateLiteral) {
if (source.flags & TypeFlags.TemplateLiteral) {

View file

@ -1164,6 +1164,10 @@
"category": "Error",
"code": 1389
},
"'{0}' is not allowed as a parameter name.": {
"category": "Error",
"code": 1390
},
"An import alias cannot use 'import type'": {
"category": "Error",
"code": 1392

View file

@ -2611,7 +2611,10 @@ namespace ts {
case ParsingContext.ObjectLiteralMembers: return parseErrorAtCurrentToken(Diagnostics.Property_assignment_expected);
case ParsingContext.ArrayLiteralMembers: return parseErrorAtCurrentToken(Diagnostics.Expression_or_comma_expected);
case ParsingContext.JSDocParameters: return parseErrorAtCurrentToken(Diagnostics.Parameter_declaration_expected);
case ParsingContext.Parameters: return parseErrorAtCurrentToken(Diagnostics.Parameter_declaration_expected);
case ParsingContext.Parameters:
return isKeyword(token())
? parseErrorAtCurrentToken(Diagnostics._0_is_not_allowed_as_a_parameter_name, tokenToString(token()))
: parseErrorAtCurrentToken(Diagnostics.Parameter_declaration_expected);
case ParsingContext.TypeParameters: return parseErrorAtCurrentToken(Diagnostics.Type_parameter_declaration_expected);
case ParsingContext.TypeArguments: return parseErrorAtCurrentToken(Diagnostics.Type_argument_expected);
case ParsingContext.TupleElementTypes: return parseErrorAtCurrentToken(Diagnostics.Type_expected);

View file

@ -6613,7 +6613,7 @@ namespace ts {
includeFilePattern: getRegularExpressionForWildcard(includes, absolutePath, "files"),
includeDirectoryPattern: getRegularExpressionForWildcard(includes, absolutePath, "directories"),
excludePattern: getRegularExpressionForWildcard(excludes, absolutePath, "exclude"),
basePaths: getBasePaths(path, includes, useCaseSensitiveFileNames)
basePaths: getBasePaths(absolutePath, includes, useCaseSensitiveFileNames)
};
}
@ -6637,22 +6637,22 @@ namespace ts {
const results: string[][] = includeFileRegexes ? includeFileRegexes.map(() => []) : [[]];
const visited = new Map<string, true>();
const toCanonical = createGetCanonicalFileName(useCaseSensitiveFileNames);
for (const basePath of patterns.basePaths) {
if (directoryExists(basePath)) {
visitDirectory(basePath, combinePaths(currentDirectory, basePath), depth);
for (const absoluteBasePath of patterns.basePaths) {
if (directoryExists(absoluteBasePath)) {
visitDirectory(absoluteBasePath, depth);
}
}
return flatten(results);
function visitDirectory(path: string, absolutePath: string, depth: number | undefined) {
function visitDirectory(absolutePath: string, depth: number | undefined) {
const canonicalPath = toCanonical(realpath(absolutePath));
if (visited.has(canonicalPath)) return;
visited.set(canonicalPath, true);
const { files, directories } = getFileSystemEntries(path);
const { files, directories } = getFileSystemEntries(absolutePath);
for (const current of sort<string>(files, compareStringsCaseSensitive)) {
const name = combinePaths(path, current);
const name = combinePaths(absolutePath, current);
const absoluteName = combinePaths(absolutePath, current);
if (extensions && !fileExtensionIsOneOf(name, extensions)) continue;
if (excludeRegex && excludeRegex.test(absoluteName)) continue;
@ -6675,11 +6675,10 @@ namespace ts {
}
for (const current of sort<string>(directories, compareStringsCaseSensitive)) {
const name = combinePaths(path, current);
const absoluteName = combinePaths(absolutePath, current);
if ((!includeDirectoryRegex || includeDirectoryRegex.test(absoluteName)) &&
(!excludeRegex || !excludeRegex.test(absoluteName))) {
visitDirectory(name, absoluteName, depth);
visitDirectory(absoluteName, depth);
}
}
}
@ -6687,10 +6686,11 @@ namespace ts {
/**
* Computes the unique non-wildcard base paths amongst the provided include patterns.
* @returns Absolute directory paths
*/
function getBasePaths(path: string, includes: readonly string[] | undefined, useCaseSensitiveFileNames: boolean): string[] {
function getBasePaths(absoluteTsconfigPath: string, includes: readonly string[] | undefined, useCaseSensitiveFileNames: boolean): string[] {
// Storage for our results in the form of literal paths (e.g. the paths as written by the user).
const basePaths: string[] = [path];
const basePaths: string[] = [absoluteTsconfigPath];
if (includes) {
// Storage for literal base paths amongst the include patterns.
@ -6698,9 +6698,9 @@ namespace ts {
for (const include of includes) {
// We also need to check the relative paths by converting them to absolute and normalizing
// in case they escape the base path (e.g "..\somedirectory")
const absolute: string = isRootedDiskPath(include) ? include : normalizePath(combinePaths(path, include));
const absoluteIncludePath: string = isRootedDiskPath(include) ? include : normalizePath(combinePaths(absoluteTsconfigPath, include));
// Append the literal and canonical candidate base paths.
includeBasePaths.push(getIncludeBasePath(absolute));
includeBasePaths.push(getIncludeBasePath(absoluteIncludePath));
}
// Sort the offsets array using either the literal or canonical path representations.
@ -6709,7 +6709,7 @@ namespace ts {
// Iterate over each include base path and include unique base paths that are not a
// subpath of an existing base path
for (const includeBasePath of includeBasePaths) {
if (every(basePaths, basePath => !containsPath(basePath, includeBasePath, path, !useCaseSensitiveFileNames))) {
if (every(basePaths, basePath => !containsPath(basePath, includeBasePath, absoluteTsconfigPath, !useCaseSensitiveFileNames))) {
basePaths.push(includeBasePath);
}
}

4
src/lib/es5.d.ts vendored
View file

@ -196,13 +196,13 @@ interface ObjectConstructor {
/**
* Prevents the modification of existing property attributes and values, and prevents the addition of new properties.
* @param o Object on which to lock the attributes.
* @param a Object on which to lock the attributes.
*/
freeze<T>(a: T[]): readonly T[];
/**
* Prevents the modification of existing property attributes and values, and prevents the addition of new properties.
* @param o Object on which to lock the attributes.
* @param f Object on which to lock the attributes.
*/
freeze<T extends Function>(f: T): T;

View file

@ -15267,6 +15267,15 @@
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";_0_is_not_allowed_as_a_parameter_name_1390" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA['{0}' is not allowed as a parameter name.]]></Val>
<Tgt Cat="Text" Stat="Loc" Orig="New">
<Val><![CDATA[不允许将 '{0}' 作为参数名。]]></Val>
</Tgt>
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";_0_is_not_allowed_as_a_variable_declaration_name_1389" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA['{0}' is not allowed as a variable declaration name.]]></Val>

View file

@ -15267,6 +15267,15 @@
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";_0_is_not_allowed_as_a_parameter_name_1390" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA['{0}' is not allowed as a parameter name.]]></Val>
<Tgt Cat="Text" Stat="Loc" Orig="New">
<Val><![CDATA[不允許 '{0}' 做為參數名稱。]]></Val>
</Tgt>
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";_0_is_not_allowed_as_a_variable_declaration_name_1389" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA['{0}' is not allowed as a variable declaration name.]]></Val>

View file

@ -15276,6 +15276,15 @@
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";_0_is_not_allowed_as_a_parameter_name_1390" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA['{0}' is not allowed as a parameter name.]]></Val>
<Tgt Cat="Text" Stat="Loc" Orig="New">
<Val><![CDATA[{0} není povolen jako název parametru.]]></Val>
</Tgt>
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";_0_is_not_allowed_as_a_variable_declaration_name_1389" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA['{0}' is not allowed as a variable declaration name.]]></Val>

View file

@ -15261,6 +15261,15 @@
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";_0_is_not_allowed_as_a_parameter_name_1390" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA['{0}' is not allowed as a parameter name.]]></Val>
<Tgt Cat="Text" Stat="Loc" Orig="New">
<Val><![CDATA["{0}" ist als Parametername nicht zulässig.]]></Val>
</Tgt>
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";_0_is_not_allowed_as_a_variable_declaration_name_1389" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA['{0}' is not allowed as a variable declaration name.]]></Val>

View file

@ -15279,6 +15279,15 @@
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";_0_is_not_allowed_as_a_parameter_name_1390" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA['{0}' is not allowed as a parameter name.]]></Val>
<Tgt Cat="Text" Stat="Loc" Orig="New">
<Val><![CDATA[No se permite “{0}” como nombre de parámetro.]]></Val>
</Tgt>
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";_0_is_not_allowed_as_a_variable_declaration_name_1389" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA['{0}' is not allowed as a variable declaration name.]]></Val>

View file

@ -15279,6 +15279,15 @@
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";_0_is_not_allowed_as_a_parameter_name_1390" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA['{0}' is not allowed as a parameter name.]]></Val>
<Tgt Cat="Text" Stat="Loc" Orig="New">
<Val><![CDATA['{0}' n'est pas autorisé comme nom de paramètre.]]></Val>
</Tgt>
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";_0_is_not_allowed_as_a_variable_declaration_name_1389" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA['{0}' is not allowed as a variable declaration name.]]></Val>

View file

@ -15267,6 +15267,15 @@
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";_0_is_not_allowed_as_a_parameter_name_1390" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA['{0}' is not allowed as a parameter name.]]></Val>
<Tgt Cat="Text" Stat="Loc" Orig="New">
<Val><![CDATA['{0}' non è un nome di parametro consentito.]]></Val>
</Tgt>
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";_0_is_not_allowed_as_a_variable_declaration_name_1389" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA['{0}' is not allowed as a variable declaration name.]]></Val>

View file

@ -15267,6 +15267,15 @@
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";_0_is_not_allowed_as_a_parameter_name_1390" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA['{0}' is not allowed as a parameter name.]]></Val>
<Tgt Cat="Text" Stat="Loc" Orig="New">
<Val><![CDATA['{0}' はパラメーター名として使用できません。]]></Val>
</Tgt>
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";_0_is_not_allowed_as_a_variable_declaration_name_1389" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA['{0}' is not allowed as a variable declaration name.]]></Val>

View file

@ -15267,6 +15267,15 @@
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";_0_is_not_allowed_as_a_parameter_name_1390" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA['{0}' is not allowed as a parameter name.]]></Val>
<Tgt Cat="Text" Stat="Loc" Orig="New">
<Val><![CDATA['{0}'은(는) 매개 변수 이름으로 사용할 수 없습니다.]]></Val>
</Tgt>
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";_0_is_not_allowed_as_a_variable_declaration_name_1389" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA['{0}' is not allowed as a variable declaration name.]]></Val>

View file

@ -15254,6 +15254,15 @@
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";_0_is_not_allowed_as_a_parameter_name_1390" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA['{0}' is not allowed as a parameter name.]]></Val>
<Tgt Cat="Text" Stat="Loc" Orig="New">
<Val><![CDATA[„{0}” jest niedozwolone jako nazwa parametru.]]></Val>
</Tgt>
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";_0_is_not_allowed_as_a_variable_declaration_name_1389" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA['{0}' is not allowed as a variable declaration name.]]></Val>

View file

@ -15257,6 +15257,15 @@
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";_0_is_not_allowed_as_a_parameter_name_1390" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA['{0}' is not allowed as a parameter name.]]></Val>
<Tgt Cat="Text" Stat="Loc" Orig="New">
<Val><![CDATA['{0}' não é permitido como um nome de parâmetro.]]></Val>
</Tgt>
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";_0_is_not_allowed_as_a_variable_declaration_name_1389" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA['{0}' is not allowed as a variable declaration name.]]></Val>

View file

@ -15266,6 +15266,15 @@
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";_0_is_not_allowed_as_a_parameter_name_1390" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA['{0}' is not allowed as a parameter name.]]></Val>
<Tgt Cat="Text" Stat="Loc" Orig="New">
<Val><![CDATA["{0}" не является допустимым именем параметра.]]></Val>
</Tgt>
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";_0_is_not_allowed_as_a_variable_declaration_name_1389" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA['{0}' is not allowed as a variable declaration name.]]></Val>

View file

@ -15260,6 +15260,15 @@
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";_0_is_not_allowed_as_a_parameter_name_1390" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA['{0}' is not allowed as a parameter name.]]></Val>
<Tgt Cat="Text" Stat="Loc" Orig="New">
<Val><![CDATA['{0}' öğesine parametre adı olarak izin verilmiyor.]]></Val>
</Tgt>
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";_0_is_not_allowed_as_a_variable_declaration_name_1389" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA['{0}' is not allowed as a variable declaration name.]]></Val>

View file

@ -53,7 +53,8 @@ namespace ts.codefix {
insertBefore = findChildOfKind(containingFunction, SyntaxKind.FunctionKeyword, sourceFile);
break;
case SyntaxKind.ArrowFunction:
insertBefore = findChildOfKind(containingFunction, SyntaxKind.OpenParenToken, sourceFile) || first(containingFunction.parameters);
const kind = containingFunction.typeParameters ? SyntaxKind.LessThanToken : SyntaxKind.OpenParenToken;
insertBefore = findChildOfKind(containingFunction, kind, sourceFile) || first(containingFunction.parameters);
break;
default:
return;

View file

@ -268,7 +268,7 @@ namespace ts.codefix {
}
export function getImportCompletionAction(
exportedSymbol: Symbol,
targetSymbol: Symbol,
moduleSymbol: Symbol,
sourceFile: SourceFile,
symbolName: string,
@ -280,8 +280,8 @@ namespace ts.codefix {
): { readonly moduleSpecifier: string, readonly codeAction: CodeAction } {
const compilerOptions = program.getCompilerOptions();
const exportInfos = pathIsBareSpecifier(stripQuotes(moduleSymbol.name))
? [getSymbolExportInfoForSymbol(exportedSymbol, moduleSymbol, program, host)]
: getAllReExportingModules(sourceFile, exportedSymbol, moduleSymbol, symbolName, host, program, preferences, /*useAutoImportProvider*/ true);
? [getSymbolExportInfoForSymbol(targetSymbol, moduleSymbol, program, host)]
: getAllReExportingModules(sourceFile, targetSymbol, moduleSymbol, symbolName, host, program, preferences, /*useAutoImportProvider*/ true);
const useRequire = shouldUseRequire(sourceFile, program);
const isValidTypeOnlyUseSite = isValidTypeOnlyAliasUseSite(getTokenAtPosition(sourceFile, position));
const fix = Debug.checkDefined(getImportFixForSymbol(sourceFile, exportInfos, moduleSymbol, symbolName, program, position, isValidTypeOnlyUseSite, useRequire, host, preferences));
@ -326,7 +326,7 @@ namespace ts.codefix {
}
}
function getAllReExportingModules(importingFile: SourceFile, exportedSymbol: Symbol, exportingModuleSymbol: Symbol, symbolName: string, host: LanguageServiceHost, program: Program, preferences: UserPreferences, useAutoImportProvider: boolean): readonly SymbolExportInfo[] {
function getAllReExportingModules(importingFile: SourceFile, targetSymbol: Symbol, exportingModuleSymbol: Symbol, symbolName: string, host: LanguageServiceHost, program: Program, preferences: UserPreferences, useAutoImportProvider: boolean): readonly SymbolExportInfo[] {
const result: SymbolExportInfo[] = [];
const compilerOptions = program.getCompilerOptions();
const getModuleSpecifierResolutionHost = memoizeOne((isFromPackageJson: boolean) => {
@ -341,12 +341,12 @@ namespace ts.codefix {
}
const defaultInfo = getDefaultLikeExportInfo(moduleSymbol, checker, compilerOptions);
if (defaultInfo && (defaultInfo.name === symbolName || moduleSymbolToValidIdentifier(moduleSymbol, getEmitScriptTarget(compilerOptions)) === symbolName) && skipAlias(defaultInfo.symbol, checker) === exportedSymbol && isImportable(program, moduleFile, isFromPackageJson)) {
if (defaultInfo && (defaultInfo.name === symbolName || moduleSymbolToValidIdentifier(moduleSymbol, getEmitScriptTarget(compilerOptions)) === symbolName) && skipAlias(defaultInfo.symbol, checker) === targetSymbol && isImportable(program, moduleFile, isFromPackageJson)) {
result.push({ symbol: defaultInfo.symbol, moduleSymbol, moduleFileName: moduleFile?.fileName, exportKind: defaultInfo.exportKind, targetFlags: skipAlias(defaultInfo.symbol, checker).flags, isFromPackageJson });
}
for (const exported of checker.getExportsAndPropertiesOfModule(moduleSymbol)) {
if (exported.name === symbolName && skipAlias(exported, checker) === exportedSymbol && isImportable(program, moduleFile, isFromPackageJson)) {
if (exported.name === symbolName && checker.getMergedSymbol(skipAlias(exported, checker)) === targetSymbol && isImportable(program, moduleFile, isFromPackageJson)) {
result.push({ symbol: exported, moduleSymbol, moduleFileName: moduleFile?.fileName, exportKind: ExportKind.Named, targetFlags: skipAlias(exported, checker).flags, isFromPackageJson });
}
}
@ -663,13 +663,15 @@ namespace ts.codefix {
}
const { allowsImportingSpecifier } = createPackageJsonImportFilter(sourceFile, preferences, host);
return fixes.reduce((best, fix) =>
// Takes true branch of conditional if `fix` is better than `best`
compareModuleSpecifiers(fix, best, sourceFile, program, allowsImportingSpecifier) === Comparison.LessThan ? fix : best
);
}
/** @returns `Comparison.LessThan` if `a` is better than `b`. */
function compareModuleSpecifiers(a: ImportFix, b: ImportFix, importingFile: SourceFile, program: Program, allowsImportingSpecifier: (specifier: string) => boolean): Comparison {
if (a.kind !== ImportFixKind.UseNamespace && b.kind !== ImportFixKind.UseNamespace) {
return compareBooleans(allowsImportingSpecifier(a.moduleSpecifier), allowsImportingSpecifier(b.moduleSpecifier))
return compareBooleans(allowsImportingSpecifier(b.moduleSpecifier), allowsImportingSpecifier(a.moduleSpecifier))
|| compareNodeCoreModuleSpecifiers(a.moduleSpecifier, b.moduleSpecifier, importingFile, program)
|| compareNumberOfDirectorySeparators(a.moduleSpecifier, b.moduleSpecifier);
}

View file

@ -1183,9 +1183,9 @@ namespace ts.Completions {
const checker = origin.isFromPackageJson ? host.getPackageJsonAutoImportProvider!()!.getTypeChecker() : program.getTypeChecker();
const { moduleSymbol } = origin;
const exportedSymbol = checker.getMergedSymbol(skipAlias(symbol.exportSymbol || symbol, checker));
const targetSymbol = checker.getMergedSymbol(skipAlias(symbol.exportSymbol || symbol, checker));
const { moduleSpecifier, codeAction } = codefix.getImportCompletionAction(
exportedSymbol,
targetSymbol,
moduleSymbol,
sourceFile,
getNameForExportedSymbol(symbol, getEmitScriptTarget(compilerOptions)),
@ -2209,8 +2209,9 @@ namespace ts.Completions {
function isNewIdentifierDefinitionLocation(): boolean {
if (contextToken) {
const containingNodeKind = contextToken.parent.kind;
const tokenKind = keywordForNode(contextToken);
// Previous token may have been a keyword that was converted to an identifier.
switch (keywordForNode(contextToken)) {
switch (tokenKind) {
case SyntaxKind.CommaToken:
return containingNodeKind === SyntaxKind.CallExpression // func( a, |
|| containingNodeKind === SyntaxKind.Constructor // constructor( a, | /* public, protected, private keywords are allowed here, so show completion */
@ -2254,10 +2255,16 @@ namespace ts.Completions {
case SyntaxKind.TemplateMiddle:
return containingNodeKind === SyntaxKind.TemplateSpan; // `aa ${10} dd ${|
case SyntaxKind.PublicKeyword:
case SyntaxKind.PrivateKeyword:
case SyntaxKind.ProtectedKeyword:
return containingNodeKind === SyntaxKind.PropertyDeclaration; // class A{ public |
case SyntaxKind.AsyncKeyword:
return containingNodeKind === SyntaxKind.MethodDeclaration // const obj = { async c|()
|| containingNodeKind === SyntaxKind.ShorthandPropertyAssignment; // const obj = { async c|
case SyntaxKind.AsteriskToken:
return containingNodeKind === SyntaxKind.MethodDeclaration; // const obj = { * c|
}
if (isClassMemberCompletionKeyword(tokenKind)) {
return true;
}
}

View file

@ -79,10 +79,14 @@ namespace ts {
}
const isDefault = exportKind === ExportKind.Default;
const namedSymbol = isDefault && getLocalSymbolForExportDefault(symbol) || symbol;
// A re-export merged with an export from a module augmentation can result in `symbol`
// being an external module symbol; the name it is re-exported by will be `symbolTableKey`
// (which comes from the keys of `moduleSymbol.exports`.)
const importedName = isExternalModuleSymbol(namedSymbol)
// 1. A named export must be imported by its key in `moduleSymbol.exports` or `moduleSymbol.members`.
// 2. A re-export merged with an export from a module augmentation can result in `symbol`
// being an external module symbol; the name it is re-exported by will be `symbolTableKey`
// (which comes from the keys of `moduleSymbol.exports`.)
// 3. Otherwise, we have a default/namespace import that can be imported by any name, and
// `symbolTableKey` will be something undesirable like `export=` or `default`, so we try to
// get a better name.
const importedName = exportKind === ExportKind.Named || isExternalModuleSymbol(namedSymbol)
? unescapeLeadingUnderscores(symbolTableKey)
: getNameForExportedSymbol(namedSymbol, scriptTarget);
const moduleName = stripQuotes(moduleSymbol.name);
@ -321,7 +325,7 @@ namespace ts {
let moduleCount = 0;
forEachExternalModuleToImportFrom(program, host, /*useAutoImportProvider*/ true, (moduleSymbol, moduleFile, program, isFromPackageJson) => {
if (++moduleCount % 100 === 0) cancellationToken?.throwIfCancellationRequested();
const seenExports = new Map<Symbol, true>();
const seenExports = new Map<__String, true>();
const checker = program.getTypeChecker();
const defaultInfo = getDefaultLikeExportInfo(moduleSymbol, checker, compilerOptions);
// Note: I think we shouldn't actually see resolved module symbols here, but weird merges
@ -339,7 +343,7 @@ namespace ts {
checker);
}
checker.forEachExportAndPropertyOfModule(moduleSymbol, (exported, key) => {
if (exported !== defaultInfo?.symbol && isImportableSymbol(exported, checker) && addToSeen(seenExports, exported)) {
if (exported !== defaultInfo?.symbol && isImportableSymbol(exported, checker) && addToSeen(seenExports, key)) {
cache.add(
importingFile.path,
exported,

View file

@ -182,3 +182,34 @@ describe("unittests:: Public APIs:: getChild* methods on EndOfFileToken with JSD
assert.equal(endOfFileToken.getChildCount(), 1);
assert.notEqual(endOfFileToken.getChildAt(0), /*expected*/ undefined);
});
describe("unittests:: Public APIs:: sys", () => {
it("readDirectory", () => {
// #45990, testing passing a non-absolute path
// `sys.readDirectory` is just `matchFiles` plugged into the real FS
const read = ts.matchFiles(
/*path*/ "",
/*extensions*/ [".ts", ".tsx"],
/*excludes*/ ["node_modules", "dist"],
/*includes*/ ["**/*"],
/*useCaseSensitiveFileNames*/ true,
/*currentDirectory*/ "/",
/*depth*/ undefined,
/*getFileSystemEntries*/ path => {
switch (path) {
case "/": return { directories: [], files: ["file.ts"] };
default: return { directories: [], files: [] };
}
},
/*realpath*/ ts.identity,
/*directoryExists*/ path => {
switch (path) {
case "/": return true;
default: return false;
}
}
);
assert.deepEqual(read, ["/file.ts"]);
});
});

View file

@ -0,0 +1,15 @@
/globals.ts(5,22): error TS2694: Namespace 'globals' has no exported member 'toString'.
==== /globals.ts (1 errors) ====
namespace globals {
export type Foo = {};
export const Bar = {};
}
import Foo = globals.toString.Blah;
~~~~~~~~
!!! error TS2694: Namespace 'globals' has no exported member 'toString'.
==== /index.ts (0 errors) ====
const Foo = {};

View file

@ -0,0 +1,21 @@
//// [tests/cases/compiler/importEqualsError45874.ts] ////
//// [globals.ts]
namespace globals {
export type Foo = {};
export const Bar = {};
}
import Foo = globals.toString.Blah;
//// [index.ts]
const Foo = {};
//// [globals.js]
var globals;
(function (globals) {
globals.Bar = {};
})(globals || (globals = {}));
var Foo = globals.toString.Blah;
//// [index.js]
var Foo = {};

View file

@ -0,0 +1,18 @@
=== /globals.ts ===
namespace globals {
>globals : Symbol(globals, Decl(globals.ts, 0, 0))
export type Foo = {};
>Foo : Symbol(Foo, Decl(globals.ts, 0, 19))
export const Bar = {};
>Bar : Symbol(Bar, Decl(globals.ts, 2, 14))
}
import Foo = globals.toString.Blah;
>Foo : Symbol(Foo, Decl(globals.ts, 3, 1))
>globals : Symbol(globals, Decl(globals.ts, 0, 0))
=== /index.ts ===
const Foo = {};
>Foo : Symbol(Foo, Decl(index.ts, 0, 5))

View file

@ -0,0 +1,22 @@
=== /globals.ts ===
namespace globals {
>globals : typeof globals
export type Foo = {};
>Foo : Foo
export const Bar = {};
>Bar : {}
>{} : {}
}
import Foo = globals.toString.Blah;
>Foo : any
>globals : typeof globals
>toString : any
>Blah : any
=== /index.ts ===
const Foo = {};
>Foo : {}
>{} : {}

View file

@ -0,0 +1,30 @@
/src/a.js(10,7): error TS2417: Class static side 'typeof ElementsArray' incorrectly extends base class static side '{ isArray(arg: any): arg is any[]; readonly prototype: any[]; }'.
Types of property 'isArray' are incompatible.
Type '(arg: any) => boolean' is not assignable to type '(arg: any) => arg is any[]'.
Signature '(arg: any): boolean' must be a type predicate.
==== /src/a.js (1 errors) ====
class Thing {
static {
this.doSomething = () => {};
}
}
Thing.doSomething();
// GH#46468
class ElementsArray extends Array {
~~~~~~~~~~~~~
!!! error TS2417: Class static side 'typeof ElementsArray' incorrectly extends base class static side '{ isArray(arg: any): arg is any[]; readonly prototype: any[]; }'.
!!! error TS2417: Types of property 'isArray' are incompatible.
!!! error TS2417: Type '(arg: any) => boolean' is not assignable to type '(arg: any) => arg is any[]'.
!!! error TS2417: Signature '(arg: any): boolean' must be a type predicate.
static {
const superisArray = super.isArray;
const customIsArray = (arg)=> superisArray(arg);
this.isArray = customIsArray;
}
}
ElementsArray.isArray(new ElementsArray());

View file

@ -0,0 +1,73 @@
//// [a.js]
class Thing {
static {
this.doSomething = () => {};
}
}
Thing.doSomething();
// GH#46468
class ElementsArray extends Array {
static {
const superisArray = super.isArray;
const customIsArray = (arg)=> superisArray(arg);
this.isArray = customIsArray;
}
}
ElementsArray.isArray(new ElementsArray());
//// [a.js]
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var _a, _b;
var _this = this;
var Thing = /** @class */ (function () {
function Thing() {
}
return Thing;
}());
_a = Thing;
(function () {
_a.doSomething = function () { };
})();
Thing.doSomething();
// GH#46468
var ElementsArray = /** @class */ (function (_super) {
__extends(ElementsArray, _super);
function ElementsArray() {
return _super !== null && _super.apply(this, arguments) || this;
}
return ElementsArray;
}(Array));
_b = ElementsArray;
(function () {
var superisArray = _super.isArray;
var customIsArray = function (arg) { return superisArray(arg); };
_b.isArray = customIsArray;
})();
ElementsArray.isArray(new ElementsArray());
//// [a.d.ts]
declare class Thing {
}
declare class ElementsArray extends Array<any> {
constructor(arrayLength?: number);
constructor(arrayLength: number);
constructor(...items: any[]);
}

View file

@ -0,0 +1,49 @@
=== /src/a.js ===
class Thing {
>Thing : Symbol(Thing, Decl(a.js, 0, 0))
static {
this.doSomething = () => {};
>this.doSomething : Symbol(Thing.doSomething, Decl(a.js, 1, 12))
>this : Symbol(Thing, Decl(a.js, 0, 0))
>doSomething : Symbol(Thing.doSomething, Decl(a.js, 1, 12))
}
}
Thing.doSomething();
>Thing.doSomething : Symbol(Thing.doSomething, Decl(a.js, 1, 12))
>Thing : Symbol(Thing, Decl(a.js, 0, 0))
>doSomething : Symbol(Thing.doSomething, Decl(a.js, 1, 12))
// GH#46468
class ElementsArray extends Array {
>ElementsArray : Symbol(ElementsArray, Decl(a.js, 6, 20))
>Array : Symbol(Array, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
static {
const superisArray = super.isArray;
>superisArray : Symbol(superisArray, Decl(a.js, 11, 13))
>super.isArray : Symbol(ArrayConstructor.isArray, Decl(lib.es5.d.ts, --, --))
>super : Symbol(ArrayConstructor, Decl(lib.es5.d.ts, --, --))
>isArray : Symbol(ArrayConstructor.isArray, Decl(lib.es5.d.ts, --, --))
const customIsArray = (arg)=> superisArray(arg);
>customIsArray : Symbol(customIsArray, Decl(a.js, 12, 13))
>arg : Symbol(arg, Decl(a.js, 12, 31))
>superisArray : Symbol(superisArray, Decl(a.js, 11, 13))
>arg : Symbol(arg, Decl(a.js, 12, 31))
this.isArray = customIsArray;
>this.isArray : Symbol(ElementsArray.isArray, Decl(a.js, 12, 56))
>this : Symbol(ElementsArray, Decl(a.js, 6, 20))
>isArray : Symbol(ElementsArray.isArray, Decl(a.js, 12, 56))
>customIsArray : Symbol(customIsArray, Decl(a.js, 12, 13))
}
}
ElementsArray.isArray(new ElementsArray());
>ElementsArray.isArray : Symbol(ElementsArray.isArray, Decl(a.js, 12, 56))
>ElementsArray : Symbol(ElementsArray, Decl(a.js, 6, 20))
>isArray : Symbol(ElementsArray.isArray, Decl(a.js, 12, 56))
>ElementsArray : Symbol(ElementsArray, Decl(a.js, 6, 20))

View file

@ -0,0 +1,57 @@
=== /src/a.js ===
class Thing {
>Thing : Thing
static {
this.doSomething = () => {};
>this.doSomething = () => {} : () => void
>this.doSomething : () => void
>this : typeof Thing
>doSomething : () => void
>() => {} : () => void
}
}
Thing.doSomething();
>Thing.doSomething() : void
>Thing.doSomething : () => void
>Thing : typeof Thing
>doSomething : () => void
// GH#46468
class ElementsArray extends Array {
>ElementsArray : ElementsArray
>Array : any[]
static {
const superisArray = super.isArray;
>superisArray : (arg: any) => arg is any[]
>super.isArray : (arg: any) => arg is any[]
>super : ArrayConstructor
>isArray : (arg: any) => arg is any[]
const customIsArray = (arg)=> superisArray(arg);
>customIsArray : (arg: any) => boolean
>(arg)=> superisArray(arg) : (arg: any) => boolean
>arg : any
>superisArray(arg) : boolean
>superisArray : (arg: any) => arg is any[]
>arg : any
this.isArray = customIsArray;
>this.isArray = customIsArray : (arg: any) => boolean
>this.isArray : (arg: any) => boolean
>this : typeof ElementsArray
>isArray : (arg: any) => boolean
>customIsArray : (arg: any) => boolean
}
}
ElementsArray.isArray(new ElementsArray());
>ElementsArray.isArray(new ElementsArray()) : boolean
>ElementsArray.isArray : (arg: any) => boolean
>ElementsArray : typeof ElementsArray
>isArray : (arg: any) => boolean
>new ElementsArray() : ElementsArray
>ElementsArray : typeof ElementsArray

View file

@ -118,5 +118,4 @@ tests/cases/compiler/reservedWords2.ts(12,17): error TS1138: Parameter declarati
!!! error TS1359: Identifier expected. 'null' is a reserved word that cannot be used here.
~
!!! error TS1138: Parameter declaration expected.

View file

@ -11,7 +11,6 @@ var [debugger, if] = [1, 2];
enum void {}
function f(default: number) {}
class C { m(null: string) {} }
//// [reservedWords2.js]

View file

@ -40,4 +40,3 @@ class C { m(null: string) {} }
> : Symbol((Missing), Decl(reservedWords2.ts, 11, 12))
>string : Symbol(string, Decl(reservedWords2.ts, 11, 17))

View file

@ -74,4 +74,3 @@ class C { m(null: string) {} }
> : any
>string : any

View file

@ -0,0 +1,45 @@
tests/cases/compiler/reservedWords3.ts(1,13): error TS1390: 'enum' is not allowed as a parameter name.
tests/cases/compiler/reservedWords3.ts(1,17): error TS2567: Enum declarations can only merge with namespace or other enum declarations.
tests/cases/compiler/reservedWords3.ts(1,17): error TS1003: Identifier expected.
tests/cases/compiler/reservedWords3.ts(2,13): error TS1390: 'class' is not allowed as a parameter name.
tests/cases/compiler/reservedWords3.ts(2,18): error TS1005: '{' expected.
tests/cases/compiler/reservedWords3.ts(3,13): error TS1390: 'function' is not allowed as a parameter name.
tests/cases/compiler/reservedWords3.ts(3,21): error TS2567: Enum declarations can only merge with namespace or other enum declarations.
tests/cases/compiler/reservedWords3.ts(3,21): error TS1003: Identifier expected.
tests/cases/compiler/reservedWords3.ts(4,13): error TS1390: 'while' is not allowed as a parameter name.
tests/cases/compiler/reservedWords3.ts(4,18): error TS1005: '(' expected.
tests/cases/compiler/reservedWords3.ts(5,13): error TS1390: 'for' is not allowed as a parameter name.
tests/cases/compiler/reservedWords3.ts(5,16): error TS1005: '(' expected.
==== tests/cases/compiler/reservedWords3.ts (12 errors) ====
function f1(enum) {}
~~~~
!!! error TS1390: 'enum' is not allowed as a parameter name.
!!! error TS2567: Enum declarations can only merge with namespace or other enum declarations.
~
!!! error TS1003: Identifier expected.
function f2(class) {}
~~~~~
!!! error TS1390: 'class' is not allowed as a parameter name.
~
!!! error TS1005: '{' expected.
function f3(function) {}
~~~~~~~~
!!! error TS1390: 'function' is not allowed as a parameter name.
!!! error TS2567: Enum declarations can only merge with namespace or other enum declarations.
~
!!! error TS1003: Identifier expected.
function f4(while) {}
~~~~~
!!! error TS1390: 'while' is not allowed as a parameter name.
~
!!! error TS1005: '(' expected.
function f5(for) {}
~~~
!!! error TS1390: 'for' is not allowed as a parameter name.
~
!!! error TS1005: '(' expected.

View file

@ -0,0 +1,28 @@
//// [reservedWords3.ts]
function f1(enum) {}
function f2(class) {}
function f3(function) {}
function f4(while) {}
function f5(for) {}
//// [reservedWords3.js]
function f1() { }
var ;
(function () {
})( || ( = {}));
{ }
function f2() { }
var default_1 = /** @class */ (function () {
function default_1() {
}
return default_1;
}());
{ }
function f3() { }
function () { }
{ }
function f4() { }
while () { }
function f5() { }
for (;;) { }

View file

@ -0,0 +1,18 @@
=== tests/cases/compiler/reservedWords3.ts ===
function f1(enum) {}
>f1 : Symbol(f1, Decl(reservedWords3.ts, 0, 0))
> : Symbol((Missing), Decl(reservedWords3.ts, 0, 12))
function f2(class) {}
>f2 : Symbol(f2, Decl(reservedWords3.ts, 0, 20))
function f3(function) {}
>f3 : Symbol(f3, Decl(reservedWords3.ts, 1, 21))
> : Symbol((Missing), Decl(reservedWords3.ts, 2, 12))
function f4(while) {}
>f4 : Symbol(f4, Decl(reservedWords3.ts, 2, 24))
function f5(for) {}
>f5 : Symbol(f5, Decl(reservedWords3.ts, 3, 21))

View file

@ -0,0 +1,20 @@
=== tests/cases/compiler/reservedWords3.ts ===
function f1(enum) {}
>f1 : () => any
> : (Missing)
function f2(class) {}
>f2 : () => any
function f3(function) {}
>f3 : () => any
> : () => any
function f4(while) {}
>f4 : () => any
> : any
function f5(for) {}
>f5 : () => any
> : any

View file

@ -0,0 +1,9 @@
// @Filename: /globals.ts
namespace globals {
export type Foo = {};
export const Bar = {};
}
import Foo = globals.toString.Blah;
// @Filename: /index.ts
const Foo = {};

View file

@ -0,0 +1,24 @@
// @allowJs: true
// @checkJs: true
// @declaration: true
// @outDir: /out/
// @filename: /src/a.js
class Thing {
static {
this.doSomething = () => {};
}
}
Thing.doSomething();
// GH#46468
class ElementsArray extends Array {
static {
const superisArray = super.isArray;
const customIsArray = (arg)=> superisArray(arg);
this.isArray = customIsArray;
}
}
ElementsArray.isArray(new ElementsArray());

View file

@ -10,4 +10,3 @@ var [debugger, if] = [1, 2];
enum void {}
function f(default: number) {}
class C { m(null: string) {} }

View file

@ -0,0 +1,5 @@
function f1(enum) {}
function f2(class) {}
function f3(function) {}
function f4(while) {}
function f5(for) {}

View file

@ -0,0 +1,16 @@
/// <reference path="fourslash.ts" />
////const foo = <T>(x: T): string => {
//// await new Promise(resolve => resolve(true));
//// return "";
////}
verify.codeFix({
description: ts.Diagnostics.Add_async_modifier_to_containing_function.message,
index: 0,
newFileContent:
`const foo = async <T>(x: T): Promise<string> => {
await new Promise(resolve => resolve(true));
return "";
}`
});

View file

@ -0,0 +1,25 @@
/// <reference path="fourslash.ts" />
//// const obj = {
//// a() {},
//// async b/*1*/
//// };
//// const obj2 = {
//// async /*2*/
//// };
//// class Foo {
//// async b/*3*/
//// }
//// class Foo2 {
//// async /*4*/
//// }
//// class Bar {
//// static async b/*5*/
//// }
test.markerNames().forEach(marker => {
verify.completions({
marker,
isNewIdentifierLocation: true
});
});

View file

@ -0,0 +1,28 @@
/// <reference path="fourslash.ts" />
//// const obj = {
//// a() {},
//// * b/*1*/
//// };
//// const obj2 = {
//// * /*2*/
//// };
//// const obj3 = {
//// async * /*3*/
//// };
//// class Foo {
//// * b/*4*/
//// }
//// class Foo2 {
//// * /*5*/
//// }
//// class Bar {
//// static * b/*6*/
//// }
test.markerNames().forEach(marker => {
verify.completions({
marker,
isNewIdentifierLocation: true
});
});

View file

@ -0,0 +1,93 @@
/// <reference path="fourslash.ts" />
// @module: esnext
// @moduleResolution: node
// @Filename: /node_modules/vue/package.json
//// {
//// "name": "vue",
//// "types": "dist/vue.d.ts"
//// }
// @Filename: /node_modules/vue/dist/vue.d.ts
//// export * from "@vue/runtime-dom"
// @Filename: /node_modules/@vue/runtime-dom/package.json
//// {
//// "name": "@vue/runtime-dom",
//// "types": "dist/runtime-dom.d.ts"
//// }
// @Filename: /node_modules/@vue/runtime-dom/dist/runtime-dom.d.ts
//// export * from "@vue/runtime-core";
//// export {}
//// declare module '@vue/reactivity' {
//// export interface RefUnwrapBailTypes {
//// runtimeDOMBailTypes: any
//// }
//// }
// @Filename: /node_modules/@vue/runtime-core/package.json
//// {
//// "name": "@vue/runtime-core",
//// "types": "dist/runtime-core.d.ts"
//// }
// @Filename: /node_modules/@vue/runtime-core/dist/runtime-core.d.ts
//// import { ref } from '@vue/reactivity';
//// export { ref };
//// declare module '@vue/reactivity' {
//// export interface RefUnwrapBailTypes {
//// runtimeCoreBailTypes: any
//// }
//// }
// @Filename: /node_modules/@vue/reactivity/package.json
//// {
//// "name": "@vue/reactivity",
//// "types": "dist/reactivity.d.ts"
//// }
// @Filename: /node_modules/@vue/reactivity/dist/reactivity.d.ts
//// export declare function ref<T = any>(): T;
// @Filename: /package.json
//// {
//// "dependencies": {
//// "vue": "*"
//// }
//// }
// @Filename: /index.ts
//// import {} from "vue";
//// ref/**/
verify.completions({
marker: "",
includes: [{
name: "ref",
source: "vue",
sourceDisplay: "vue",
hasAction: true,
sortText: completion.SortText.AutoImportSuggestions,
}],
preferences: {
includeCompletionsForModuleExports: true,
allowIncompleteCompletions: true,
},
});
verify.applyCodeActionFromCompletion("", {
name: "ref",
source: "vue",
description: `Add 'ref' to existing import declaration from "vue"`,
data: {
exportName: "ref",
fileName: "/node_modules/vue/dist/vue.d.ts",
},
preferences: {
includeCompletionsForModuleExports: true,
allowIncompleteCompletions: true,
},
newFileContent: `import { ref } from "vue";\nref`
});

View file

@ -0,0 +1,57 @@
/// <reference path="../fourslash.ts" />
// @Filename: /tsconfig.json
//// { "compilerOptions": { "module": "commonjs", "allowJs": true } }
// @Filename: /third_party/marked/src/defaults.js
//// function getDefaults() {
//// return {
//// baseUrl: null,
//// };
//// }
////
//// function changeDefaults(newDefaults) {
//// module.exports.defaults = newDefaults;
//// }
////
//// module.exports = {
//// defaults: getDefaults(),
//// getDefaults,
//// changeDefaults
//// };
// @Filename: /index.ts
//// /**/
format.setOption("newLineCharacter", "\n")
goTo.marker("");
// Create the exportInfoMap
verify.completions({ marker: "", preferences: { includeCompletionsForModuleExports: true } });
// Create a new program and reuse the exportInfoMap from the last request
edit.insert("d");
verify.completions({
marker: "",
excludes: ["newDefaults"],
includes: [{
name: "defaults",
source: "/third_party/marked/src/defaults",
hasAction: true,
sortText: completion.SortText.AutoImportSuggestions,
}],
preferences: { includeCompletionsForModuleExports: true }
});
verify.applyCodeActionFromCompletion("", {
name: "defaults",
source: "/third_party/marked/src/defaults",
description: `Import 'defaults' from module "./third_party/marked/src/defaults"`,
data: {
exportName: "defaults",
fileName: "/third_party/marked/src/defaults.js",
},
newFileContent: `import { defaults } from "./third_party/marked/src/defaults";
d`
});