Compare commits

..

15 commits

Author SHA1 Message Date
Daniel Rosenwasser b7d31bcd69 Switch to sparse array for deferred nodes. 2021-11-09 02:23:49 +00:00
Daniel Rosenwasser e23710aae5 Redo checker changes, see if these are wins. 2021-11-09 01:34:49 +00:00
Daniel Rosenwasser d42b2b708d Try just the fetching change in checker. 2021-11-09 01:09:57 +00:00
Daniel Rosenwasser 083db3a677 Fix ID usage in services. 2021-11-09 00:58:52 +00:00
Daniel Rosenwasser cc3836911f Switch to Set of Symbols in extractSymbol. 2021-11-09 00:35:10 +00:00
Daniel Rosenwasser ced38f315e Same trick for symbol.id, and always set it to 0. 2021-11-09 00:34:36 +00:00
Daniel Rosenwasser f9d2db3540 Restore id check to harness. 2021-11-08 07:12:41 +00:00
Daniel Rosenwasser 6a7d2c0a3e Restore redirect accessors. 2021-11-08 07:10:36 +00:00
Daniel Rosenwasser 41faf73bfc Switch back to putting Node IDs on Nodes. 2021-11-08 07:09:06 +00:00
Daniel Rosenwasser 5479adffc3 node -> originalNode 2021-11-06 10:49:42 +00:00
Daniel Rosenwasser 6f76b625a1 Remove uses of getNodeId in compiler outside of checker. 2021-11-06 10:41:57 +00:00
Daniel Rosenwasser ca13132e84 Remove getOriginalNodeId. 2021-11-06 10:39:03 +00:00
Daniel Rosenwasser e64dbabab8 More removals. 2021-11-06 09:33:40 +00:00
Daniel Rosenwasser 044de3ec63 More removal of getNodeId uses. 2021-11-06 07:59:41 +00:00
Daniel Rosenwasser e83d14434d Use getNodeId() less, specifically for NodeLinks. 2021-10-29 22:49:47 +00:00
263 changed files with 768 additions and 6110 deletions

20
package-lock.json generated
View file

