Skip to content

Commit d14183c

Browse files
committed
merge with origin/release-2.0.5
2 parents 2b8d963 + 82a4d58 commit d14183c

File tree

189 files changed

+2854
-1443
lines changed

Some content is hidden

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

189 files changed

+2854
-1443
lines changed

src/compiler/checker.ts

+81-20
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
/* @internal */
44
namespace ts {
5+
const ambientModuleSymbolRegex = /^".+"$/;
6+
57
let nextSymbolId = 1;
68
let nextNodeId = 1;
79
let nextMergeId = 1;
@@ -100,6 +102,7 @@ namespace ts {
100102
getAliasedSymbol: resolveAlias,
101103
getEmitResolver,
102104
getExportsOfModule: getExportsOfModuleAsArray,
105+
getAmbientModules,
103106

104107
getJsxElementAttributesType,
105108
getJsxIntrinsicTagNames,
@@ -329,6 +332,7 @@ namespace ts {
329332
const assignableRelation = createMap<RelationComparisonResult>();
330333
const comparableRelation = createMap<RelationComparisonResult>();
331334
const identityRelation = createMap<RelationComparisonResult>();
335+
const enumRelation = createMap<boolean>();
332336

333337
// This is for caching the result of getSymbolDisplayBuilder. Do not access directly.
334338
let _displayBuilder: SymbolDisplayBuilder;
@@ -3347,7 +3351,13 @@ namespace ts {
33473351
// Otherwise, fall back to 'any'.
33483352
else {
33493353
if (compilerOptions.noImplicitAny) {
3350-
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+
}
33513361
}
33523362
type = anyType;
33533363
}
@@ -6186,8 +6196,14 @@ namespace ts {
61866196
if (source === target) {
61876197
return true;
61886198
}
6189-
if (source.symbol.name !== target.symbol.name || !(source.symbol.flags & SymbolFlags.RegularEnum) || !(target.symbol.flags & SymbolFlags.RegularEnum)) {
6190-
return false;
6199+
const id = source.id + "," + target.id;
6200+
if (enumRelation[id] !== undefined) {
6201+
return enumRelation[id];
6202+
}
6203+
if (source.symbol.name !== target.symbol.name ||
6204+
!(source.symbol.flags & SymbolFlags.RegularEnum) || !(target.symbol.flags & SymbolFlags.RegularEnum) ||
6205+
(source.flags & TypeFlags.Union) !== (target.flags & TypeFlags.Union)) {
6206+
return enumRelation[id] = false;
61916207
}
61926208
const targetEnumType = getTypeOfSymbol(target.symbol);
61936209
for (const property of getPropertiesOfType(getTypeOfSymbol(source.symbol))) {
@@ -6198,11 +6214,11 @@ namespace ts {
61986214
errorReporter(Diagnostics.Property_0_is_missing_in_type_1, property.name,
61996215
typeToString(target, /*enclosingDeclaration*/ undefined, TypeFormatFlags.UseFullyQualifiedType));
62006216
}
6201-
return false;
6217+
return enumRelation[id] = false;
62026218
}
62036219
}
62046220
}
6205-
return true;
6221+
return enumRelation[id] = true;
62066222
}
62076223

62086224
function isSimpleTypeRelatedTo(source: Type, target: Type, relation: Map<RelationComparisonResult>, errorReporter?: ErrorReporter) {
@@ -6217,8 +6233,18 @@ namespace ts {
62176233
if (source.flags & TypeFlags.Null && (!strictNullChecks || target.flags & TypeFlags.Null)) return true;
62186234
if (relation === assignableRelation || relation === comparableRelation) {
62196235
if (source.flags & TypeFlags.Any) return true;
6220-
if (source.flags & (TypeFlags.Number | TypeFlags.NumberLiteral) && target.flags & TypeFlags.Enum) return true;
6221-
if (source.flags & TypeFlags.NumberLiteral && target.flags & TypeFlags.EnumLiteral && (<LiteralType>source).text === (<LiteralType>target).text) return true;
6236+
if ((source.flags & TypeFlags.Number | source.flags & TypeFlags.NumberLiteral) && target.flags & TypeFlags.EnumLike) return true;
6237+
if (source.flags & TypeFlags.EnumLiteral &&
6238+
target.flags & TypeFlags.EnumLiteral &&
6239+
(<LiteralType>source).text === (<LiteralType>target).text &&
6240+
isEnumTypeRelatedTo((<EnumLiteralType>source).baseType, (<EnumLiteralType>target).baseType, errorReporter)) {
6241+
return true;
6242+
}
6243+
if (source.flags & TypeFlags.EnumLiteral &&
6244+
target.flags & TypeFlags.Enum &&
6245+
isEnumTypeRelatedTo(<EnumType>target, (<EnumLiteralType>source).baseType, errorReporter)) {
6246+
return true;
6247+
}
62226248
}
62236249
return false;
62246250
}
@@ -11961,18 +11987,12 @@ namespace ts {
1196111987
// Function interface, since they have none by default. This is a bit of a leap of faith
1196211988
// that the user will not add any.
1196311989
const callSignatures = getSignaturesOfType(apparentType, SignatureKind.Call);
11964-
1196511990
const constructSignatures = getSignaturesOfType(apparentType, SignatureKind.Construct);
11966-
// TS 1.0 spec: 4.12
11967-
// If FuncExpr is of type Any, or of an object type that has no call or construct signatures
11968-
// but is a subtype of the Function interface, the call is an untyped function call. In an
11969-
// untyped function call no TypeArgs are permitted, Args can be any argument list, no contextual
11991+
11992+
// TS 1.0 Spec: 4.12
11993+
// In an untyped function call no TypeArgs are permitted, Args can be any argument list, no contextual
1197011994
// types are provided for the argument expressions, and the result is always of type Any.
11971-
// We exclude union types because we may have a union of function types that happen to have
11972-
// no common signatures.
11973-
if (isTypeAny(funcType) ||
11974-
(isTypeAny(apparentType) && funcType.flags & TypeFlags.TypeParameter) ||
11975-
(!callSignatures.length && !constructSignatures.length && !(funcType.flags & TypeFlags.Union) && isTypeAssignableTo(funcType, globalFunctionType))) {
11995+
if (isUntypedFunctionCall(funcType, apparentType, callSignatures.length, constructSignatures.length)) {
1197611996
// The unknownType indicates that an error already occurred (and was reported). No
1197711997
// need to report another error in this case.
1197811998
if (funcType !== unknownType && node.typeArguments) {
@@ -11995,6 +12015,29 @@ namespace ts {
1199512015
return resolveCall(node, callSignatures, candidatesOutArray);
1199612016
}
1199712017

12018+
/**
12019+
* TS 1.0 spec: 4.12
12020+
* If FuncExpr is of type Any, or of an object type that has no call or construct signatures
12021+
* but is a subtype of the Function interface, the call is an untyped function call.
12022+
*/
12023+
function isUntypedFunctionCall(funcType: Type, apparentFuncType: Type, numCallSignatures: number, numConstructSignatures: number) {
12024+
if (isTypeAny(funcType)) {
12025+
return true;
12026+
}
12027+
if (isTypeAny(apparentFuncType) && funcType.flags & TypeFlags.TypeParameter) {
12028+
return true;
12029+
}
12030+
if (!numCallSignatures && !numConstructSignatures) {
12031+
// We exclude union types because we may have a union of function types that happen to have
12032+
// no common signatures.
12033+
if (funcType.flags & TypeFlags.Union) {
12034+
return false;
12035+
}
12036+
return isTypeAssignableTo(funcType, globalFunctionType);
12037+
}
12038+
return false;
12039+
}
12040+
1199812041
function resolveNewExpression(node: NewExpression, candidatesOutArray: Signature[]): Signature {
1199912042
if (node.arguments && languageVersion < ScriptTarget.ES5) {
1200012043
const spreadIndex = getSpreadArgumentIndex(node.arguments);
@@ -12120,8 +12163,9 @@ namespace ts {
1212012163
}
1212112164

1212212165
const callSignatures = getSignaturesOfType(apparentType, SignatureKind.Call);
12166+
const constructSignatures = getSignaturesOfType(apparentType, SignatureKind.Construct);
1212312167

12124-
if (isTypeAny(tagType) || (!callSignatures.length && !(tagType.flags & TypeFlags.Union) && isTypeAssignableTo(tagType, globalFunctionType))) {
12168+
if (isUntypedFunctionCall(tagType, apparentType, callSignatures.length, constructSignatures.length)) {
1212512169
return resolveUntypedCall(node);
1212612170
}
1212712171

@@ -12166,7 +12210,8 @@ namespace ts {
1216612210
}
1216712211

1216812212
const callSignatures = getSignaturesOfType(apparentType, SignatureKind.Call);
12169-
if (funcType === anyType || (!callSignatures.length && !(funcType.flags & TypeFlags.Union) && isTypeAssignableTo(funcType, globalFunctionType))) {
12213+
const constructSignatures = getSignaturesOfType(apparentType, SignatureKind.Construct);
12214+
if (isUntypedFunctionCall(funcType, apparentType, callSignatures.length, constructSignatures.length)) {
1217012215
return resolveUntypedCall(node);
1217112216
}
1217212217

@@ -18767,7 +18812,13 @@ namespace ts {
1876718812
(augmentations || (augmentations = [])).push(file.moduleAugmentations);
1876818813
}
1876918814
if (file.symbol && file.symbol.globalExports) {
18770-
mergeSymbolTable(globals, file.symbol.globalExports);
18815+
// Merge in UMD exports with first-in-wins semantics (see #9771)
18816+
const source = file.symbol.globalExports;
18817+
for (const id in source) {
18818+
if (!(id in globals)) {
18819+
globals[id] = source[id];
18820+
}
18821+
}
1877118822
}
1877218823
});
1877318824

@@ -19992,5 +20043,15 @@ namespace ts {
1999220043
return true;
1999320044
}
1999420045
}
20046+
20047+
function getAmbientModules(): Symbol[] {
20048+
const result: Symbol[] = [];
20049+
for (const sym in globals) {
20050+
if (ambientModuleSymbolRegex.test(sym)) {
20051+
result.push(globals[sym]);
20052+
}
20053+
}
20054+
return result;
20055+
}
1999520056
}
1999620057
}

src/compiler/diagnosticMessages.json

+9-5
Original file line numberDiff line numberDiff line change
@@ -2875,11 +2875,7 @@
28752875
"Element implicitly has an 'any' type because index expression is not of type 'number'.": {
28762876
"category": "Error",
28772877
"code": 7015
2878-
},
2879-
"Property '{0}' implicitly has type 'any', because its 'set' accessor lacks a type annotation.": {
2880-
"category": "Error",
2881-
"code": 7016
2882-
},
2878+
},
28832879
"Index signature of object type implicitly has an 'any' type.": {
28842880
"category": "Error",
28852881
"code": 7017
@@ -2936,6 +2932,14 @@
29362932
"category": "Error",
29372933
"code": 7031
29382934
},
2935+
"Property '{0}' implicitly has type 'any', because its set accessor lacks a parameter type annotation.": {
2936+
"category": "Error",
2937+
"code": 7032
2938+
},
2939+
"Property '{0}' implicitly has type 'any', because its get accessor lacks a return type annotation.": {
2940+
"category": "Error",
2941+
"code": 7033
2942+
},
29392943
"You cannot rename this element.": {
29402944
"category": "Error",
29412945
"code": 8000

src/compiler/emitter.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -6587,7 +6587,7 @@ const _super = (function (geti, seti) {
65876587
// import { x, y } from "foo"
65886588
// import d, * as x from "foo"
65896589
// import d, { x, y } from "foo"
6590-
const isNakedImport = SyntaxKind.ImportDeclaration && !(<ImportDeclaration>node).importClause;
6590+
const isNakedImport = node.kind === SyntaxKind.ImportDeclaration && !(<ImportDeclaration>node).importClause;
65916591
if (!isNakedImport) {
65926592
write(varOrConst);
65936593
write(getGeneratedNameForNode(<ImportDeclaration>node));

src/compiler/parser.ts

+1
Original file line numberDiff line numberDiff line change
@@ -2340,6 +2340,7 @@ namespace ts {
23402340
token() === SyntaxKind.LessThanToken ||
23412341
token() === SyntaxKind.QuestionToken ||
23422342
token() === SyntaxKind.ColonToken ||
2343+
token() === SyntaxKind.CommaToken ||
23432344
canParseSemicolon();
23442345
}
23452346
return false;

src/compiler/program.ts

+6-9
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ namespace ts {
1111

1212
const defaultTypeRoots = ["node_modules/@types"];
1313

14-
export function findConfigFile(searchPath: string, fileExists: (fileName: string) => boolean): string {
14+
export function findConfigFile(searchPath: string, fileExists: (fileName: string) => boolean, configName = "tsconfig.json"): string {
1515
while (true) {
16-
const fileName = combinePaths(searchPath, "tsconfig.json");
16+
const fileName = combinePaths(searchPath, configName);
1717
if (fileExists(fileName)) {
1818
return fileName;
1919
}
@@ -79,22 +79,19 @@ namespace ts {
7979

8080
const typeReferenceExtensions = [".d.ts"];
8181

82-
function getEffectiveTypeRoots(options: CompilerOptions, host: ModuleResolutionHost) {
82+
export function getEffectiveTypeRoots(options: CompilerOptions, currentDirectory: string) {
8383
if (options.typeRoots) {
8484
return options.typeRoots;
8585
}
8686

87-
let currentDirectory: string;
8887
if (options.configFilePath) {
8988
currentDirectory = getDirectoryPath(options.configFilePath);
9089
}
91-
else if (host.getCurrentDirectory) {
92-
currentDirectory = host.getCurrentDirectory();
93-
}
9490

9591
if (!currentDirectory) {
9692
return undefined;
9793
}
94+
9895
return map(defaultTypeRoots, d => combinePaths(currentDirectory, d));
9996
}
10097

@@ -112,7 +109,7 @@ namespace ts {
112109
traceEnabled
113110
};
114111

115-
const typeRoots = getEffectiveTypeRoots(options, host);
112+
const typeRoots = getEffectiveTypeRoots(options, host.getCurrentDirectory && host.getCurrentDirectory());
116113
if (traceEnabled) {
117114
if (containingFile === undefined) {
118115
if (typeRoots === undefined) {
@@ -427,7 +424,7 @@ namespace ts {
427424
// Walk the primary type lookup locations
428425
const result: string[] = [];
429426
if (host.directoryExists && host.getDirectories) {
430-
const typeRoots = getEffectiveTypeRoots(options, host);
427+
const typeRoots = getEffectiveTypeRoots(options, host.getCurrentDirectory && host.getCurrentDirectory());
431428
if (typeRoots) {
432429
for (const root of typeRoots) {
433430
if (host.directoryExists(root)) {

src/compiler/types.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1891,6 +1891,7 @@ namespace ts {
18911891
getJsxElementAttributesType(elementNode: JsxOpeningLikeElement): Type;
18921892
getJsxIntrinsicTagNames(): Symbol[];
18931893
isOptionalParameter(node: ParameterDeclaration): boolean;
1894+
getAmbientModules(): Symbol[];
18941895

18951896
// Should not be called directly. Should only be accessed through the Program instance.
18961897
/* @internal */ getDiagnostics(sourceFile?: SourceFile, cancellationToken?: CancellationToken): Diagnostic[];

0 commit comments

Comments
 (0)