Skip to content

Commit 1b7d3bf

Browse files
author
Kanchalai Tanglertsampan
committed
Merge branch 'master' into master-dynamicImport
2 parents 1b0d020 + c1b180d commit 1b7d3bf

File tree

78 files changed

+2311
-984
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+2311
-984
lines changed

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
"@types/gulp-help": "latest",
4040
"@types/gulp-newer": "latest",
4141
"@types/gulp-sourcemaps": "latest",
42-
"@types/gulp-typescript": "latest",
4342
"@types/merge2": "latest",
4443
"@types/minimatch": "latest",
4544
"@types/minimist": "latest",

src/compiler/checker.ts

Lines changed: 70 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1400,10 +1400,10 @@ namespace ts {
14001400
return resolveExternalModuleSymbol(node.parent.symbol, dontResolveAlias);
14011401
}
14021402

1403-
function getTargetOfExportSpecifier(node: ExportSpecifier, dontResolveAlias?: boolean): Symbol {
1404-
return (<ExportDeclaration>node.parent.parent).moduleSpecifier ?
1405-
getExternalModuleMember(<ExportDeclaration>node.parent.parent, node, dontResolveAlias) :
1406-
resolveEntityName(node.propertyName || node.name, SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace, /*ignoreErrors*/ false, dontResolveAlias);
1403+
function getTargetOfExportSpecifier(node: ExportSpecifier, meaning: SymbolFlags, dontResolveAlias?: boolean) {
1404+
return node.parent.parent.moduleSpecifier ?
1405+
getExternalModuleMember(node.parent.parent, node, dontResolveAlias) :
1406+
resolveEntityName(node.propertyName || node.name, meaning, /*ignoreErrors*/ false, dontResolveAlias);
14071407
}
14081408

14091409
function getTargetOfExportAssignment(node: ExportAssignment, dontResolveAlias: boolean): Symbol {
@@ -1421,7 +1421,7 @@ namespace ts {
14211421
case SyntaxKind.ImportSpecifier:
14221422
return getTargetOfImportSpecifier(<ImportSpecifier>node, dontRecursivelyResolve);
14231423
case SyntaxKind.ExportSpecifier:
1424-
return getTargetOfExportSpecifier(<ExportSpecifier>node, dontRecursivelyResolve);
1424+
return getTargetOfExportSpecifier(<ExportSpecifier>node, SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace, dontRecursivelyResolve);
14251425
case SyntaxKind.ExportAssignment:
14261426
return getTargetOfExportAssignment(<ExportAssignment>node, dontRecursivelyResolve);
14271427
case SyntaxKind.NamespaceExportDeclaration:
@@ -3721,10 +3721,7 @@ namespace ts {
37213721
exportSymbol = resolveName(node.parent, node.text, SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace | SymbolFlags.Alias, Diagnostics.Cannot_find_name_0, node);
37223722
}
37233723
else if (node.parent.kind === SyntaxKind.ExportSpecifier) {
3724-
const exportSpecifier = <ExportSpecifier>node.parent;
3725-
exportSymbol = (<ExportDeclaration>exportSpecifier.parent.parent).moduleSpecifier ?
3726-
getExternalModuleMember(<ExportDeclaration>exportSpecifier.parent.parent, exportSpecifier) :
3727-
resolveEntityName(exportSpecifier.propertyName || exportSpecifier.name, SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace | SymbolFlags.Alias);
3724+
exportSymbol = getTargetOfExportSpecifier(<ExportSpecifier>node.parent, SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace | SymbolFlags.Alias);
37283725
}
37293726
const result: Node[] = [];
37303727
if (exportSymbol) {
@@ -7257,7 +7254,7 @@ namespace ts {
72577254
accessExpression && checkThatExpressionIsProperSymbolReference(accessExpression.argumentExpression, indexType, /*reportError*/ false) ?
72587255
getPropertyNameForKnownSymbolName((<Identifier>(<PropertyAccessExpression>accessExpression.argumentExpression).name).text) :
72597256
undefined;
7260-
if (propName) {
7257+
if (propName !== undefined) {
72617258
const prop = getPropertyOfType(objectType, propName);
72627259
if (prop) {
72637260
if (accessExpression) {
@@ -9234,25 +9231,39 @@ namespace ts {
92349231
let result = Ternary.True;
92359232
const saveErrorInfo = errorInfo;
92369233

9237-
outer: for (const t of targetSignatures) {
9238-
// Only elaborate errors from the first failure
9239-
let shouldElaborateErrors = reportErrors;
9240-
for (const s of sourceSignatures) {
9241-
const related = signatureRelatedTo(s, t, shouldElaborateErrors);
9242-
if (related) {
9243-
result &= related;
9244-
errorInfo = saveErrorInfo;
9245-
continue outer;
9234+
if (getObjectFlags(source) & ObjectFlags.Instantiated && getObjectFlags(target) & ObjectFlags.Instantiated && source.symbol === target.symbol) {
9235+
// We instantiations of the same anonymous type (which typically will be the type of a method).
9236+
// Simply do a pairwise comparison of the signatures in the two signature lists instead of the
9237+
// much more expensive N * M comparison matrix we explore below.
9238+
for (let i = 0; i < targetSignatures.length; i++) {
9239+
const related = signatureRelatedTo(sourceSignatures[i], targetSignatures[i], reportErrors);
9240+
if (!related) {
9241+
return Ternary.False;
92469242
}
9247-
shouldElaborateErrors = false;
9243+
result &= related;
92489244
}
9245+
}
9246+
else {
9247+
outer: for (const t of targetSignatures) {
9248+
// Only elaborate errors from the first failure
9249+
let shouldElaborateErrors = reportErrors;
9250+
for (const s of sourceSignatures) {
9251+
const related = signatureRelatedTo(s, t, shouldElaborateErrors);
9252+
if (related) {
9253+
result &= related;
9254+
errorInfo = saveErrorInfo;
9255+
continue outer;
9256+
}
9257+
shouldElaborateErrors = false;
9258+
}
92499259

9250-
if (shouldElaborateErrors) {
9251-
reportError(Diagnostics.Type_0_provides_no_match_for_the_signature_1,
9252-
typeToString(source),
9253-
signatureToString(t, /*enclosingDeclaration*/ undefined, /*flags*/ undefined, kind));
9260+
if (shouldElaborateErrors) {
9261+
reportError(Diagnostics.Type_0_provides_no_match_for_the_signature_1,
9262+
typeToString(source),
9263+
signatureToString(t, /*enclosingDeclaration*/ undefined, /*flags*/ undefined, kind));
9264+
}
9265+
return Ternary.False;
92549266
}
9255-
return Ternary.False;
92569267
}
92579268
return result;
92589269
}
@@ -13243,6 +13254,8 @@ namespace ts {
1324313254
let attributesTable = createMap<Symbol>();
1324413255
let spread: Type = emptyObjectType;
1324513256
let attributesArray: Symbol[] = [];
13257+
let hasSpreadAnyType = false;
13258+
1324613259
for (const attributeDecl of attributes.properties) {
1324713260
const member = attributeDecl.symbol;
1324813261
if (isJsxAttribute(attributeDecl)) {
@@ -13271,31 +13284,33 @@ namespace ts {
1327113284
const exprType = checkExpression(attributeDecl.expression);
1327213285
if (!isValidSpreadType(exprType)) {
1327313286
error(attributeDecl, Diagnostics.Spread_types_may_only_be_created_from_object_types);
13274-
return anyType;
13287+
hasSpreadAnyType = true;
1327513288
}
1327613289
if (isTypeAny(exprType)) {
13277-
return anyType;
13290+
hasSpreadAnyType = true;
1327813291
}
1327913292
spread = getSpreadType(spread, exprType);
1328013293
}
1328113294
}
1328213295

13283-
if (spread !== emptyObjectType) {
13284-
if (attributesArray.length > 0) {
13285-
spread = getSpreadType(spread, createJsxAttributesType(attributes.symbol, attributesTable));
13286-
attributesArray = [];
13287-
attributesTable = createMap<Symbol>();
13296+
if (!hasSpreadAnyType) {
13297+
if (spread !== emptyObjectType) {
13298+
if (attributesArray.length > 0) {
13299+
spread = getSpreadType(spread, createJsxAttributesType(attributes.symbol, attributesTable));
13300+
attributesArray = [];
13301+
attributesTable = createMap<Symbol>();
13302+
}
13303+
attributesArray = getPropertiesOfType(spread);
1328813304
}
13289-
attributesArray = getPropertiesOfType(spread);
13290-
}
1329113305

13292-
attributesTable = createMap<Symbol>();
13293-
if (attributesArray) {
13294-
forEach(attributesArray, (attr) => {
13295-
if (!filter || filter(attr)) {
13296-
attributesTable.set(attr.name, attr);
13297-
}
13298-
});
13306+
attributesTable = createMap<Symbol>();
13307+
if (attributesArray) {
13308+
forEach(attributesArray, (attr) => {
13309+
if (!filter || filter(attr)) {
13310+
attributesTable.set(attr.name, attr);
13311+
}
13312+
});
13313+
}
1329913314
}
1330013315

1330113316
// Handle children attribute
@@ -13319,7 +13334,7 @@ namespace ts {
1331913334
// Error if there is a attribute named "children" and children element.
1332013335
// This is because children element will overwrite the value from attributes
1332113336
const jsxChildrenPropertyName = getJsxElementChildrenPropertyname();
13322-
if (jsxChildrenPropertyName && jsxChildrenPropertyName !== "") {
13337+
if (!hasSpreadAnyType && jsxChildrenPropertyName && jsxChildrenPropertyName !== "") {
1332313338
if (attributesTable.has(jsxChildrenPropertyName)) {
1332413339
error(attributes, Diagnostics._0_are_specified_twice_The_attribute_named_0_will_be_overwritten, jsxChildrenPropertyName);
1332513340
}
@@ -13333,7 +13348,7 @@ namespace ts {
1333313348
}
1333413349
}
1333513350

13336-
return createJsxAttributesType(attributes.symbol, attributesTable);
13351+
return hasSpreadAnyType ? anyType : createJsxAttributesType(attributes.symbol, attributesTable);
1333713352

1333813353
/**
1333913354
* Create anonymous type from given attributes symbol table.
@@ -13429,7 +13444,18 @@ namespace ts {
1342913444
}
1343013445
}
1343113446

13432-
return getUnionType(map(signatures, getReturnTypeOfSignature), /*subtypeReduction*/ true);
13447+
const instantiatedSignatures = [];
13448+
for (const signature of signatures) {
13449+
if (signature.typeParameters) {
13450+
const typeArguments = fillMissingTypeArguments(/*typeArguments*/ undefined, signature.typeParameters, /*minTypeArgumentCount*/ 0);
13451+
instantiatedSignatures.push(getSignatureInstantiation(signature, typeArguments));
13452+
}
13453+
else {
13454+
instantiatedSignatures.push(signature);
13455+
}
13456+
}
13457+
13458+
return getUnionType(map(instantiatedSignatures, getReturnTypeOfSignature), /*subtypeReduction*/ true);
1343313459
}
1343413460

1343513461
/**

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
@@ -3224,9 +3224,16 @@
32243224
},
32253225
"Scoped package detected, looking in '{0}'": {
32263226
"category": "Message",
3227-
"code": "6182"
3227+
"code": 6182
3228+
},
3229+
"Reusing resolution of module '{0}' to file '{1}' from old program.": {
3230+
"category": "Message",
3231+
"code": 6183
3232+
},
3233+
"Reusing module resolutions originating in '{0}' since resolutions are unchanged from old program.": {
3234+
"category": "Message",
3235+
"code": 6184
32283236
},
3229-
32303237
"Variable '{0}' implicitly has an '{1}' type.": {
32313238
"category": "Error",
32323239
"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)