Skip to content

Commit 9eaf40b

Browse files
committed
Merge branch 'master' into spelling-correction
2 parents 0c10098 + 975bc76 commit 9eaf40b

39 files changed

+1401
-567
lines changed

src/compiler/checker.ts

Lines changed: 58 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1436,10 +1436,10 @@ namespace ts {
14361436
return resolveExternalModuleSymbol(node.parent.symbol, dontResolveAlias);
14371437
}
14381438

1439-
function getTargetOfExportSpecifier(node: ExportSpecifier, dontResolveAlias?: boolean): Symbol {
1440-
return (<ExportDeclaration>node.parent.parent).moduleSpecifier ?
1441-
getExternalModuleMember(<ExportDeclaration>node.parent.parent, node, dontResolveAlias) :
1442-
resolveEntityName(node.propertyName || node.name, SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace, /*ignoreErrors*/ false, dontResolveAlias);
1439+
function getTargetOfExportSpecifier(node: ExportSpecifier, meaning: SymbolFlags, dontResolveAlias?: boolean) {
1440+
return node.parent.parent.moduleSpecifier ?
1441+
getExternalModuleMember(node.parent.parent, node, dontResolveAlias) :
1442+
resolveEntityName(node.propertyName || node.name, meaning, /*ignoreErrors*/ false, dontResolveAlias);
14431443
}
14441444

14451445
function getTargetOfExportAssignment(node: ExportAssignment, dontResolveAlias: boolean): Symbol {
@@ -1457,7 +1457,7 @@ namespace ts {
14571457
case SyntaxKind.ImportSpecifier:
14581458
return getTargetOfImportSpecifier(<ImportSpecifier>node, dontRecursivelyResolve);
14591459
case SyntaxKind.ExportSpecifier:
1460-
return getTargetOfExportSpecifier(<ExportSpecifier>node, dontRecursivelyResolve);
1460+
return getTargetOfExportSpecifier(<ExportSpecifier>node, SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace, dontRecursivelyResolve);
14611461
case SyntaxKind.ExportAssignment:
14621462
return getTargetOfExportAssignment(<ExportAssignment>node, dontRecursivelyResolve);
14631463
case SyntaxKind.NamespaceExportDeclaration:
@@ -3757,10 +3757,7 @@ namespace ts {
37573757
exportSymbol = resolveName(node.parent, node.text, SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace | SymbolFlags.Alias, Diagnostics.Cannot_find_name_0, node);
37583758
}
37593759
else if (node.parent.kind === SyntaxKind.ExportSpecifier) {
3760-
const exportSpecifier = <ExportSpecifier>node.parent;
3761-
exportSymbol = (<ExportDeclaration>exportSpecifier.parent.parent).moduleSpecifier ?
3762-
getExternalModuleMember(<ExportDeclaration>exportSpecifier.parent.parent, exportSpecifier) :
3763-
resolveEntityName(exportSpecifier.propertyName || exportSpecifier.name, SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace | SymbolFlags.Alias);
3760+
exportSymbol = getTargetOfExportSpecifier(<ExportSpecifier>node.parent, SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace | SymbolFlags.Alias);
37643761
}
37653762
const result: Node[] = [];
37663763
if (exportSymbol) {
@@ -7293,7 +7290,7 @@ namespace ts {
72937290
accessExpression && checkThatExpressionIsProperSymbolReference(accessExpression.argumentExpression, indexType, /*reportError*/ false) ?
72947291
getPropertyNameForKnownSymbolName((<Identifier>(<PropertyAccessExpression>accessExpression.argumentExpression).name).text) :
72957292
undefined;
7296-
if (propName) {
7293+
if (propName !== undefined) {
72977294
const prop = getPropertyOfType(objectType, propName);
72987295
if (prop) {
72997296
if (accessExpression) {
@@ -9264,25 +9261,39 @@ namespace ts {
92649261
let result = Ternary.True;
92659262
const saveErrorInfo = errorInfo;
92669263

9267-
outer: for (const t of targetSignatures) {
9268-
// Only elaborate errors from the first failure
9269-
let shouldElaborateErrors = reportErrors;
9270-
for (const s of sourceSignatures) {
9271-
const related = signatureRelatedTo(s, t, shouldElaborateErrors);
9272-
if (related) {
9273-
result &= related;
9274-
errorInfo = saveErrorInfo;
9275-
continue outer;
9264+
if (getObjectFlags(source) & ObjectFlags.Instantiated && getObjectFlags(target) & ObjectFlags.Instantiated && source.symbol === target.symbol) {
9265+
// We instantiations of the same anonymous type (which typically will be the type of a method).
9266+
// Simply do a pairwise comparison of the signatures in the two signature lists instead of the
9267+
// much more expensive N * M comparison matrix we explore below.
9268+
for (let i = 0; i < targetSignatures.length; i++) {
9269+
const related = signatureRelatedTo(sourceSignatures[i], targetSignatures[i], reportErrors);
9270+
if (!related) {
9271+
return Ternary.False;
92769272
}
9277-
shouldElaborateErrors = false;
9273+
result &= related;
92789274
}
9275+
}
9276+
else {
9277+
outer: for (const t of targetSignatures) {
9278+
// Only elaborate errors from the first failure
9279+
let shouldElaborateErrors = reportErrors;
9280+
for (const s of sourceSignatures) {
9281+
const related = signatureRelatedTo(s, t, shouldElaborateErrors);
9282+
if (related) {
9283+
result &= related;
9284+
errorInfo = saveErrorInfo;
9285+
continue outer;
9286+
}
9287+
shouldElaborateErrors = false;
9288+
}
92799289

9280-
if (shouldElaborateErrors) {
9281-
reportError(Diagnostics.Type_0_provides_no_match_for_the_signature_1,
9282-
typeToString(source),
9283-
signatureToString(t, /*enclosingDeclaration*/ undefined, /*flags*/ undefined, kind));
9290+
if (shouldElaborateErrors) {
9291+
reportError(Diagnostics.Type_0_provides_no_match_for_the_signature_1,
9292+
typeToString(source),
9293+
signatureToString(t, /*enclosingDeclaration*/ undefined, /*flags*/ undefined, kind));
9294+
}
9295+
return Ternary.False;
92849296
}
9285-
return Ternary.False;
92869297
}
92879298
return result;
92889299
}
@@ -13273,6 +13284,8 @@ namespace ts {
1327313284
let attributesTable = createMap<Symbol>();
1327413285
let spread: Type = emptyObjectType;
1327513286
let attributesArray: Symbol[] = [];
13287+
let hasSpreadAnyType = false;
13288+
1327613289
for (const attributeDecl of attributes.properties) {
1327713290
const member = attributeDecl.symbol;
1327813291
if (isJsxAttribute(attributeDecl)) {
@@ -13301,31 +13314,33 @@ namespace ts {
1330113314
const exprType = checkExpression(attributeDecl.expression);
1330213315
if (!isValidSpreadType(exprType)) {
1330313316
error(attributeDecl, Diagnostics.Spread_types_may_only_be_created_from_object_types);
13304-
return anyType;
13317+
hasSpreadAnyType = true;
1330513318
}
1330613319
if (isTypeAny(exprType)) {
13307-
return anyType;
13320+
hasSpreadAnyType = true;
1330813321
}
1330913322
spread = getSpreadType(spread, exprType);
1331013323
}
1331113324
}
1331213325

13313-
if (spread !== emptyObjectType) {
13314-
if (attributesArray.length > 0) {
13315-
spread = getSpreadType(spread, createJsxAttributesType(attributes.symbol, attributesTable));
13316-
attributesArray = [];
13317-
attributesTable = createMap<Symbol>();
13326+
if (!hasSpreadAnyType) {
13327+
if (spread !== emptyObjectType) {
13328+
if (attributesArray.length > 0) {
13329+
spread = getSpreadType(spread, createJsxAttributesType(attributes.symbol, attributesTable));
13330+
attributesArray = [];
13331+
attributesTable = createMap<Symbol>();
13332+
}
13333+
attributesArray = getPropertiesOfType(spread);
1331813334
}
13319-
attributesArray = getPropertiesOfType(spread);
13320-
}
1332113335

13322-
attributesTable = createMap<Symbol>();
13323-
if (attributesArray) {
13324-
forEach(attributesArray, (attr) => {
13325-
if (!filter || filter(attr)) {
13326-
attributesTable.set(attr.name, attr);
13327-
}
13328-
});
13336+
attributesTable = createMap<Symbol>();
13337+
if (attributesArray) {
13338+
forEach(attributesArray, (attr) => {
13339+
if (!filter || filter(attr)) {
13340+
attributesTable.set(attr.name, attr);
13341+
}
13342+
});
13343+
}
1332913344
}
1333013345

1333113346
// Handle children attribute
@@ -13349,7 +13364,7 @@ namespace ts {
1334913364
// Error if there is a attribute named "children" and children element.
1335013365
// This is because children element will overwrite the value from attributes
1335113366
const jsxChildrenPropertyName = getJsxElementChildrenPropertyname();
13352-
if (jsxChildrenPropertyName && jsxChildrenPropertyName !== "") {
13367+
if (!hasSpreadAnyType && jsxChildrenPropertyName && jsxChildrenPropertyName !== "") {
1335313368
if (attributesTable.has(jsxChildrenPropertyName)) {
1335413369
error(attributes, Diagnostics._0_are_specified_twice_The_attribute_named_0_will_be_overwritten, jsxChildrenPropertyName);
1335513370
}
@@ -13363,7 +13378,7 @@ namespace ts {
1336313378
}
1336413379
}
1336513380

13366-
return createJsxAttributesType(attributes.symbol, attributesTable);
13381+
return hasSpreadAnyType ? anyType : createJsxAttributesType(attributes.symbol, attributesTable);
1336713382

1336813383
/**
1336913384
* Create anonymous type from given attributes symbol table.

src/compiler/core.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,15 @@ namespace ts {
251251
}
252252
}
253253

254+
export function zipToMap<T>(keys: string[], values: T[]): Map<T> {
255+
Debug.assert(keys.length === values.length);
256+
const map = createMap<T>();
257+
for (let i = 0; i < keys.length; ++i) {
258+
map.set(keys[i], values[i]);
259+
}
260+
return map;
261+
}
262+
254263
/**
255264
* Iterates through `array` by index and performs the callback on each element of array until the callback
256265
* returns a falsey value, then returns false.

src/compiler/diagnosticMessages.json

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3211,9 +3211,16 @@
32113211
},
32123212
"Scoped package detected, looking in '{0}'": {
32133213
"category": "Message",
3214-
"code": "6182"
3214+
"code": 6182
3215+
},
3216+
"Reusing resolution of module '{0}' to file '{1}' from old program.": {
3217+
"category": "Message",
3218+
"code": 6183
3219+
},
3220+
"Reusing module resolutions originating in '{0}' since resolutions are unchanged from old program.": {
3221+
"category": "Message",
3222+
"code": 6184
32153223
},
3216-
32173224
"Variable '{0}' implicitly has an '{1}' type.": {
32183225
"category": "Error",
32193226
"code": 7005

src/compiler/factory.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1440,6 +1440,44 @@ namespace ts {
14401440
: node;
14411441
}
14421442

1443+
export function createInterfaceDeclaration(decorators: Decorator[] | undefined, modifiers: Modifier[] | undefined, name: string | Identifier, typeParameters: TypeParameterDeclaration[] | undefined, heritageClauses: HeritageClause[] | undefined, members: TypeElement[]) {
1444+
const node = <InterfaceDeclaration>createSynthesizedNode(SyntaxKind.InterfaceDeclaration);
1445+
node.decorators = asNodeArray(decorators);
1446+
node.modifiers = asNodeArray(modifiers);
1447+
node.name = asName(name);
1448+
node.typeParameters = asNodeArray(typeParameters);
1449+
node.heritageClauses = asNodeArray(heritageClauses);
1450+
node.members = createNodeArray(members);
1451+
return node;
1452+
}
1453+
1454+
export function updateInterfaceDeclaration(node: InterfaceDeclaration, decorators: Decorator[] | undefined, modifiers: Modifier[] | undefined, name: Identifier, typeParameters: TypeParameterDeclaration[] | undefined, heritageClauses: HeritageClause[] | undefined, members: TypeElement[]) {
1455+
return node.decorators !== decorators
1456+
|| node.modifiers !== modifiers
1457+
|| node.name !== name
1458+
|| node.typeParameters !== typeParameters
1459+
|| node.heritageClauses !== heritageClauses
1460+
|| node.members !== members
1461+
? updateNode(createInterfaceDeclaration(decorators, modifiers, name, typeParameters, heritageClauses, members), node)
1462+
: node;
1463+
}
1464+
1465+
export function createTypeAliasDeclaration(name: string | Identifier, typeParameters: TypeParameterDeclaration[] | undefined, type: TypeNode) {
1466+
const node = <TypeAliasDeclaration>createSynthesizedNode(SyntaxKind.TypeAliasDeclaration);
1467+
node.name = asName(name);
1468+
node.typeParameters = asNodeArray(typeParameters);
1469+
node.type = type;
1470+
return node;
1471+
}
1472+
1473+
export function updateTypeAliasDeclaration(node: TypeAliasDeclaration, name: Identifier, typeParameters: TypeParameterDeclaration[] | undefined, type: TypeNode) {
1474+
return node.name !== name
1475+
|| node.typeParameters !== typeParameters
1476+
|| node.type !== type
1477+
? updateNode(createTypeAliasDeclaration(name, typeParameters, type), node)
1478+
: node;
1479+
}
1480+
14431481
export function createEnumDeclaration(decorators: Decorator[] | undefined, modifiers: Modifier[] | undefined, name: string | Identifier, members: EnumMember[]) {
14441482
const node = <EnumDeclaration>createSynthesizedNode(SyntaxKind.EnumDeclaration);
14451483
node.decorators = asNodeArray(decorators);

0 commit comments

Comments
 (0)