@ -1,6 +1,6 @@
{
"name": "typescript",
"version": "4.6.0",
"version": "4.5.0",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
@ -676,9 +676,9 @@
"dev": true
},
"@types/node": {
"version": "16.11.10",
"resolved": "https://registry.npmjs.org/@types/node/-/node-16.11.10.tgz",
"integrity": "sha512-3aRnHa1KlOEEhJ6+CvyHKK5vE9BcLGjtUpwvqYLRvYNQKMfabu3BwfJaA/SLW8dxe28LsNDjtHwePTuzn3gmOA==",
"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": {
@ -6997,9 +6997,9 @@
}
},
"source-map-support": {
"version": "0.5.21",
"resolved": "https://registry.npmjs.org/source-map-support/-/source-map-support-0.5.21.tgz",
"integrity": "sha512-uBHU3L3czsIyYXKX88fdrGovxdSCoTGDRZ6SYXtSRxLZUzHg5P/66Ht6uoUlHu9EZod+inXhKo3qQgwXUT/y1w==",
"version": "0.5.20",
"resolved": "https://registry.npmjs.org/source-map-support/-/source-map-support-0.5.20.tgz",
"integrity": "sha512-n1lZZ8Ve4ksRqizaBQgxXDgKwttHDhyfQjA6YZZn8+AroHbsIz+JjwxQDxbp+7y5OYCI8t1Yk7etjD9CRd2hIw==",
"dev": true,
"requires": {
"buffer-from": "^1.0.0",
@ -8423,9 +8423,9 @@
},
"dependencies": {
"camelcase": {
"version": "6.2.1",
"resolved": "https://registry.npmjs.org/camelcase/-/camelcase-6.2.1.tgz",
"integrity": "sha512-tVI4q5jjFV5CavAU8DXfza/TJcZutVKo/5Foskmsqcm0MsL91moHvwiGNnqaa2o6PF/7yT5ikDRcVcl8Rj6LCA==",
"version": "6.2.0",
"resolved": "https://registry.npmjs.org/camelcase/-/camelcase-6.2.0.tgz",
"integrity": "sha512-c7wVvbw3f37nuobQNtgsgG9POC9qMbNuMQmTCqZv23b6MIz0fcYpBiOlv9gEN/hdLdnZTDQhg6e9Dq5M1vKvfg==",
"dev": true
},
"decamelize": {

View file

@ -2,7 +2,7 @@
"name": "typescript",
"author": "Microsoft Corp.",
"homepage": "https://www.typescriptlang.org/",
"version": "4.6.0",
"version": "4.5.0",
"license": "Apache-2.0",
"description": "TypeScript is a language for application scale JavaScript development",
"keywords": [

View file

@ -39,7 +39,7 @@ const execTsc = (lkg, ...args) =>
exec(process.execPath,
[resolve(findUpRoot(), lkg ? "./lib/tsc" : "./built/local/tsc"),
"-b", ...args],
{ hidePrompt: true });
{ hidePrompt: true })
const projectBuilder = new ProjectQueue((projects, lkg, force) => execTsc(lkg, ...(force ? ["--force"] : []), ...projects));

View file

@ -33,9 +33,9 @@ async function main() {
const inputPR = (await gh.pulls.get({ pull_number: +process.env.SOURCE_ISSUE, owner: "microsoft", repo: "TypeScript" })).data;
let remoteName = "origin";
if (inputPR.base.repo.git_url !== `git:github.com/microsoft/TypeScript` && inputPR.base.repo.git_url !== `git://github.com/microsoft/TypeScript`) {
if (inputPR.base.repo.git_url !== `git:github.com/microsoft/TypeScript`) {
runSequence([
["git", ["remote", "add", "nonlocal", inputPR.base.repo.git_url.replace(/^git:(?:\/\/)?/, "https://")]]
["git", ["remote", "add", "nonlocal", inputPR.base.repo.git_url]]
]);
remoteName = "nonlocal";
}

View file

@ -278,20 +278,22 @@ namespace ts {
}
export function getNodeId(node: Node): number {
if (!node.id) {
node.id = nextNodeId;
let id = node.id;
if (!id) {
node.id = id = nextNodeId;
nextNodeId++;
}
return node.id;
return id;
}
export function getSymbolId(symbol: Symbol): SymbolId {
if (!symbol.id) {
symbol.id = nextSymbolId;
let id = symbol.id;
if (!id) {
symbol.id = id = nextSymbolId;
nextSymbolId++;
}
return symbol.id;
return id;
}
export function isInstantiatedModule(node: ModuleDeclaration, preserveConstEnums: boolean) {
@ -3885,10 +3887,9 @@ namespace ts {
function getAlternativeContainingModules(symbol: Symbol, enclosingDeclaration: Node): Symbol[] {
const containingFile = getSourceFileOfNode(enclosingDeclaration);
const id = getNodeId(containingFile);
const links = getSymbolLinks(symbol);
let results: Symbol[] | undefined;
if (links.extendedContainersByFile && (results = links.extendedContainersByFile.get(id))) {
if (links.extendedContainersByFile && (results = links.extendedContainersByFile.get(containingFile))) {
return results;
}
if (containingFile && containingFile.imports) {
@ -3902,7 +3903,7 @@ namespace ts {
results = append(results, resolvedModule);
}
if (length(results)) {
(links.extendedContainersByFile || (links.extendedContainersByFile = new Map())).set(id, results!);
(links.extendedContainersByFile ||= new Map()).set(containingFile, results!);
return results!;
}
}
@ -5657,8 +5658,8 @@ namespace ts {
const expandedParams = getExpandedParameters(signature, /*skipUnionExpanding*/ true)[0];
// If the expanded parameter list had a variadic in a non-trailing position, don't expand it
const parameters = (some(expandedParams, p => p !== expandedParams[expandedParams.length - 1] && !!(getCheckFlags(p) & CheckFlags.RestParameter)) ? signature.parameters : expandedParams).map(parameter => symbolToParameterDeclaration(parameter, context, kind === SyntaxKind.Constructor, options?.privateSymbolVisitor, options?.bundledImports));
const thisParameter = tryGetThisParameterDeclaration(signature, context);
if (thisParameter) {
if (signature.thisParameter) {
const thisParameter = symbolToParameterDeclaration(signature.thisParameter, context);
parameters.unshift(thisParameter);
}
@ -5713,25 +5714,6 @@ namespace ts {
return node;
}
function tryGetThisParameterDeclaration(signature: Signature, context: NodeBuilderContext) {
if (signature.thisParameter) {
return symbolToParameterDeclaration(signature.thisParameter, context);
}
if (signature.declaration) {
const thisTag = getJSDocThisTag(signature.declaration);
if (thisTag && thisTag.typeExpression) {
return factory.createParameterDeclaration(
/* decorators */ undefined,
/* modifiers */ undefined,
/* dotDotDotToken */ undefined,
"this",
/* questionToken */ undefined,
typeToTypeNodeHelper(getTypeFromTypeNode(thisTag.typeExpression), context)
);
}
}
}
function typeParameterToDeclarationWithConstraint(type: TypeParameter, context: NodeBuilderContext, constraintNode: TypeNode | undefined): TypeParameterDeclaration {
const savedContextFlags = context.flags;
context.flags &= ~NodeBuilderFlags.WriteTypeParametersInQualifiedName; // Avoids potential infinite loop when building for a claimspace with a generic
@ -6223,8 +6205,12 @@ namespace ts {
firstChar = symbolName.charCodeAt(0);
}
let expression: Expression | undefined;
if (isSingleOrDoubleQuote(firstChar) && !(symbol.flags & SymbolFlags.EnumMember)) {
expression = factory.createStringLiteral(stripQuotes(symbolName).replace(/\\./g, s => s.substring(1)), firstChar === CharacterCodes.singleQuote);
if (isSingleOrDoubleQuote(firstChar)) {
expression = factory.createStringLiteral(
symbolName
.substring(1, symbolName.length - 1)
.replace(/\\./g, s => s.substring(1)),
firstChar === CharacterCodes.singleQuote);
}
else if (("" + +symbolName) === symbolName) {
expression = factory.createNumericLiteral(+symbolName);
@ -8559,16 +8545,12 @@ namespace ts {
/** Return the inferred type for a binding element */
function getTypeForBindingElement(declaration: BindingElement): Type | undefined {
const parentType = getTypeForBindingElementParent(declaration.parent.parent);
return parentType && getBindingElementTypeFromParentType(declaration, parentType);
}
function getBindingElementTypeFromParentType(declaration: BindingElement, parentType: Type): Type {
// If an any type was inferred for parent, infer that for the binding element
if (isTypeAny(parentType)) {
const pattern = declaration.parent;
let parentType = getTypeForBindingElementParent(pattern.parent);
// If no type or an any type was inferred for parent, infer that for the binding element
if (!parentType || isTypeAny(parentType)) {
return parentType;
}
const pattern = declaration.parent;
// Relax null check on ambient destructuring parameters, since the parameters have no implementation and are just documentation
if (strictNullChecks && declaration.flags & NodeFlags.Ambient && isParameterDeclaration(declaration)) {
parentType = getNonNullableType(parentType);
@ -14172,7 +14154,6 @@ namespace ts {
// We ignore 'never' types in unions
if (!(flags & TypeFlags.Never)) {
includes |= flags & TypeFlags.IncludesMask;
if (flags & TypeFlags.Instantiable) includes |= TypeFlags.IncludesInstantiable;
if (type === wildcardType) includes |= TypeFlags.IncludesWildcard;
if (!strictNullChecks && flags & TypeFlags.Nullable) {
if (!(getObjectFlags(type) & ObjectFlags.ContainsWideningType)) includes |= TypeFlags.IncludesNonWideningType;
@ -16028,7 +16009,7 @@ namespace ts {
const declarations = concatenate(leftProp.declarations, rightProp.declarations);
const flags = SymbolFlags.Property | (leftProp.flags & SymbolFlags.Optional);
const result = createSymbol(flags, leftProp.escapedName);
result.type = getUnionType([getTypeOfSymbol(leftProp), removeMissingOrUndefinedType(rightType)], UnionReduction.Subtype);
result.type = getUnionType([getTypeOfSymbol(leftProp), removeMissingOrUndefinedType(rightType)]);
result.leftSpread = leftProp;
result.rightSpread = rightProp;
result.declarations = declarations;
@ -16624,8 +16605,7 @@ namespace ts {
if (t.flags & (TypeFlags.AnyOrUnknown | TypeFlags.InstantiableNonPrimitive | TypeFlags.Object | TypeFlags.Intersection) && t !== wildcardType && !isErrorType(t)) {
if (!type.declaration.nameType) {
let constraint;
if (isArrayType(t) || t.flags & TypeFlags.Any && findResolutionCycleStartIndex(typeVariable, TypeSystemPropertyName.ImmediateBaseConstraint) < 0 &&
(constraint = getConstraintOfTypeParameter(typeVariable)) && everyType(constraint, or(isArrayType, isTupleType))) {
if (isArrayType(t) || (t.flags & TypeFlags.Any) && (constraint = getConstraintOfTypeParameter(typeVariable)) && everyType(constraint, or(isArrayType, isTupleType))) {
return instantiateMappedArrayType(t, type, prependTypeMapping(typeVariable, t, mapper));
}
if (isGenericTupleType(t)) {
@ -17823,7 +17803,7 @@ namespace ts {
if (source.flags & TypeFlags.Singleton) return true;
}
if (source.flags & TypeFlags.Object && target.flags & TypeFlags.Object) {
const related = relation.get(getRelationKey(source, target, IntersectionState.None, relation, /*ignoreConstraints*/ false));
const related = relation.get(getRelationKey(source, target, IntersectionState.None, relation));
if (related !== undefined) {
return !!(related & RelationComparisonResult.Succeeded);
}
@ -18723,8 +18703,7 @@ namespace ts {
if (overflow) {
return Ternary.False;
}
const keyIntersectionState = intersectionState | (inPropertyCheck ? IntersectionState.InPropertyCheck : 0);
const id = getRelationKey(source, target, keyIntersectionState, relation, /*ingnoreConstraints*/ false);
const id = getRelationKey(source, target, intersectionState | (inPropertyCheck ? IntersectionState.InPropertyCheck : 0), relation);
const entry = relation.get(id);
if (entry !== undefined) {
if (reportErrors && entry & RelationComparisonResult.Failed && !(entry & RelationComparisonResult.Reported)) {
@ -18751,13 +18730,16 @@ namespace ts {
targetStack = [];
}
else {
// A key that starts with "*" is an indication that we have type references that reference constrained
// type parameters. For such keys we also check against the key we would have gotten if all type parameters
// were unconstrained.
const broadestEquivalentId = id.startsWith("*") ? getRelationKey(source, target, keyIntersectionState, relation, /*ignoreConstraints*/ true) : undefined;
// generate a key where all type parameter id positions are replaced with unconstrained type parameter ids
// this isn't perfect - nested type references passed as type arguments will muck up the indexes and thus
// prevent finding matches- but it should hit up the common cases
const broadestEquivalentId = id.split(",").map(i => i.replace(/-\d+/g, (_match, offset: number) => {
const index = length(id.slice(0, offset).match(/[-=]/g) || undefined);
return `=${index}`;
})).join(",");
for (let i = 0; i < maybeCount; i++) {
// If source and target are already being compared, consider them related with assumptions
if (id === maybeKeys[i] || broadestEquivalentId && broadestEquivalentId === maybeKeys[i]) {
if (id === maybeKeys[i] || broadestEquivalentId === maybeKeys[i]) {
return Ternary.Maybe;
}
}
@ -19064,7 +19046,7 @@ namespace ts {
originalErrorInfo = undefined;
}
}
else if (isGenericMappedType(target) && relation !== identityRelation) {
else if (isGenericMappedType(target)) {
// Check if source type `S` is related to target type `{ [P in Q]: T }` or `{ [P in Q as R]: T}`.
const keysRemapped = !!target.declaration.nameType;
const templateType = getTemplateTypeFromMappedType(target);
@ -20312,55 +20294,47 @@ namespace ts {
return isNonDeferredTypeReference(type) && some(getTypeArguments(type), t => !!(t.flags & TypeFlags.TypeParameter) || isTypeReferenceWithGenericArguments(t));
}
function getGenericTypeReferenceRelationKey(source: TypeReference, target: TypeReference, postFix: string, ignoreConstraints: boolean) {
const typeParameters: Type[] = [];
let constraintMarker = "";
const sourceId = getTypeReferenceId(source, 0);
const targetId = getTypeReferenceId(target, 0);
return `${constraintMarker}${sourceId},${targetId}${postFix}`;
// getTypeReferenceId(A<T, number, U>) returns "111=0-12=1"
// where A.id=111 and number.id=12
function getTypeReferenceId(type: TypeReference, depth = 0) {
let result = "" + type.target.id;
for (const t of getTypeArguments(type)) {
if (t.flags & TypeFlags.TypeParameter) {
if (ignoreConstraints || isUnconstrainedTypeParameter(t)) {
let index = typeParameters.indexOf(t);
if (index < 0) {
index = typeParameters.length;
typeParameters.push(t);
}
result += "=" + index;
continue;
}
// We mark type references that reference constrained type parameters such that we know to obtain
// and look for a "broadest equivalent key" in the cache.
constraintMarker = "*";
}
else if (depth < 4 && isTypeReferenceWithGenericArguments(t)) {
result += "<" + getTypeReferenceId(t as TypeReference, depth + 1) + ">";
continue;
/**
* getTypeReferenceId(A<T, number, U>) returns "111=0-12=1"
* where A.id=111 and number.id=12
*/
function getTypeReferenceId(type: TypeReference, typeParameters: Type[], depth = 0) {
let result = "" + type.target.id;
for (const t of getTypeArguments(type)) {
if (isUnconstrainedTypeParameter(t)) {
let index = typeParameters.indexOf(t);
if (index < 0) {
index = typeParameters.length;
typeParameters.push(t);
}
result += "=" + index;
}
else if (depth < 4 && isTypeReferenceWithGenericArguments(t)) {
result += "<" + getTypeReferenceId(t as TypeReference, typeParameters, depth + 1) + ">";
}
else {
result += "-" + t.id;
}
return result;
}
return result;
}
/**
* To improve caching, the relation key for two generic types uses the target's id plus ids of the type parameters.
* For other cases, the types ids are used.
*/
function getRelationKey(source: Type, target: Type, intersectionState: IntersectionState, relation: ESMap<string, RelationComparisonResult>, ignoreConstraints: boolean) {
function getRelationKey(source: Type, target: Type, intersectionState: IntersectionState, relation: ESMap<string, RelationComparisonResult>) {
if (relation === identityRelation && source.id > target.id) {
const temp = source;
source = target;
target = temp;
}
const postFix = intersectionState ? ":" + intersectionState : "";
return isTypeReferenceWithGenericArguments(source) && isTypeReferenceWithGenericArguments(target) ?
getGenericTypeReferenceRelationKey(source as TypeReference, target as TypeReference, postFix, ignoreConstraints) :
`${source.id},${target.id}${postFix}`;
if (isTypeReferenceWithGenericArguments(source) && isTypeReferenceWithGenericArguments(target)) {
const typeParameters: Type[] = [];
return getTypeReferenceId(source as TypeReference, typeParameters) + "," + getTypeReferenceId(target as TypeReference, typeParameters) + postFix;
}
return source.id + "," + target.id + postFix;
}
// Invoke the callback for each underlying property symbol of the given symbol and return the first
@ -20414,34 +20388,27 @@ namespace ts {
}
// Return true if the given type is deeply nested. We consider this to be the case when structural type comparisons
// for maxDepth or more occurrences or instantiations of the type have been recorded on the given stack. It is possible,
// for 5 or more occurrences or instantiations of the type have been recorded on the given stack. It is possible,
// though highly unlikely, for this test to be true in a situation where a chain of instantiations is not infinitely
// expanding. Effectively, we will generate a false positive when two types are structurally equal to at least maxDepth
// expanding. Effectively, we will generate a false positive when two types are structurally equal to at least 5
// levels, but unequal at some level beyond that.
// In addition, this will also detect when an indexed access has been chained off of maxDepth more times (which is
// essentially the dual of the structural comparison), and likewise mark the type as deeply nested, potentially adding
// false positives for finite but deeply expanding indexed accesses (eg, for `Q[P1][P2][P3][P4][P5]`).
// It also detects when a recursive type reference has expanded maxDepth or more times, e.g. if the true branch of
// In addition, this will also detect when an indexed access has been chained off of 5 or more times (which is essentially
// the dual of the structural comparison), and likewise mark the type as deeply nested, potentially adding false positives
// for finite but deeply expanding indexed accesses (eg, for `Q[P1][P2][P3][P4][P5]`).
// It also detects when a recursive type reference has expanded 5 or more times, eg, if the true branch of
// `type A<T> = null extends T ? [A<NonNullable<T>>] : [T]`
// has expanded into `[A<NonNullable<NonNullable<NonNullable<NonNullable<NonNullable<T>>>>>>]`. In such cases we need
// to terminate the expansion, and we do so here.
function isDeeplyNestedType(type: Type, stack: Type[], depth: number, maxDepth = 3): boolean {
// has expanded into `[A<NonNullable<NonNullable<NonNullable<NonNullable<NonNullable<T>>>>>>]`
// in such cases we need to terminate the expansion, and we do so here.
function isDeeplyNestedType(type: Type, stack: Type[], depth: number, maxDepth = 5): boolean {
if (depth >= maxDepth) {
const identity = getRecursionIdentity(type);
let count = 0;
let lastTypeId = 0;
for (let i = 0; i < depth; i++) {
const t = stack[i];
if (getRecursionIdentity(t) === identity) {
// We only count occurrences with a higher type id than the previous occurrence, since higher
// type ids are an indicator of newer instantiations caused by recursion.
if (t.id >= lastTypeId) {
count++;
if (count >= maxDepth) {
return true;
}
if (getRecursionIdentity(stack[i]) === identity) {
count++;
if (count >= maxDepth) {
return true;
}
lastTypeId = t.id;
}
}
}
@ -21236,10 +21203,9 @@ namespace ts {
(isCallSignatureDeclaration(param.parent) || isMethodSignature(param.parent) || isFunctionTypeNode(param.parent)) &&
param.parent.parameters.indexOf(param) > -1 &&
(resolveName(param, param.name.escapedText, SymbolFlags.Type, undefined, param.name.escapedText, /*isUse*/ true) ||
param.name.originalKeywordKind && isTypeNodeKind(param.name.originalKeywordKind))) {
param.name.originalKeywordKind && isTypeNodeKind(param.name.originalKeywordKind))) {
const newName = "arg" + param.parent.parameters.indexOf(param);
const typeName = declarationNameToString(param.name) + (param.dotDotDotToken ? "[]" : "");
errorOrSuggestion(noImplicitAny, declaration, Diagnostics.Parameter_has_a_name_but_no_type_Did_you_mean_0_Colon_1, newName, typeName);
errorOrSuggestion(noImplicitAny, declaration, Diagnostics.Parameter_has_a_name_but_no_type_Did_you_mean_0_Colon_1, newName, declarationNameToString(param.name));
return;
}
diagnostic = (declaration as ParameterDeclaration).dotDotDotToken ?
@ -22653,6 +22619,30 @@ namespace ts {
return false;
}
function getPropertyAccess(expr: Expression) {
if (isAccessExpression(expr)) {
return expr;
}
if (isIdentifier(expr)) {
const symbol = getResolvedSymbol(expr);
if (isConstVariable(symbol)) {
const declaration = symbol.valueDeclaration!;
// Given 'const x = obj.kind', allow 'x' as an alias for 'obj.kind'
if (isVariableDeclaration(declaration) && !declaration.type && declaration.initializer && isAccessExpression(declaration.initializer)) {
return declaration.initializer;
}
// Given 'const { kind: x } = obj', allow 'x' as an alias for 'obj.kind'
if (isBindingElement(declaration) && !declaration.initializer) {
const parent = declaration.parent.parent;
if (isVariableDeclaration(parent) && !parent.type && parent.initializer && (isIdentifier(parent.initializer) || isAccessExpression(parent.initializer))) {
return declaration;
}
}
}
}
return undefined;
}
function getAccessedPropertyName(access: AccessExpression | BindingElement): __String | undefined {
let propertyName;
return access.kind === SyntaxKind.PropertyAccessExpression ? access.name.escapedText :
@ -23622,19 +23612,19 @@ namespace ts {
return false;
}
function getFlowTypeOfReference(reference: Node, declaredType: Type, initialType = declaredType, flowContainer?: Node, flowNode = reference.flowNode) {
function getFlowTypeOfReference(reference: Node, declaredType: Type, initialType = declaredType, flowContainer?: Node) {
let key: string | undefined;
let isKeySet = false;
let flowDepth = 0;
if (flowAnalysisDisabled) {
return errorType;
}
if (!flowNode) {
if (!reference.flowNode) {
return declaredType;
}
flowInvocationCount++;
const sharedFlowStart = sharedFlowCount;
const evolvedType = getTypeFromFlowType(getTypeAtFlowNode(flowNode));
const evolvedType = getTypeFromFlowType(getTypeAtFlowNode(reference.flowNode));
sharedFlowCount = sharedFlowStart;
// When the reference is 'x' in an 'x.length', 'x.push(value)', 'x.unshift(value)' or x[n] = value' operation,
// we give type 'any[]' to 'x' instead of using the type determined by control flow analysis such that operations
@ -24078,58 +24068,13 @@ namespace ts {
return result;
}
function getCandidateDiscriminantPropertyAccess(expr: Expression) {
if (isBindingPattern(reference)) {
// When the reference is a binding pattern, we are narrowing a pesudo-reference in getNarrowedTypeOfSymbol.
// An identifier for a destructuring variable declared in the same binding pattern is a candidate.
if (isIdentifier(expr)) {
const symbol = getResolvedSymbol(expr);
const declaration = symbol.valueDeclaration;
if (declaration && isBindingElement(declaration) && !declaration.initializer && !declaration.dotDotDotToken && reference === declaration.parent) {
return declaration;
}
}
}
else if (isAccessExpression(expr)) {
// An access expression is a candidate if the reference matches the left hand expression.
if (isMatchingReference(reference, expr.expression)) {
return expr;
}
}
else if (isIdentifier(expr)) {
const symbol = getResolvedSymbol(expr);
if (isConstVariable(symbol)) {
const declaration = symbol.valueDeclaration!;
// Given 'const x = obj.kind', allow 'x' as an alias for 'obj.kind'
if (isVariableDeclaration(declaration) && !declaration.type && declaration.initializer && isAccessExpression(declaration.initializer) &&
isMatchingReference(reference, declaration.initializer.expression)) {
return declaration.initializer;
}
// Given 'const { kind: x } = obj', allow 'x' as an alias for 'obj.kind'
if (isBindingElement(declaration) && !declaration.initializer) {
const parent = declaration.parent.parent;
if (isVariableDeclaration(parent) && !parent.type && parent.initializer && (isIdentifier(parent.initializer) || isAccessExpression(parent.initializer)) &&
isMatchingReference(reference, parent.initializer)) {
return declaration;
}
}
}
}
return undefined;
}
function getDiscriminantPropertyAccess(expr: Expression, computedType: Type) {
let access, name;
const type = declaredType.flags & TypeFlags.Union ? declaredType : computedType;
if (type.flags & TypeFlags.Union) {
const access = getCandidateDiscriminantPropertyAccess(expr);
if (access) {
const name = getAccessedPropertyName(access);
if (name && isDiscriminantProperty(type, name)) {
return access;
}
}
}
return undefined;
return type.flags & TypeFlags.Union && (access = getPropertyAccess(expr)) && (name = getAccessedPropertyName(access)) &&
isMatchingReference(reference, isAccessExpression(access) ? access.expression : access.parent.parent.initializer!) &&
isDiscriminantProperty(type, name) ?
access : undefined;
}
function narrowTypeByDiscriminant(type: Type, access: AccessExpression | BindingElement, narrowType: (t: Type) => Type): Type {
@ -24942,50 +24887,6 @@ namespace ts {
}
}
function getNarrowedTypeOfSymbol(symbol: Symbol, location: Identifier) {
// If we have a non-rest binding element with no initializer declared as a const variable or a const-like
// parameter (a parameter for which there are no assignments in the function body), and if the parent type
// for the destructuring is a union type, one or more of the binding elements may represent discriminant
// properties, and we want the effects of conditional checks on such discriminants to affect the types of
// other binding elements from the same destructuring. Consider:
//
// type Action =
// | { kind: 'A', payload: number }
// | { kind: 'B', payload: string };
//
// function f1({ kind, payload }: Action) {
// if (kind === 'A') {
// payload.toFixed();
// }
// if (kind === 'B') {
// payload.toUpperCase();
// }
// }
//
// Above, we want the conditional checks on 'kind' to affect the type of 'payload'. To facilitate this, we use
// the binding pattern AST instance for '{ kind, payload }' as a pseudo-reference and narrow this reference
// as if it occurred in the specified location. We then recompute the narrowed binding element type by
// destructuring from the narrowed parent type.
const declaration = symbol.valueDeclaration;
if (declaration && isBindingElement(declaration) && !declaration.initializer && !declaration.dotDotDotToken && declaration.parent.elements.length >= 2) {
const parent = declaration.parent.parent;
if (parent.kind === SyntaxKind.VariableDeclaration && getCombinedNodeFlags(declaration) & NodeFlags.Const || parent.kind === SyntaxKind.Parameter) {
const links = getNodeLinks(location);
if (!(links.flags & NodeCheckFlags.InCheckIdentifier)) {
links.flags |= NodeCheckFlags.InCheckIdentifier;
const parentType = getTypeForBindingElementParent(parent);
links.flags &= ~NodeCheckFlags.InCheckIdentifier;
if (parentType && parentType.flags & TypeFlags.Union && !(parent.kind === SyntaxKind.Parameter && isSymbolAssigned(symbol))) {
const pattern = declaration.parent;
const narrowedType = getFlowTypeOfReference(pattern, parentType, parentType, /*flowContainer*/ undefined, location.flowNode);
return getBindingElementTypeFromParentType(declaration, narrowedType);
}
}
}
}
return getTypeOfSymbol(symbol);
}
function checkIdentifier(node: Identifier, checkMode: CheckMode | undefined): Type {
const symbol = getResolvedSymbol(node);
if (symbol === unknownSymbol) {
@ -25069,7 +24970,7 @@ namespace ts {
checkNestedBlockScopedBinding(node, symbol);
let type = getNarrowedTypeOfSymbol(localOrExportSymbol, node);
let type = getTypeOfSymbol(localOrExportSymbol);
const assignmentKind = getAssignmentTargetKind(node);
if (assignmentKind) {
@ -26207,12 +26108,12 @@ namespace ts {
return !!(getCheckFlags(symbol) & CheckFlags.Mapped && !(symbol as MappedSymbol).type && findResolutionCycleStartIndex(symbol, TypeSystemPropertyName.Type) >= 0);
}
function getTypeOfPropertyOfContextualType(type: Type, name: __String, nameType?: Type) {
function getTypeOfPropertyOfContextualType(type: Type, name: __String) {
return mapType(type, t => {
if (isGenericMappedType(t)) {
const constraint = getConstraintTypeFromMappedType(t);
const constraintOfConstraint = getBaseConstraintOfType(constraint) || constraint;
const propertyNameType = nameType || getStringLiteralType(unescapeLeadingUnderscores(name));
const propertyNameType = getStringLiteralType(unescapeLeadingUnderscores(name));
if (isTypeAssignableTo(propertyNameType, constraintOfConstraint)) {
return substituteIndexedMappedType(t, propertyNameType);
}
@ -26228,7 +26129,7 @@ namespace ts {
return restType;
}
}
return findApplicableIndexInfo(getIndexInfosOfStructuredType(t), nameType || getStringLiteralType(unescapeLeadingUnderscores(name)))?.type;
return findApplicableIndexInfo(getIndexInfosOfStructuredType(t), getStringLiteralType(unescapeLeadingUnderscores(name)))?.type;
}
return undefined;
}, /*noReductions*/ true);
@ -26258,8 +26159,7 @@ namespace ts {
// For a (non-symbol) computed property, there is no reason to look up the name
// in the type. It will just be "__computed", which does not appear in any
// SymbolTable.
const symbol = getSymbolOfNode(element);
return getTypeOfPropertyOfContextualType(type, symbol.escapedName, getSymbolLinks(symbol).nameType);
return getTypeOfPropertyOfContextualType(type, getSymbolOfNode(element).escapedName);
}
if (element.name) {
const nameType = getLiteralTypeFromPropertyName(element.name);
@ -33895,7 +33795,7 @@ namespace ts {
const type = checkExpression(node);
// If control flow analysis was required to determine the type, it is worth caching.
if (flowInvocationCount !== startInvocationCount) {
const cache = flowTypeCache || (flowTypeCache = []);
const cache = (flowTypeCache ||= []);
cache[getNodeId(node)] = type;
setNodeFlags(node, node.flags | NodeFlags.TypeCached);
}
@ -34829,8 +34729,7 @@ namespace ts {
function getTypeArgumentConstraint(node: TypeNode): Type | undefined {
const typeReferenceNode = tryCast(node.parent, isTypeReferenceType);
if (!typeReferenceNode) return undefined;
const typeParameters = getTypeParametersForTypeReference(typeReferenceNode);
if (!typeParameters) return undefined;
const typeParameters = getTypeParametersForTypeReference(typeReferenceNode)!; // TODO: GH#18217
const constraint = getConstraintOfTypeParameter(typeParameters[typeReferenceNode.typeArguments!.indexOf(node)]);
return constraint && instantiateType(constraint, createTypeMapper(typeParameters, getEffectiveTypeArguments(typeReferenceNode, typeParameters)));
}
@ -39780,12 +39679,8 @@ namespace ts {
function checkAssertClause(declaration: ImportDeclaration | ExportDeclaration) {
if (declaration.assertClause) {
const mode = (moduleKind === ModuleKind.NodeNext) && declaration.moduleSpecifier && getUsageModeForExpression(declaration.moduleSpecifier);
if (mode !== ModuleKind.ESNext && moduleKind !== ModuleKind.ESNext) {
return grammarErrorOnNode(declaration.assertClause,
moduleKind === ModuleKind.NodeNext
? Diagnostics.Import_assertions_are_not_allowed_on_statements_that_transpile_to_commonjs_require_calls
: Diagnostics.Import_assertions_are_only_supported_when_the_module_option_is_set_to_esnext_or_nodenext);
if (moduleKind !== ModuleKind.ESNext) {
return grammarErrorOnNode(declaration.assertClause, Diagnostics.Import_assertions_are_only_supported_when_the_module_option_is_set_to_esnext);
}
if (isImportDeclaration(declaration) ? declaration.importClause?.isTypeOnly : declaration.isTypeOnly) {
@ -40422,8 +40317,8 @@ namespace ts {
const enclosingFile = getSourceFileOfNode(node);
const links = getNodeLinks(enclosingFile);
if (!(links.flags & NodeCheckFlags.TypeChecked)) {
links.deferredNodes ||= new Set();
links.deferredNodes.add(node);
links.deferredNodes ||= [];
links.deferredNodes[getNodeId(node)] = node;
}
}
@ -41603,7 +41498,7 @@ namespace ts {
if (!symbol) {
return false;
}
const target = getExportSymbolOfValueSymbolIfExported(resolveAlias(symbol));
const target = resolveAlias(symbol);
if (target === unknownSymbol) {
return true;
}
@ -43076,7 +42971,8 @@ namespace ts {
// Modifiers are never allowed on properties except for 'async' on a method declaration
if (prop.modifiers) {
for (const mod of prop.modifiers) {
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
for (const mod of prop.modifiers!) { // TODO: GH#19955
if (mod.kind !== SyntaxKind.AsyncKeyword || prop.kind !== SyntaxKind.MethodDeclaration) {
grammarErrorOnNode(mod, Diagnostics._0_modifier_cannot_be_used_here, getTextOfNode(mod));
}
@ -43993,13 +43889,13 @@ namespace ts {
}
const nodeArguments = node.arguments;
if (moduleKind !== ModuleKind.ESNext && moduleKind !== ModuleKind.NodeNext) {
if (moduleKind !== ModuleKind.ESNext) {
// We are allowed trailing comma after proposal-import-assertions.
checkGrammarForDisallowedTrailingComma(nodeArguments);
if (nodeArguments.length > 1) {
const assertionArgument = nodeArguments[1];
return grammarErrorOnNode(assertionArgument, Diagnostics.Dynamic_imports_only_support_a_second_argument_when_the_module_option_is_set_to_esnext_or_nodenext);
return grammarErrorOnNode(assertionArgument, Diagnostics.Dynamic_imports_only_support_a_second_argument_when_the_module_option_is_set_to_esnext);
}
}

View file

@ -29,7 +29,6 @@ namespace ts {
["es2019", "lib.es2019.d.ts"],
["es2020", "lib.es2020.d.ts"],
["es2021", "lib.es2021.d.ts"],
["es2022", "lib.es2022.d.ts"],
["esnext", "lib.esnext.d.ts"],
// Host only
["dom", "lib.dom.d.ts"],
@ -73,16 +72,12 @@ namespace ts {
["es2021.string", "lib.es2021.string.d.ts"],
["es2021.weakref", "lib.es2021.weakref.d.ts"],
["es2021.intl", "lib.es2021.intl.d.ts"],
["es2022.array", "lib.es2022.array.d.ts"],
["es2022.error", "lib.es2022.error.d.ts"],
["es2022.object", "lib.es2022.object.d.ts"],
["es2022.string", "lib.es2022.string.d.ts"],
["esnext.array", "lib.es2022.array.d.ts"],
["esnext.array", "lib.es2019.array.d.ts"],
["esnext.symbol", "lib.es2019.symbol.d.ts"],
["esnext.asynciterable", "lib.es2018.asynciterable.d.ts"],
["esnext.intl", "lib.esnext.intl.d.ts"],
["esnext.bigint", "lib.es2020.bigint.d.ts"],
["esnext.string", "lib.es2022.string.d.ts"],
["esnext.string", "lib.es2021.string.d.ts"],
["esnext.promise", "lib.es2021.promise.d.ts"],
["esnext.weakref", "lib.es2021.weakref.d.ts"]
];
@ -319,7 +314,6 @@ namespace ts {
es2019: ScriptTarget.ES2019,
es2020: ScriptTarget.ES2020,
es2021: ScriptTarget.ES2021,
es2022: ScriptTarget.ES2022,
esnext: ScriptTarget.ESNext,
})),
affectsSourceFile: true,

View file

@ -23,6 +23,34 @@ namespace ts {
export const emptyMap: ReadonlyESMap<never, never> = new Map<never, never>();
export const emptySet: ReadonlySet<never> = new Set<never>();
/**
* Create a new map.
* @deprecated Use `new Map()` instead.
*/
export function createMap<K, V>(): ESMap<K, V>;
export function createMap<T>(): ESMap<string, T>;
export function createMap<K, V>(): ESMap<K, V> {
return new Map<K, V>();
}
/**
* Create a new map from a template object is provided, the map will copy entries from it.
* @deprecated Use `new Map(getEntries(template))` instead.
*/
export function createMapFromTemplate<T>(template: MapLike<T>): ESMap<string, T> {
const map: ESMap<string, T> = new Map<string, T>();
// Copies keys/values from template. Note that for..in will not throw if
// template is undefined, and instead will just exit the loop.
for (const key in template) {
if (hasOwnProperty.call(template, key)) {
map.set(key, template[key]);
}
}
return map;
}
export function length(array: readonly any[] | undefined): number {
return array ? array.length : 0;
}

View file

@ -1,7 +1,7 @@
namespace ts {
// WARNING: The script `configurePrerelease.ts` uses a regexp to parse out these values.
// If changing the text in this section, be sure to test `configurePrerelease` too.
export const versionMajorMinor = "4.6";
export const versionMajorMinor = "4.5";
// The following is baselined as a literal template type without intervention
/** The version of the TypeScript compiler release */
// eslint-disable-next-line @typescript-eslint/no-inferrable-types

View file

@ -171,6 +171,12 @@ namespace ts {
return value;
}
/**
* @deprecated Use `checkDefined` to check whether a value is defined inline. Use `assertIsDefined` to check whether
* a value is defined at the statement level.
*/
export const assertDefined = checkDefined;
export function assertEachIsDefined<T extends Node>(value: NodeArray<T>, message?: string, stackCrawlMark?: AnyFunction): asserts value is NodeArray<T>;
export function assertEachIsDefined<T>(value: readonly T[], message?: string, stackCrawlMark?: AnyFunction): asserts value is readonly NonNullable<T>[];
export function assertEachIsDefined<T>(value: readonly T[], message?: string, stackCrawlMark?: AnyFunction) {
@ -184,6 +190,12 @@ namespace ts {
return value;
}
/**
* @deprecated Use `checkEachDefined` to check whether the elements of an array are defined inline. Use `assertEachIsDefined` to check whether
* the elements of an array are defined at the statement level.
*/
export const assertEachDefined = checkEachDefined;
export function assertNever(member: never, message = "Illegal value:", stackCrawlMark?: AnyFunction): never {
const detail = typeof member === "object" && hasProperty(member, "kind") && hasProperty(member, "pos") && formatSyntaxKind ? "SyntaxKind: " + formatSyntaxKind((member as Node).kind) : JSON.stringify(member);
return fail(`${message} ${detail}`, stackCrawlMark || assertNever);

View file

@ -924,7 +924,7 @@
"category": "Error",
"code": 1323
},
"Dynamic imports only support a second argument when the '--module' option is set to 'esnext' or 'nodenext'.": {
"Dynamic imports only support a second argument when the '--module' option is set to 'esnext'.": {
"category": "Error",
"code": 1324
},
@ -3333,7 +3333,7 @@
"category": "Error",
"code": 2820
},
"Import assertions are only supported when the '--module' option is set to 'esnext' or 'nodenext'.": {
"Import assertions are only supported when the '--module' option is set to 'esnext'.": {
"category": "Error",
"code": 2821
},
@ -3353,10 +3353,6 @@
"category": "Error",
"code": 2835
},
"Import assertions are not allowed on statements that transpile to commonjs 'require' calls.": {
"category": "Error",
"code": 2836
},
"Import declaration '{0}' is using private name '{1}'.": {
"category": "Error",
@ -6437,11 +6433,6 @@
"category": "Message",
"code": 90053
},
"Includes imports of types referenced by '{0}'": {
"category": "Message",
"code": 90054
},
"Convert function to an ES2015 class": {
"category": "Message",
"code": 95001

View file

@ -1604,7 +1604,6 @@ namespace ts {
return emitJSDocSignature(node as JSDocSignature);
case SyntaxKind.JSDocTag:
case SyntaxKind.JSDocClassTag:
case SyntaxKind.JSDocOverrideTag:
return emitJSDocSimpleTag(node as JSDocTag);
case SyntaxKind.JSDocAugmentsTag:
case SyntaxKind.JSDocImplementsTag:
@ -1617,6 +1616,7 @@ namespace ts {
case SyntaxKind.JSDocPrivateTag:
case SyntaxKind.JSDocProtectedTag:
case SyntaxKind.JSDocReadonlyTag:
case SyntaxKind.JSDocOverrideTag:
return;
case SyntaxKind.JSDocCallbackTag:
return emitJSDocCallbackTag(node as JSDocCallbackTag);

View file

@ -6387,7 +6387,7 @@ namespace ts {
sourceMapText = mapTextOrStripInternal as string;
}
const node = oldFileOfCurrentEmit ?
parseOldFileOfCurrentEmit(Debug.checkDefined(bundleFileInfo)) :
parseOldFileOfCurrentEmit(Debug.assertDefined(bundleFileInfo)) :
parseUnparsedSourceFile(bundleFileInfo, stripInternal, length);
node.fileName = fileName;
node.sourceMapPath = sourceMapPath;
@ -6587,13 +6587,13 @@ namespace ts {
};
node.javascriptPath = declarationTextOrJavascriptPath;
node.javascriptMapPath = javascriptMapPath;
node.declarationPath = Debug.checkDefined(javascriptMapTextOrDeclarationPath);
node.declarationPath = Debug.assertDefined(javascriptMapTextOrDeclarationPath);
node.declarationMapPath = declarationMapPath;
node.buildInfoPath = declarationMapTextOrBuildInfoPath;
Object.defineProperties(node, {
javascriptText: { get() { return definedTextGetter(declarationTextOrJavascriptPath); } },
javascriptMapText: { get() { return textGetter(javascriptMapPath); } }, // TODO:: if there is inline sourceMap in jsFile, use that
declarationText: { get() { return definedTextGetter(Debug.checkDefined(javascriptMapTextOrDeclarationPath)); } },
declarationText: { get() { return definedTextGetter(Debug.assertDefined(javascriptMapTextOrDeclarationPath)); } },
declarationMapText: { get() { return textGetter(declarationMapPath); } }, // TODO:: if there is inline sourceMap in dtsFile, use that
buildInfo: { get() { return getAndCacheBuildInfo(() => textGetter(declarationMapTextOrBuildInfoPath)); } }
});

View file

@ -707,15 +707,13 @@ namespace ts.moduleSpecifiers {
if (host.fileExists(packageJsonPath)) {
const packageJsonContent = JSON.parse(host.readFile!(packageJsonPath)!);
// TODO: Inject `require` or `import` condition based on the intended import mode
if (getEmitModuleResolutionKind(options) === ModuleResolutionKind.Node12 || getEmitModuleResolutionKind(options) === ModuleResolutionKind.NodeNext) {
const fromExports = packageJsonContent.exports && typeof packageJsonContent.name === "string" ? tryGetModuleNameFromExports(options, path, packageRootPath, packageJsonContent.name, packageJsonContent.exports, ["node", "types"]) : undefined;
if (fromExports) {
const withJsExtension = !hasTSFileExtension(fromExports.moduleFileToTry) ? fromExports : { moduleFileToTry: removeFileExtension(fromExports.moduleFileToTry) + tryGetJSExtensionForFile(fromExports.moduleFileToTry, options) };
return { ...withJsExtension, verbatimFromExports: true };
}
if (packageJsonContent.exports) {
return { moduleFileToTry: path, blockedByExports: true };
}
const fromExports = packageJsonContent.exports && typeof packageJsonContent.name === "string" ? tryGetModuleNameFromExports(options, path, packageRootPath, packageJsonContent.name, packageJsonContent.exports, ["node", "types"]) : undefined;
if (fromExports) {
const withJsExtension = !hasTSFileExtension(fromExports.moduleFileToTry) ? fromExports : { moduleFileToTry: removeFileExtension(fromExports.moduleFileToTry) + tryGetJSExtensionForFile(fromExports.moduleFileToTry, options) };
return { ...withJsExtension, verbatimFromExports: true };
}
if (packageJsonContent.exports) {
return { moduleFileToTry: path, blockedByExports: true };
}
const versionPaths = packageJsonContent.typesVersions
? getPackageJsonTypesVersionsPaths(packageJsonContent.typesVersions)

View file

@ -818,25 +818,6 @@ namespace ts {
}
}
/** @internal */
export const plainJSErrors: Set<number> = new Set([
Diagnostics.Cannot_redeclare_block_scoped_variable_0.code,
Diagnostics.A_module_cannot_have_multiple_default_exports.code,
Diagnostics.Another_export_default_is_here.code,
Diagnostics.The_first_export_default_is_here.code,
Diagnostics.Identifier_expected_0_is_a_reserved_word_at_the_top_level_of_a_module.code,
Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode_Modules_are_automatically_in_strict_mode.code,
Diagnostics.Identifier_expected_0_is_a_reserved_word_that_cannot_be_used_here.code,
Diagnostics.constructor_is_a_reserved_word.code,
Diagnostics.delete_cannot_be_called_on_an_identifier_in_strict_mode.code,
Diagnostics.Code_contained_in_a_class_is_evaluated_in_JavaScript_s_strict_mode_which_does_not_allow_this_use_of_0_For_more_information_see_https_Colon_Slash_Slashdeveloper_mozilla_org_Slashen_US_Slashdocs_SlashWeb_SlashJavaScript_SlashReference_SlashStrict_mode.code,
Diagnostics.Invalid_use_of_0_Modules_are_automatically_in_strict_mode.code,
Diagnostics.Invalid_use_of_0_in_strict_mode.code,
Diagnostics.A_label_is_not_allowed_here.code,
Diagnostics.Octal_literals_are_not_allowed_in_strict_mode.code,
Diagnostics.with_statements_are_not_allowed_in_strict_mode.code,
]);
/**
* Determine if source file needs to be re-created even if its text hasn't changed
*/
@ -1596,7 +1577,6 @@ namespace ts {
newSourceFile.originalFileName = oldSourceFile.originalFileName;
newSourceFile.resolvedPath = oldSourceFile.resolvedPath;
newSourceFile.fileName = oldSourceFile.fileName;
newSourceFile.impliedNodeFormat = oldSourceFile.impliedNodeFormat;
const packageName = oldProgram.sourceFileToPackageName.get(oldSourceFile.path);
if (packageName !== undefined) {
@ -1694,8 +1674,8 @@ namespace ts {
const typesReferenceDirectives = map(newSourceFile.typeReferenceDirectives, ref => toFileNameLowerCase(ref.fileName));
const typeReferenceResolutions = resolveTypeReferenceDirectiveNamesWorker(typesReferenceDirectives, newSourceFile);
// ensure that types resolutions are still correct
const typeReferenceResolutionsChanged = hasChangesInResolutions(typesReferenceDirectives, typeReferenceResolutions, oldSourceFile.resolvedTypeReferenceDirectiveNames, oldSourceFile, typeDirectiveIsEqualTo);
if (typeReferenceResolutionsChanged) {
const typeReferenceEesolutionsChanged = hasChangesInResolutions(typesReferenceDirectives, typeReferenceResolutions, oldSourceFile.resolvedTypeReferenceDirectiveNames, oldSourceFile, typeDirectiveIsEqualTo);
if (typeReferenceEesolutionsChanged) {
structureIsReused = StructureIsReused.SafeModules;
newSourceFile.resolvedTypeReferenceDirectiveNames = zipToModeAwareCache(newSourceFile, typesReferenceDirectives, typeReferenceResolutions);
}
@ -2024,24 +2004,15 @@ namespace ts {
Debug.assert(!!sourceFile.bindDiagnostics);
const isJs = sourceFile.scriptKind === ScriptKind.JS || sourceFile.scriptKind === ScriptKind.JSX;
const isCheckJs = isJs && isCheckJsEnabledForFile(sourceFile, options);
const isPlainJs = isJs && !sourceFile.checkJsDirective && options.checkJs === undefined;
const isCheckJs = isCheckJsEnabledForFile(sourceFile, options);
const isTsNoCheck = !!sourceFile.checkJsDirective && sourceFile.checkJsDirective.enabled === false;
// By default, only type-check .ts, .tsx, Deferred, plain JS, checked JS and External
// - plain JS: .js files with no // ts-check and checkJs: undefined
// - check JS: .js files with either // ts-check or checkJs: true
// - external: files that are added by plugins
// By default, only type-check .ts, .tsx, 'Deferred' and 'External' files (external files are added by plugins)
const includeBindAndCheckDiagnostics = !isTsNoCheck && (sourceFile.scriptKind === ScriptKind.TS || sourceFile.scriptKind === ScriptKind.TSX
|| sourceFile.scriptKind === ScriptKind.External || isPlainJs || isCheckJs || sourceFile.scriptKind === ScriptKind.Deferred);
let bindDiagnostics: readonly Diagnostic[] = includeBindAndCheckDiagnostics ? sourceFile.bindDiagnostics : emptyArray;
const checkDiagnostics = includeBindAndCheckDiagnostics && !isPlainJs ? typeChecker.getDiagnostics(sourceFile, cancellationToken) : emptyArray;
if (isPlainJs) {
bindDiagnostics = filter(bindDiagnostics, d => plainJSErrors.has(d.code));
}
// skip ts-expect-error errors in plain JS files, and skip JSDoc errors except in checked JS
return getMergedBindAndCheckDiagnostics(sourceFile, includeBindAndCheckDiagnostics && !isPlainJs, bindDiagnostics, checkDiagnostics, isCheckJs ? sourceFile.jsDocDiagnostics : undefined);
|| sourceFile.scriptKind === ScriptKind.External || isCheckJs || sourceFile.scriptKind === ScriptKind.Deferred);
const bindDiagnostics: readonly Diagnostic[] = includeBindAndCheckDiagnostics ? sourceFile.bindDiagnostics : emptyArray;
const checkDiagnostics = includeBindAndCheckDiagnostics ? typeChecker.getDiagnostics(sourceFile, cancellationToken) : emptyArray;
return getMergedBindAndCheckDiagnostics(sourceFile, includeBindAndCheckDiagnostics, bindDiagnostics, checkDiagnostics, isCheckJs ? sourceFile.jsDocDiagnostics : undefined);
});
}
@ -3189,7 +3160,7 @@ namespace ts {
}
function verifyCompilerOptions() {
const isNightly = stringContains(version, "-dev") || stringContains(version, "-insiders");
const isNightly = stringContains(version, "-dev");
if (!isNightly) {
if (getEmitModuleKind(options) === ModuleKind.Node12) {
createOptionValueDiagnostic("module", Diagnostics.Compiler_option_0_of_value_1_is_unstable_Use_nightly_TypeScript_to_silence_this_error_Try_updating_with_npm_install_D_typescript_next, "module", "node12");

View file

@ -66,7 +66,6 @@ namespace ts {
getCurrentProgram(): Program | undefined;
fileIsOpen(filePath: Path): boolean;
getCompilerHost?(): CompilerHost | undefined;
onDiscoveredSymlink?(): void;
}
interface DirectoryWatchesOfFailedLookup {
@ -432,9 +431,6 @@ namespace ts {
else {
resolution = loader(name, containingFile, compilerOptions, resolutionHost.getCompilerHost?.() || resolutionHost, redirectedReference, containingSourceFile);
perDirectoryResolution.set(name, mode, resolution);
if (resolutionHost.onDiscoveredSymlink && resolutionIsSymlink(resolution)) {
resolutionHost.onDiscoveredSymlink();
}
}
resolutionsInFile.set(name, mode, resolution);
watchFailedLookupLocationsOfExternalModuleResolutions(name, resolution, path, getResolutionWithResolvedFileName);
@ -619,7 +615,7 @@ namespace ts {
) {
if (resolution.refCount) {
resolution.refCount++;
Debug.assertIsDefined(resolution.files);
Debug.assertDefined(resolution.files);
}
else {
resolution.refCount = 1;
@ -696,7 +692,7 @@ namespace ts {
filePath: Path,
getResolutionWithResolvedFileName: GetResolutionWithResolvedFileName<T, R>,
) {
unorderedRemoveItem(Debug.checkDefined(resolution.files), filePath);
unorderedRemoveItem(Debug.assertDefined(resolution.files), filePath);
resolution.refCount!--;
if (resolution.refCount) {
return;
@ -798,7 +794,7 @@ namespace ts {
for (const resolution of resolutions) {
if (resolution.isInvalidated || !canInvalidate(resolution)) continue;
resolution.isInvalidated = invalidated = true;
for (const containingFilePath of Debug.checkDefined(resolution.files)) {
for (const containingFilePath of Debug.assertDefined(resolution.files)) {
(filesWithInvalidatedResolutions || (filesWithInvalidatedResolutions = new Set())).add(containingFilePath);
// When its a file with inferred types resolution, invalidate type reference directive resolution
hasChangedAutomaticTypeDirectiveNames = hasChangedAutomaticTypeDirectiveNames || endsWith(containingFilePath, inferredTypesContainingFile);
@ -969,11 +965,4 @@ namespace ts {
return dirPath === rootPath || canWatchDirectory(dirPath);
}
}
function resolutionIsSymlink(resolution: ResolutionWithFailedLookupLocations) {
return !!(
(resolution as ResolvedModuleWithFailedLookupLocations).resolvedModule?.originalPath ||
(resolution as ResolvedTypeReferenceDirectiveWithFailedLookupLocations).resolvedTypeReferenceDirective?.originalPath
);
}
}

View file

@ -2374,7 +2374,6 @@ namespace ts {
tokenValue = tokenValue.slice(0, -1);
pos--;
}
return getIdentifierToken();
}
return token;
}

View file

@ -1625,6 +1625,7 @@ namespace ts {
sysLog(`sysLog:: ${fileOrDirectory}:: Defaulting to fsWatchFile`);
return watchPresentFileSystemEntryWithFsWatchFile();
}
try {
const presentWatcher = _fs.watch(
fileOrDirectory,
@ -1803,7 +1804,7 @@ namespace ts {
}
function readDirectory(path: string, extensions?: readonly string[], excludes?: readonly string[], includes?: readonly string[], depth?: number): string[] {
return matchFiles(path, extensions, excludes, includes, useCaseSensitiveFileNames, process.cwd(), depth, getAccessibleFileSystemEntries, realpath);
return matchFiles(path, extensions, excludes, includes, useCaseSensitiveFileNames, process.cwd(), depth, getAccessibleFileSystemEntries, realpath, directoryExists);
}
function fileSystemEntryExists(path: string, entryKind: FileSystemEntryKind): boolean {

View file

@ -282,7 +282,7 @@ namespace ts {
function visitYieldExpression(node: YieldExpression) {
if (enclosingFunctionFlags & FunctionFlags.Async && enclosingFunctionFlags & FunctionFlags.Generator) {
if (node.asteriskToken) {
const expression = visitNode(Debug.checkDefined(node.expression), visitor, isExpression);
const expression = visitNode(Debug.assertDefined(node.expression), visitor, isExpression);
return setOriginalNode(
setTextRange(

View file

@ -48,11 +48,11 @@ namespace ts {
return existing.name;
}
if (!currentFileState.utilizedImplicitRuntimeImports) {
currentFileState.utilizedImplicitRuntimeImports = new Map();
currentFileState.utilizedImplicitRuntimeImports = createMap();
}
let specifierSourceImports = currentFileState.utilizedImplicitRuntimeImports.get(importSource);
if (!specifierSourceImports) {
specifierSourceImports = new Map();
specifierSourceImports = createMap();
currentFileState.utilizedImplicitRuntimeImports.set(importSource, specifierSourceImports);
}
const generatedName = factory.createUniqueName(`_${name}`, GeneratedIdentifierFlags.Optimistic | GeneratedIdentifierFlags.FileLevel | GeneratedIdentifierFlags.AllowNameSubstitution);

View file

@ -1609,7 +1609,7 @@ namespace ts {
export interface TypePredicateNode extends TypeNode {
readonly kind: SyntaxKind.TypePredicate;
readonly parent: SignatureDeclaration | JSDocTypeExpression;
readonly assertsModifier?: AssertsKeyword;
readonly assertsModifier?: AssertsToken;
readonly parameterName: Identifier | ThisTypeNode;
readonly type?: TypeNode;
}
@ -1702,7 +1702,7 @@ namespace ts {
export interface MappedTypeNode extends TypeNode, Declaration {
readonly kind: SyntaxKind.MappedType;
readonly readonlyToken?: ReadonlyKeyword | PlusToken | MinusToken;
readonly readonlyToken?: ReadonlyToken | PlusToken | MinusToken;
readonly typeParameter: TypeParameterDeclaration;
readonly nameType?: TypeNode;
readonly questionToken?: QuestionToken | PlusToken | MinusToken;
@ -2756,7 +2756,7 @@ namespace ts {
export interface ForOfStatement extends IterationStatement {
readonly kind: SyntaxKind.ForOfStatement;
readonly awaitModifier?: AwaitKeyword;
readonly awaitModifier?: AwaitKeywordToken;
readonly initializer: ForInitializer;
readonly expression: Expression;
}
@ -4900,7 +4900,7 @@ namespace ts {
members?: SymbolTable; // Class, interface or object literal instance members
exports?: SymbolTable; // Module exports
globalExports?: SymbolTable; // Conditional global UMD exports
/* @internal */ id?: SymbolId; // Unique id (used to look up SymbolLinks)
/* @internal */ id: SymbolId; // Unique id (used to look up SymbolLinks)
/* @internal */ mergeId?: number; // Merge id (used to look up merged symbol)
/* @internal */ parent?: Symbol; // Parent symbol
/* @internal */ exportSymbol?: Symbol; // Exported symbol associated with this symbol
@ -4946,7 +4946,7 @@ namespace ts {
lateSymbol?: Symbol; // Late-bound symbol for a computed property
specifierCache?: ESMap<string, string>; // For symbols corresponding to external modules, a cache of incoming path -> module specifier name mappings
extendedContainers?: Symbol[]; // Containers (other than the parent) which this symbol is aliased in
extendedContainersByFile?: ESMap<NodeId, Symbol[]>; // Containers (other than the parent) which this symbol is aliased in
extendedContainersByFile?: ESMap<Node, Symbol[]>; // Containers (other than the parent) which this symbol is aliased in
variances?: VarianceFlags[]; // Alias symbol type argument variance cache
deferralConstituents?: Type[]; // Calculated list of constituents for a deferred type
deferralParent?: Type; // Source union/intersection of a deferred type
@ -5083,7 +5083,6 @@ namespace ts {
ConstructorReferenceInClass = 0x02000000, // Binding to a class constructor inside of the class's body.
ContainsClassWithPrivateIdentifiers = 0x04000000, // Marked on all block-scoped containers containing a class with private identifiers.
ContainsSuperPropertyInStaticInitializer = 0x08000000, // Marked on all block-scoped containers containing a static initializer with 'super.x' or 'super[x]'.
InCheckIdentifier = 0x10000000,
}
/* @internal */
@ -5107,7 +5106,7 @@ namespace ts {
jsxNamespace?: Symbol | false; // Resolved jsx namespace symbol for this node
jsxImplicitImportContainer?: Symbol | false; // Resolved module symbol the implicit jsx import of this file should refer to
contextFreeType?: Type; // Cached context-free type used by the first pass of inference; used when a function's return is partially contextually sensitive
deferredNodes?: Set<Node>; // Set of nodes whose checking has been deferred
deferredNodes?: Node[]; // Sparse array of nodes whose checking has been deferred
capturedBlockScopeBindings?: Symbol[]; // Block-scoped bindings captured beneath this part of an IterationStatement
outerTypeParameters?: TypeParameter[]; // Outer type parameters of anonymous object type
isExhaustive?: boolean; // Is node an exhaustive switch statement
@ -5188,6 +5187,8 @@ namespace ts {
// 'Narrowable' types are types where narrowing actually narrows.
// This *should* be every type other than null, undefined, void, and never
Narrowable = Any | Unknown | StructuredOrInstantiable | StringLike | NumberLike | BigIntLike | BooleanLike | ESSymbol | UniqueESSymbol | NonPrimitive,
/* @internal */
NotPrimitiveUnion = Any | Unknown | Enum | Void | Never | Object | Intersection | Instantiable,
// The following flags are aggregated during union and intersection type construction
/* @internal */
IncludesMask = Any | Unknown | Primitive | Never | Object | Union | Intersection | NonPrimitive | TemplateLiteral,
@ -5200,10 +5201,6 @@ namespace ts {
IncludesWildcard = IndexedAccess,
/* @internal */
IncludesEmptyObject = Conditional,
/* @internal */
IncludesInstantiable = Substitution,
/* @internal */
NotPrimitiveUnion = Any | Unknown | Enum | Void | Never | Object | Intersection | IncludesInstantiable,
}
export type DestructuringPattern = BindingPattern | ObjectLiteralExpression | ArrayLiteralExpression;
@ -6268,7 +6265,6 @@ namespace ts {
ES2019 = 6,
ES2020 = 7,
ES2021 = 8,
ES2022 = 9,
ESNext = 99,
JSON = 100,
Latest = ESNext,
@ -6726,16 +6722,15 @@ namespace ts {
ContainsTypeScript = 1 << 0,
ContainsJsx = 1 << 1,
ContainsESNext = 1 << 2,
ContainsES2022 = 1 << 3,
ContainsES2021 = 1 << 4,
ContainsES2020 = 1 << 5,
ContainsES2019 = 1 << 6,
ContainsES2018 = 1 << 7,
ContainsES2017 = 1 << 8,
ContainsES2016 = 1 << 9,
ContainsES2015 = 1 << 10,
ContainsGenerator = 1 << 11,
ContainsDestructuringAssignment = 1 << 12,
ContainsES2021 = 1 << 3,
ContainsES2020 = 1 << 4,
ContainsES2019 = 1 << 5,
ContainsES2018 = 1 << 6,
ContainsES2017 = 1 << 7,
ContainsES2016 = 1 << 8,
ContainsES2015 = 1 << 9,
ContainsGenerator = 1 << 10,
ContainsDestructuringAssignment = 1 << 11,
// Markers
// - Flags used to indicate that a subtree contains a specific transformation.
@ -6764,7 +6759,6 @@ namespace ts {
AssertTypeScript = ContainsTypeScript,
AssertJsx = ContainsJsx,
AssertESNext = ContainsESNext,
AssertES2022 = ContainsES2022,
AssertES2021 = ContainsES2021,
AssertES2020 = ContainsES2020,
AssertES2019 = ContainsES2019,

View file

@ -20,6 +20,21 @@ namespace ts {
return undefined;
}
/**
* Create a new escaped identifier map.
* @deprecated Use `new Map<__String, T>()` instead.
*/
export function createUnderscoreEscapedMap<T>(): UnderscoreEscapedMap<T> {
return new Map<__String, T>();
}
/**
* @deprecated Use `!!map?.size` instead
*/
export function hasEntries(map: ReadonlyCollection<any> | undefined): map is ReadonlyCollection<any> {
return !!map && !!map.size;
}
export function createSymbolTable(symbols?: readonly Symbol[]): SymbolTable {
const result = new Map<__String, Symbol>();
if (symbols) {
@ -591,7 +606,6 @@ namespace ts {
AsyncIterableIterator: emptyArray,
AsyncGenerator: emptyArray,
AsyncGeneratorFunction: emptyArray,
NumberFormat: ["formatToParts"]
},
es2019: {
Array: ["flat", "flatMap"],
@ -613,21 +627,8 @@ namespace ts {
PromiseConstructor: ["any"],
String: ["replaceAll"]
},
es2022: {
Array: ["at"],
String: ["at"],
Int8Array: ["at"],
Uint8Array: ["at"],
Uint8ClampedArray: ["at"],
Int16Array: ["at"],
Uint16Array: ["at"],
Int32Array: ["at"],
Uint32Array: ["at"],
Float32Array: ["at"],
Float64Array: ["at"],
BigInt64Array: ["at"],
BigUint64Array: ["at"],
ObjectConstructor: ["hasOwn"]
esnext: {
NumberFormat: ["formatToParts"]
}
};
}
@ -5797,7 +5798,7 @@ namespace ts {
this.escapedName = name;
this.declarations = undefined;
this.valueDeclaration = undefined;
this.id = undefined;
this.id = 0;
this.mergeId = undefined;
this.parent = undefined;
}
@ -6614,7 +6615,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)
};
}
@ -6623,7 +6624,7 @@ namespace ts {
}
/** @param path directory of the tsconfig.json */
export function matchFiles(path: string, extensions: readonly string[] | undefined, excludes: readonly string[] | undefined, includes: readonly string[] | undefined, useCaseSensitiveFileNames: boolean, currentDirectory: string, depth: number | undefined, getFileSystemEntries: (path: string) => FileSystemEntries, realpath: (path: string) => string): string[] {
export function matchFiles(path: string, extensions: readonly string[] | undefined, excludes: readonly string[] | undefined, includes: readonly string[] | undefined, useCaseSensitiveFileNames: boolean, currentDirectory: string, depth: number | undefined, getFileSystemEntries: (path: string) => FileSystemEntries, realpath: (path: string) => string, directoryExists: (path: string) => boolean): string[] {
path = normalizePath(path);
currentDirectory = normalizePath(currentDirectory);
@ -6638,20 +6639,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) {
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;
@ -6674,11 +6677,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);
}
}
}
@ -6686,10 +6688,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.
@ -6697,9 +6700,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.
@ -6708,7 +6711,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);
}
}
@ -6979,6 +6982,18 @@ namespace ts {
return { min, max };
}
/** @deprecated Use `ReadonlySet<TNode>` instead. */
export type ReadonlyNodeSet<TNode extends Node> = ReadonlySet<TNode>;
/** @deprecated Use `Set<TNode>` instead. */
export type NodeSet<TNode extends Node> = Set<TNode>;
/** @deprecated Use `ReadonlyMap<TNode, TValue>` instead. */
export type ReadonlyNodeMap<TNode extends Node, TValue> = ReadonlyESMap<TNode, TValue>;
/** @deprecated Use `Map<TNode, TValue>` instead. */
export type NodeMap<TNode extends Node, TValue> = ESMap<TNode, TValue>;
export function rangeOfNode(node: Node): TextRange {
return { pos: getTokenPosOfNode(node), end: node.end };
}

View file

@ -14,8 +14,6 @@ namespace ts {
switch (getEmitScriptTarget(options)) {
case ScriptTarget.ESNext:
return "lib.esnext.full.d.ts";
case ScriptTarget.ES2022:
return "lib.es2022.full.d.ts";
case ScriptTarget.ES2021:
return "lib.es2021.full.d.ts";
case ScriptTarget.ES2020:

View file

@ -184,7 +184,7 @@ namespace ts {
const rootResult = tryReadDirectory(rootDir, rootDirPath);
let rootSymLinkResult: FileSystemEntries | undefined;
if (rootResult !== undefined) {
return matchFiles(rootDir, extensions, excludes, includes, useCaseSensitiveFileNames, currentDirectory, depth, getFileSystemEntries, realpath);
return matchFiles(rootDir, extensions, excludes, includes, useCaseSensitiveFileNames, currentDirectory, depth, getFileSystemEntries, realpath, directoryExists);
}
return host.readDirectory!(rootDir, extensions, excludes, includes, depth);

View file

@ -95,7 +95,7 @@ namespace fakes {
}
public readDirectory(path: string, extensions?: readonly string[], exclude?: readonly string[], include?: readonly string[], depth?: number): string[] {
return ts.matchFiles(path, extensions, exclude, include, this.useCaseSensitiveFileNames, this.getCurrentDirectory(), depth, path => this.getAccessibleFileSystemEntries(path), path => this.realpath(path));
return ts.matchFiles(path, extensions, exclude, include, this.useCaseSensitiveFileNames, this.getCurrentDirectory(), depth, path => this.getAccessibleFileSystemEntries(path), path => this.realpath(path), path => this.directoryExists(path));
}
public getAccessibleFileSystemEntries(path: string): ts.FileSystemEntries {

View file

@ -1,11 +1,11 @@
namespace Utils {
const { join, resolve, dirname } = require("path") as typeof import("path");
const { existsSync } = require("fs") as typeof import("fs");
namespace findUpDir {
import { join, resolve, dirname } from "path";
import { existsSync } from "fs";
// search directories upward to avoid hard-wired paths based on the
// build tree (same as scripts/build/findUpDir.js)
export function findUpFile(name: string): string {
export function findUpFile(name: string) {
let dir = __dirname;
while (true) {
const fullPath = join(dir, name);

View file

@ -637,8 +637,7 @@ namespace FourSlash {
ts.forEachKey(this.inputFiles, fileName => {
if (!ts.isAnySupportedFileExtension(fileName)
|| Harness.getConfigNameFromFileName(fileName)
// Can't get a Program in Server tests
|| this.testType !== FourSlashTestType.Server && !ts.getAllowJSCompilerOption(this.getProgram().getCompilerOptions()) && !ts.resolutionExtensionIsTSOrJson(ts.extensionFromPath(fileName))
|| !ts.getAllowJSCompilerOption(this.getProgram().getCompilerOptions()) && !ts.resolutionExtensionIsTSOrJson(ts.extensionFromPath(fileName))
|| ts.getBaseFileName(fileName) === "package.json") return;
const errors = this.getDiagnostics(fileName).filter(e => e.category !== ts.DiagnosticCategory.Suggestion);
if (errors.length) {
@ -943,7 +942,7 @@ namespace FourSlash {
expected = typeof expected === "string" ? { name: expected } : expected;
if (actual.insertText !== expected.insertText) {
this.raiseError(`Completion insert text did not match: ${showTextDiff(expected.insertText || "", actual.insertText || "")}`);
this.raiseError(`Expected completion insert text to be ${expected.insertText}, got ${actual.insertText}`);
}
const convertedReplacementSpan = expected.replacementSpan && ts.createTextSpanFromRange(expected.replacementSpan);
if (convertedReplacementSpan?.length) {

View file

@ -41,7 +41,6 @@ namespace Harness {
export const virtualFileSystemRoot = "/";
function createNodeIO(): IO {
const workspaceRoot = Utils.findUpRoot();
let fs: any, pathModule: any;
if (require) {
fs = require("fs");
@ -155,7 +154,7 @@ namespace Harness {
log: s => console.log(s),
args: () => ts.sys.args,
getExecutingFilePath: () => ts.sys.getExecutingFilePath(),
getWorkspaceRoot: () => workspaceRoot,
getWorkspaceRoot: () => vpath.resolve(__dirname, "../.."),
exit: exitCode => ts.sys.exit(exitCode),
readDirectory: (path, extension, exclude, include, depth) => ts.sys.readDirectory(path, extension, exclude, include, depth),
getAccessibleFileSystemEntries,

View file

@ -28,7 +28,6 @@
"evaluatorImpl.ts",
"fakesHosts.ts",
"client.ts",
"findUpDir.ts",
"runnerbase.ts",
"sourceMapRecorder.ts",

View file

@ -922,7 +922,7 @@ interface Array<T> { length: number; [n: number]: T; }`
});
}
return { directories, files };
}, path => this.realpath(path));
}, path => this.realpath(path), path => this.directoryExists(path));
}
createHash(s: string): string {

View file

@ -200,7 +200,7 @@ declare namespace Intl {
interface NumberFormatOptions {
compactDisplay?: "short" | "long" | undefined;
notation?: "standard" | "scientific" | "engineering" | "compact" | undefined;
signDisplay?: "auto" | "never" | "always" | "exceptZero" | undefined;
signDisplay?: "auto" | "never" | "always" | undefined;
unit?: string | undefined;
unitDisplay?: "short" | "long" | "narrow" | undefined;
}
@ -208,7 +208,7 @@ declare namespace Intl {
interface ResolvedNumberFormatOptions {
compactDisplay?: "short" | "long";
notation?: "standard" | "scientific" | "engineering" | "compact";
signDisplay?: "auto" | "never" | "always" | "exceptZero";
signDisplay?: "auto" | "never" | "always";
unit?: string;
unitDisplay?: "short" | "long" | "narrow";
}

View file

@ -1,103 +0,0 @@
interface Array<T> {
/**
* Returns the item located at the specified index.
* @param index The zero-based index of the desired code unit. A negative index will count back from the last item.
*/
at(index: number): T | undefined;
}
interface ReadonlyArray<T> {
/**
* Returns the item located at the specified index.
* @param index The zero-based index of the desired code unit. A negative index will count back from the last item.
*/
at(index: number): T | undefined;
}
interface Int8Array {
/**
* Returns the item located at the specified index.
* @param index The zero-based index of the desired code unit. A negative index will count back from the last item.
*/
at(index: number): number | undefined;
}
interface Uint8Array {
/**
* Returns the item located at the specified index.
* @param index The zero-based index of the desired code unit. A negative index will count back from the last item.
*/
at(index: number): number | undefined;
}
interface Uint8ClampedArray {
/**
* Returns the item located at the specified index.
* @param index The zero-based index of the desired code unit. A negative index will count back from the last item.
*/
at(index: number): number | undefined;
}
interface Int16Array {
/**
* Returns the item located at the specified index.
* @param index The zero-based index of the desired code unit. A negative index will count back from the last item.
*/
at(index: number): number | undefined;
}
interface Uint16Array {
/**
* Returns the item located at the specified index.
* @param index The zero-based index of the desired code unit. A negative index will count back from the last item.
*/
at(index: number): number | undefined;
}
interface Int32Array {
/**
* Returns the item located at the specified index.
* @param index The zero-based index of the desired code unit. A negative index will count back from the last item.
*/
at(index: number): number | undefined;
}
interface Uint32Array {
/**
* Returns the item located at the specified index.
* @param index The zero-based index of the desired code unit. A negative index will count back from the last item.
*/
at(index: number): number | undefined;
}
interface Float32Array {
/**
* Returns the item located at the specified index.
* @param index The zero-based index of the desired code unit. A negative index will count back from the last item.
*/
at(index: number): number | undefined;
}
interface Float64Array {
/**
* Returns the item located at the specified index.
* @param index The zero-based index of the desired code unit. A negative index will count back from the last item.
*/
at(index: number): number | undefined;
}
interface BigInt64Array {
/**
* Returns the item located at the specified index.
* @param index The zero-based index of the desired code unit. A negative index will count back from the last item.
*/
at(index: number): bigint | undefined;
}
interface BigUint64Array {
/**
* Returns the item located at the specified index.
* @param index The zero-based index of the desired code unit. A negative index will count back from the last item.
*/
at(index: number): bigint | undefined;
}

5
src/lib/es2022.d.ts vendored
View file

@ -1,5 +0,0 @@
/// <reference lib="es2021" />
/// <reference lib="es2022.array" />
/// <reference lib="es2022.error" />
/// <reference lib="es2022.object" />
/// <reference lib="es2022.string" />

View file

@ -1,8 +0,0 @@
interface ErrorOptions {
cause?: Error;
}
interface ErrorConstructor {
new(message?: string, options?: ErrorOptions): Error;
(message?: string, options?: ErrorOptions): Error;
}

View file

@ -1,5 +0,0 @@
/// <reference lib="es2022" />
/// <reference lib="dom" />
/// <reference lib="webworker.importscripts" />
/// <reference lib="scripthost" />
/// <reference lib="dom.iterable" />

View file

@ -1,8 +0,0 @@
interface Object {
/**
* Determines whether an object has a property with the specified name.
* @param o An object.
* @param v A property name.
*/
hasOwn(o: object, v: PropertyKey): boolean;
}

View file

@ -1,7 +0,0 @@
interface String {
/**
* Returns a new String consisting of the single UTF-16 code unit located at the specified index.
* @param index The zero-based index of the desired code unit. A negative index will count back from the last item.
*/
at(index: number): string | undefined;
}

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

@ -96,7 +96,7 @@ interface PropertyDescriptor {
}
interface PropertyDescriptorMap {
[key: PropertyKey]: PropertyDescriptor;
[s: string]: PropertyDescriptor;
}
interface Object {

2
src/lib/esnext.d.ts vendored
View file

@ -1,2 +1,2 @@
/// <reference lib="es2022" />
/// <reference lib="es2021" />
/// <reference lib="esnext.intl" />

View file

@ -9,7 +9,6 @@
"es2019",
"es2020",
"es2021",
"es2022",
"esnext",
// Host only
"dom.generated",
@ -53,10 +52,6 @@
"es2021.promise",
"es2021.weakref",
"es2021.intl",
"es2022.array",
"es2022.error",
"es2022.object",
"es2022.string",
"esnext.intl",
// Default libraries
"es5.full",
@ -67,7 +62,6 @@
"es2019.full",
"es2020.full",
"es2021.full",
"es2022.full",
"esnext.full"
],
"paths": {

View file

@ -7773,15 +7773,6 @@
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";JSON_imports_are_experimental_in_ES_module_mode_imports_7062" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[JSON imports are experimental in ES module mode imports.]]></Val>
<Tgt Cat="Text" Stat="Loc" Orig="New">
<Val><![CDATA[Importy JSON jsou v importech režimu modulu ES experimentální.]]></Val>
</Tgt>
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";JSX_attributes_must_only_be_assigned_a_non_empty_expression_17000" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[JSX attributes must only be assigned a non-empty 'expression'.]]></Val>

View file

@ -7776,15 +7776,6 @@
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";JSON_imports_are_experimental_in_ES_module_mode_imports_7062" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[JSON imports are experimental in ES module mode imports.]]></Val>
<Tgt Cat="Text" Stat="Loc" Orig="New">
<Val><![CDATA[Les importations JSON sont expérimentales dans les importations en mode module ES.]]></Val>
</Tgt>
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";JSX_attributes_must_only_be_assigned_a_non_empty_expression_17000" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[JSX attributes must only be assigned a non-empty 'expression'.]]></Val>

View file

@ -7764,15 +7764,6 @@
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";JSON_imports_are_experimental_in_ES_module_mode_imports_7062" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[JSON imports are experimental in ES module mode imports.]]></Val>
<Tgt Cat="Text" Stat="Loc" Orig="New">
<Val><![CDATA[Le importazioni JSON sono sperimentali nelle importazioni in modalità modulo ES.]]></Val>
</Tgt>
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";JSX_attributes_must_only_be_assigned_a_non_empty_expression_17000" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[JSX attributes must only be assigned a non-empty 'expression'.]]></Val>

View file

@ -1031,11 +1031,6 @@ namespace ts.server {
}
}
/* @internal */
onDiscoveredSymlink() {
this.hasAddedOrRemovedSymlinks = true;
}
/**
* Updates set of files that contribute to this project
* @returns: true if set of files in the project stays the same and false - otherwise.
@ -1944,15 +1939,15 @@ namespace ts.server {
for (const resolution of resolutions) {
if (!resolution.resolvedFileName) continue;
const { resolvedFileName, originalPath } = resolution;
if (originalPath) {
symlinkCache.setSymlinkedDirectoryFromSymlinkedFile(originalPath, resolvedFileName);
}
if (!program.getSourceFile(resolvedFileName) && (!originalPath || !program.getSourceFile(originalPath))) {
rootNames = append(rootNames, resolvedFileName);
// Avoid creating a large project that would significantly slow down time to editor interactivity
if (dependencySelection === PackageJsonAutoImportPreference.Auto && rootNames.length > this.maxDependencies) {
return ts.emptyArray;
}
if (originalPath) {
symlinkCache.setSymlinkedDirectoryFromSymlinkedFile(originalPath, resolvedFileName);
}
}
}
}

View file

@ -3199,25 +3199,6 @@ namespace ts.server.protocol {
payload: TypingsInstalledTelemetryEventPayload;
}
// A __GDPR__FRAGMENT__ has no meaning until it is ${include}d by a __GDPR__ comment, at which point
// the included properties are effectively inlined into the __GDPR__ declaration. In this case, for
// example, any __GDPR__ comment including the TypeScriptCommonProperties will be updated with an
// additional version property with the classification below. Obviously, the purpose of such a construct
// is to reduce duplication and keep multiple use sites consistent (e.g. by making sure that all reflect
// any newly added TypeScriptCommonProperties). Unfortunately, the system has limits - in particular,
// these reusable __GDPR__FRAGMENT__s are not accessible across repo boundaries. Therefore, even though
// the code for adding the common properties (i.e. version), along with the corresponding __GDPR__FRAGMENT__,
// lives in the VS Code repo (see https://github.com/microsoft/vscode/blob/main/extensions/typescript-language-features/src/utils/telemetry.ts)
// we have to duplicate it here. It would be nice to keep them in sync, but the only likely failure mode
// is adding a property to the VS Code repro but not here and the only consequence would be having that
// property suppressed on the events (i.e. __GDPT__ comments) in this repo that reference the out-of-date
// local __GDPR__FRAGMENT__.
/* __GDPR__FRAGMENT__
"TypeScriptCommonProperties" : {
"version" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" }
}
*/
/* __GDPR__
"typingsinstalled" : {
"${include}": ["${TypeScriptCommonProperties}"],
@ -3534,7 +3515,6 @@ namespace ts.server.protocol {
ES2019 = "ES2019",
ES2020 = "ES2020",
ES2021 = "ES2021",
ES2022 = "ES2022",
ESNext = "ESNext"
}

View file

@ -2112,7 +2112,7 @@ namespace ts.server {
private getFullNavigateToItems(args: protocol.NavtoRequestArgs): CombineOutputResult<NavigateToItem> {
const { currentFileOnly, searchValue, maxResultCount, projectFileName } = args;
if (currentFileOnly) {
Debug.assertIsDefined(args.file);
Debug.assertDefined(args.file);
const { file, project } = this.getFileAndProject(args as protocol.FileRequestArgs);
return [{ project, result: project.getLanguageService().getNavigateToItems(searchValue, maxResultCount, file) }];
}

View file

@ -3,6 +3,13 @@ namespace ts.codefix {
const errorCodeToFixes = createMultiMap<CodeFixRegistration>();
const fixIdToRegistration = new Map<string, CodeFixRegistration>();
export type DiagnosticAndArguments = DiagnosticMessage | [DiagnosticMessage, string] | [DiagnosticMessage, string, string];
function diagnosticToString(diag: DiagnosticAndArguments): string {
return isArray(diag)
? formatStringFromArgs(getLocaleSpecificMessage(diag[0]), diag.slice(1) as readonly string[])
: getLocaleSpecificMessage(diag);
}
export function createCodeFixActionWithoutFixAll(fixName: string, changes: FileTextChanges[], description: DiagnosticAndArguments) {
return createCodeFixActionWorker(fixName, diagnosticToString(description), changes, /*fixId*/ undefined, /*fixAllDescription*/ undefined);
}

View file

@ -14,24 +14,24 @@ namespace ts.codefix {
function makeChange(changeTracker: textChanges.ChangeTracker, sourceFile: SourceFile, pos: number) {
const token = getTokenAtPosition(sourceFile, pos);
if (!isIdentifier(token)) {
return Debug.fail("add-name-to-nameless-parameter operates on identifiers, but got a " + Debug.formatSyntaxKind(token.kind));
}
const param = token.parent;
if (!isParameter(param)) {
return Debug.fail("Tried to add a parameter name to a non-parameter: " + Debug.formatSyntaxKind(token.kind));
}
const i = param.parent.parameters.indexOf(param);
Debug.assert(!param.type, "Tried to add a parameter name to a parameter that already had one.");
Debug.assert(i > -1, "Parameter not found in parent parameter list.");
const typeNode = factory.createTypeReferenceNode(param.name as Identifier, /*typeArguments*/ undefined);
const replacement = factory.createParameterDeclaration(
/*decorators*/ undefined,
param.modifiers,
param.dotDotDotToken,
"arg" + i,
param.questionToken,
param.dotDotDotToken ? factory.createArrayTypeNode(typeNode) : typeNode,
factory.createTypeReferenceNode(token, /*typeArguments*/ undefined),
param.initializer);
changeTracker.replaceNode(sourceFile, param, replacement);
changeTracker.replaceNode(sourceFile, token, replacement);
}
}

View file

@ -408,7 +408,9 @@ namespace ts.codefix {
const importSpecifiers = mapAllOrFail(name.elements, e =>
e.dotDotDotToken || e.initializer || e.propertyName && !isIdentifier(e.propertyName) || !isIdentifier(e.name)
? undefined
: makeImportSpecifier(e.propertyName && e.propertyName.text, e.name.text));
// (TODO: GH#18217)
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
: makeImportSpecifier(e.propertyName && (e.propertyName as Identifier).text, e.name.text));
if (importSpecifiers) {
return convertedImports([makeImport(/*name*/ undefined, importSpecifiers, moduleSpecifier, quotePreference)]);
}

View file

@ -26,9 +26,9 @@ namespace ts.codefix {
if (!isFunctionDeclaration(fn) && !isFunctionExpression(fn)) return undefined;
if (!isSourceFile(getThisContainer(fn, /*includeArrowFunctions*/ false))) { // 'this' is defined outside, convert to arrow function
const fnKeyword = Debug.checkDefined(findChildOfKind(fn, SyntaxKind.FunctionKeyword, sourceFile));
const fnKeyword = Debug.assertDefined(findChildOfKind(fn, SyntaxKind.FunctionKeyword, sourceFile));
const { name } = fn;
const body = Debug.checkDefined(fn.body); // Should be defined because the function contained a 'this' expression
const body = Debug.assertDefined(fn.body); // Should be defined because the function contained a 'this' expression
if (isFunctionExpression(fn)) {
if (name && FindAllReferences.Core.isSymbolReferencedInFile(name, checker, sourceFile, body)) {
// Function expression references itself. To fix we would have to extract it to a const.

View file

@ -17,81 +17,37 @@ namespace ts.codefix {
Diagnostics.This_member_cannot_have_an_override_modifier_because_its_containing_class_0_does_not_extend_another_class.code,
Diagnostics.This_member_must_have_an_override_modifier_because_it_overrides_an_abstract_method_that_is_declared_in_the_base_class_0.code,
Diagnostics.This_member_must_have_an_override_modifier_because_it_overrides_a_member_in_the_base_class_0.code,
Diagnostics.This_parameter_property_must_have_an_override_modifier_because_it_overrides_a_member_in_base_class_0.code,
Diagnostics.This_member_must_have_a_JSDoc_comment_with_an_override_tag_because_it_overrides_a_member_in_the_base_class_0.code,
Diagnostics.This_member_cannot_have_a_JSDoc_comment_with_an_override_tag_because_its_containing_class_0_does_not_extend_another_class.code,
Diagnostics.This_parameter_property_must_have_a_JSDoc_comment_with_an_override_tag_because_it_overrides_a_member_in_the_base_class_0.code,
Diagnostics.This_member_cannot_have_a_JSDoc_comment_with_an_override_tag_because_it_is_not_declared_in_the_base_class_0.code,
Diagnostics.This_parameter_property_must_have_an_override_modifier_because_it_overrides_a_member_in_base_class_0.code
];
interface ErrorCodeFixInfo {
descriptions: DiagnosticMessage;
fixId?: string | undefined;
fixAllDescriptions?: DiagnosticMessage | undefined;
}
const errorCodeFixIdMap: Record<number, ErrorCodeFixInfo> = {
// case #1:
[Diagnostics.This_member_must_have_an_override_modifier_because_it_overrides_a_member_in_the_base_class_0.code]: {
descriptions: Diagnostics.Add_override_modifier,
fixId: fixAddOverrideId,
fixAllDescriptions: Diagnostics.Add_all_missing_override_modifiers,
},
[Diagnostics.This_member_must_have_a_JSDoc_comment_with_an_override_tag_because_it_overrides_a_member_in_the_base_class_0.code]: {
descriptions: Diagnostics.Add_override_modifier,
fixId: fixAddOverrideId,
fixAllDescriptions: Diagnostics.Add_all_missing_override_modifiers
},
// case #2:
[Diagnostics.This_member_cannot_have_an_override_modifier_because_its_containing_class_0_does_not_extend_another_class.code]: {
descriptions: Diagnostics.Remove_override_modifier,
fixId: fixRemoveOverrideId,
fixAllDescriptions: Diagnostics.Remove_all_unnecessary_override_modifiers,
},
[Diagnostics.This_member_cannot_have_a_JSDoc_comment_with_an_override_tag_because_its_containing_class_0_does_not_extend_another_class.code]: {
descriptions: Diagnostics.Remove_override_modifier,
fixId: fixRemoveOverrideId,
fixAllDescriptions: Diagnostics.Remove_override_modifier
},
// case #3:
[Diagnostics.This_parameter_property_must_have_an_override_modifier_because_it_overrides_a_member_in_base_class_0.code]: {
descriptions: Diagnostics.Add_override_modifier,
fixId: fixAddOverrideId,
fixAllDescriptions: Diagnostics.Add_all_missing_override_modifiers,
},
[Diagnostics.This_parameter_property_must_have_a_JSDoc_comment_with_an_override_tag_because_it_overrides_a_member_in_the_base_class_0.code]: {
descriptions: Diagnostics.Add_override_modifier,
fixId: fixAddOverrideId,
fixAllDescriptions: Diagnostics.Add_all_missing_override_modifiers,
},
// case #4:
[Diagnostics.This_member_must_have_an_override_modifier_because_it_overrides_an_abstract_method_that_is_declared_in_the_base_class_0.code]: {
descriptions: Diagnostics.Add_override_modifier,
fixId: fixAddOverrideId,
fixAllDescriptions: Diagnostics.Remove_all_unnecessary_override_modifiers,
},
// case #5:
[Diagnostics.This_member_cannot_have_an_override_modifier_because_it_is_not_declared_in_the_base_class_0.code]: {
descriptions: Diagnostics.Remove_override_modifier,
fixId: fixRemoveOverrideId,
fixAllDescriptions: Diagnostics.Remove_all_unnecessary_override_modifiers,
},
[Diagnostics.This_member_cannot_have_a_JSDoc_comment_with_an_override_tag_because_it_is_not_declared_in_the_base_class_0.code]: {
descriptions: Diagnostics.Remove_override_modifier,
fixId: fixRemoveOverrideId,
fixAllDescriptions: Diagnostics.Remove_all_unnecessary_override_modifiers,
}
const errorCodeFixIdMap: Record<number, [DiagnosticMessage, string | undefined, DiagnosticMessage | undefined]> = {
[Diagnostics.This_member_must_have_an_override_modifier_because_it_overrides_a_member_in_the_base_class_0.code]: [
Diagnostics.Add_override_modifier, fixAddOverrideId, Diagnostics.Add_all_missing_override_modifiers,
],
[Diagnostics.This_member_cannot_have_an_override_modifier_because_its_containing_class_0_does_not_extend_another_class.code]: [
Diagnostics.Remove_override_modifier, fixRemoveOverrideId, Diagnostics.Remove_all_unnecessary_override_modifiers
],
[Diagnostics.This_parameter_property_must_have_an_override_modifier_because_it_overrides_a_member_in_base_class_0.code]: [
Diagnostics.Add_override_modifier, fixAddOverrideId, Diagnostics.Add_all_missing_override_modifiers,
],
[Diagnostics.This_member_must_have_an_override_modifier_because_it_overrides_an_abstract_method_that_is_declared_in_the_base_class_0.code]: [
Diagnostics.Add_override_modifier, fixAddOverrideId, Diagnostics.Remove_all_unnecessary_override_modifiers
],
[Diagnostics.This_member_cannot_have_an_override_modifier_because_it_is_not_declared_in_the_base_class_0.code]: [
Diagnostics.Remove_override_modifier, fixRemoveOverrideId, Diagnostics.Remove_all_unnecessary_override_modifiers
]
};
registerCodeFix({
errorCodes,
getCodeActions: context => {
const { errorCode, span } = context;
const { errorCode, span, sourceFile } = context;
const info = errorCodeFixIdMap[errorCode];
if (!info) return emptyArray;
const { descriptions, fixId, fixAllDescriptions } = info;
const [ descriptions, fixId, fixAllDescriptions ] = info;
if (isSourceFileJS(sourceFile)) return emptyArray;
const changes = textChanges.ChangeTracker.with(context, changes => dispatchChanges(changes, context, errorCode, span.start));
return [
@ -101,9 +57,9 @@ namespace ts.codefix {
fixIds: [fixName, fixAddOverrideId, fixRemoveOverrideId],
getAllCodeActions: context =>
codeFixAll(context, errorCodes, (changes, diag) => {
const { code, start } = diag;
const { code, start, file } = diag;
const info = errorCodeFixIdMap[code];
if (!info || info.fixId !== context.fixId) {
if (!info || info[1] !== context.fixId || isSourceFileJS(file)) {
return;
}
@ -118,15 +74,11 @@ namespace ts.codefix {
pos: number) {
switch (errorCode) {
case Diagnostics.This_member_must_have_an_override_modifier_because_it_overrides_a_member_in_the_base_class_0.code:
case Diagnostics.This_member_must_have_a_JSDoc_comment_with_an_override_tag_because_it_overrides_a_member_in_the_base_class_0.code:
case Diagnostics.This_member_must_have_an_override_modifier_because_it_overrides_an_abstract_method_that_is_declared_in_the_base_class_0.code:
case Diagnostics.This_parameter_property_must_have_an_override_modifier_because_it_overrides_a_member_in_base_class_0.code:
case Diagnostics.This_parameter_property_must_have_a_JSDoc_comment_with_an_override_tag_because_it_overrides_a_member_in_the_base_class_0.code:
return doAddOverrideModifierChange(changeTracker, context.sourceFile, pos);
case Diagnostics.This_member_cannot_have_an_override_modifier_because_it_is_not_declared_in_the_base_class_0.code:
case Diagnostics.This_member_cannot_have_a_JSDoc_comment_with_an_override_tag_because_it_is_not_declared_in_the_base_class_0.code:
case Diagnostics.This_member_cannot_have_an_override_modifier_because_its_containing_class_0_does_not_extend_another_class.code:
case Diagnostics.This_member_cannot_have_a_JSDoc_comment_with_an_override_tag_because_its_containing_class_0_does_not_extend_another_class.code:
return doRemoveOverrideModifierChange(changeTracker, context.sourceFile, pos);
default:
Debug.fail("Unexpected error code: " + errorCode);
@ -135,10 +87,6 @@ namespace ts.codefix {
function doAddOverrideModifierChange(changeTracker: textChanges.ChangeTracker, sourceFile: SourceFile, pos: number) {
const classElement = findContainerClassElementLike(sourceFile, pos);
if (isSourceFileJS(sourceFile)) {
changeTracker.addJSDocTags(sourceFile, classElement, [factory.createJSDocOverrideTag(factory.createIdentifier("override"))]);
return;
}
const modifiers = classElement.modifiers || emptyArray;
const staticModifier = find(modifiers, isStaticModifier);
const abstractModifier = find(modifiers, isAbstractModifier);
@ -153,10 +101,6 @@ namespace ts.codefix {
function doRemoveOverrideModifierChange(changeTracker: textChanges.ChangeTracker, sourceFile: SourceFile, pos: number) {
const classElement = findContainerClassElementLike(sourceFile, pos);
if (isSourceFileJS(sourceFile)) {
changeTracker.filterJSDocTags(sourceFile, classElement, not(isJSDocOverrideTag));
return;
}
const overrideModifier = classElement.modifiers && find(classElement.modifiers, modifier => modifier.kind === SyntaxKind.OverrideKeyword);
Debug.assertIsDefined(overrideModifier);

View file

@ -37,12 +37,6 @@ namespace ts.codefix {
type AddNode = PropertyDeclaration | GetAccessorDeclaration | SetAccessorDeclaration | MethodDeclaration | FunctionExpression | ArrowFunction;
export const enum PreserveOptionalFlags {
Method = 1 << 0,
Property = 1 << 1,
All = Method | Property
}
/**
* `addClassElement` will not be called if we can't figure out a representation for `symbol` in `enclosingDeclaration`.
* @param body If defined, this will be the body of the member node passed to `addClassElement`. Otherwise, the body will default to a stub.
@ -56,7 +50,6 @@ namespace ts.codefix {
importAdder: ImportAdder | undefined,
addClassElement: (node: AddNode) => void,
body: Block | undefined,
preserveOptional = PreserveOptionalFlags.All,
isAmbient = false,
): void {
const declarations = symbol.getDeclarations();
@ -90,7 +83,7 @@ namespace ts.codefix {
/*decorators*/ undefined,
modifiers,
name,
optional && (preserveOptional & PreserveOptionalFlags.Property) ? factory.createToken(SyntaxKind.QuestionToken) : undefined,
optional ? factory.createToken(SyntaxKind.QuestionToken) : undefined,
typeNode,
/*initializer*/ undefined));
break;
@ -165,14 +158,14 @@ namespace ts.codefix {
}
else {
Debug.assert(declarations.length === signatures.length, "Declarations and signatures should match count");
addClassElement(createMethodImplementingSignatures(checker, context, enclosingDeclaration, signatures, name, optional && !!(preserveOptional & PreserveOptionalFlags.Method), modifiers, quotePreference, body));
addClassElement(createMethodImplementingSignatures(checker, context, enclosingDeclaration, signatures, name, optional, modifiers, quotePreference, body));
}
}
break;
}
function outputMethod(quotePreference: QuotePreference, signature: Signature, modifiers: NodeArray<Modifier> | undefined, name: PropertyName, body?: Block): void {
const method = createSignatureDeclarationFromSignature(SyntaxKind.MethodDeclaration, context, quotePreference, signature, body, name, modifiers, optional && !!(preserveOptional & PreserveOptionalFlags.Method), enclosingDeclaration, importAdder);
const method = createSignatureDeclarationFromSignature(SyntaxKind.MethodDeclaration, context, quotePreference, signature, body, name, modifiers, optional, enclosingDeclaration, importAdder);
if (method) addClassElement(method);
}
}

View file

@ -33,7 +33,6 @@ namespace ts.codefix {
});
export interface ImportAdder {
hasFixes(): boolean;
addImportFromDiagnostic: (diagnostic: DiagnosticWithLocation, context: CodeFixContextBase) => void;
addImportFromExportedSymbol: (exportedSymbol: Symbol, isValidTypeOnlyUseSite?: boolean) => void;
writeFixes: (changeTracker: textChanges.ChangeTracker) => void;
@ -60,7 +59,7 @@ namespace ts.codefix {
type NewImportsKey = `${0 | 1}|${string}`;
/** Use `getNewImportEntry` for access */
const newImports = new Map<NewImportsKey, Mutable<ImportsCollection & { useRequire: boolean }>>();
return { addImportFromDiagnostic, addImportFromExportedSymbol, writeFixes, hasFixes };
return { addImportFromDiagnostic, addImportFromExportedSymbol, writeFixes };
function addImportFromDiagnostic(diagnostic: DiagnosticWithLocation, context: CodeFixContextBase) {
const info = getFixesInfo(context, diagnostic.code, diagnostic.start, useAutoImportProvider);
@ -218,10 +217,6 @@ namespace ts.codefix {
insertImports(changeTracker, sourceFile, newDeclarations, /*blankLineBetween*/ true);
}
}
function hasFixes() {
return addToNamespace.length > 0 || importType.length > 0 || addToExisting.size > 0 || newImports.size > 0;
}
}
// Sorted with the preferred fix coming first.

View file

@ -131,7 +131,7 @@ namespace ts.codefix {
if (typeNode) {
// Note that the codefix will never fire with an existing `@type` tag, so there is no need to merge tags
const typeTag = factory.createJSDocTypeTag(/*tagName*/ undefined, factory.createJSDocTypeExpression(typeNode), /*comment*/ undefined);
changes.addJSDocTags(sourceFile, cast(parent.parent.parent, isExpressionStatement), [typeTag]);
addJSDocTags(changes, sourceFile, cast(parent.parent.parent, isExpressionStatement), [typeTag]);
}
importAdder.writeFixes(changes);
return parent;
@ -271,7 +271,7 @@ namespace ts.codefix {
}
function annotateJSDocThis(changes: textChanges.ChangeTracker, sourceFile: SourceFile, containingFunction: SignatureDeclaration, typeNode: TypeNode) {
changes.addJSDocTags(sourceFile, containingFunction, [
addJSDocTags(changes, sourceFile, containingFunction, [
factory.createJSDocThisTag(/*tagName*/ undefined, factory.createJSDocTypeExpression(typeNode)),
]);
}
@ -311,7 +311,7 @@ namespace ts.codefix {
}
const typeExpression = factory.createJSDocTypeExpression(typeNode);
const typeTag = isGetAccessorDeclaration(declaration) ? factory.createJSDocReturnTag(/*tagName*/ undefined, typeExpression, /*comment*/ undefined) : factory.createJSDocTypeTag(/*tagName*/ undefined, typeExpression, /*comment*/ undefined);
changes.addJSDocTags(sourceFile, parent, [typeTag]);
addJSDocTags(changes, sourceFile, parent, [typeTag]);
}
else if (!tryReplaceImportTypeNodeWithAutoImport(typeNode, declaration, sourceFile, changes, importAdder, getEmitScriptTarget(program.getCompilerOptions()))) {
changes.tryInsertTypeAnnotation(sourceFile, declaration, typeNode);
@ -378,7 +378,46 @@ namespace ts.codefix {
else {
const paramTags = map(inferences, ({ name, typeNode, isOptional }) =>
factory.createJSDocParameterTag(/*tagName*/ undefined, name, /*isBracketed*/ !!isOptional, factory.createJSDocTypeExpression(typeNode), /* isNameFirst */ false, /*comment*/ undefined));
changes.addJSDocTags(sourceFile, signature, paramTags);
addJSDocTags(changes, sourceFile, signature, paramTags);
}
}
export function addJSDocTags(changes: textChanges.ChangeTracker, sourceFile: SourceFile, parent: HasJSDoc, newTags: readonly JSDocTag[]): void {
const comments = flatMap(parent.jsDoc, j => typeof j.comment === "string" ? factory.createJSDocText(j.comment) : j.comment) as JSDocComment[];
const oldTags = flatMapToMutable(parent.jsDoc, j => j.tags);
const unmergedNewTags = newTags.filter(newTag => !oldTags || !oldTags.some((tag, i) => {
const merged = tryMergeJsdocTags(tag, newTag);
if (merged) oldTags[i] = merged;
return !!merged;
}));
const tag = factory.createJSDocComment(factory.createNodeArray(intersperse(comments, factory.createJSDocText("\n"))), factory.createNodeArray([...(oldTags || emptyArray), ...unmergedNewTags]));
const jsDocNode = parent.kind === SyntaxKind.ArrowFunction ? getJsDocNodeForArrowFunction(parent) : parent;
jsDocNode.jsDoc = parent.jsDoc;
jsDocNode.jsDocCache = parent.jsDocCache;
changes.insertJsdocCommentBefore(sourceFile, jsDocNode, tag);
}
function getJsDocNodeForArrowFunction(signature: ArrowFunction): HasJSDoc {
if (signature.parent.kind === SyntaxKind.PropertyDeclaration) {
return signature.parent as HasJSDoc;
}
return signature.parent.parent as HasJSDoc;
}
function tryMergeJsdocTags(oldTag: JSDocTag, newTag: JSDocTag): JSDocTag | undefined {
if (oldTag.kind !== newTag.kind) {
return undefined;
}
switch (oldTag.kind) {
case SyntaxKind.JSDocParameterTag: {
const oldParam = oldTag as JSDocParameterTag;
const newParam = newTag as JSDocParameterTag;
return isIdentifier(oldParam.name) && isIdentifier(newParam.name) && oldParam.name.escapedText === newParam.name.escapedText
? factory.createJSDocParameterTag(/*tagName*/ undefined, newParam.name, /*isBracketed*/ false, newParam.typeExpression, newParam.isNameFirst, oldParam.comment)
: undefined;
}
case SyntaxKind.JSDocReturnTag:
return factory.createJSDocReturnTag(/*tagName*/ undefined, (newTag as JSDocReturnTag).typeExpression, oldTag.comment);
}
}
@ -961,25 +1000,13 @@ namespace ts.codefix {
if (usage.numberIndex) {
types.push(checker.createArrayType(combineFromUsage(usage.numberIndex)));
}
if (usage.properties?.size || usage.constructs?.length || usage.stringIndex) {
if (usage.properties?.size || usage.calls?.length || usage.constructs?.length || usage.stringIndex) {
types.push(inferStructuralType(usage));
}
const candidateTypes = (usage.candidateTypes || []).map(t => checker.getBaseTypeOfLiteralType(t));
const callsType = usage.calls?.length ? inferStructuralType(usage) : undefined;
if (callsType && candidateTypes) {
types.push(checker.getUnionType([callsType, ...candidateTypes], UnionReduction.Subtype));
}
else {
if (callsType) {
types.push(callsType);
}
if (length(candidateTypes)) {
types.push(...candidateTypes);
}
}
types.push(...(usage.candidateTypes || []).map(t => checker.getBaseTypeOfLiteralType(t)));
types.push(...inferNamedTypesFromProperties(usage));
return types;
}

View file

@ -57,9 +57,7 @@ namespace ts.Completions {
*/
export enum CompletionSource {
/** Completions that require `this.` insertion text */
ThisProperty = "ThisProperty/",
/** Auto-import that comes attached to a class member snippet */
ClassMemberSnippet = "ClassMemberSnippet/",
ThisProperty = "ThisProperty/"
}
const enum SymbolOriginInfoKind {
@ -643,7 +641,6 @@ namespace ts.Completions {
let replacementSpan = getReplacementSpanForContextToken(replacementToken);
let data: CompletionEntryData | undefined;
let isSnippet: true | undefined;
let source = getSourceFromOrigin(origin);
let sourceDisplay;
let hasAction;
@ -705,12 +702,7 @@ namespace ts.Completions {
preferences.includeCompletionsWithInsertText &&
completionKind === CompletionKind.MemberLike &&
isClassLikeMemberCompletion(symbol, location)) {
let importAdder;
({ insertText, isSnippet, importAdder } = getEntryForMemberCompletion(host, program, options, preferences, name, symbol, location, contextToken));
if (importAdder?.hasFixes()) {
hasAction = true;
source = CompletionSource.ClassMemberSnippet;
}
({ insertText, isSnippet } = getEntryForMemberCompletion(host, program, options, preferences, name, symbol, location, contextToken));
}
const kind = SymbolDisplay.getSymbolKind(typeChecker, symbol, location);
@ -738,6 +730,10 @@ namespace ts.Completions {
insertText = `${escapeSnippetText(name)}={$1}`;
isSnippet = true;
}
if (isSnippet) {
replacementSpan = createTextSpanFromNode(location, sourceFile);
}
}
if (insertText !== undefined && !preferences.includeCompletionsWithInsertText) {
@ -762,7 +758,7 @@ namespace ts.Completions {
kind,
kindModifiers: SymbolDisplay.getSymbolModifiers(typeChecker, symbol),
sortText,
source,
source: getSourceFromOrigin(origin),
hasAction: hasAction ? true : undefined,
isRecommended: isRecommendedCompletionMatch(symbol, recommendedCompletion, typeChecker) || undefined,
insertText,
@ -832,7 +828,7 @@ namespace ts.Completions {
symbol: Symbol,
location: Node,
contextToken: Node | undefined,
): { insertText: string, isSnippet?: true, importAdder?: codefix.ImportAdder } {
): { insertText: string, isSnippet?: true } {
const classLikeDeclaration = findAncestor(location, isClassLike);
if (!classLikeDeclaration) {
return { insertText: name };
@ -847,20 +843,21 @@ namespace ts.Completions {
removeComments: true,
module: options.module,
target: options.target,
omitTrailingSemicolon: false,
omitTrailingSemicolon: true,
newLine: getNewLineKind(getNewLineCharacter(options, maybeBind(host, host.getNewLine))),
});
const importAdder = codefix.createImportAdder(sourceFile, program, preferences, host);
let body;
let tabstopStart = 1;
if (preferences.includeCompletionsWithSnippetText) {
isSnippet = true;
// We are adding a tabstop (i.e. `$0`) in the body of the suggested member,
// if it has one, so that the cursor ends up in the body once the completion is inserted.
// We are adding a final tabstop (i.e. $0) in the body of the suggested member, if it has one.
// Note: this assumes we won't have more than one body in the completion nodes, which should be the case.
const emptyStatement = factory.createExpressionStatement(factory.createIdentifier(""));
setSnippetElement(emptyStatement, { kind: SnippetKind.TabStop, order: 0 });
body = factory.createBlock([emptyStatement], /* multiline */ true);
const emptyStatement1 = factory.createExpressionStatement(factory.createIdentifier(""));
setSnippetElement(emptyStatement1, { kind: SnippetKind.TabStop, order: 1 });
tabstopStart = 2;
body = factory.createBlock([emptyStatement1], /* multiline */ true);
}
else {
body = factory.createBlock([], /* multiline */ true);
@ -891,7 +888,7 @@ namespace ts.Completions {
node => {
let requiredModifiers = ModifierFlags.None;
if (isAbstract) {
requiredModifiers |= ModifierFlags.Abstract;
requiredModifiers |= ModifierFlags.Abstract;
}
if (isClassElement(node)
&& checker.getMemberOverrideModifierStatus(classLikeDeclaration, node) === MemberOverrideStatus.NeedsOverride) {
@ -915,17 +912,16 @@ namespace ts.Completions {
completionNodes.push(node);
},
body,
codefix.PreserveOptionalFlags.Property,
isAbstract);
if (completionNodes.length) {
insertText = printer.printSnippetList(
ListFormat.MultiLine | ListFormat.NoTrailingNewLine,
factory.createNodeArray(completionNodes),
sourceFile);
if (preferences.includeCompletionsWithSnippetText) {
addSnippets(completionNodes, tabstopStart);
}
insertText = printer.printSnippetList(ListFormat.MultiLine, factory.createNodeArray(completionNodes), sourceFile);
}
return { insertText, isSnippet, importAdder };
return { insertText, isSnippet };
}
function getPresentModifiers(contextToken: Node): ModifierFlags {
@ -969,6 +965,35 @@ namespace ts.Completions {
return undefined;
}
function addSnippets(nodes: Node[], orderStart: number): void {
let order = orderStart;
for (const node of nodes) {
addSnippetsWorker(node, /*parent*/ undefined);
}
function addSnippetsWorker(node: Node, parent: Node | undefined) {
if (isVariableLike(node) && node.kind === SyntaxKind.Parameter) {
// Placeholder
setSnippetElement(node.name, { kind: SnippetKind.Placeholder, order });
order += 1;
if (node.type) {
setSnippetElement(node.type, { kind: SnippetKind.Placeholder, order });
order += 1;
}
}
else if (isTypeNode(node) && parent && isFunctionLikeDeclaration(parent)) {
setSnippetElement(node, { kind: SnippetKind.Placeholder, order });
order += 1;
}
else if (isTypeParameterDeclaration(node) && parent && isFunctionLikeDeclaration(parent)) {
setSnippetElement(node, { kind: SnippetKind.Placeholder, order });
order += 1;
}
forEachChild(node, child => addSnippetsWorker(child, node));
}
}
function createSnippetPrinter(
printerOptions: PrinterOptions,
) {
@ -1272,7 +1297,6 @@ namespace ts.Completions {
location: Node;
origin: SymbolOriginInfo | SymbolOriginInfoExport | SymbolOriginInfoResolvedExport | undefined;
previousToken: Node | undefined;
contextToken: Node | undefined;
readonly isJsxInitializer: IsJsxInitializer;
readonly isTypeOnlyLocation: boolean;
}
@ -1288,13 +1312,11 @@ namespace ts.Completions {
if (entryId.data) {
const autoImport = getAutoImportSymbolFromCompletionEntryData(entryId.name, entryId.data, program, host);
if (autoImport) {
const { contextToken, previousToken } = getRelevantTokens(position, sourceFile);
return {
type: "symbol",
symbol: autoImport.symbol,
location: getTouchingPropertyName(sourceFile, position),
previousToken,
contextToken,
previousToken: findPrecedingToken(position, sourceFile, /*startNode*/ undefined)!,
isJsxInitializer: false,
isTypeOnlyLocation: false,
origin: autoImport.origin,
@ -1311,7 +1333,7 @@ namespace ts.Completions {
return { type: "request", request: completionData };
}
const { symbols, literals, location, completionKind, symbolToOriginInfoMap, contextToken, previousToken, isJsxInitializer, isTypeOnlyLocation } = completionData;
const { symbols, literals, location, completionKind, symbolToOriginInfoMap, previousToken, isJsxInitializer, isTypeOnlyLocation } = completionData;
const literal = find(literals, l => completionNameForLiteral(sourceFile, preferences, l) === entryId.name);
if (literal !== undefined) return { type: "literal", literal };
@ -1323,8 +1345,8 @@ namespace ts.Completions {
return firstDefined(symbols, (symbol, index): SymbolCompletion | undefined => {
const origin = symbolToOriginInfoMap[index];
const info = getCompletionEntryDisplayNameForSymbol(symbol, getEmitScriptTarget(compilerOptions), origin, completionKind, completionData.isJsxIdentifierExpected);
return info && info.name === entryId.name && (entryId.source === CompletionSource.ClassMemberSnippet && symbol.flags & SymbolFlags.ClassMember || getSourceFromOrigin(origin) === entryId.source)
? { type: "symbol" as const, symbol, location, origin, contextToken, previousToken, isJsxInitializer, isTypeOnlyLocation }
return info && info.name === entryId.name && getSourceFromOrigin(origin) === entryId.source
? { type: "symbol" as const, symbol, location, origin, previousToken, isJsxInitializer, isTypeOnlyLocation }
: undefined;
}) || { type: "none" };
}
@ -1348,7 +1370,7 @@ namespace ts.Completions {
): CompletionEntryDetails | undefined {
const typeChecker = program.getTypeChecker();
const compilerOptions = program.getCompilerOptions();
const { name, source, data } = entryId;
const { name } = entryId;
const contextToken = findPrecedingToken(position, sourceFile);
if (isInString(sourceFile, position, contextToken)) {
@ -1374,8 +1396,8 @@ namespace ts.Completions {
}
}
case "symbol": {
const { symbol, location, contextToken, origin, previousToken } = symbolCompletion;
const { codeActions, sourceDisplay } = getCompletionEntryCodeActionsAndSourceDisplay(name, location, contextToken, origin, symbol, program, host, compilerOptions, sourceFile, position, previousToken, formatContext, preferences, data, source);
const { symbol, location, origin, previousToken } = symbolCompletion;
const { codeActions, sourceDisplay } = getCompletionEntryCodeActionsAndSourceDisplay(origin, symbol, program, host, compilerOptions, sourceFile, position, previousToken, formatContext, preferences, entryId.data);
return createCompletionDetailsForSymbol(symbol, typeChecker, sourceFile, location, cancellationToken, codeActions, sourceDisplay); // TODO: GH#18217
}
case "literal": {
@ -1411,9 +1433,6 @@ namespace ts.Completions {
readonly sourceDisplay: SymbolDisplayPart[] | undefined;
}
function getCompletionEntryCodeActionsAndSourceDisplay(
name: string,
location: Node,
contextToken: Node | undefined,
origin: SymbolOriginInfo | SymbolOriginInfoExport | SymbolOriginInfoResolvedExport | undefined,
symbol: Symbol,
program: Program,
@ -1425,7 +1444,6 @@ namespace ts.Completions {
formatContext: formatting.FormatContext,
preferences: UserPreferences,
data: CompletionEntryData | undefined,
source: string | undefined,
): CodeActionsAndSourceDisplay {
if (data?.moduleSpecifier) {
const { contextToken, previousToken } = getRelevantTokens(position, sourceFile);
@ -1435,30 +1453,6 @@ namespace ts.Completions {
}
}
if (source === CompletionSource.ClassMemberSnippet) {
const { importAdder } = getEntryForMemberCompletion(
host,
program,
compilerOptions,
preferences,
name,
symbol,
location,
contextToken);
if (importAdder) {
const changes = textChanges.ChangeTracker.with(
{ host, formatContext, preferences },
importAdder.writeFixes);
return {
sourceDisplay: undefined,
codeActions: [{
changes,
description: diagnosticToString([Diagnostics.Includes_imports_of_types_referenced_by_0, name]),
}],
};
}
}
if (!origin || !(originIsExport(origin) || originIsResolvedExport(origin))) {
return { codeActions: undefined, sourceDisplay: undefined };
}
@ -3525,7 +3519,6 @@ namespace ts.Completions {
// function f<T>(x: T) {}
// f({ abc/**/: "" }) // `abc` is a member of `T` but only because it declares itself
function hasDeclarationOtherThanSelf(member: Symbol) {
if (!length(member.declarations)) return true;
return some(member.declarations, decl => decl.parent !== obj);
}
}
@ -3889,6 +3882,5 @@ namespace ts.Completions {
}
return charCode;
}
}

View file

@ -1323,7 +1323,7 @@ namespace ts.FindAllReferences {
if (!symbol) return undefined;
for (const token of getPossibleSymbolReferenceNodes(sourceFile, symbol.name, searchContainer)) {
if (!isIdentifier(token) || token === definition || token.escapedText !== definition.escapedText) continue;
const referenceSymbol = checker.getSymbolAtLocation(token)!;
const referenceSymbol: Symbol = checker.getSymbolAtLocation(token)!; // See GH#19955 for why the type annotation is necessary
if (referenceSymbol === symbol
|| checker.getShorthandAssignmentValueSymbol(token.parent) === symbol
|| isExportSpecifier(token.parent) && getLocalSymbolForExportSpecifier(token, referenceSymbol, token.parent, checker) === symbol) {
@ -2021,8 +2021,7 @@ namespace ts.FindAllReferences {
}
}
else {
return isNoSubstitutionTemplateLiteral(ref) && !rangeIsOnSingleLine(ref, sourceFile) ? undefined :
nodeEntry(ref, EntryKind.StringLiteral);
return nodeEntry(ref, EntryKind.StringLiteral);
}
}
});

View file

@ -198,17 +198,14 @@ namespace ts.GoToDefinition {
return undefined;
}
const symbol = getSymbol(node, typeChecker);
const symbol = typeChecker.getSymbolAtLocation(node);
if (!symbol) return undefined;
const typeAtLocation = typeChecker.getTypeOfSymbolAtLocation(symbol, node);
const returnType = tryGetReturnTypeOfFunction(symbol, typeAtLocation, typeChecker);
const fromReturnType = returnType && definitionFromType(returnType, typeChecker, node);
// If a function returns 'void' or some other type with no definition, just return the function definition.
const typeDefinitions = fromReturnType && fromReturnType.length !== 0 ? fromReturnType : definitionFromType(typeAtLocation, typeChecker, node);
return typeDefinitions.length ? typeDefinitions
: !(symbol.flags & SymbolFlags.Value) && symbol.flags & SymbolFlags.Type ? getDefinitionFromSymbol(typeChecker, skipAlias(symbol, typeChecker), node)
: undefined;
return fromReturnType && fromReturnType.length !== 0 ? fromReturnType : definitionFromType(typeAtLocation, typeChecker, node);
}
function definitionFromType(type: Type, checker: TypeChecker, node: Node): readonly DefinitionInfo[] {

View file

@ -34,7 +34,7 @@ namespace ts.OutliningElementsCollector {
if (depthRemaining === 0) return;
cancellationToken.throwIfCancellationRequested();
if (isDeclaration(n) || isVariableStatement(n) || isReturnStatement(n) || isCallOrNewExpression(n) || n.kind === SyntaxKind.EndOfFileToken) {
if (isDeclaration(n) || isVariableStatement(n) || isReturnStatement(n) || n.kind === SyntaxKind.EndOfFileToken) {
addOutliningForLeadingCommentsForNode(n, sourceFile, cancellationToken, out);
}

View file

@ -314,7 +314,8 @@ namespace ts.refactor.extractSymbol {
return { errors: [createFileDiagnostic(sourceFile, span.start, length, Messages.cannotExtractRange)] };
}
const statements: Statement[] = [];
for (const statement of start.parent.statements) {
const start2 = start; // TODO: GH#18217 Need to alias `start` to get this to compile. See https://github.com/Microsoft/TypeScript/issues/19955#issuecomment-344118248
for (const statement of (start2.parent as BlockLike).statements) {
if (statement === start || statements.length) {
const errors = checkNode(statement);
if (errors) {
@ -363,11 +364,10 @@ namespace ts.refactor.extractSymbol {
return node.expression;
}
}
else if (isVariableStatement(node) || isVariableDeclarationList(node)) {
const declarations = isVariableStatement(node) ? node.declarationList.declarations : node.declarations;
else if (isVariableStatement(node)) {
let numInitializers = 0;
let lastInitializer: Expression | undefined;
for (const declaration of declarations) {
for (const declaration of node.declarationList.declarations) {
if (declaration.initializer) {
numInitializers++;
lastInitializer = declaration.initializer;
@ -383,6 +383,7 @@ namespace ts.refactor.extractSymbol {
return node.initializer;
}
}
return node;
}
@ -1596,7 +1597,7 @@ namespace ts.refactor.extractSymbol {
const functionErrorsPerScope: Diagnostic[][] = [];
const constantErrorsPerScope: Diagnostic[][] = [];
const visibleDeclarationsInExtractedRange: NamedDeclaration[] = [];
const exposedVariableSymbolSet = new Map<string, true>(); // Key is symbol ID
const exposedVariableSymbolSet = new Set<Symbol>(); // Key is symbol ID
const exposedVariableDeclarations: VariableDeclaration[] = [];
let firstExposedNonVariableDeclaration: NamedDeclaration | undefined;
@ -1902,10 +1903,10 @@ namespace ts.refactor.extractSymbol {
const decl = find(visibleDeclarationsInExtractedRange, d => d.symbol === sym);
if (decl) {
if (isVariableDeclaration(decl)) {
const idString = decl.symbol.id!.toString();
if (!exposedVariableSymbolSet.has(idString)) {
const declSymbol = decl.symbol;
if (!exposedVariableSymbolSet.has(declSymbol)) {
exposedVariableDeclarations.push(decl);
exposedVariableSymbolSet.set(idString, true);
exposedVariableSymbolSet.add(declSymbol);
}
}
else {

View file

@ -287,6 +287,7 @@ namespace ts {
class SymbolObject implements Symbol {
flags: SymbolFlags;
id = 0;
escapedName: __String;
declarations!: Declaration[];
valueDeclaration!: Declaration;
@ -599,11 +600,10 @@ namespace ts {
}
function findBaseOfDeclaration<T>(checker: TypeChecker, declaration: Declaration, cb: (symbol: Symbol) => T[] | undefined): T[] | undefined {
if (hasStaticModifier(declaration)) return;
const classOrInterfaceDeclaration = declaration.parent?.kind === SyntaxKind.Constructor ? declaration.parent.parent : declaration.parent;
if (!classOrInterfaceDeclaration) return;
if (!classOrInterfaceDeclaration) {
return;
}
return firstDefined(getAllSuperTypeNodes(classOrInterfaceDeclaration), superTypeNode => {
const symbol = checker.getPropertyOfType(checker.getTypeAtLocation(superTypeNode), declaration.symbol.name);
return symbol ? cb(symbol) : undefined;

View file

@ -494,27 +494,6 @@ namespace ts.textChanges {
this.insertNodeAt(sourceFile, fnStart, tag, { preserveLeadingWhitespace: false, suffix: this.newLineCharacter + indent });
}
public addJSDocTags(sourceFile: SourceFile, parent: HasJSDoc, newTags: readonly JSDocTag[]): void {
const comments = flatMap(parent.jsDoc, j => typeof j.comment === "string" ? factory.createJSDocText(j.comment) : j.comment) as JSDocComment[];
const oldTags = flatMapToMutable(parent.jsDoc, j => j.tags);
const unmergedNewTags = newTags.filter(newTag => !oldTags.some((tag, i) => {
const merged = tryMergeJsdocTags(tag, newTag);
if (merged) oldTags[i] = merged;
return !!merged;
}));
const tag = factory.createJSDocComment(factory.createNodeArray(intersperse(comments, factory.createJSDocText("\n"))), factory.createNodeArray([...oldTags, ...unmergedNewTags]));
const host = updateJSDocHost(parent);
this.insertJsdocCommentBefore(sourceFile, host, tag);
}
public filterJSDocTags(sourceFile: SourceFile, parent: HasJSDoc, predicate: (tag: JSDocTag) => boolean): void {
const comments = flatMap(parent.jsDoc, j => typeof j.comment === "string" ? factory.createJSDocText(j.comment) : j.comment) as JSDocComment[];
const oldTags = flatMapToMutable(parent.jsDoc, j => j.tags);
const tag = factory.createJSDocComment(factory.createNodeArray(intersperse(comments, factory.createJSDocText("\n"))), factory.createNodeArray([...(filter(oldTags, predicate) || emptyArray)]));
const host = updateJSDocHost(parent);
this.insertJsdocCommentBefore(sourceFile, host, tag);
}
public replaceRangeWithText(sourceFile: SourceFile, range: TextRange, text: string): void {
this.changes.push({ kind: ChangeKind.Text, sourceFile, range, text });
}
@ -941,35 +920,6 @@ namespace ts.textChanges {
}
}
function updateJSDocHost(parent: HasJSDoc): HasJSDoc {
if (parent.kind !== SyntaxKind.ArrowFunction) {
return parent;
}
const jsDocNode = parent.parent.kind === SyntaxKind.PropertyDeclaration ?
parent.parent as HasJSDoc :
parent.parent.parent as HasJSDoc;
jsDocNode.jsDoc = parent.jsDoc;
jsDocNode.jsDocCache = parent.jsDocCache;
return jsDocNode;
}
function tryMergeJsdocTags(oldTag: JSDocTag, newTag: JSDocTag): JSDocTag | undefined {
if (oldTag.kind !== newTag.kind) {
return undefined;
}
switch (oldTag.kind) {
case SyntaxKind.JSDocParameterTag: {
const oldParam = oldTag as JSDocParameterTag;
const newParam = newTag as JSDocParameterTag;
return isIdentifier(oldParam.name) && isIdentifier(newParam.name) && oldParam.name.escapedText === newParam.name.escapedText
? factory.createJSDocParameterTag(/*tagName*/ undefined, newParam.name, /*isBracketed*/ false, newParam.typeExpression, newParam.isNameFirst, oldParam.comment)
: undefined;
}
case SyntaxKind.JSDocReturnTag:
return factory.createJSDocReturnTag(/*tagName*/ undefined, (newTag as JSDocReturnTag).typeExpression, oldTag.comment);
}
}
// find first non-whitespace position in the leading trivia of the node
function startPositionToDeleteNodeInList(sourceFile: SourceFile, node: Node): number {
return skipTrivia(sourceFile.text, getAdjustedStartPosition(sourceFile, node, { leadingTriviaOption: LeadingTriviaOption.IncludeAll }), /*stopAfterLineBreak*/ false, /*stopAtComments*/ true);

View file

@ -3283,12 +3283,5 @@ namespace ts {
return newLineCharacter === "\n" ? NewLineKind.LineFeed : NewLineKind.CarriageReturnLineFeed;
}
export type DiagnosticAndArguments = DiagnosticMessage | [DiagnosticMessage, string] | [DiagnosticMessage, string, string];
export function diagnosticToString(diag: DiagnosticAndArguments): string {
return isArray(diag)
? formatStringFromArgs(getLocaleSpecificMessage(diag[0]), diag.slice(1) as readonly string[])
: getLocaleSpecificMessage(diag);
}
// #endregion
}

View file

@ -14,7 +14,7 @@ namespace Harness.Parallel.Host {
const { statSync } = require("fs") as typeof import("fs");
// NOTE: paths for module and types for FailedTestReporter _do not_ line up due to our use of --outFile for run.js
const FailedTestReporter = require(Utils.findUpFile("scripts/failed-tests.js")) as typeof import("../../../scripts/failed-tests");
const FailedTestReporter = require(path.resolve(__dirname, "../../scripts/failed-tests")) as typeof import("../../../scripts/failed-tests");
const perfdataFileNameFragment = ".parallelperf";
const perfData = readSavedPerfData(configOption);

View file

@ -211,7 +211,7 @@ namespace ts {
start: undefined,
length: undefined,
}, {
messageText: "Argument for '--target' option must be: 'es3', 'es5', 'es6', 'es2015', 'es2016', 'es2017', 'es2018', 'es2019', 'es2020', 'es2021', 'es2022', 'esnext'.",
messageText: "Argument for '--target' option must be: 'es3', 'es5', 'es6', 'es2015', 'es2016', 'es2017', 'es2018', 'es2019', 'es2020', 'es2021', 'esnext'.",
category: Diagnostics.Argument_for_0_option_must_be_Colon_1.category,
code: Diagnostics.Argument_for_0_option_must_be_Colon_1.code,

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

@ -191,7 +191,7 @@ namespace ts {
testExtractRange("extractRange28", `[#|return [$|1|];|]`);
// For statements
testExtractRange("extractRange29", `for ([#|var i = [$|1|]|]; i < 2; i++) {}`);
testExtractRange("extractRange29", `for ([#|var i = 1|]; i < 2; i++) {}`);
testExtractRange("extractRange30", `for (var i = [#|[$|1|]|]; i < 2; i++) {}`);
});

View file

@ -326,7 +326,7 @@ namespace ts.projectSystem {
};
function updateFile(path: string, newText: string) {
Debug.assertIsDefined(files.find(f => f.path === path));
Debug.assertDefined(files.find(f => f.path === path));
session.executeCommandSeq<protocol.ApplyChangedToOpenFilesRequest>({
command: protocol.CommandTypes.ApplyChangedToOpenFiles,
arguments: {
@ -339,7 +339,7 @@ namespace ts.projectSystem {
}
function findAllReferences(file: string, line: number, offset: number) {
Debug.assertIsDefined(files.find(f => f.path === file));
Debug.assertDefined(files.find(f => f.path === file));
session.executeCommandSeq<protocol.ReferencesRequest>({
command: protocol.CommandTypes.References,
arguments: {

View file

@ -14,7 +14,7 @@ and limitations under the License.
***************************************************************************** */
declare namespace ts {
const versionMajorMinor = "4.6";
const versionMajorMinor = "4.5";
/** The version of the TypeScript compiler release */
const version: string;
/**
@ -897,7 +897,7 @@ declare namespace ts {
export interface TypePredicateNode extends TypeNode {
readonly kind: SyntaxKind.TypePredicate;
readonly parent: SignatureDeclaration | JSDocTypeExpression;
readonly assertsModifier?: AssertsKeyword;
readonly assertsModifier?: AssertsToken;
readonly parameterName: Identifier | ThisTypeNode;
readonly type?: TypeNode;
}
@ -968,7 +968,7 @@ declare namespace ts {
}
export interface MappedTypeNode extends TypeNode, Declaration {
readonly kind: SyntaxKind.MappedType;
readonly readonlyToken?: ReadonlyKeyword | PlusToken | MinusToken;
readonly readonlyToken?: ReadonlyToken | PlusToken | MinusToken;
readonly typeParameter: TypeParameterDeclaration;
readonly nameType?: TypeNode;
readonly questionToken?: QuestionToken | PlusToken | MinusToken;
@ -1465,7 +1465,7 @@ declare namespace ts {
}
export interface ForOfStatement extends IterationStatement {
readonly kind: SyntaxKind.ForOfStatement;
readonly awaitModifier?: AwaitKeyword;
readonly awaitModifier?: AwaitKeywordToken;
readonly initializer: ForInitializer;
readonly expression: Expression;
}
@ -3078,7 +3078,6 @@ declare namespace ts {
ES2019 = 6,
ES2020 = 7,
ES2021 = 8,
ES2022 = 9,
ESNext = 99,
JSON = 100,
Latest = 99
@ -9667,7 +9666,6 @@ declare namespace ts.server.protocol {
ES2019 = "ES2019",
ES2020 = "ES2020",
ES2021 = "ES2021",
ES2022 = "ES2022",
ESNext = "ESNext"
}
enum ClassificationType {

View file

@ -14,7 +14,7 @@ and limitations under the License.
***************************************************************************** */
declare namespace ts {
const versionMajorMinor = "4.6";
const versionMajorMinor = "4.5";
/** The version of the TypeScript compiler release */
const version: string;
/**
@ -897,7 +897,7 @@ declare namespace ts {
export interface TypePredicateNode extends TypeNode {
readonly kind: SyntaxKind.TypePredicate;
readonly parent: SignatureDeclaration | JSDocTypeExpression;
readonly assertsModifier?: AssertsKeyword;
readonly assertsModifier?: AssertsToken;
readonly parameterName: Identifier | ThisTypeNode;
readonly type?: TypeNode;
}
@ -968,7 +968,7 @@ declare namespace ts {
}
export interface MappedTypeNode extends TypeNode, Declaration {
readonly kind: SyntaxKind.MappedType;
readonly readonlyToken?: ReadonlyKeyword | PlusToken | MinusToken;
readonly readonlyToken?: ReadonlyToken | PlusToken | MinusToken;
readonly typeParameter: TypeParameterDeclaration;
readonly nameType?: TypeNode;
readonly questionToken?: QuestionToken | PlusToken | MinusToken;
@ -1465,7 +1465,7 @@ declare namespace ts {
}
export interface ForOfStatement extends IterationStatement {
readonly kind: SyntaxKind.ForOfStatement;
readonly awaitModifier?: AwaitKeyword;
readonly awaitModifier?: AwaitKeywordToken;
readonly initializer: ForInitializer;
readonly expression: Expression;
}
@ -3078,7 +3078,6 @@ declare namespace ts {
ES2019 = 6,
ES2020 = 7,
ES2021 = 8,
ES2022 = 9,
ESNext = 99,
JSON = 100,
Latest = 99

View file

@ -1,46 +0,0 @@
/a.js(18,9): error TS1210: Code contained in a class is evaluated in JavaScript's strict mode which does not allow this use of 'arguments'. For more information, see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode.
==== /a.js (1 errors) ====
class A {
/**
* Constructor
*
* @param {object} [foo={}]
*/
constructor(foo = {}) {
const key = "bar";
/**
* @type object
*/
this.foo = foo;
/**
* @type object
*/
const arguments = this.arguments;
~~~~~~~~~
!!! error TS1210: Code contained in a class is evaluated in JavaScript's strict mode which does not allow this use of 'arguments'. For more information, see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode.
/**
* @type object
*/
this.bar = arguments.bar;
/**
* @type object
*/
this.baz = arguments[key];
/**
* @type object
*/
this.options = arguments;
}
get arguments() {
return { bar: {} };
}
}

View file

@ -1,44 +0,0 @@
/a.js(16,9): error TS1210: Code contained in a class is evaluated in JavaScript's strict mode which does not allow this use of 'arguments'. For more information, see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode.
==== /a.js (1 errors) ====
class A {
/**
* @param {object} [foo={}]
*/
m(foo = {}) {
const key = "bar";
/**
* @type object
*/
this.foo = foo;
/**
* @type object
*/
const arguments = this.arguments;
~~~~~~~~~
!!! error TS1210: Code contained in a class is evaluated in JavaScript's strict mode which does not allow this use of 'arguments'. For more information, see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode.
/**
* @type object
*/
this.bar = arguments.bar;
/**
* @type object
*/
this.baz = arguments[key];
/**
* @type object
*/
this.options = arguments;
}
get arguments() {
return { bar: {} };
}
}

View file

@ -1,18 +0,0 @@
//// [callChainWithSuper.ts]
// GH#34952
class Base { method?() {} }
class Derived extends Base {
method1() { return super.method?.(); }
method2() { return super["method"]?.(); }
}
//// [callChainWithSuper.js]
"use strict";
// GH#34952
class Base {
method() { }
}
class Derived extends Base {
method1() { return super.method?.(); }
method2() { return super["method"]?.(); }
}

View file

@ -30,7 +30,7 @@ declare const pli: {
(streams: ReadonlyArray<R | W | RW>): Promise<void>;
>streams : Symbol(streams, Decl(callWithSpread4.ts, 5, 5))
>ReadonlyArray : Symbol(ReadonlyArray, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2016.array.include.d.ts, --, --), Decl(lib.es2019.array.d.ts, --, --) ... and 1 more)
>ReadonlyArray : Symbol(ReadonlyArray, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2016.array.include.d.ts, --, --), Decl(lib.es2019.array.d.ts, --, --))
>R : Symbol(R, Decl(callWithSpread4.ts, 0, 0))
>W : Symbol(W, Decl(callWithSpread4.ts, 0, 22))
>RW : Symbol(RW, Decl(callWithSpread4.ts, 1, 22))
@ -43,7 +43,7 @@ declare const pli: {
>RW : Symbol(RW, Decl(callWithSpread4.ts, 1, 22))
>W : Symbol(W, Decl(callWithSpread4.ts, 0, 22))
>streams : Symbol(streams, Decl(callWithSpread4.ts, 6, 23))
>Array : Symbol(Array, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --) ... and 3 more)
>Array : Symbol(Array, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --) ... and 2 more)
>RW : Symbol(RW, Decl(callWithSpread4.ts, 1, 22))
>W : Symbol(W, Decl(callWithSpread4.ts, 0, 22))
>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2018.promise.d.ts, --, --))

View file

@ -1,53 +0,0 @@
//// [contextuallyTypedSymbolNamedProperties.ts]
// Repros from #43628
const A = Symbol("A");
const B = Symbol("B");
type Action =
| {type: typeof A, data: string}
| {type: typeof B, data: number}
declare const ab: Action;
declare function f<T extends { type: string | symbol }>(action: T, blah: { [K in T['type']]: (p: K) => void }): any;
f(ab, {
[A]: ap => { ap.description },
[B]: bp => { bp.description },
})
const x: { [sym: symbol]: (p: string) => void } = { [A]: s => s.length };
//// [contextuallyTypedSymbolNamedProperties.js]
"use strict";
// Repros from #43628
const A = Symbol("A");
const B = Symbol("B");
f(ab, {
[A]: ap => { ap.description; },
[B]: bp => { bp.description; },
});
const x = { [A]: s => s.length };
//// [contextuallyTypedSymbolNamedProperties.d.ts]
declare const A: unique symbol;
declare const B: unique symbol;
declare type Action = {
type: typeof A;
data: string;
} | {
type: typeof B;
data: number;
};
declare const ab: Action;
declare function f<T extends {
type: string | symbol;
}>(action: T, blah: {
[K in T['type']]: (p: K) => void;
}): any;
declare const x: {
[sym: symbol]: (p: string) => void;
};

View file

@ -1,73 +0,0 @@
=== tests/cases/compiler/contextuallyTypedSymbolNamedProperties.ts ===
// Repros from #43628
const A = Symbol("A");
>A : Symbol(A, Decl(contextuallyTypedSymbolNamedProperties.ts, 2, 5))
>Symbol : Symbol(Symbol, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2019.symbol.d.ts, --, --))
const B = Symbol("B");
>B : Symbol(B, Decl(contextuallyTypedSymbolNamedProperties.ts, 3, 5))
>Symbol : Symbol(Symbol, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2019.symbol.d.ts, --, --))
type Action =
>Action : Symbol(Action, Decl(contextuallyTypedSymbolNamedProperties.ts, 3, 22))
| {type: typeof A, data: string}
>type : Symbol(type, Decl(contextuallyTypedSymbolNamedProperties.ts, 6, 7))
>A : Symbol(A, Decl(contextuallyTypedSymbolNamedProperties.ts, 2, 5))
>data : Symbol(data, Decl(contextuallyTypedSymbolNamedProperties.ts, 6, 22))
| {type: typeof B, data: number}
>type : Symbol(type, Decl(contextuallyTypedSymbolNamedProperties.ts, 7, 7))
>B : Symbol(B, Decl(contextuallyTypedSymbolNamedProperties.ts, 3, 5))
>data : Symbol(data, Decl(contextuallyTypedSymbolNamedProperties.ts, 7, 22))
declare const ab: Action;
>ab : Symbol(ab, Decl(contextuallyTypedSymbolNamedProperties.ts, 9, 13))
>Action : Symbol(Action, Decl(contextuallyTypedSymbolNamedProperties.ts, 3, 22))
declare function f<T extends { type: string | symbol }>(action: T, blah: { [K in T['type']]: (p: K) => void }): any;
>f : Symbol(f, Decl(contextuallyTypedSymbolNamedProperties.ts, 9, 25))
>T : Symbol(T, Decl(contextuallyTypedSymbolNamedProperties.ts, 11, 19))
>type : Symbol(type, Decl(contextuallyTypedSymbolNamedProperties.ts, 11, 30))
>action : Symbol(action, Decl(contextuallyTypedSymbolNamedProperties.ts, 11, 56))
>T : Symbol(T, Decl(contextuallyTypedSymbolNamedProperties.ts, 11, 19))
>blah : Symbol(blah, Decl(contextuallyTypedSymbolNamedProperties.ts, 11, 66))
>K : Symbol(K, Decl(contextuallyTypedSymbolNamedProperties.ts, 11, 76))
>T : Symbol(T, Decl(contextuallyTypedSymbolNamedProperties.ts, 11, 19))
>p : Symbol(p, Decl(contextuallyTypedSymbolNamedProperties.ts, 11, 94))
>K : Symbol(K, Decl(contextuallyTypedSymbolNamedProperties.ts, 11, 76))
f(ab, {
>f : Symbol(f, Decl(contextuallyTypedSymbolNamedProperties.ts, 9, 25))
>ab : Symbol(ab, Decl(contextuallyTypedSymbolNamedProperties.ts, 9, 13))
[A]: ap => { ap.description },
>[A] : Symbol([A], Decl(contextuallyTypedSymbolNamedProperties.ts, 13, 7))
>A : Symbol(A, Decl(contextuallyTypedSymbolNamedProperties.ts, 2, 5))
>ap : Symbol(ap, Decl(contextuallyTypedSymbolNamedProperties.ts, 14, 8))
>ap.description : Symbol(Symbol.description, Decl(lib.es2019.symbol.d.ts, --, --))
>ap : Symbol(ap, Decl(contextuallyTypedSymbolNamedProperties.ts, 14, 8))
>description : Symbol(Symbol.description, Decl(lib.es2019.symbol.d.ts, --, --))
[B]: bp => { bp.description },
>[B] : Symbol([B], Decl(contextuallyTypedSymbolNamedProperties.ts, 14, 34))
>B : Symbol(B, Decl(contextuallyTypedSymbolNamedProperties.ts, 3, 5))
>bp : Symbol(bp, Decl(contextuallyTypedSymbolNamedProperties.ts, 15, 8))
>bp.description : Symbol(Symbol.description, Decl(lib.es2019.symbol.d.ts, --, --))
>bp : Symbol(bp, Decl(contextuallyTypedSymbolNamedProperties.ts, 15, 8))
>description : Symbol(Symbol.description, Decl(lib.es2019.symbol.d.ts, --, --))
})
const x: { [sym: symbol]: (p: string) => void } = { [A]: s => s.length };
>x : Symbol(x, Decl(contextuallyTypedSymbolNamedProperties.ts, 18, 5))
>sym : Symbol(sym, Decl(contextuallyTypedSymbolNamedProperties.ts, 18, 12))
>p : Symbol(p, Decl(contextuallyTypedSymbolNamedProperties.ts, 18, 27))
>[A] : Symbol([A], Decl(contextuallyTypedSymbolNamedProperties.ts, 18, 51))
>A : Symbol(A, Decl(contextuallyTypedSymbolNamedProperties.ts, 2, 5))
>s : Symbol(s, Decl(contextuallyTypedSymbolNamedProperties.ts, 18, 56))
>s.length : Symbol(String.length, Decl(lib.es5.d.ts, --, --))
>s : Symbol(s, Decl(contextuallyTypedSymbolNamedProperties.ts, 18, 56))
>length : Symbol(String.length, Decl(lib.es5.d.ts, --, --))

View file

@ -1,77 +0,0 @@
=== tests/cases/compiler/contextuallyTypedSymbolNamedProperties.ts ===
// Repros from #43628
const A = Symbol("A");
>A : unique symbol
>Symbol("A") : unique symbol
>Symbol : SymbolConstructor
>"A" : "A"
const B = Symbol("B");
>B : unique symbol
>Symbol("B") : unique symbol
>Symbol : SymbolConstructor
>"B" : "B"
type Action =
>Action : Action
| {type: typeof A, data: string}
>type : unique symbol
>A : unique symbol
>data : string
| {type: typeof B, data: number}
>type : unique symbol
>B : unique symbol
>data : number
declare const ab: Action;
>ab : Action
declare function f<T extends { type: string | symbol }>(action: T, blah: { [K in T['type']]: (p: K) => void }): any;
>f : <T extends { type: string | symbol; }>(action: T, blah: { [K in T["type"]]: (p: K) => void; }) => any
>type : string | symbol
>action : T
>blah : { [K in T["type"]]: (p: K) => void; }
>p : K
f(ab, {
>f(ab, { [A]: ap => { ap.description }, [B]: bp => { bp.description },}) : any
>f : <T extends { type: string | symbol; }>(action: T, blah: { [K in T["type"]]: (p: K) => void; }) => any
>ab : Action
>{ [A]: ap => { ap.description }, [B]: bp => { bp.description },} : { [A]: (ap: unique symbol) => void; [B]: (bp: unique symbol) => void; }
[A]: ap => { ap.description },
>[A] : (ap: unique symbol) => void
>A : unique symbol
>ap => { ap.description } : (ap: unique symbol) => void
>ap : unique symbol
>ap.description : string | undefined
>ap : unique symbol
>description : string | undefined
[B]: bp => { bp.description },
>[B] : (bp: unique symbol) => void
>B : unique symbol
>bp => { bp.description } : (bp: unique symbol) => void
>bp : unique symbol
>bp.description : string | undefined
>bp : unique symbol
>description : string | undefined
})
const x: { [sym: symbol]: (p: string) => void } = { [A]: s => s.length };
>x : { [sym: symbol]: (p: string) => void; }
>sym : symbol
>p : string
>{ [A]: s => s.length } : { [A]: (s: string) => number; }
>[A] : (s: string) => number
>A : unique symbol
>s => s.length : (s: string) => number
>s : string
>s.length : number
>s : string
>length : number

View file

@ -28,11 +28,15 @@ tests/cases/conformance/controlFlow/controlFlowAliasing.ts(232,13): error TS2322
Type 'number' is not assignable to type 'string'.
tests/cases/conformance/controlFlow/controlFlowAliasing.ts(233,13): error TS2322: Type 'string | number' is not assignable to type 'string'.
Type 'number' is not assignable to type 'string'.
tests/cases/conformance/controlFlow/controlFlowAliasing.ts(267,13): error TS2322: Type 'string | number' is not assignable to type 'string'.
Type 'number' is not assignable to type 'string'.
tests/cases/conformance/controlFlow/controlFlowAliasing.ts(270,13): error TS2322: Type 'string | number' is not assignable to type 'number'.
Type 'string' is not assignable to type 'number'.
tests/cases/conformance/controlFlow/controlFlowAliasing.ts(280,5): error TS2448: Block-scoped variable 'a' used before its declaration.
tests/cases/conformance/controlFlow/controlFlowAliasing.ts(280,5): error TS2454: Variable 'a' is used before being assigned.
==== tests/cases/conformance/controlFlow/controlFlowAliasing.ts (17 errors) ====
==== tests/cases/conformance/controlFlow/controlFlowAliasing.ts (19 errors) ====
// Narrowing by aliased conditional expressions
function f10(x: string | number) {
@ -345,9 +349,15 @@ tests/cases/conformance/controlFlow/controlFlowAliasing.ts(280,5): error TS2454:
function foo({ kind, payload }: Data) {
if (kind === 'str') {
let t: string = payload;
~
!!! error TS2322: Type 'string | number' is not assignable to type 'string'.
!!! error TS2322: Type 'number' is not assignable to type 'string'.
}
else {
let t: number = payload;
~
!!! error TS2322: Type 'string | number' is not assignable to type 'number'.
!!! error TS2322: Type 'string' is not assignable to type 'number'.
}
}

View file

@ -888,12 +888,12 @@ function foo({ kind, payload }: Data) {
let t: string = payload;
>t : string
>payload : string
>payload : string | number
}
else {
let t: number = payload;
>t : number
>payload : number
>payload : string | number
}
}

View file

@ -1,9 +0,0 @@
//// [defaultNamedExportWithType1.ts]
type Foo = number;
export const Foo = 1;
export default Foo;
//// [defaultNamedExportWithType1.js]
export const Foo = 1;
export default Foo;

View file

@ -1,10 +0,0 @@
=== tests/cases/compiler/defaultNamedExportWithType1.ts ===
type Foo = number;
>Foo : Symbol(Foo, Decl(defaultNamedExportWithType1.ts, 0, 0), Decl(defaultNamedExportWithType1.ts, 1, 12))
export const Foo = 1;
>Foo : Symbol(Foo, Decl(defaultNamedExportWithType1.ts, 1, 12))
export default Foo;
>Foo : Symbol(Foo, Decl(defaultNamedExportWithType1.ts, 0, 0), Decl(defaultNamedExportWithType1.ts, 1, 12))

View file

@ -1,11 +0,0 @@
=== tests/cases/compiler/defaultNamedExportWithType1.ts ===
type Foo = number;
>Foo : number
export const Foo = 1;
>Foo : 1
>1 : 1
export default Foo;
>Foo : number

View file

@ -1,9 +0,0 @@
//// [defaultNamedExportWithType2.ts]
type Foo = number;
const Foo = 1;
export default Foo;
//// [defaultNamedExportWithType2.js]
const Foo = 1;
export default Foo;

View file

@ -1,10 +0,0 @@
=== tests/cases/compiler/defaultNamedExportWithType2.ts ===
type Foo = number;
>Foo : Symbol(Foo, Decl(defaultNamedExportWithType2.ts, 0, 0), Decl(defaultNamedExportWithType2.ts, 1, 5))
const Foo = 1;
>Foo : Symbol(Foo, Decl(defaultNamedExportWithType2.ts, 0, 0), Decl(defaultNamedExportWithType2.ts, 1, 5))
export default Foo;
>Foo : Symbol(Foo, Decl(defaultNamedExportWithType2.ts, 0, 0), Decl(defaultNamedExportWithType2.ts, 1, 5))

View file

@ -1,11 +0,0 @@
=== tests/cases/compiler/defaultNamedExportWithType2.ts ===
type Foo = number;
>Foo : number
const Foo = 1;
>Foo : 1
>1 : 1
export default Foo;
>Foo : number

View file

@ -1,9 +0,0 @@
//// [defaultNamedExportWithType3.ts]
interface Foo {}
export const Foo = {};
export default Foo;
//// [defaultNamedExportWithType3.js]
export const Foo = {};
export default Foo;

View file

@ -1,10 +0,0 @@
=== tests/cases/compiler/defaultNamedExportWithType3.ts ===
interface Foo {}
>Foo : Symbol(Foo, Decl(defaultNamedExportWithType3.ts, 0, 0), Decl(defaultNamedExportWithType3.ts, 1, 12))
export const Foo = {};
>Foo : Symbol(Foo, Decl(defaultNamedExportWithType3.ts, 1, 12))
export default Foo;
>Foo : Symbol(Foo, Decl(defaultNamedExportWithType3.ts, 0, 0), Decl(defaultNamedExportWithType3.ts, 1, 12))

View file

@ -1,9 +0,0 @@
=== tests/cases/compiler/defaultNamedExportWithType3.ts ===
interface Foo {}
export const Foo = {};
>Foo : {}
>{} : {}
export default Foo;
>Foo : Foo

View file

@ -1,9 +0,0 @@
//// [defaultNamedExportWithType4.ts]
interface Foo {}
const Foo = {};
export default Foo;
//// [defaultNamedExportWithType4.js]
const Foo = {};
export default Foo;

View file

@ -1,10 +0,0 @@
=== tests/cases/compiler/defaultNamedExportWithType4.ts ===
interface Foo {}
>Foo : Symbol(Foo, Decl(defaultNamedExportWithType4.ts, 0, 0), Decl(defaultNamedExportWithType4.ts, 1, 5))
const Foo = {};
>Foo : Symbol(Foo, Decl(defaultNamedExportWithType4.ts, 0, 0), Decl(defaultNamedExportWithType4.ts, 1, 5))
export default Foo;
>Foo : Symbol(Foo, Decl(defaultNamedExportWithType4.ts, 0, 0), Decl(defaultNamedExportWithType4.ts, 1, 5))

View file

@ -1,9 +0,0 @@
=== tests/cases/compiler/defaultNamedExportWithType4.ts ===
interface Foo {}
const Foo = {};
>Foo : {}
>{} : {}
export default Foo;
>Foo : Foo

View file

@ -1,336 +0,0 @@
//// [dependentDestructuredVariables.ts]
type Action =
| { kind: 'A', payload: number }
| { kind: 'B', payload: string };
function f10({ kind, payload }: Action) {
if (kind === 'A') {
payload.toFixed();
}
if (kind === 'B') {
payload.toUpperCase();
}
}
function f11(action: Action) {
const { kind, payload } = action;
if (kind === 'A') {
payload.toFixed();
}
if (kind === 'B') {
payload.toUpperCase();
}
}
function f12({ kind, payload }: Action) {
switch (kind) {
case 'A':
payload.toFixed();
break;
case 'B':
payload.toUpperCase();
break;
default:
payload; // never
}
}
type Action2 =
| { kind: 'A', payload: number | undefined }
| { kind: 'B', payload: string | undefined };
function f20({ kind, payload }: Action2) {
if (payload) {
if (kind === 'A') {
payload.toFixed();
}
if (kind === 'B') {
payload.toUpperCase();
}
}
}
function f21(action: Action2) {
const { kind, payload } = action;
if (payload) {
if (kind === 'A') {
payload.toFixed();
}
if (kind === 'B') {
payload.toUpperCase();
}
}
}
function f22(action: Action2) {
if (action.payload) {
const { kind, payload } = action;
if (kind === 'A') {
payload.toFixed();
}
if (kind === 'B') {
payload.toUpperCase();
}
}
}
function f23({ kind, payload }: Action2) {
if (payload) {
switch (kind) {
case 'A':
payload.toFixed();
break;
case 'B':
payload.toUpperCase();
break;
default:
payload; // never
}
}
}
type Foo =
| { kind: 'A', isA: true }
| { kind: 'B', isA: false }
| { kind: 'C', isA: false };
function f30({ kind, isA }: Foo) {
if (kind === 'A') {
isA; // true
}
if (kind === 'B') {
isA; // false
}
if (kind === 'C') {
isA; // false
}
if (isA) {
kind; // 'A'
}
else {
kind; // 'B' | 'C'
}
}
// Repro from #35283
interface A<T> { variant: 'a', value: T }
interface B<T> { variant: 'b', value: Array<T> }
type AB<T> = A<T> | B<T>;
declare function printValue<T>(t: T): void;
declare function printValueList<T>(t: Array<T>): void;
function unrefined1<T>(ab: AB<T>): void {
const { variant, value } = ab;
if (variant === 'a') {
printValue<T>(value);
}
else {
printValueList<T>(value);
}
}
// Repro from #38020
type Action3 =
| {type: 'add', payload: { toAdd: number } }
| {type: 'remove', payload: { toRemove: number } };
const reducerBroken = (state: number, { type, payload }: Action3) => {
switch (type) {
case 'add':
return state + payload.toAdd;
case 'remove':
return state - payload.toRemove;
}
}
// Repro from #46143
declare var it: Iterator<number>;
const { value, done } = it.next();
if (!done) {
value; // number
}
//// [dependentDestructuredVariables.js]
"use strict";
function f10({ kind, payload }) {
if (kind === 'A') {
payload.toFixed();
}
if (kind === 'B') {
payload.toUpperCase();
}
}
function f11(action) {
const { kind, payload } = action;
if (kind === 'A') {
payload.toFixed();
}
if (kind === 'B') {
payload.toUpperCase();
}
}
function f12({ kind, payload }) {
switch (kind) {
case 'A':
payload.toFixed();
break;
case 'B':
payload.toUpperCase();
break;
default:
payload; // never
}
}
function f20({ kind, payload }) {
if (payload) {
if (kind === 'A') {
payload.toFixed();
}
if (kind === 'B') {
payload.toUpperCase();
}
}
}
function f21(action) {
const { kind, payload } = action;
if (payload) {
if (kind === 'A') {
payload.toFixed();
}
if (kind === 'B') {
payload.toUpperCase();
}
}
}
function f22(action) {
if (action.payload) {
const { kind, payload } = action;
if (kind === 'A') {
payload.toFixed();
}
if (kind === 'B') {
payload.toUpperCase();
}
}
}
function f23({ kind, payload }) {
if (payload) {
switch (kind) {
case 'A':
payload.toFixed();
break;
case 'B':
payload.toUpperCase();
break;
default:
payload; // never
}
}
}
function f30({ kind, isA }) {
if (kind === 'A') {
isA; // true
}
if (kind === 'B') {
isA; // false
}
if (kind === 'C') {
isA; // false
}
if (isA) {
kind; // 'A'
}
else {
kind; // 'B' | 'C'
}
}
function unrefined1(ab) {
const { variant, value } = ab;
if (variant === 'a') {
printValue(value);
}
else {
printValueList(value);
}
}
const reducerBroken = (state, { type, payload }) => {
switch (type) {
case 'add':
return state + payload.toAdd;
case 'remove':
return state - payload.toRemove;
}
};
const { value, done } = it.next();
if (!done) {
value; // number
}
//// [dependentDestructuredVariables.d.ts]
declare type Action = {
kind: 'A';
payload: number;
} | {
kind: 'B';
payload: string;
};
declare function f10({ kind, payload }: Action): void;
declare function f11(action: Action): void;
declare function f12({ kind, payload }: Action): void;
declare type Action2 = {
kind: 'A';
payload: number | undefined;
} | {
kind: 'B';
payload: string | undefined;
};
declare function f20({ kind, payload }: Action2): void;
declare function f21(action: Action2): void;
declare function f22(action: Action2): void;
declare function f23({ kind, payload }: Action2): void;
declare type Foo = {
kind: 'A';
isA: true;
} | {
kind: 'B';
isA: false;
} | {
kind: 'C';
isA: false;
};
declare function f30({ kind, isA }: Foo): void;
interface A<T> {
variant: 'a';
value: T;
}
interface B<T> {
variant: 'b';
value: Array<T>;
}
declare type AB<T> = A<T> | B<T>;
declare function printValue<T>(t: T): void;
declare function printValueList<T>(t: Array<T>): void;
declare function unrefined1<T>(ab: AB<T>): void;
declare type Action3 = {
type: 'add';
payload: {
toAdd: number;
};
} | {
type: 'remove';
payload: {
toRemove: number;
};
};
declare const reducerBroken: (state: number, { type, payload }: Action3) => number;
declare var it: Iterator<number>;
declare const value: any, done: boolean | undefined;

View file

@ -1,409 +0,0 @@
=== tests/cases/conformance/controlFlow/dependentDestructuredVariables.ts ===
type Action =
>Action : Symbol(Action, Decl(dependentDestructuredVariables.ts, 0, 0))
| { kind: 'A', payload: number }
>kind : Symbol(kind, Decl(dependentDestructuredVariables.ts, 1, 7))
>payload : Symbol(payload, Decl(dependentDestructuredVariables.ts, 1, 18))
| { kind: 'B', payload: string };
>kind : Symbol(kind, Decl(dependentDestructuredVariables.ts, 2, 7))
>payload : Symbol(payload, Decl(dependentDestructuredVariables.ts, 2, 18))
function f10({ kind, payload }: Action) {
>f10 : Symbol(f10, Decl(dependentDestructuredVariables.ts, 2, 37))
>kind : Symbol(kind, Decl(dependentDestructuredVariables.ts, 4, 14))
>payload : Symbol(payload, Decl(dependentDestructuredVariables.ts, 4, 20))
>Action : Symbol(Action, Decl(dependentDestructuredVariables.ts, 0, 0))
if (kind === 'A') {
>kind : Symbol(kind, Decl(dependentDestructuredVariables.ts, 4, 14))
payload.toFixed();
>payload.toFixed : Symbol(Number.toFixed, Decl(lib.es5.d.ts, --, --))
>payload : Symbol(payload, Decl(dependentDestructuredVariables.ts, 4, 20))
>toFixed : Symbol(Number.toFixed, Decl(lib.es5.d.ts, --, --))
}
if (kind === 'B') {
>kind : Symbol(kind, Decl(dependentDestructuredVariables.ts, 4, 14))
payload.toUpperCase();
>payload.toUpperCase : Symbol(String.toUpperCase, Decl(lib.es5.d.ts, --, --))
>payload : Symbol(payload, Decl(dependentDestructuredVariables.ts, 4, 20))
>toUpperCase : Symbol(String.toUpperCase, Decl(lib.es5.d.ts, --, --))
}
}
function f11(action: Action) {
>f11 : Symbol(f11, Decl(dependentDestructuredVariables.ts, 11, 1))
>action : Symbol(action, Decl(dependentDestructuredVariables.ts, 13, 13))
>Action : Symbol(Action, Decl(dependentDestructuredVariables.ts, 0, 0))
const { kind, payload } = action;
>kind : Symbol(kind, Decl(dependentDestructuredVariables.ts, 14, 11))
>payload : Symbol(payload, Decl(dependentDestructuredVariables.ts, 14, 17))
>action : Symbol(action, Decl(dependentDestructuredVariables.ts, 13, 13))
if (kind === 'A') {
>kind : Symbol(kind, Decl(dependentDestructuredVariables.ts, 14, 11))
payload.toFixed();
>payload.toFixed : Symbol(Number.toFixed, Decl(lib.es5.d.ts, --, --))
>payload : Symbol(payload, Decl(dependentDestructuredVariables.ts, 14, 17))
>toFixed : Symbol(Number.toFixed, Decl(lib.es5.d.ts, --, --))
}
if (kind === 'B') {
>kind : Symbol(kind, Decl(dependentDestructuredVariables.ts, 14, 11))
payload.toUpperCase();
>payload.toUpperCase : Symbol(String.toUpperCase, Decl(lib.es5.d.ts, --, --))
>payload : Symbol(payload, Decl(dependentDestructuredVariables.ts, 14, 17))
>toUpperCase : Symbol(String.toUpperCase, Decl(lib.es5.d.ts, --, --))
}
}
function f12({ kind, payload }: Action) {
>f12 : Symbol(f12, Decl(dependentDestructuredVariables.ts, 21, 1))
>kind : Symbol(kind, Decl(dependentDestructuredVariables.ts, 23, 14))
>payload : Symbol(payload, Decl(dependentDestructuredVariables.ts, 23, 20))
>Action : Symbol(Action, Decl(dependentDestructuredVariables.ts, 0, 0))
switch (kind) {
>kind : Symbol(kind, Decl(dependentDestructuredVariables.ts, 23, 14))
case 'A':
payload.toFixed();
>payload.toFixed : Symbol(Number.toFixed, Decl(lib.es5.d.ts, --, --))
>payload : Symbol(payload, Decl(dependentDestructuredVariables.ts, 23, 20))
>toFixed : Symbol(Number.toFixed, Decl(lib.es5.d.ts, --, --))
break;
case 'B':
payload.toUpperCase();
>payload.toUpperCase : Symbol(String.toUpperCase, Decl(lib.es5.d.ts, --, --))
>payload : Symbol(payload, Decl(dependentDestructuredVariables.ts, 23, 20))
>toUpperCase : Symbol(String.toUpperCase, Decl(lib.es5.d.ts, --, --))
break;
default:
payload; // never
>payload : Symbol(payload, Decl(dependentDestructuredVariables.ts, 23, 20))
}
}
type Action2 =
>Action2 : Symbol(Action2, Decl(dependentDestructuredVariables.ts, 34, 1))
| { kind: 'A', payload: number | undefined }
>kind : Symbol(kind, Decl(dependentDestructuredVariables.ts, 37, 7))
>payload : Symbol(payload, Decl(dependentDestructuredVariables.ts, 37, 18))
| { kind: 'B', payload: string | undefined };
>kind : Symbol(kind, Decl(dependentDestructuredVariables.ts, 38, 7))
>payload : Symbol(payload, Decl(dependentDestructuredVariables.ts, 38, 18))
function f20({ kind, payload }: Action2) {
>f20 : Symbol(f20, Decl(dependentDestructuredVariables.ts, 38, 49))
>kind : Symbol(kind, Decl(dependentDestructuredVariables.ts, 40, 14))
>payload : Symbol(payload, Decl(dependentDestructuredVariables.ts, 40, 20))
>Action2 : Symbol(Action2, Decl(dependentDestructuredVariables.ts, 34, 1))
if (payload) {
>payload : Symbol(payload, Decl(dependentDestructuredVariables.ts, 40, 20))
if (kind === 'A') {
>kind : Symbol(kind, Decl(dependentDestructuredVariables.ts, 40, 14))
payload.toFixed();
>payload.toFixed : Symbol(Number.toFixed, Decl(lib.es5.d.ts, --, --))
>payload : Symbol(payload, Decl(dependentDestructuredVariables.ts, 40, 20))
>toFixed : Symbol(Number.toFixed, Decl(lib.es5.d.ts, --, --))
}
if (kind === 'B') {
>kind : Symbol(kind, Decl(dependentDestructuredVariables.ts, 40, 14))
payload.toUpperCase();
>payload.toUpperCase : Symbol(String.toUpperCase, Decl(lib.es5.d.ts, --, --))
>payload : Symbol(payload, Decl(dependentDestructuredVariables.ts, 40, 20))
>toUpperCase : Symbol(String.toUpperCase, Decl(lib.es5.d.ts, --, --))
}
}
}
function f21(action: Action2) {
>f21 : Symbol(f21, Decl(dependentDestructuredVariables.ts, 49, 1))
>action : Symbol(action, Decl(dependentDestructuredVariables.ts, 51, 13))
>Action2 : Symbol(Action2, Decl(dependentDestructuredVariables.ts, 34, 1))
const { kind, payload } = action;
>kind : Symbol(kind, Decl(dependentDestructuredVariables.ts, 52, 11))
>payload : Symbol(payload, Decl(dependentDestructuredVariables.ts, 52, 17))
>action : Symbol(action, Decl(dependentDestructuredVariables.ts, 51, 13))
if (payload) {
>payload : Symbol(payload, Decl(dependentDestructuredVariables.ts, 52, 17))
if (kind === 'A') {
>kind : Symbol(kind, Decl(dependentDestructuredVariables.ts, 52, 11))
payload.toFixed();
>payload.toFixed : Symbol(Number.toFixed, Decl(lib.es5.d.ts, --, --))
>payload : Symbol(payload, Decl(dependentDestructuredVariables.ts, 52, 17))
>toFixed : Symbol(Number.toFixed, Decl(lib.es5.d.ts, --, --))
}
if (kind === 'B') {
>kind : Symbol(kind, Decl(dependentDestructuredVariables.ts, 52, 11))
payload.toUpperCase();
>payload.toUpperCase : Symbol(String.toUpperCase, Decl(lib.es5.d.ts, --, --))
>payload : Symbol(payload, Decl(dependentDestructuredVariables.ts, 52, 17))
>toUpperCase : Symbol(String.toUpperCase, Decl(lib.es5.d.ts, --, --))
}
}
}
function f22(action: Action2) {
>f22 : Symbol(f22, Decl(dependentDestructuredVariables.ts, 61, 1))
>action : Symbol(action, Decl(dependentDestructuredVariables.ts, 63, 13))
>Action2 : Symbol(Action2, Decl(dependentDestructuredVariables.ts, 34, 1))
if (action.payload) {
>action.payload : Symbol(payload, Decl(dependentDestructuredVariables.ts, 37, 18), Decl(dependentDestructuredVariables.ts, 38, 18))
>action : Symbol(action, Decl(dependentDestructuredVariables.ts, 63, 13))
>payload : Symbol(payload, Decl(dependentDestructuredVariables.ts, 37, 18), Decl(dependentDestructuredVariables.ts, 38, 18))
const { kind, payload } = action;
>kind : Symbol(kind, Decl(dependentDestructuredVariables.ts, 65, 15))
>payload : Symbol(payload, Decl(dependentDestructuredVariables.ts, 65, 21))
>action : Symbol(action, Decl(dependentDestructuredVariables.ts, 63, 13))
if (kind === 'A') {
>kind : Symbol(kind, Decl(dependentDestructuredVariables.ts, 65, 15))
payload.toFixed();
>payload.toFixed : Symbol(Number.toFixed, Decl(lib.es5.d.ts, --, --))
>payload : Symbol(payload, Decl(dependentDestructuredVariables.ts, 65, 21))
>toFixed : Symbol(Number.toFixed, Decl(lib.es5.d.ts, --, --))
}
if (kind === 'B') {
>kind : Symbol(kind, Decl(dependentDestructuredVariables.ts, 65, 15))
payload.toUpperCase();
>payload.toUpperCase : Symbol(String.toUpperCase, Decl(lib.es5.d.ts, --, --))
>payload : Symbol(payload, Decl(dependentDestructuredVariables.ts, 65, 21))
>toUpperCase : Symbol(String.toUpperCase, Decl(lib.es5.d.ts, --, --))
}
}
}
function f23({ kind, payload }: Action2) {
>f23 : Symbol(f23, Decl(dependentDestructuredVariables.ts, 73, 1))
>kind : Symbol(kind, Decl(dependentDestructuredVariables.ts, 75, 14))
>payload : Symbol(payload, Decl(dependentDestructuredVariables.ts, 75, 20))
>Action2 : Symbol(Action2, Decl(dependentDestructuredVariables.ts, 34, 1))
if (payload) {
>payload : Symbol(payload, Decl(dependentDestructuredVariables.ts, 75, 20))
switch (kind) {
>kind : Symbol(kind, Decl(dependentDestructuredVariables.ts, 75, 14))
case 'A':
payload.toFixed();
>payload.toFixed : Symbol(Number.toFixed, Decl(lib.es5.d.ts, --, --))
>payload : Symbol(payload, Decl(dependentDestructuredVariables.ts, 75, 20))
>toFixed : Symbol(Number.toFixed, Decl(lib.es5.d.ts, --, --))
break;
case 'B':
payload.toUpperCase();
>payload.toUpperCase : Symbol(String.toUpperCase, Decl(lib.es5.d.ts, --, --))
>payload : Symbol(payload, Decl(dependentDestructuredVariables.ts, 75, 20))
>toUpperCase : Symbol(String.toUpperCase, Decl(lib.es5.d.ts, --, --))
break;
default:
payload; // never
>payload : Symbol(payload, Decl(dependentDestructuredVariables.ts, 75, 20))
}
}
}
type Foo =
>Foo : Symbol(Foo, Decl(dependentDestructuredVariables.ts, 88, 1))
| { kind: 'A', isA: true }
>kind : Symbol(kind, Decl(dependentDestructuredVariables.ts, 91, 7))
>isA : Symbol(isA, Decl(dependentDestructuredVariables.ts, 91, 18))
| { kind: 'B', isA: false }
>kind : Symbol(kind, Decl(dependentDestructuredVariables.ts, 92, 7))
>isA : Symbol(isA, Decl(dependentDestructuredVariables.ts, 92, 18))
| { kind: 'C', isA: false };
>kind : Symbol(kind, Decl(dependentDestructuredVariables.ts, 93, 7))
>isA : Symbol(isA, Decl(dependentDestructuredVariables.ts, 93, 18))
function f30({ kind, isA }: Foo) {
>f30 : Symbol(f30, Decl(dependentDestructuredVariables.ts, 93, 32))
>kind : Symbol(kind, Decl(dependentDestructuredVariables.ts, 95, 14))
>isA : Symbol(isA, Decl(dependentDestructuredVariables.ts, 95, 20))
>Foo : Symbol(Foo, Decl(dependentDestructuredVariables.ts, 88, 1))
if (kind === 'A') {
>kind : Symbol(kind, Decl(dependentDestructuredVariables.ts, 95, 14))
isA; // true
>isA : Symbol(isA, Decl(dependentDestructuredVariables.ts, 95, 20))
}
if (kind === 'B') {
>kind : Symbol(kind, Decl(dependentDestructuredVariables.ts, 95, 14))
isA; // false
>isA : Symbol(isA, Decl(dependentDestructuredVariables.ts, 95, 20))
}
if (kind === 'C') {
>kind : Symbol(kind, Decl(dependentDestructuredVariables.ts, 95, 14))
isA; // false
>isA : Symbol(isA, Decl(dependentDestructuredVariables.ts, 95, 20))
}
if (isA) {
>isA : Symbol(isA, Decl(dependentDestructuredVariables.ts, 95, 20))
kind; // 'A'
>kind : Symbol(kind, Decl(dependentDestructuredVariables.ts, 95, 14))
}
else {
kind; // 'B' | 'C'
>kind : Symbol(kind, Decl(dependentDestructuredVariables.ts, 95, 14))
}
}
// Repro from #35283
interface A<T> { variant: 'a', value: T }
>A : Symbol(A, Decl(dependentDestructuredVariables.ts, 111, 1))
>T : Symbol(T, Decl(dependentDestructuredVariables.ts, 115, 12))
>variant : Symbol(A.variant, Decl(dependentDestructuredVariables.ts, 115, 16))
>value : Symbol(A.value, Decl(dependentDestructuredVariables.ts, 115, 30))
>T : Symbol(T, Decl(dependentDestructuredVariables.ts, 115, 12))
interface B<T> { variant: 'b', value: Array<T> }
>B : Symbol(B, Decl(dependentDestructuredVariables.ts, 115, 41))
>T : Symbol(T, Decl(dependentDestructuredVariables.ts, 117, 12))
>variant : Symbol(B.variant, Decl(dependentDestructuredVariables.ts, 117, 16))
>value : Symbol(B.value, Decl(dependentDestructuredVariables.ts, 117, 30))
>Array : Symbol(Array, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --))
>T : Symbol(T, Decl(dependentDestructuredVariables.ts, 117, 12))
type AB<T> = A<T> | B<T>;
>AB : Symbol(AB, Decl(dependentDestructuredVariables.ts, 117, 48))
>T : Symbol(T, Decl(dependentDestructuredVariables.ts, 119, 8))
>A : Symbol(A, Decl(dependentDestructuredVariables.ts, 111, 1))
>T : Symbol(T, Decl(dependentDestructuredVariables.ts, 119, 8))
>B : Symbol(B, Decl(dependentDestructuredVariables.ts, 115, 41))
>T : Symbol(T, Decl(dependentDestructuredVariables.ts, 119, 8))
declare function printValue<T>(t: T): void;
>printValue : Symbol(printValue, Decl(dependentDestructuredVariables.ts, 119, 25))
>T : Symbol(T, Decl(dependentDestructuredVariables.ts, 121, 28))
>t : Symbol(t, Decl(dependentDestructuredVariables.ts, 121, 31))
>T : Symbol(T, Decl(dependentDestructuredVariables.ts, 121, 28))
declare function printValueList<T>(t: Array<T>): void;
>printValueList : Symbol(printValueList, Decl(dependentDestructuredVariables.ts, 121, 43))
>T : Symbol(T, Decl(dependentDestructuredVariables.ts, 123, 32))
>t : Symbol(t, Decl(dependentDestructuredVariables.ts, 123, 35))
>Array : Symbol(Array, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --))
>T : Symbol(T, Decl(dependentDestructuredVariables.ts, 123, 32))
function unrefined1<T>(ab: AB<T>): void {
>unrefined1 : Symbol(unrefined1, Decl(dependentDestructuredVariables.ts, 123, 54))
>T : Symbol(T, Decl(dependentDestructuredVariables.ts, 125, 20))
>ab : Symbol(ab, Decl(dependentDestructuredVariables.ts, 125, 23))
>AB : Symbol(AB, Decl(dependentDestructuredVariables.ts, 117, 48))
>T : Symbol(T, Decl(dependentDestructuredVariables.ts, 125, 20))
const { variant, value } = ab;
>variant : Symbol(variant, Decl(dependentDestructuredVariables.ts, 126, 11))
>value : Symbol(value, Decl(dependentDestructuredVariables.ts, 126, 20))
>ab : Symbol(ab, Decl(dependentDestructuredVariables.ts, 125, 23))
if (variant === 'a') {
>variant : Symbol(variant, Decl(dependentDestructuredVariables.ts, 126, 11))
printValue<T>(value);
>printValue : Symbol(printValue, Decl(dependentDestructuredVariables.ts, 119, 25))
>T : Symbol(T, Decl(dependentDestructuredVariables.ts, 125, 20))
>value : Symbol(value, Decl(dependentDestructuredVariables.ts, 126, 20))
}
else {
printValueList<T>(value);
>printValueList : Symbol(printValueList, Decl(dependentDestructuredVariables.ts, 121, 43))
>T : Symbol(T, Decl(dependentDestructuredVariables.ts, 125, 20))
>value : Symbol(value, Decl(dependentDestructuredVariables.ts, 126, 20))
}
}
// Repro from #38020
type Action3 =
>Action3 : Symbol(Action3, Decl(dependentDestructuredVariables.ts, 133, 1))
| {type: 'add', payload: { toAdd: number } }
>type : Symbol(type, Decl(dependentDestructuredVariables.ts, 138, 7))
>payload : Symbol(payload, Decl(dependentDestructuredVariables.ts, 138, 19))
>toAdd : Symbol(toAdd, Decl(dependentDestructuredVariables.ts, 138, 30))
| {type: 'remove', payload: { toRemove: number } };
>type : Symbol(type, Decl(dependentDestructuredVariables.ts, 139, 7))
>payload : Symbol(payload, Decl(dependentDestructuredVariables.ts, 139, 22))
>toRemove : Symbol(toRemove, Decl(dependentDestructuredVariables.ts, 139, 33))
const reducerBroken = (state: number, { type, payload }: Action3) => {
>reducerBroken : Symbol(reducerBroken, Decl(dependentDestructuredVariables.ts, 141, 5))
>state : Symbol(state, Decl(dependentDestructuredVariables.ts, 141, 23))
>type : Symbol(type, Decl(dependentDestructuredVariables.ts, 141, 39))
>payload : Symbol(payload, Decl(dependentDestructuredVariables.ts, 141, 45))
>Action3 : Symbol(Action3, Decl(dependentDestructuredVariables.ts, 133, 1))
switch (type) {
>type : Symbol(type, Decl(dependentDestructuredVariables.ts, 141, 39))
case 'add':
return state + payload.toAdd;
>state : Symbol(state, Decl(dependentDestructuredVariables.ts, 141, 23))
>payload.toAdd : Symbol(toAdd, Decl(dependentDestructuredVariables.ts, 138, 30))
>payload : Symbol(payload, Decl(dependentDestructuredVariables.ts, 141, 45))
>toAdd : Symbol(toAdd, Decl(dependentDestructuredVariables.ts, 138, 30))
case 'remove':
return state - payload.toRemove;
>state : Symbol(state, Decl(dependentDestructuredVariables.ts, 141, 23))
>payload.toRemove : Symbol(toRemove, Decl(dependentDestructuredVariables.ts, 139, 33))
>payload : Symbol(payload, Decl(dependentDestructuredVariables.ts, 141, 45))
>toRemove : Symbol(toRemove, Decl(dependentDestructuredVariables.ts, 139, 33))
}
}
// Repro from #46143
declare var it: Iterator<number>;
>it : Symbol(it, Decl(dependentDestructuredVariables.ts, 152, 11))
>Iterator : Symbol(Iterator, Decl(lib.es2015.iterable.d.ts, --, --))
const { value, done } = it.next();
>value : Symbol(value, Decl(dependentDestructuredVariables.ts, 153, 7))
>done : Symbol(done, Decl(dependentDestructuredVariables.ts, 153, 14))
>it.next : Symbol(Iterator.next, Decl(lib.es2015.iterable.d.ts, --, --))
>it : Symbol(it, Decl(dependentDestructuredVariables.ts, 152, 11))
>next : Symbol(Iterator.next, Decl(lib.es2015.iterable.d.ts, --, --))
if (!done) {
>done : Symbol(done, Decl(dependentDestructuredVariables.ts, 153, 14))
value; // number
>value : Symbol(value, Decl(dependentDestructuredVariables.ts, 153, 7))
}

View file

@ -1,441 +0,0 @@
=== tests/cases/conformance/controlFlow/dependentDestructuredVariables.ts ===
type Action =
>Action : Action
| { kind: 'A', payload: number }
>kind : "A"
>payload : number
| { kind: 'B', payload: string };
>kind : "B"
>payload : string
function f10({ kind, payload }: Action) {
>f10 : ({ kind, payload }: Action) => void
>kind : "A" | "B"
>payload : string | number
if (kind === 'A') {
>kind === 'A' : boolean
>kind : "A" | "B"
>'A' : "A"
payload.toFixed();
>payload.toFixed() : string
>payload.toFixed : (fractionDigits?: number | undefined) => string
>payload : number
>toFixed : (fractionDigits?: number | undefined) => string
}
if (kind === 'B') {
>kind === 'B' : boolean
>kind : "A" | "B"
>'B' : "B"
payload.toUpperCase();
>payload.toUpperCase() : string
>payload.toUpperCase : () => string
>payload : string
>toUpperCase : () => string
}
}
function f11(action: Action) {
>f11 : (action: Action) => void
>action : Action
const { kind, payload } = action;
>kind : "A" | "B"
>payload : string | number
>action : Action
if (kind === 'A') {
>kind === 'A' : boolean
>kind : "A" | "B"
>'A' : "A"
payload.toFixed();
>payload.toFixed() : string
>payload.toFixed : (fractionDigits?: number | undefined) => string
>payload : number
>toFixed : (fractionDigits?: number | undefined) => string
}
if (kind === 'B') {
>kind === 'B' : boolean
>kind : "A" | "B"
>'B' : "B"
payload.toUpperCase();
>payload.toUpperCase() : string
>payload.toUpperCase : () => string
>payload : string
>toUpperCase : () => string
}
}
function f12({ kind, payload }: Action) {
>f12 : ({ kind, payload }: Action) => void
>kind : "A" | "B"
>payload : string | number
switch (kind) {
>kind : "A" | "B"
case 'A':
>'A' : "A"
payload.toFixed();
>payload.toFixed() : string
>payload.toFixed : (fractionDigits?: number | undefined) => string
>payload : number
>toFixed : (fractionDigits?: number | undefined) => string
break;
case 'B':
>'B' : "B"
payload.toUpperCase();
>payload.toUpperCase() : string
>payload.toUpperCase : () => string
>payload : string
>toUpperCase : () => string
break;
default:
payload; // never
>payload : never
}
}
type Action2 =
>Action2 : Action2
| { kind: 'A', payload: number | undefined }
>kind : "A"
>payload : number | undefined
| { kind: 'B', payload: string | undefined };
>kind : "B"
>payload : string | undefined
function f20({ kind, payload }: Action2) {
>f20 : ({ kind, payload }: Action2) => void
>kind : "A" | "B"
>payload : string | number | undefined
if (payload) {
>payload : string | number | undefined
if (kind === 'A') {
>kind === 'A' : boolean
>kind : "A" | "B"
>'A' : "A"
payload.toFixed();
>payload.toFixed() : string
>payload.toFixed : (fractionDigits?: number | undefined) => string
>payload : number
>toFixed : (fractionDigits?: number | undefined) => string
}
if (kind === 'B') {
>kind === 'B' : boolean
>kind : "A" | "B"
>'B' : "B"
payload.toUpperCase();
>payload.toUpperCase() : string
>payload.toUpperCase : () => string
>payload : string
>toUpperCase : () => string
}
}
}
function f21(action: Action2) {
>f21 : (action: Action2) => void
>action : Action2
const { kind, payload } = action;
>kind : "A" | "B"
>payload : string | number | undefined
>action : Action2
if (payload) {
>payload : string | number | undefined
if (kind === 'A') {
>kind === 'A' : boolean
>kind : "A" | "B"
>'A' : "A"
payload.toFixed();
>payload.toFixed() : string
>payload.toFixed : (fractionDigits?: number | undefined) => string
>payload : number
>toFixed : (fractionDigits?: number | undefined) => string
}
if (kind === 'B') {
>kind === 'B' : boolean
>kind : "A" | "B"
>'B' : "B"
payload.toUpperCase();
>payload.toUpperCase() : string
>payload.toUpperCase : () => string
>payload : string
>toUpperCase : () => string
}
}
}
function f22(action: Action2) {
>f22 : (action: Action2) => void
>action : Action2
if (action.payload) {
>action.payload : string | number | undefined
>action : Action2
>payload : string | number | undefined
const { kind, payload } = action;
>kind : "A" | "B"
>payload : string | number
>action : Action2
if (kind === 'A') {
>kind === 'A' : boolean
>kind : "A" | "B"
>'A' : "A"
payload.toFixed();
>payload.toFixed() : string
>payload.toFixed : (fractionDigits?: number | undefined) => string
>payload : number
>toFixed : (fractionDigits?: number | undefined) => string
}
if (kind === 'B') {
>kind === 'B' : boolean
>kind : "A" | "B"
>'B' : "B"
payload.toUpperCase();
>payload.toUpperCase() : string
>payload.toUpperCase : () => string
>payload : string
>toUpperCase : () => string
}
}
}
function f23({ kind, payload }: Action2) {
>f23 : ({ kind, payload }: Action2) => void
>kind : "A" | "B"
>payload : string | number | undefined
if (payload) {
>payload : string | number | undefined
switch (kind) {
>kind : "A" | "B"
case 'A':
>'A' : "A"
payload.toFixed();
>payload.toFixed() : string
>payload.toFixed : (fractionDigits?: number | undefined) => string
>payload : number
>toFixed : (fractionDigits?: number | undefined) => string
break;
case 'B':
>'B' : "B"
payload.toUpperCase();
>payload.toUpperCase() : string
>payload.toUpperCase : () => string
>payload : string
>toUpperCase : () => string
break;
default:
payload; // never
>payload : never
}
}
}
type Foo =
>Foo : Foo
| { kind: 'A', isA: true }
>kind : "A"
>isA : true
>true : true
| { kind: 'B', isA: false }
>kind : "B"
>isA : false
>false : false
| { kind: 'C', isA: false };
>kind : "C"
>isA : false
>false : false
function f30({ kind, isA }: Foo) {
>f30 : ({ kind, isA }: Foo) => void
>kind : "A" | "B" | "C"
>isA : boolean
if (kind === 'A') {
>kind === 'A' : boolean
>kind : "A" | "B" | "C"
>'A' : "A"
isA; // true
>isA : true
}
if (kind === 'B') {
>kind === 'B' : boolean
>kind : "A" | "B" | "C"
>'B' : "B"
isA; // false
>isA : false
}
if (kind === 'C') {
>kind === 'C' : boolean
>kind : "A" | "B" | "C"
>'C' : "C"
isA; // false
>isA : false
}
if (isA) {
>isA : boolean
kind; // 'A'
>kind : "A"
}
else {
kind; // 'B' | 'C'
>kind : "B" | "C"
}
}
// Repro from #35283
interface A<T> { variant: 'a', value: T }
>variant : "a"
>value : T
interface B<T> { variant: 'b', value: Array<T> }
>variant : "b"
>value : T[]
type AB<T> = A<T> | B<T>;
>AB : AB<T>
declare function printValue<T>(t: T): void;
>printValue : <T>(t: T) => void
>t : T
declare function printValueList<T>(t: Array<T>): void;
>printValueList : <T>(t: Array<T>) => void
>t : T[]
function unrefined1<T>(ab: AB<T>): void {
>unrefined1 : <T>(ab: AB<T>) => void
>ab : AB<T>
const { variant, value } = ab;
>variant : "a" | "b"
>value : T | T[]
>ab : AB<T>
if (variant === 'a') {
>variant === 'a' : boolean
>variant : "a" | "b"
>'a' : "a"
printValue<T>(value);
>printValue<T>(value) : void
>printValue : <T>(t: T) => void
>value : T
}
else {
printValueList<T>(value);
>printValueList<T>(value) : void
>printValueList : <T>(t: T[]) => void
>value : T[]
}
}
// Repro from #38020
type Action3 =
>Action3 : Action3
| {type: 'add', payload: { toAdd: number } }
>type : "add"
>payload : { toAdd: number; }
>toAdd : number
| {type: 'remove', payload: { toRemove: number } };
>type : "remove"
>payload : { toRemove: number; }
>toRemove : number
const reducerBroken = (state: number, { type, payload }: Action3) => {
>reducerBroken : (state: number, { type, payload }: Action3) => number
>(state: number, { type, payload }: Action3) => { switch (type) { case 'add': return state + payload.toAdd; case 'remove': return state - payload.toRemove; }} : (state: number, { type, payload }: Action3) => number
>state : number
>type : "add" | "remove"
>payload : { toAdd: number; } | { toRemove: number; }
switch (type) {
>type : "add" | "remove"
case 'add':
>'add' : "add"
return state + payload.toAdd;
>state + payload.toAdd : number
>state : number
>payload.toAdd : number
>payload : { toAdd: number; }
>toAdd : number
case 'remove':
>'remove' : "remove"
return state - payload.toRemove;
>state - payload.toRemove : number
>state : number
>payload.toRemove : number
>payload : { toRemove: number; }
>toRemove : number
}
}
// Repro from #46143
declare var it: Iterator<number>;
>it : Iterator<number, any, undefined>
const { value, done } = it.next();
>value : any
>done : boolean | undefined
>it.next() : IteratorResult<number, any>
>it.next : (...args: [] | [undefined]) => IteratorResult<number, any>
>it : Iterator<number, any, undefined>
>next : (...args: [] | [undefined]) => IteratorResult<number, any>
if (!done) {
>!done : boolean
>done : boolean | undefined
value; // number
>value : number
}

View file

@ -16,7 +16,7 @@ tests/cases/compiler/doYouNeedToChangeYourTargetLibraryES2016Plus.ts(20,27): err
tests/cases/compiler/doYouNeedToChangeYourTargetLibraryES2016Plus.ts(21,35): error TS2583: Cannot find name 'AsyncGeneratorFunction'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2018' or later.
tests/cases/compiler/doYouNeedToChangeYourTargetLibraryES2016Plus.ts(22,26): error TS2583: Cannot find name 'AsyncIterable'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2018' or later.
tests/cases/compiler/doYouNeedToChangeYourTargetLibraryES2016Plus.ts(23,34): error TS2583: Cannot find name 'AsyncIterableIterator'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2018' or later.
tests/cases/compiler/doYouNeedToChangeYourTargetLibraryES2016Plus.ts(24,70): error TS2550: Property 'formatToParts' does not exist on type 'NumberFormat'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2018' or later.
tests/cases/compiler/doYouNeedToChangeYourTargetLibraryES2016Plus.ts(24,70): error TS2550: Property 'formatToParts' does not exist on type 'NumberFormat'. Do you need to change your target library? Try changing the 'lib' compiler option to 'esnext' or later.
tests/cases/compiler/doYouNeedToChangeYourTargetLibraryES2016Plus.ts(27,26): error TS2550: Property 'flat' does not exist on type 'undefined[]'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2019' or later.
tests/cases/compiler/doYouNeedToChangeYourTargetLibraryES2016Plus.ts(28,29): error TS2550: Property 'flatMap' does not exist on type 'undefined[]'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2019' or later.
tests/cases/compiler/doYouNeedToChangeYourTargetLibraryES2016Plus.ts(29,49): error TS2550: Property 'fromEntries' does not exist on type 'ObjectConstructor'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2019' or later.
@ -95,7 +95,7 @@ tests/cases/compiler/doYouNeedToChangeYourTargetLibraryES2016Plus.ts(44,33): err
!!! error TS2583: Cannot find name 'AsyncIterableIterator'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2018' or later.
const testNumberFormatFormatToParts = new Intl.NumberFormat("en-US").formatToParts();
~~~~~~~~~~~~~
!!! error TS2550: Property 'formatToParts' does not exist on type 'NumberFormat'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2018' or later.
!!! error TS2550: Property 'formatToParts' does not exist on type 'NumberFormat'. Do you need to change your target library? Try changing the 'lib' compiler option to 'esnext' or later.
// es2019
const testArrayFlat = [].flat();

View file

@ -43,7 +43,6 @@ var x = 0;
var y = "";
var z = 0;
//// [duplicateVarsAcrossFileBoundaries_4.js]
var p = P;
var q;
//// [duplicateVarsAcrossFileBoundaries_5.js]
var p;

View file

@ -3,6 +3,6 @@ enum E {
>E : Symbol(E, Decl(enumWithUnicodeEscape1.ts, 0, 0))
'gold \u2730'
>'gold \u2730' : Symbol(E['gold \u2730'], Decl(enumWithUnicodeEscape1.ts, 0, 8))
>'gold \u2730' : Symbol(E['gold u2730'], Decl(enumWithUnicodeEscape1.ts, 0, 8))
}

View file

@ -1,8 +0,0 @@
tests/cases/compiler/errorCause.ts(1,18): error TS2554: Expected 0-1 arguments, but got 2.
==== tests/cases/compiler/errorCause.ts (1 errors) ====
new Error("foo", { cause: new Error("bar") });
~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2554: Expected 0-1 arguments, but got 2.

View file

@ -1,6 +0,0 @@
//// [errorCause.ts]
new Error("foo", { cause: new Error("bar") });
//// [errorCause.js]
new Error("foo", { cause: new Error("bar") });

View file

@ -1,6 +0,0 @@
=== tests/cases/compiler/errorCause.ts ===
new Error("foo", { cause: new Error("bar") });
>Error : Symbol(Error, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
>cause : Symbol(cause, Decl(errorCause.ts, 0, 18))
>Error : Symbol(Error, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))

View file

@ -1,11 +0,0 @@
=== tests/cases/compiler/errorCause.ts ===
new Error("foo", { cause: new Error("bar") });
>new Error("foo", { cause: new Error("bar") }) : Error
>Error : ErrorConstructor
>"foo" : "foo"
>{ cause: new Error("bar") } : { cause: Error; }
>cause : Error
>new Error("bar") : Error
>Error : ErrorConstructor
>"bar" : "bar"

View file

@ -1,6 +0,0 @@
//// [errorCause.ts]
new Error("foo", { cause: new Error("bar") });
//// [errorCause.js]
new Error("foo", { cause: new Error("bar") });

Some files were not shown because too many files have changed in this diff Show more