Skip to content

Commit 7daf2e3

Browse files
authored
Merge pull request #10679 from Microsoft/mergeMaster_09/01
[Transforms] Merge master 09/01
2 parents d7a20f5 + e1be0bc commit 7daf2e3

File tree

250 files changed

+7952
-2976
lines changed

Some content is hidden

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

250 files changed

+7952
-2976
lines changed

Jakefile.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ var servicesSources = [
128128
"services.ts",
129129
"shims.ts",
130130
"signatureHelp.ts",
131+
"types.ts",
131132
"utilities.ts",
132133
"formatting/formatting.ts",
133134
"formatting/formattingContext.ts",

src/compiler/checker.ts

Lines changed: 55 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ namespace ts {
143143

144144
const anySignature = createSignature(undefined, undefined, undefined, emptyArray, anyType, /*typePredicate*/ undefined, 0, /*hasRestParameter*/ false, /*hasLiteralTypes*/ false);
145145
const unknownSignature = createSignature(undefined, undefined, undefined, emptyArray, unknownType, /*typePredicate*/ undefined, 0, /*hasRestParameter*/ false, /*hasLiteralTypes*/ false);
146+
const resolvingSignature = createSignature(undefined, undefined, undefined, emptyArray, anyType, /*typePredicate*/ undefined, 0, /*hasRestParameter*/ false, /*hasLiteralTypes*/ false);
146147

147148
const enumNumberIndexInfo = createIndexInfo(stringType, /*isReadonly*/ true);
148149

@@ -1024,8 +1025,8 @@ namespace ts {
10241025
}
10251026
}
10261027

1027-
function getDeclarationOfAliasSymbol(symbol: Symbol): Declaration {
1028-
return findMap(symbol.declarations, d => isAliasSymbolDeclaration(d) ? d : undefined);
1028+
function getDeclarationOfAliasSymbol(symbol: Symbol): Declaration | undefined {
1029+
return forEach(symbol.declarations, d => isAliasSymbolDeclaration(d) ? d : undefined);
10291030
}
10301031

10311032
function getTargetOfImportEqualsDeclaration(node: ImportEqualsDeclaration): Symbol {
@@ -1192,6 +1193,7 @@ namespace ts {
11921193
if (!links.target) {
11931194
links.target = resolvingSymbol;
11941195
const node = getDeclarationOfAliasSymbol(symbol);
1196+
Debug.assert(!!node);
11951197
const target = getTargetOfAliasDeclaration(node);
11961198
if (links.target === resolvingSymbol) {
11971199
links.target = target || unknownSymbol;
@@ -1227,6 +1229,7 @@ namespace ts {
12271229
if (!links.referenced) {
12281230
links.referenced = true;
12291231
const node = getDeclarationOfAliasSymbol(symbol);
1232+
Debug.assert(!!node);
12301233
if (node.kind === SyntaxKind.ExportAssignment) {
12311234
// export default <symbol>
12321235
checkExpressionCached((<ExportAssignment>node).expression);
@@ -3348,7 +3351,13 @@ namespace ts {
33483351
// Otherwise, fall back to 'any'.
33493352
else {
33503353
if (compilerOptions.noImplicitAny) {
3351-
error(setter, Diagnostics.Property_0_implicitly_has_type_any_because_its_set_accessor_lacks_a_type_annotation, symbolToString(symbol));
3354+
if (setter) {
3355+
error(setter, Diagnostics.Property_0_implicitly_has_type_any_because_its_set_accessor_lacks_a_parameter_type_annotation, symbolToString(symbol));
3356+
}
3357+
else {
3358+
Debug.assert(!!getter, "there must existed getter as we are current checking either setter or getter in this function");
3359+
error(getter, Diagnostics.Property_0_implicitly_has_type_any_because_its_get_accessor_lacks_a_return_type_annotation, symbolToString(symbol));
3360+
}
33523361
}
33533362
type = anyType;
33543363
}
@@ -5374,7 +5383,7 @@ namespace ts {
53745383
while (i > 0) {
53755384
i--;
53765385
if (isSubtypeOfAny(types[i], types)) {
5377-
types.splice(i, 1);
5386+
orderedRemoveItemAt(types, i);
53785387
}
53795388
}
53805389
}
@@ -8758,7 +8767,7 @@ namespace ts {
87588767
// The location isn't a reference to the given symbol, meaning we're being asked
87598768
// a hypothetical question of what type the symbol would have if there was a reference
87608769
// to it at the given location. Since we have no control flow information for the
8761-
// hypotherical reference (control flow information is created and attached by the
8770+
// hypothetical reference (control flow information is created and attached by the
87628771
// binder), we simply return the declared type of the symbol.
87638772
return getTypeOfSymbol(symbol);
87648773
}
@@ -11993,18 +12002,12 @@ namespace ts {
1199312002
// Function interface, since they have none by default. This is a bit of a leap of faith
1199412003
// that the user will not add any.
1199512004
const callSignatures = getSignaturesOfType(apparentType, SignatureKind.Call);
11996-
1199712005
const constructSignatures = getSignaturesOfType(apparentType, SignatureKind.Construct);
11998-
// TS 1.0 spec: 4.12
11999-
// If FuncExpr is of type Any, or of an object type that has no call or construct signatures
12000-
// but is a subtype of the Function interface, the call is an untyped function call. In an
12001-
// untyped function call no TypeArgs are permitted, Args can be any argument list, no contextual
12006+
12007+
// TS 1.0 Spec: 4.12
12008+
// In an untyped function call no TypeArgs are permitted, Args can be any argument list, no contextual
1200212009
// types are provided for the argument expressions, and the result is always of type Any.
12003-
// We exclude union types because we may have a union of function types that happen to have
12004-
// no common signatures.
12005-
if (isTypeAny(funcType) ||
12006-
(isTypeAny(apparentType) && funcType.flags & TypeFlags.TypeParameter) ||
12007-
(!callSignatures.length && !constructSignatures.length && !(funcType.flags & TypeFlags.Union) && isTypeAssignableTo(funcType, globalFunctionType))) {
12010+
if (isUntypedFunctionCall(funcType, apparentType, callSignatures.length, constructSignatures.length)) {
1200812011
// The unknownType indicates that an error already occurred (and was reported). No
1200912012
// need to report another error in this case.
1201012013
if (funcType !== unknownType && node.typeArguments) {
@@ -12027,6 +12030,29 @@ namespace ts {
1202712030
return resolveCall(node, callSignatures, candidatesOutArray);
1202812031
}
1202912032

12033+
/**
12034+
* TS 1.0 spec: 4.12
12035+
* If FuncExpr is of type Any, or of an object type that has no call or construct signatures
12036+
* but is a subtype of the Function interface, the call is an untyped function call.
12037+
*/
12038+
function isUntypedFunctionCall(funcType: Type, apparentFuncType: Type, numCallSignatures: number, numConstructSignatures: number) {
12039+
if (isTypeAny(funcType)) {
12040+
return true;
12041+
}
12042+
if (isTypeAny(apparentFuncType) && funcType.flags & TypeFlags.TypeParameter) {
12043+
return true;
12044+
}
12045+
if (!numCallSignatures && !numConstructSignatures) {
12046+
// We exclude union types because we may have a union of function types that happen to have
12047+
// no common signatures.
12048+
if (funcType.flags & TypeFlags.Union) {
12049+
return false;
12050+
}
12051+
return isTypeAssignableTo(funcType, globalFunctionType);
12052+
}
12053+
return false;
12054+
}
12055+
1203012056
function resolveNewExpression(node: NewExpression, candidatesOutArray: Signature[]): Signature {
1203112057
if (node.arguments && languageVersion < ScriptTarget.ES5) {
1203212058
const spreadIndex = getSpreadArgumentIndex(node.arguments);
@@ -12152,8 +12178,9 @@ namespace ts {
1215212178
}
1215312179

1215412180
const callSignatures = getSignaturesOfType(apparentType, SignatureKind.Call);
12181+
const constructSignatures = getSignaturesOfType(apparentType, SignatureKind.Construct);
1215512182

12156-
if (isTypeAny(tagType) || (!callSignatures.length && !(tagType.flags & TypeFlags.Union) && isTypeAssignableTo(tagType, globalFunctionType))) {
12183+
if (isUntypedFunctionCall(tagType, apparentType, callSignatures.length, constructSignatures.length)) {
1215712184
return resolveUntypedCall(node);
1215812185
}
1215912186

@@ -12198,7 +12225,8 @@ namespace ts {
1219812225
}
1219912226

1220012227
const callSignatures = getSignaturesOfType(apparentType, SignatureKind.Call);
12201-
if (funcType === anyType || (!callSignatures.length && !(funcType.flags & TypeFlags.Union) && isTypeAssignableTo(funcType, globalFunctionType))) {
12228+
const constructSignatures = getSignaturesOfType(apparentType, SignatureKind.Construct);
12229+
if (isUntypedFunctionCall(funcType, apparentType, callSignatures.length, constructSignatures.length)) {
1220212230
return resolveUntypedCall(node);
1220312231
}
1220412232

@@ -12237,10 +12265,10 @@ namespace ts {
1223712265
// or that a different candidatesOutArray was passed in. Therefore, we need to redo the work
1223812266
// to correctly fill the candidatesOutArray.
1223912267
const cached = links.resolvedSignature;
12240-
if (cached && cached !== anySignature && !candidatesOutArray) {
12268+
if (cached && cached !== resolvingSignature && !candidatesOutArray) {
1224112269
return cached;
1224212270
}
12243-
links.resolvedSignature = anySignature;
12271+
links.resolvedSignature = resolvingSignature;
1224412272
const result = resolveSignature(node, candidatesOutArray);
1224512273
// If signature resolution originated in control flow type analysis (for example to compute the
1224612274
// assigned type in a flow assignment) we don't cache the result as it may be based on temporary
@@ -12252,7 +12280,7 @@ namespace ts {
1225212280
function getResolvedOrAnySignature(node: CallLikeExpression) {
1225312281
// If we're already in the process of resolving the given signature, don't resolve again as
1225412282
// that could cause infinite recursion. Instead, return anySignature.
12255-
return getNodeLinks(node).resolvedSignature === anySignature ? anySignature : getResolvedSignature(node);
12283+
return getNodeLinks(node).resolvedSignature === resolvingSignature ? resolvingSignature : getResolvedSignature(node);
1225612284
}
1225712285

1225812286
function getInferredClassType(symbol: Symbol) {
@@ -18885,7 +18913,13 @@ namespace ts {
1888518913
(augmentations || (augmentations = [])).push(file.moduleAugmentations);
1888618914
}
1888718915
if (file.symbol && file.symbol.globalExports) {
18888-
mergeSymbolTable(globals, file.symbol.globalExports);
18916+
// Merge in UMD exports with first-in-wins semantics (see #9771)
18917+
const source = file.symbol.globalExports;
18918+
for (const id in source) {
18919+
if (!(id in globals)) {
18920+
globals[id] = source[id];
18921+
}
18922+
}
1888918923
}
1889018924
if ((compilerOptions.isolatedModules || isExternalModule(file)) && !file.isDeclarationFile) {
1889118925
const fileRequestedExternalEmitHelpers = file.flags & NodeFlags.EmitHelperFlags;

src/compiler/commandLineParser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -891,7 +891,7 @@ namespace ts {
891891
function convertCompilerOptionsFromJsonWorker(jsonOptions: any,
892892
basePath: string, errors: Diagnostic[], configFileName?: string): CompilerOptions {
893893

894-
const options: CompilerOptions = getBaseFileName(configFileName) === "jsconfig.json" ? { allowJs: true } : {};
894+
const options: CompilerOptions = getBaseFileName(configFileName) === "jsconfig.json" ? { allowJs: true, maxNodeModuleJsDepth: 2 } : {};
895895
convertOptionsFromJson(optionDeclarations, jsonOptions, basePath, options, Diagnostics.Unknown_compiler_option_0, errors);
896896
return options;
897897
}

src/compiler/core.ts

Lines changed: 62 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,10 @@ namespace ts {
199199
return count;
200200
}
201201

202+
/**
203+
* Filters an array by a predicate function. Returns the same array instance if the predicate is
204+
* true for all elements, otherwise returns a new array instance containing the filtered subset.
205+
*/
202206
export function filter<T, U extends T>(array: T[], f: (x: T) => x is U): U[];
203207
export function filter<T>(array: T[], f: (x: T) => boolean): T[]
204208
export function filter<T>(array: T[], f: (x: T) => boolean): T[] {
@@ -746,6 +750,36 @@ namespace ts {
746750
return result;
747751
}
748752

753+
/**
754+
* Adds the value to an array of values associated with the key, and returns the array.
755+
* Creates the array if it does not already exist.
756+
*/
757+
export function multiMapAdd<V>(map: Map<V[]>, key: string, value: V): V[] {
758+
const values = map[key];
759+
if (values) {
760+
values.push(value);
761+
return values;
762+
}
763+
else {
764+
return map[key] = [value];
765+
}
766+
}
767+
768+
/**
769+
* Removes a value from an array of values associated with the key.
770+
* Does not preserve the order of those values.
771+
* Does nothing if `key` is not in `map`, or `value` is not in `map[key]`.
772+
*/
773+
export function multiMapRemove<V>(map: Map<V[]>, key: string, value: V): void {
774+
const values = map[key];
775+
if (values) {
776+
unorderedRemoveItem(values, value);
777+
if (!values.length) {
778+
delete map[key];
779+
}
780+
}
781+
}
782+
749783
/**
750784
* Tests whether a value is an array.
751785
*/
@@ -1717,20 +1751,39 @@ namespace ts {
17171751
return "";
17181752
}
17191753

1720-
export function copyListRemovingItem<T>(item: T, list: T[]) {
1721-
const copiedList: T[] = [];
1722-
for (const e of list) {
1723-
if (e !== item) {
1724-
copiedList.push(e);
1754+
/** Remove an item from an array, moving everything to its right one space left. */
1755+
export function orderedRemoveItemAt<T>(array: T[], index: number): void {
1756+
// This seems to be faster than either `array.splice(i, 1)` or `array.copyWithin(i, i+ 1)`.
1757+
for (let i = index; i < array.length - 1; i++) {
1758+
array[i] = array[i + 1];
1759+
}
1760+
array.pop();
1761+
}
1762+
1763+
export function unorderedRemoveItemAt<T>(array: T[], index: number): void {
1764+
// Fill in the "hole" left at `index`.
1765+
array[index] = array[array.length - 1];
1766+
array.pop();
1767+
}
1768+
1769+
/** Remove the *first* occurrence of `item` from the array. */
1770+
export function unorderedRemoveItem<T>(array: T[], item: T): void {
1771+
unorderedRemoveFirstItemWhere(array, element => element === item);
1772+
}
1773+
1774+
/** Remove the *first* element satisfying `predicate`. */
1775+
function unorderedRemoveFirstItemWhere<T>(array: T[], predicate: (element: T) => boolean): void {
1776+
for (let i = 0; i < array.length; i++) {
1777+
if (predicate(array[i])) {
1778+
unorderedRemoveItemAt(array, i);
1779+
break;
17251780
}
17261781
}
1727-
return copiedList;
17281782
}
17291783

1730-
export function createGetCanonicalFileName(useCaseSensitivefileNames: boolean): (fileName: string) => string {
1731-
return useCaseSensitivefileNames
1784+
export function createGetCanonicalFileName(useCaseSensitiveFileNames: boolean): (fileName: string) => string {
1785+
return useCaseSensitiveFileNames
17321786
? ((fileName) => fileName)
17331787
: ((fileName) => fileName.toLowerCase());
17341788
}
1735-
17361789
}

src/compiler/declarationEmitter.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1133,8 +1133,10 @@ namespace ts {
11331133
// it if it's not a well known symbol. In that case, the text of the name will be exactly
11341134
// what we want, namely the name expression enclosed in brackets.
11351135
writeTextOfNode(currentText, node.name);
1136-
// If optional property emit ?
1137-
if ((node.kind === SyntaxKind.PropertyDeclaration || node.kind === SyntaxKind.PropertySignature || node.kind === SyntaxKind.Parameter) && hasQuestionToken(node)) {
1136+
// If optional property emit ? but in the case of parameterProperty declaration with "?" indicating optional parameter for the constructor
1137+
// we don't want to emit property declaration with "?"
1138+
if ((node.kind === SyntaxKind.PropertyDeclaration || node.kind === SyntaxKind.PropertySignature ||
1139+
(node.kind === SyntaxKind.Parameter && !isParameterPropertyDeclaration(node))) && hasQuestionToken(node)) {
11381140
write("?");
11391141
}
11401142
if ((node.kind === SyntaxKind.PropertyDeclaration || node.kind === SyntaxKind.PropertySignature) && node.parent.kind === SyntaxKind.TypeLiteral) {

src/compiler/diagnosticMessages.json

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2871,11 +2871,7 @@
28712871
"Element implicitly has an 'any' type because index expression is not of type 'number'.": {
28722872
"category": "Error",
28732873
"code": 7015
2874-
},
2875-
"Property '{0}' implicitly has type 'any', because its 'set' accessor lacks a type annotation.": {
2876-
"category": "Error",
2877-
"code": 7016
2878-
},
2874+
},
28792875
"Index signature of object type implicitly has an 'any' type.": {
28802876
"category": "Error",
28812877
"code": 7017
@@ -2932,6 +2928,14 @@
29322928
"category": "Error",
29332929
"code": 7031
29342930
},
2931+
"Property '{0}' implicitly has type 'any', because its set accessor lacks a parameter type annotation.": {
2932+
"category": "Error",
2933+
"code": 7032
2934+
},
2935+
"Property '{0}' implicitly has type 'any', because its get accessor lacks a return type annotation.": {
2936+
"category": "Error",
2937+
"code": 7033
2938+
},
29352939
"You cannot rename this element.": {
29362940
"category": "Error",
29372941
"code": 8000

src/compiler/parser.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2338,6 +2338,7 @@ namespace ts {
23382338
token() === SyntaxKind.LessThanToken ||
23392339
token() === SyntaxKind.QuestionToken ||
23402340
token() === SyntaxKind.ColonToken ||
2341+
token() === SyntaxKind.CommaToken ||
23412342
canParseSemicolon();
23422343
}
23432344
return false;

0 commit comments

Comments
 (0)