@@ -2216,7 +2216,22 @@ namespace ts {
2216
2216
// An external module with an 'export =' declaration resolves to the target of the 'export =' declaration,
2217
2217
// and an external module with no 'export =' declaration resolves to the module itself.
2218
2218
function resolveExternalModuleSymbol(moduleSymbol: Symbol, dontResolveAlias?: boolean): Symbol {
2219
- return moduleSymbol && getMergedSymbol(resolveSymbol(moduleSymbol.exports.get(InternalSymbolName.ExportEquals), dontResolveAlias)) || moduleSymbol;
2219
+ return moduleSymbol && getMergedSymbol(resolveSymbol(getCommonJsExportEquals(moduleSymbol), dontResolveAlias)) || moduleSymbol;
2220
+ }
2221
+
2222
+ function getCommonJsExportEquals(moduleSymbol: Symbol): Symbol {
2223
+ const exported = moduleSymbol.exports.get(InternalSymbolName.ExportEquals);
2224
+ if (!exported || !exported.exports || moduleSymbol.exports.size === 1) {
2225
+ return exported;
2226
+ }
2227
+ const merged = cloneSymbol(exported);
2228
+ moduleSymbol.exports.forEach((s, name) => {
2229
+ if (name === InternalSymbolName.ExportEquals) return;
2230
+ if (!merged.exports.has(name)) {
2231
+ merged.exports.set(name, s);
2232
+ }
2233
+ });
2234
+ return merged;
2220
2235
}
2221
2236
2222
2237
// An external module with an 'export =' declaration may be referenced as an ES6 module provided the 'export ='
@@ -4350,7 +4365,8 @@ namespace ts {
4350
4365
return unknownType;
4351
4366
}
4352
4367
4353
- if (isPropertyAccessExpression(expression.left) && expression.left.expression.kind === SyntaxKind.ThisKeyword) {
4368
+ const special = getSpecialPropertyAssignmentKind(expression);
4369
+ if (special === SpecialPropertyAssignmentKind.ThisProperty) {
4354
4370
const thisContainer = getThisContainer(expression, /*includeArrowFunctions*/ false);
4355
4371
// Properties defined in a constructor (or javascript constructor function) don't get undefined added.
4356
4372
// Function expressions that are assigned to the prototype count as methods.
@@ -4380,7 +4396,33 @@ namespace ts {
4380
4396
}
4381
4397
else if (!jsDocType) {
4382
4398
// If we don't have an explicit JSDoc type, get the type from the expression.
4383
- const type = getWidenedLiteralType(checkExpressionCached(expression.right));
4399
+ let type = getWidenedLiteralType(checkExpressionCached(expression.right));
4400
+
4401
+ if (getObjectFlags(type) & ObjectFlags.Anonymous &&
4402
+ special === SpecialPropertyAssignmentKind.ModuleExports &&
4403
+ symbol.escapedName === InternalSymbolName.ExportEquals) {
4404
+ const exportedType = resolveStructuredTypeMembers(type as AnonymousType);
4405
+ const members = createSymbolTable();
4406
+ copyEntries(exportedType.members, members);
4407
+ symbol.exports.forEach((s, name) => {
4408
+ if (members.has(name)) {
4409
+ const exportedMember = exportedType.members.get(name);
4410
+ const union = createSymbol(s.flags | exportedMember.flags, name);
4411
+ union.type = getUnionType([getTypeOfSymbol(s), getTypeOfSymbol(exportedMember)]);
4412
+ members.set(name, union);
4413
+ }
4414
+ else {
4415
+ members.set(name, s);
4416
+ }
4417
+ });
4418
+ type = createAnonymousType(
4419
+ exportedType.symbol,
4420
+ members,
4421
+ exportedType.callSignatures,
4422
+ exportedType.constructSignatures,
4423
+ exportedType.stringIndexInfo,
4424
+ exportedType.numberIndexInfo);
4425
+ }
4384
4426
let anyedType = type;
4385
4427
if (isEmptyArrayLiteralType(type)) {
4386
4428
anyedType = anyArrayType;
@@ -7158,15 +7200,15 @@ namespace ts {
7158
7200
return symbol.members.get(InternalSymbolName.Index);
7159
7201
}
7160
7202
7161
- function getIndexDeclarationOfSymbol(symbol: Symbol, kind: IndexKind): SignatureDeclaration {
7203
+ function getIndexDeclarationOfSymbol(symbol: Symbol, kind: IndexKind): IndexSignatureDeclaration {
7162
7204
const syntaxKind = kind === IndexKind.Number ? SyntaxKind.NumberKeyword : SyntaxKind.StringKeyword;
7163
7205
const indexSymbol = getIndexSymbol(symbol);
7164
7206
if (indexSymbol) {
7165
7207
for (const decl of indexSymbol.declarations) {
7166
- const node = <SignatureDeclaration> decl;
7208
+ const node = cast( decl, isIndexSignatureDeclaration) ;
7167
7209
if (node.parameters.length === 1) {
7168
7210
const parameter = node.parameters[0];
7169
- if (parameter && parameter .type && parameter.type.kind === syntaxKind) {
7211
+ if (parameter.type && parameter.type.kind === syntaxKind) {
7170
7212
return node;
7171
7213
}
7172
7214
}
@@ -7176,7 +7218,7 @@ namespace ts {
7176
7218
return undefined;
7177
7219
}
7178
7220
7179
- function createIndexInfo(type: Type, isReadonly: boolean, declaration?: SignatureDeclaration ): IndexInfo {
7221
+ function createIndexInfo(type: Type, isReadonly: boolean, declaration?: IndexSignatureDeclaration ): IndexInfo {
7180
7222
return { type, isReadonly, declaration };
7181
7223
}
7182
7224
@@ -16624,12 +16666,18 @@ namespace ts {
16624
16666
}
16625
16667
}
16626
16668
}
16627
- const suggestion = getSuggestionForNonexistentProperty(propNode, containingType);
16628
- if (suggestion !== undefined ) {
16629
- errorInfo = chainDiagnosticMessages(errorInfo, Diagnostics.Property_0_does_not_exist_on_type_1_Did_you_mean_2 , declarationNameToString(propNode), typeToString(containingType), suggestion );
16669
+ const promisedType = getPromisedTypeOfPromise( containingType);
16670
+ if (promisedType && getPropertyOfType(promisedType, propNode.escapedText) ) {
16671
+ errorInfo = chainDiagnosticMessages(errorInfo, Diagnostics.Property_0_does_not_exist_on_type_1_Did_you_forget_to_use_await , declarationNameToString(propNode), typeToString(containingType));
16630
16672
}
16631
16673
else {
16632
- errorInfo = chainDiagnosticMessages(errorInfo, Diagnostics.Property_0_does_not_exist_on_type_1, declarationNameToString(propNode), typeToString(containingType));
16674
+ const suggestion = getSuggestionForNonexistentProperty(propNode, containingType);
16675
+ if (suggestion !== undefined) {
16676
+ errorInfo = chainDiagnosticMessages(errorInfo, Diagnostics.Property_0_does_not_exist_on_type_1_Did_you_mean_2, declarationNameToString(propNode), typeToString(containingType), suggestion);
16677
+ }
16678
+ else {
16679
+ errorInfo = chainDiagnosticMessages(errorInfo, Diagnostics.Property_0_does_not_exist_on_type_1, declarationNameToString(propNode), typeToString(containingType));
16680
+ }
16633
16681
}
16634
16682
diagnostics.add(createDiagnosticForNodeFromMessageChain(propNode, errorInfo));
16635
16683
}
@@ -24576,7 +24624,7 @@ namespace ts {
24576
24624
const exportEqualsSymbol = moduleSymbol.exports.get("export=" as __String);
24577
24625
if (exportEqualsSymbol && hasExportedMembers(moduleSymbol)) {
24578
24626
const declaration = getDeclarationOfAliasSymbol(exportEqualsSymbol) || exportEqualsSymbol.valueDeclaration;
24579
- if (!isTopLevelInExternalModuleAugmentation(declaration)) {
24627
+ if (!isTopLevelInExternalModuleAugmentation(declaration) && !isInJavaScriptFile(declaration) ) {
24580
24628
error(declaration, Diagnostics.An_export_assignment_cannot_be_used_in_a_module_with_other_exported_elements);
24581
24629
}
24582
24630
}
@@ -24657,7 +24705,6 @@ namespace ts {
24657
24705
case SyntaxKind.ConstructorType:
24658
24706
case SyntaxKind.CallSignature:
24659
24707
case SyntaxKind.ConstructSignature:
24660
- return checkSignatureDeclaration(<SignatureDeclaration>node);
24661
24708
case SyntaxKind.IndexSignature:
24662
24709
return checkSignatureDeclaration(<SignatureDeclaration>node);
24663
24710
case SyntaxKind.MethodDeclaration:
@@ -24777,8 +24824,6 @@ namespace ts {
24777
24824
case SyntaxKind.ExportAssignment:
24778
24825
return checkExportAssignment(<ExportAssignment>node);
24779
24826
case SyntaxKind.EmptyStatement:
24780
- checkGrammarStatementInAmbientContext(node);
24781
- return;
24782
24827
case SyntaxKind.DebuggerStatement:
24783
24828
checkGrammarStatementInAmbientContext(node);
24784
24829
return;
@@ -25456,9 +25501,6 @@ namespace ts {
25456
25501
}
25457
25502
25458
25503
function getShorthandAssignmentValueSymbol(location: Node): Symbol {
25459
- // The function returns a value symbol of an identifier in the short-hand property assignment.
25460
- // This is necessary as an identifier in short-hand property assignment can contains two meaning:
25461
- // property name and property value.
25462
25504
if (location && location.kind === SyntaxKind.ShorthandPropertyAssignment) {
25463
25505
return resolveEntityName((<ShorthandPropertyAssignment>location).name, SymbolFlags.Value | SymbolFlags.Alias);
25464
25506
}
0 commit comments