@@ -4183,7 +4183,8 @@ namespace ts {
4183
4183
return {
4184
4184
accessibility: SymbolAccessibility.CannotBeNamed,
4185
4185
errorSymbolName: symbolToString(symbol, enclosingDeclaration, meaning),
4186
- errorModuleName: symbolToString(symbolExternalModule)
4186
+ errorModuleName: symbolToString(symbolExternalModule),
4187
+ errorNode: isInJSFile(enclosingDeclaration) ? enclosingDeclaration : undefined,
4187
4188
};
4188
4189
}
4189
4190
}
@@ -4699,7 +4700,7 @@ namespace ts {
4699
4700
4700
4701
function createMappedTypeNodeFromType(type: MappedType) {
4701
4702
Debug.assert(!!(type.flags & TypeFlags.Object));
4702
- const readonlyToken = type.declaration.readonlyToken ? <ReadonlyToken | PlusToken | MinusToken>factory.createToken(type.declaration.readonlyToken.kind) : undefined;
4703
+ const readonlyToken = type.declaration.readonlyToken ? <ReadonlyKeyword | PlusToken | MinusToken>factory.createToken(type.declaration.readonlyToken.kind) : undefined;
4703
4704
const questionToken = type.declaration.questionToken ? <QuestionToken | PlusToken | MinusToken>factory.createToken(type.declaration.questionToken.kind) : undefined;
4704
4705
let appropriateConstraintTypeNode: TypeNode;
4705
4706
if (isMappedTypeWithKeyofConstraintDeclaration(type)) {
@@ -6183,7 +6184,7 @@ namespace ts {
6183
6184
tracker: {
6184
6185
...oldcontext.tracker,
6185
6186
trackSymbol: (sym, decl, meaning) => {
6186
- const accessibleResult = isSymbolAccessible(sym, decl, meaning, /*computeALiases */ false);
6187
+ const accessibleResult = isSymbolAccessible(sym, decl, meaning, /*computeAliases */ false);
6187
6188
if (accessibleResult.accessibility === SymbolAccessibility.Accessible) {
6188
6189
// Lookup the root symbol of the chain of refs we'll use to access it and serialize it
6189
6190
const chain = lookupSymbolChainWorker(sym, context, meaning);
@@ -6625,16 +6626,17 @@ namespace ts {
6625
6626
function addResult(node: Statement, additionalModifierFlags: ModifierFlags) {
6626
6627
if (canHaveModifiers(node)) {
6627
6628
let newModifierFlags: ModifierFlags = ModifierFlags.None;
6629
+ const enclosingDeclaration = context.enclosingDeclaration &&
6630
+ (isJSDocTypeAlias(context.enclosingDeclaration) ? getSourceFileOfNode(context.enclosingDeclaration) : context.enclosingDeclaration);
6628
6631
if (additionalModifierFlags & ModifierFlags.Export &&
6629
- context.enclosingDeclaration &&
6630
- (isExportingScope(context.enclosingDeclaration) || isModuleDeclaration(context.enclosingDeclaration)) &&
6632
+ enclosingDeclaration && (isExportingScope(enclosingDeclaration) || isModuleDeclaration(enclosingDeclaration)) &&
6631
6633
canHaveExportModifier(node)
6632
6634
) {
6633
6635
// Classes, namespaces, variables, functions, interfaces, and types should all be `export`ed in a module context if not private
6634
6636
newModifierFlags |= ModifierFlags.Export;
6635
6637
}
6636
6638
if (addingDeclare && !(newModifierFlags & ModifierFlags.Export) &&
6637
- (!context. enclosingDeclaration || !(context. enclosingDeclaration.flags & NodeFlags.Ambient)) &&
6639
+ (!enclosingDeclaration || !(enclosingDeclaration.flags & NodeFlags.Ambient)) &&
6638
6640
(isEnumDeclaration(node) || isVariableStatement(node) || isFunctionDeclaration(node) || isClassDeclaration(node) || isModuleDeclaration(node))) {
6639
6641
// Classes, namespaces, variables, enums, and functions all need `declare` modifiers to be valid in a declaration file top-level scope
6640
6642
newModifierFlags |= ModifierFlags.Ambient;
@@ -6657,6 +6659,8 @@ namespace ts {
6657
6659
const commentText = jsdocAliasDecl ? jsdocAliasDecl.comment || jsdocAliasDecl.parent.comment : undefined;
6658
6660
const oldFlags = context.flags;
6659
6661
context.flags |= NodeBuilderFlags.InTypeAlias;
6662
+ const oldEnclosingDecl = context.enclosingDeclaration;
6663
+ context.enclosingDeclaration = jsdocAliasDecl;
6660
6664
const typeNode = jsdocAliasDecl && jsdocAliasDecl.typeExpression
6661
6665
&& isJSDocTypeExpression(jsdocAliasDecl.typeExpression)
6662
6666
&& serializeExistingTypeNode(context, jsdocAliasDecl.typeExpression.type, includePrivateSymbol, bundled)
@@ -6666,6 +6670,7 @@ namespace ts {
6666
6670
!commentText ? [] : [{ kind: SyntaxKind.MultiLineCommentTrivia, text: "*\n * " + commentText.replace(/\n/g, "\n * ") + "\n ", pos: -1, end: -1, hasTrailingNewLine: true }]
6667
6671
), modifierFlags);
6668
6672
context.flags = oldFlags;
6673
+ context.enclosingDeclaration = oldEnclosingDecl;
6669
6674
}
6670
6675
6671
6676
function serializeInterface(symbol: Symbol, symbolName: string, modifierFlags: ModifierFlags) {
@@ -14642,6 +14647,7 @@ namespace ts {
14642
14647
// types of the form 'A extends B ? X : C extends D ? Y : E extends F ? Z : ...' as a single construct for
14643
14648
// purposes of resolution. This means such types aren't subject to the instatiation depth limiter.
14644
14649
while (true) {
14650
+ const isUnwrapped = isTypicalNondistributiveConditional(root);
14645
14651
const checkType = instantiateType(unwrapNondistributiveConditionalTuple(root, root.checkType), mapper);
14646
14652
const checkTypeInstantiable = isGenericObjectType(checkType) || isGenericIndexType(checkType);
14647
14653
const extendsType = instantiateType(unwrapNondistributiveConditionalTuple(root, root.extendsType), mapper);
@@ -14667,9 +14673,9 @@ namespace ts {
14667
14673
// types with type parameters mapped to the wildcard type, the most permissive instantiations
14668
14674
// possible (the wildcard type is assignable to and from all types). If those are not related,
14669
14675
// then no instantiations will be and we can just return the false branch type.
14670
- if (!(inferredExtendsType.flags & TypeFlags.AnyOrUnknown) && ((checkType.flags & TypeFlags.Any && root.isDistributive ) || !isTypeAssignableTo(getPermissiveInstantiation(checkType), getPermissiveInstantiation(inferredExtendsType)))) {
14676
+ if (!(inferredExtendsType.flags & TypeFlags.AnyOrUnknown) && ((checkType.flags & TypeFlags.Any && !isUnwrapped ) || !isTypeAssignableTo(getPermissiveInstantiation(checkType), getPermissiveInstantiation(inferredExtendsType)))) {
14671
14677
// Return union of trueType and falseType for 'any' since it matches anything
14672
- if (checkType.flags & TypeFlags.Any && root.isDistributive ) {
14678
+ if (checkType.flags & TypeFlags.Any && !isUnwrapped ) {
14673
14679
(extraTypes || (extraTypes = [])).push(instantiateType(getTypeFromTypeNode(root.node.trueType), combinedMapper || mapper));
14674
14680
}
14675
14681
// If falseType is an immediately nested conditional type that isn't distributive or has an
@@ -21284,8 +21290,12 @@ namespace ts {
21284
21290
case SyntaxKind.PropertyAccessExpression:
21285
21291
case SyntaxKind.ElementAccessExpression:
21286
21292
return isAccessExpression(target) &&
21287
- getAccessedPropertyName(<AccessExpression>source) === getAccessedPropertyName(target) &&
21288
- isMatchingReference((<AccessExpression>source).expression, target.expression);
21293
+ getAccessedPropertyName(source as AccessExpression) === getAccessedPropertyName(target) &&
21294
+ isMatchingReference((source as AccessExpression).expression, target.expression);
21295
+ case SyntaxKind.QualifiedName:
21296
+ return isAccessExpression(target) &&
21297
+ (source as QualifiedName).right.escapedText === getAccessedPropertyName(target) &&
21298
+ isMatchingReference((source as QualifiedName).left, target.expression);
21289
21299
case SyntaxKind.BinaryExpression:
21290
21300
return (isBinaryExpression(source) && source.operatorToken.kind === SyntaxKind.CommaToken && isMatchingReference(source.right, target));
21291
21301
}
@@ -22631,13 +22641,13 @@ namespace ts {
22631
22641
if (propName === undefined) {
22632
22642
return type;
22633
22643
}
22634
- const includesUndefined = strictNullChecks && maybeTypeOfKind(type, TypeFlags.Undefined );
22635
- const removeOptional = includesUndefined && isOptionalChain(access);
22636
- let propType = getTypeOfPropertyOfType(removeOptional ? getTypeWithFacts(type, TypeFacts.NEUndefined ) : type, propName);
22644
+ const includesNullable = strictNullChecks && maybeTypeOfKind(type, TypeFlags.Nullable );
22645
+ const removeNullable = includesNullable && isOptionalChain(access);
22646
+ let propType = getTypeOfPropertyOfType(removeNullable ? getTypeWithFacts(type, TypeFacts.NEUndefinedOrNull ) : type, propName);
22637
22647
if (!propType) {
22638
22648
return type;
22639
22649
}
22640
- propType = removeOptional ? getOptionalType(propType) : propType;
22650
+ propType = removeNullable ? getOptionalType(propType) : propType;
22641
22651
const narrowedPropType = narrowType(propType);
22642
22652
return filterType(type, t => {
22643
22653
const discriminantType = getTypeOfPropertyOrIndexSignature(t, propName);
@@ -24752,6 +24762,8 @@ namespace ts {
24752
24762
const tag = isInJSFile(parent) ? getJSDocTypeTag(parent) : undefined;
24753
24763
return tag ? getTypeFromTypeNode(tag.typeExpression.type) : getContextualType(<ParenthesizedExpression>parent, contextFlags);
24754
24764
}
24765
+ case SyntaxKind.NonNullExpression:
24766
+ return getContextualType(parent as NonNullExpression, contextFlags);
24755
24767
case SyntaxKind.JsxExpression:
24756
24768
return getContextualTypeForJsxExpression(<JsxExpression>parent);
24757
24769
case SyntaxKind.JsxAttribute:
@@ -26414,8 +26426,7 @@ namespace ts {
26414
26426
// assignment target, and the referenced property was declared as a variable, property,
26415
26427
// accessor, or optional method.
26416
26428
const assignmentKind = getAssignmentTargetKind(node);
26417
- if (!isAccessExpression(node) ||
26418
- assignmentKind === AssignmentKind.Definite ||
26429
+ if (assignmentKind === AssignmentKind.Definite ||
26419
26430
prop && !(prop.flags & (SymbolFlags.Variable | SymbolFlags.Property | SymbolFlags.Accessor)) && !(prop.flags & SymbolFlags.Method && propType.flags & TypeFlags.Union)) {
26420
26431
return propType;
26421
26432
}
@@ -26427,7 +26438,7 @@ namespace ts {
26427
26438
// and if we are in a constructor of the same class as the property declaration, assume that
26428
26439
// the property is uninitialized at the top of the control flow.
26429
26440
let assumeUninitialized = false;
26430
- if (strictNullChecks && strictPropertyInitialization && node.expression.kind === SyntaxKind.ThisKeyword) {
26441
+ if (strictNullChecks && strictPropertyInitialization && isAccessExpression(node) && node.expression.kind === SyntaxKind.ThisKeyword) {
26431
26442
const declaration = prop && prop.valueDeclaration;
26432
26443
if (declaration && isInstancePropertyWithoutInitializer(declaration)) {
26433
26444
const flowContainer = getControlFlowContainer(node);
0 commit comments