Skip to content

Commit e7e1ac9

Browse files
committed
Merge remote-tracking branch 'origin/master' into vladima/textChanges
2 parents c07fb70 + ea57fbc commit e7e1ac9

File tree

136 files changed

+7142
-822
lines changed

Some content is hidden

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

136 files changed

+7142
-822
lines changed

Jakefile.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ compileFile(buildProtocolJs,
419419
[buildProtocolTs],
420420
[],
421421
/*useBuiltCompiler*/ false,
422-
{noOutFile: true});
422+
{ noOutFile: true, lib: "es6" });
423423

424424
file(buildProtocolDts, [buildProtocolTs, buildProtocolJs, typescriptServicesDts], function() {
425425

@@ -581,16 +581,16 @@ compileFile(
581581
file(typescriptServicesDts, [servicesFile]);
582582

583583
var cancellationTokenFile = path.join(builtLocalDirectory, "cancellationToken.js");
584-
compileFile(cancellationTokenFile, cancellationTokenSources, [builtLocalDirectory].concat(cancellationTokenSources), /*prefixes*/ [copyright], /*useBuiltCompiler*/ true, { outDir: builtLocalDirectory, noOutFile: true });
584+
compileFile(cancellationTokenFile, cancellationTokenSources, [builtLocalDirectory].concat(cancellationTokenSources), /*prefixes*/ [copyright], /*useBuiltCompiler*/ true, { types: ["node"], outDir: builtLocalDirectory, noOutFile: true, lib: "es6" });
585585

586586
var typingsInstallerFile = path.join(builtLocalDirectory, "typingsInstaller.js");
587-
compileFile(typingsInstallerFile, typingsInstallerSources, [builtLocalDirectory].concat(typingsInstallerSources), /*prefixes*/ [copyright], /*useBuiltCompiler*/ true, { outDir: builtLocalDirectory, noOutFile: false });
587+
compileFile(typingsInstallerFile, typingsInstallerSources, [builtLocalDirectory].concat(typingsInstallerSources), /*prefixes*/ [copyright], /*useBuiltCompiler*/ true, { types: ["node"], outDir: builtLocalDirectory, noOutFile: false, lib: "es6,scripthost" });
588588

589589
var watchGuardFile = path.join(builtLocalDirectory, "watchGuard.js");
590-
compileFile(watchGuardFile, watchGuardSources, [builtLocalDirectory].concat(watchGuardSources), /*prefixes*/ [copyright], /*useBuiltCompiler*/ true, { outDir: builtLocalDirectory, noOutFile: false });
590+
compileFile(watchGuardFile, watchGuardSources, [builtLocalDirectory].concat(watchGuardSources), /*prefixes*/ [copyright], /*useBuiltCompiler*/ true, { types: ["node"], outDir: builtLocalDirectory, noOutFile: false, lib: "es6" });
591591

592592
var serverFile = path.join(builtLocalDirectory, "tsserver.js");
593-
compileFile(serverFile, serverSources, [builtLocalDirectory, copyright, cancellationTokenFile, typingsInstallerFile, watchGuardFile].concat(serverSources).concat(servicesSources), /*prefixes*/ [copyright], /*useBuiltCompiler*/ true, { types: ["node"], preserveConstEnums: true });
593+
compileFile(serverFile, serverSources, [builtLocalDirectory, copyright, cancellationTokenFile, typingsInstallerFile, watchGuardFile].concat(serverSources).concat(servicesSources), /*prefixes*/ [copyright], /*useBuiltCompiler*/ true, { types: ["node"], preserveConstEnums: true, lib: "es6,scripthost" });
594594
var tsserverLibraryFile = path.join(builtLocalDirectory, "tsserverlibrary.js");
595595
var tsserverLibraryDefinitionFile = path.join(builtLocalDirectory, "tsserverlibrary.d.ts");
596596
compileFile(
@@ -714,7 +714,7 @@ compileFile(
714714
/*prereqs*/[builtLocalDirectory, tscFile].concat(libraryTargets).concat(servicesSources).concat(harnessSources),
715715
/*prefixes*/[],
716716
/*useBuiltCompiler:*/ true,
717-
/*opts*/ { inlineSourceMap: true, types: ["node", "mocha", "chai"] });
717+
/*opts*/ { inlineSourceMap: true, types: ["node", "mocha", "chai"], lib: "es6,scripthost" });
718718

719719
var internalTests = "internal/";
720720

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ with any additional questions or comments.
3939

4040
## Documentation
4141

42-
* [Quick tutorial](http://www.typescriptlang.org/Tutorial)
43-
* [Programming handbook](http://www.typescriptlang.org/Handbook)
42+
* [Quick tutorial](http://www.typescriptlang.org/docs/tutorial.html)
43+
* [Programming handbook](http://www.typescriptlang.org/docs/handbook/basic-types.html)
4444
* [Language specification](https://github.com/Microsoft/TypeScript/blob/master/doc/spec.md)
4545
* [Homepage](http://www.typescriptlang.org/)
4646

@@ -95,4 +95,4 @@ node built/local/tsc.js hello.ts
9595

9696
## Roadmap
9797

98-
For details on our planned features and future direction please refer to our [roadmap](https://github.com/Microsoft/TypeScript/wiki/Roadmap).
98+
For details on our planned features and future direction please refer to our [roadmap](https://github.com/Microsoft/TypeScript/wiki/Roadmap).

issue_template.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<!-- QUESTIONS: This is not a general support forum! Ask Qs at http://stackoverflow.com/questions/tagged/typescript -->
33
<!-- SUGGESTIONS: See https://github.com/Microsoft/TypeScript-wiki/blob/master/Writing-Good-Design-Proposals.md -->
44

5-
**TypeScript Version:** 2.1.1 / nightly (2.2.0-dev.201xxxxx)
5+
**TypeScript Version:** 2.2.1 / nightly (2.2.0-dev.201xxxxx)
66

77
**Code**
88

src/compiler/binder.ts

+2
Original file line numberDiff line numberDiff line change
@@ -2332,6 +2332,7 @@ namespace ts {
23322332

23332333
function bindThisPropertyAssignment(node: BinaryExpression) {
23342334
Debug.assert(isInJavaScriptFile(node));
2335+
const container = getThisContainer(node, /*includeArrowFunctions*/false);
23352336
switch (container.kind) {
23362337
case SyntaxKind.FunctionDeclaration:
23372338
case SyntaxKind.FunctionExpression:
@@ -2342,6 +2343,7 @@ namespace ts {
23422343
break;
23432344

23442345
case SyntaxKind.Constructor:
2346+
case SyntaxKind.PropertyDeclaration:
23452347
case SyntaxKind.MethodDeclaration:
23462348
case SyntaxKind.GetAccessor:
23472349
case SyntaxKind.SetAccessor:

src/compiler/checker.ts

+33-16
Original file line numberDiff line numberDiff line change
@@ -3973,7 +3973,7 @@ namespace ts {
39733973
return true;
39743974
}
39753975
if (type.flags & TypeFlags.TypeVariable) {
3976-
const constraint = getBaseConstraintOfType(<TypeVariable>type);
3976+
const constraint = getBaseConstraintOfType(type);
39773977
return constraint && isValidBaseType(constraint) && isMixinConstructorType(constraint);
39783978
}
39793979
return false;
@@ -4989,16 +4989,32 @@ namespace ts {
49894989
}
49904990

49914991
function getConstraintOfType(type: TypeVariable | UnionOrIntersectionType): Type {
4992-
return type.flags & TypeFlags.TypeParameter ? getConstraintOfTypeParameter(<TypeParameter>type) : getBaseConstraintOfType(type);
4992+
return type.flags & TypeFlags.TypeParameter ? getConstraintOfTypeParameter(<TypeParameter>type) :
4993+
type.flags & TypeFlags.IndexedAccess ? getConstraintOfIndexedAccess(<IndexedAccessType>type) :
4994+
getBaseConstraintOfType(type);
49934995
}
49944996

49954997
function getConstraintOfTypeParameter(typeParameter: TypeParameter): Type {
49964998
return hasNonCircularBaseConstraint(typeParameter) ? getConstraintFromTypeParameter(typeParameter) : undefined;
49974999
}
49985000

4999-
function getBaseConstraintOfType(type: TypeVariable | UnionOrIntersectionType): Type {
5000-
const constraint = getResolvedBaseConstraint(type);
5001-
return constraint !== noConstraintType && constraint !== circularConstraintType ? constraint : undefined;
5001+
function getConstraintOfIndexedAccess(type: IndexedAccessType) {
5002+
const baseObjectType = getBaseConstraintOfType(type.objectType);
5003+
const baseIndexType = getBaseConstraintOfType(type.indexType);
5004+
return baseObjectType || baseIndexType ? getIndexedAccessType(baseObjectType || type.objectType, baseIndexType || type.indexType) : undefined;
5005+
}
5006+
5007+
function getBaseConstraintOfType(type: Type): Type {
5008+
if (type.flags & (TypeFlags.TypeVariable | TypeFlags.UnionOrIntersection)) {
5009+
const constraint = getResolvedBaseConstraint(<TypeVariable | UnionOrIntersectionType>type);
5010+
if (constraint !== noConstraintType && constraint !== circularConstraintType) {
5011+
return constraint;
5012+
}
5013+
}
5014+
else if (type.flags & TypeFlags.Index) {
5015+
return stringType;
5016+
}
5017+
return undefined;
50025018
}
50035019

50045020
function hasNonCircularBaseConstraint(type: TypeVariable): boolean {
@@ -5096,7 +5112,7 @@ namespace ts {
50965112
* type itself. Note that the apparent type of a union type is the union type itself.
50975113
*/
50985114
function getApparentType(type: Type): Type {
5099-
const t = type.flags & TypeFlags.TypeVariable ? getBaseConstraintOfType(<TypeVariable>type) || emptyObjectType : type;
5115+
const t = type.flags & TypeFlags.TypeVariable ? getBaseConstraintOfType(type) || emptyObjectType : type;
51005116
return t.flags & TypeFlags.Intersection ? getApparentTypeOfIntersectionType(<IntersectionType>t) :
51015117
t.flags & TypeFlags.StringLike ? globalStringType :
51025118
t.flags & TypeFlags.NumberLike ? globalNumberType :
@@ -7921,7 +7937,7 @@ namespace ts {
79217937
}
79227938
// A type S is related to a type T[K] if S is related to A[K], where K is string-like and
79237939
// A is the apparent type of S.
7924-
const constraint = getBaseConstraintOfType(<IndexedAccessType>target);
7940+
const constraint = getBaseConstraintOfType(target);
79257941
if (constraint) {
79267942
if (result = isRelatedTo(source, constraint, reportErrors)) {
79277943
errorInfo = saveErrorInfo;
@@ -7961,7 +7977,7 @@ namespace ts {
79617977
else if (source.flags & TypeFlags.IndexedAccess) {
79627978
// A type S[K] is related to a type T if A[K] is related to T, where K is string-like and
79637979
// A is the apparent type of S.
7964-
const constraint = getBaseConstraintOfType(<IndexedAccessType>source);
7980+
const constraint = getConstraintOfType(<IndexedAccessType>source);
79657981
if (constraint) {
79667982
if (result = isRelatedTo(constraint, target, reportErrors)) {
79677983
errorInfo = saveErrorInfo;
@@ -9184,13 +9200,14 @@ namespace ts {
91849200
}
91859201
}
91869202

9187-
function createInferenceContext(signature: Signature, inferUnionTypes: boolean): InferenceContext {
9203+
function createInferenceContext(signature: Signature, inferUnionTypes: boolean, useAnyForNoInferences: boolean): InferenceContext {
91889204
const inferences = map(signature.typeParameters, createTypeInferencesObject);
91899205
return {
91909206
signature,
91919207
inferUnionTypes,
91929208
inferences,
91939209
inferredTypes: new Array(signature.typeParameters.length),
9210+
useAnyForNoInferences
91949211
};
91959212
}
91969213

@@ -9604,7 +9621,7 @@ namespace ts {
96049621
getInferenceMapper(context)));
96059622
}
96069623
else {
9607-
inferredType = emptyObjectType;
9624+
inferredType = context.useAnyForNoInferences ? anyType : emptyObjectType;
96089625
}
96099626

96109627
inferenceSucceeded = true;
@@ -9873,7 +9890,7 @@ namespace ts {
98739890
return strictNullChecks ? TypeFacts.ObjectStrictFacts : TypeFacts.ObjectFacts;
98749891
}
98759892
if (flags & TypeFlags.TypeVariable) {
9876-
return getTypeFacts(getBaseConstraintOfType(<TypeVariable>type) || emptyObjectType);
9893+
return getTypeFacts(getBaseConstraintOfType(type) || emptyObjectType);
98779894
}
98789895
if (flags & TypeFlags.UnionOrIntersection) {
98799896
return getTypeFactsOfTypes((<UnionOrIntersectionType>type).types);
@@ -10685,7 +10702,7 @@ namespace ts {
1068510702
return targetType;
1068610703
}
1068710704
if (type.flags & TypeFlags.TypeVariable) {
10688-
const constraint = getBaseConstraintOfType(<TypeVariable>type) || anyType;
10705+
const constraint = getBaseConstraintOfType(type) || anyType;
1068910706
if (isTypeSubtypeOf(targetType, constraint)) {
1069010707
return getIntersectionType([type, targetType]);
1069110708
}
@@ -13652,7 +13669,7 @@ namespace ts {
1365213669

1365313670
// Instantiate a generic signature in the context of a non-generic signature (section 3.8.5 in TypeScript spec)
1365413671
function instantiateSignatureInContextOf(signature: Signature, contextualSignature: Signature, contextualMapper: TypeMapper): Signature {
13655-
const context = createInferenceContext(signature, /*inferUnionTypes*/ true);
13672+
const context = createInferenceContext(signature, /*inferUnionTypes*/ true, /*useAnyForNoInferences*/ false);
1365613673
forEachMatchingParameterType(contextualSignature, signature, (source, target) => {
1365713674
// Type parameters from outer context referenced by source type are fixed by instantiation of the source type
1365813675
inferTypesWithContext(context, instantiateType(source, contextualMapper), target);
@@ -14353,7 +14370,7 @@ namespace ts {
1435314370
let candidate: Signature;
1435414371
let typeArgumentsAreValid: boolean;
1435514372
const inferenceContext = originalCandidate.typeParameters
14356-
? createInferenceContext(originalCandidate, /*inferUnionTypes*/ false)
14373+
? createInferenceContext(originalCandidate, /*inferUnionTypes*/ false, /*useAnyForNoInferences*/ isInJavaScriptFile(node))
1435714374
: undefined;
1435814375

1435914376
while (true) {
@@ -16233,7 +16250,7 @@ namespace ts {
1623316250
function isLiteralContextualType(contextualType: Type) {
1623416251
if (contextualType) {
1623516252
if (contextualType.flags & TypeFlags.TypeVariable) {
16236-
const constraint = getBaseConstraintOfType(<TypeVariable>contextualType) || emptyObjectType;
16253+
const constraint = getBaseConstraintOfType(contextualType) || emptyObjectType;
1623716254
// If the type parameter is constrained to the base primitive type we're checking for,
1623816255
// consider this a literal context. For example, given a type parameter 'T extends string',
1623916256
// this causes us to infer string literal types for T.
@@ -17123,7 +17140,7 @@ namespace ts {
1712317140
// Check if we're indexing with a numeric type and the object type is a generic
1712417141
// type with a constraint that has a numeric index signature.
1712517142
if (maybeTypeOfKind(objectType, TypeFlags.TypeVariable) && isTypeOfKind(indexType, TypeFlags.NumberLike)) {
17126-
const constraint = getBaseConstraintOfType(<TypeVariable | UnionOrIntersectionType>objectType);
17143+
const constraint = getBaseConstraintOfType(objectType);
1712717144
if (constraint && getIndexInfoOfType(constraint, IndexKind.Number)) {
1712817145
return type;
1712917146
}

src/compiler/types.ts

+1
Original file line numberDiff line numberDiff line change
@@ -3245,6 +3245,7 @@ namespace ts {
32453245
mapper?: TypeMapper; // Type mapper for this inference context
32463246
failedTypeParameterIndex?: number; // Index of type parameter for which inference failed
32473247
// It is optional because in contextual signature instantiation, nothing fails
3248+
useAnyForNoInferences?: boolean; // Use any instead of {} for no inferences
32483249
}
32493250

32503251
/* @internal */

src/harness/fourslash.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -2251,22 +2251,23 @@ namespace FourSlash {
22512251

22522252
if (expected === undefined) {
22532253
if (actual) {
2254-
this.raiseError(name + " failed - expected no template but got {newText: \"" + actual.newText + "\" caretOffset: " + actual.caretOffset + "}");
2254+
this.raiseError(`${name} failed - expected no template but got {newText: "${actual.newText}", caretOffset: ${actual.caretOffset}}`);
22552255
}
22562256

22572257
return;
22582258
}
22592259
else {
22602260
if (actual === undefined) {
2261-
this.raiseError(name + " failed - expected the template {newText: \"" + actual.newText + "\" caretOffset: " + actual.caretOffset + "} but got nothing instead");
2261+
this.raiseError(`${name} failed - expected the template {newText: "${expected.newText}", caretOffset: "${expected.caretOffset}"} but got nothing instead`);
2262+
22622263
}
22632264

22642265
if (actual.newText !== expected.newText) {
2265-
this.raiseError(name + " failed - expected insertion:\n" + this.clarifyNewlines(expected.newText) + "\nactual insertion:\n" + this.clarifyNewlines(actual.newText));
2266+
this.raiseError(`${name} failed - expected insertion:\n"${this.clarifyNewlines(expected.newText)}"\nactual insertion:\n"${this.clarifyNewlines(actual.newText)}"`);
22662267
}
22672268

22682269
if (actual.caretOffset !== expected.caretOffset) {
2269-
this.raiseError(name + " failed - expected caretOffset: " + expected.caretOffset + ",\nactual caretOffset:" + actual.caretOffset);
2270+
this.raiseError(`${name} failed - expected caretOffset: ${expected.caretOffset}\nactual caretOffset:${actual.caretOffset}`);
22702271
}
22712272
}
22722273
}

src/harness/tsconfig.json

+4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
"declaration": false,
77
"types": [
88
"node", "mocha", "chai"
9+
],
10+
"lib": [
11+
"es6",
12+
"scripthost"
913
]
1014
},
1115
"files": [

0 commit comments

Comments
 (0)