Skip to content

Commit 3a67174

Browse files
committed
Merge branch 'master' into streamlineDestructuring
2 parents a0da47f + a7d97c0 commit 3a67174

27 files changed

+894
-421
lines changed

Gulpfile.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ for (const i in libraryTargets) {
177177
const configureNightlyJs = path.join(scriptsDirectory, "configureNightly.js");
178178
const configureNightlyTs = path.join(scriptsDirectory, "configureNightly.ts");
179179
const packageJson = "package.json";
180-
const programTs = path.join(compilerDirectory, "program.ts");
180+
const versionFile = path.join(compilerDirectory, "core.ts");
181181

182182
function needsUpdate(source: string | string[], dest: string | string[]): boolean {
183183
if (typeof source === "string" && typeof dest === "string") {
@@ -285,7 +285,7 @@ gulp.task(configureNightlyJs, false, [], () => {
285285

286286
// Nightly management tasks
287287
gulp.task("configure-nightly", "Runs scripts/configureNightly.ts to prepare a build for nightly publishing", [configureNightlyJs], (done) => {
288-
exec(host, [configureNightlyJs, packageJson, programTs], done, done);
288+
exec(host, [configureNightlyJs, packageJson, versionFile], done, done);
289289
});
290290
gulp.task("publish-nightly", "Runs `npm publish --tag next` to create a new nightly build on npm", ["LKG"], () => {
291291
return runSequence("clean", "useDebugMode", "runtests", (done) => {

Jakefile.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,7 @@ task("generate-diagnostics", [diagnosticInfoMapTs]);
593593
var configureNightlyJs = path.join(scriptsDirectory, "configureNightly.js");
594594
var configureNightlyTs = path.join(scriptsDirectory, "configureNightly.ts");
595595
var packageJson = "package.json";
596-
var programTs = path.join(compilerDirectory, "program.ts");
596+
var versionFile = path.join(compilerDirectory, "core.ts");
597597

598598
file(configureNightlyTs);
599599

@@ -609,7 +609,7 @@ task("setDebugMode", function () {
609609
});
610610

611611
task("configure-nightly", [configureNightlyJs], function () {
612-
var cmd = host + " " + configureNightlyJs + " " + packageJson + " " + programTs;
612+
var cmd = host + " " + configureNightlyJs + " " + packageJson + " " + versionFile;
613613
console.log(cmd);
614614
exec(cmd);
615615
}, { async: true });

src/compiler/checker.ts

Lines changed: 49 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4550,6 +4550,10 @@ namespace ts {
45504550
unknownType);
45514551
}
45524552

4553+
function getErasedTemplateTypeFromMappedType(type: MappedType) {
4554+
return instantiateType(getTemplateTypeFromMappedType(type), createUnaryTypeMapper(getTypeParameterFromMappedType(type), anyType));
4555+
}
4556+
45534557
function isGenericMappedType(type: Type) {
45544558
if (getObjectFlags(type) & ObjectFlags.Mapped) {
45554559
const constraintType = getConstraintTypeFromMappedType(<MappedType>type);
@@ -7190,29 +7194,18 @@ namespace ts {
71907194
return result;
71917195
}
71927196
}
7193-
if (isGenericMappedType(target)) {
7194-
// A type [P in S]: X is related to a type [P in T]: Y if T is related to S and X is related to Y.
7195-
if (isGenericMappedType(source)) {
7196-
if ((result = isRelatedTo(getConstraintTypeFromMappedType(<MappedType>target), getConstraintTypeFromMappedType(<MappedType>source), reportErrors)) &&
7197-
(result = isRelatedTo(getTemplateTypeFromMappedType(<MappedType>source), getTemplateTypeFromMappedType(<MappedType>target), reportErrors))) {
7198-
return result;
7199-
}
7200-
}
7201-
}
7202-
else {
7203-
// Even if relationship doesn't hold for unions, intersections, or generic type references,
7204-
// it may hold in a structural comparison.
7205-
const apparentSource = getApparentType(source);
7206-
// In a check of the form X = A & B, we will have previously checked if A relates to X or B relates
7207-
// to X. Failing both of those we want to check if the aggregation of A and B's members structurally
7208-
// relates to X. Thus, we include intersection types on the source side here.
7209-
if (apparentSource.flags & (TypeFlags.Object | TypeFlags.Intersection) && target.flags & TypeFlags.Object) {
7210-
// Report structural errors only if we haven't reported any errors yet
7211-
const reportStructuralErrors = reportErrors && errorInfo === saveErrorInfo && !(source.flags & TypeFlags.Primitive);
7212-
if (result = objectTypeRelatedTo(apparentSource, source, target, reportStructuralErrors)) {
7213-
errorInfo = saveErrorInfo;
7214-
return result;
7215-
}
7197+
// Even if relationship doesn't hold for unions, intersections, or generic type references,
7198+
// it may hold in a structural comparison.
7199+
const apparentSource = getApparentType(source);
7200+
// In a check of the form X = A & B, we will have previously checked if A relates to X or B relates
7201+
// to X. Failing both of those we want to check if the aggregation of A and B's members structurally
7202+
// relates to X. Thus, we include intersection types on the source side here.
7203+
if (apparentSource.flags & (TypeFlags.Object | TypeFlags.Intersection) && target.flags & TypeFlags.Object) {
7204+
// Report structural errors only if we haven't reported any errors yet
7205+
const reportStructuralErrors = reportErrors && errorInfo === saveErrorInfo && !(source.flags & TypeFlags.Primitive);
7206+
if (result = objectTypeRelatedTo(apparentSource, source, target, reportStructuralErrors)) {
7207+
errorInfo = saveErrorInfo;
7208+
return result;
72167209
}
72177210
}
72187211
}
@@ -7441,6 +7434,9 @@ namespace ts {
74417434
if (expandingFlags === 3) {
74427435
result = Ternary.Maybe;
74437436
}
7437+
else if (isGenericMappedType(source) || isGenericMappedType(target)) {
7438+
result = mappedTypeRelatedTo(source, target, reportErrors);
7439+
}
74447440
else {
74457441
result = propertiesRelatedTo(source, target, reportErrors);
74467442
if (result) {
@@ -7472,6 +7468,30 @@ namespace ts {
74727468
return result;
74737469
}
74747470

7471+
// A type [P in S]: X is related to a type [P in T]: Y if T is related to S and X is related to Y.
7472+
function mappedTypeRelatedTo(source: Type, target: Type, reportErrors: boolean): Ternary {
7473+
if (isGenericMappedType(source) && isGenericMappedType(target)) {
7474+
let result: Ternary;
7475+
if (relation === identityRelation) {
7476+
const readonlyMatches = !(<MappedType>source).declaration.readonlyToken === !(<MappedType>target).declaration.readonlyToken;
7477+
const optionalMatches = !(<MappedType>source).declaration.questionToken === !(<MappedType>target).declaration.questionToken;
7478+
if (readonlyMatches && optionalMatches) {
7479+
if (result = isRelatedTo(getConstraintTypeFromMappedType(<MappedType>target), getConstraintTypeFromMappedType(<MappedType>source), reportErrors)) {
7480+
return result & isRelatedTo(getErasedTemplateTypeFromMappedType(<MappedType>source), getErasedTemplateTypeFromMappedType(<MappedType>target), reportErrors);
7481+
}
7482+
}
7483+
}
7484+
else {
7485+
if (relation === comparableRelation || !(<MappedType>source).declaration.questionToken || (<MappedType>target).declaration.questionToken) {
7486+
if (result = isRelatedTo(getConstraintTypeFromMappedType(<MappedType>target), getConstraintTypeFromMappedType(<MappedType>source), reportErrors)) {
7487+
return result & isRelatedTo(getTemplateTypeFromMappedType(<MappedType>source), getTemplateTypeFromMappedType(<MappedType>target), reportErrors);
7488+
}
7489+
}
7490+
}
7491+
}
7492+
return Ternary.False;
7493+
}
7494+
74757495
function propertiesRelatedTo(source: Type, target: Type, reportErrors: boolean): Ternary {
74767496
if (relation === identityRelation) {
74777497
return propertiesIdenticalTo(source, target);
@@ -9721,20 +9741,20 @@ namespace ts {
97219741
}
97229742

97239743
if (targetType) {
9724-
return getNarrowedType(type, targetType, assumeTrue);
9744+
return getNarrowedType(type, targetType, assumeTrue, isTypeInstanceOf);
97259745
}
97269746

97279747
return type;
97289748
}
97299749

9730-
function getNarrowedType(type: Type, candidate: Type, assumeTrue: boolean) {
9750+
function getNarrowedType(type: Type, candidate: Type, assumeTrue: boolean, isRelated: (source: Type, target: Type) => boolean) {
97319751
if (!assumeTrue) {
9732-
return filterType(type, t => !isTypeInstanceOf(t, candidate));
9752+
return filterType(type, t => !isRelated(t, candidate));
97339753
}
97349754
// If the current type is a union type, remove all constituents that couldn't be instances of
97359755
// the candidate type. If one or more constituents remain, return a union of those.
97369756
if (type.flags & TypeFlags.Union) {
9737-
const assignableType = filterType(type, t => isTypeInstanceOf(t, candidate));
9757+
const assignableType = filterType(type, t => isRelated(t, candidate));
97389758
if (!(assignableType.flags & TypeFlags.Never)) {
97399759
return assignableType;
97409760
}
@@ -9770,7 +9790,7 @@ namespace ts {
97709790
const predicateArgument = callExpression.arguments[predicate.parameterIndex];
97719791
if (predicateArgument) {
97729792
if (isMatchingReference(reference, predicateArgument)) {
9773-
return getNarrowedType(type, predicate.type, assumeTrue);
9793+
return getNarrowedType(type, predicate.type, assumeTrue, isTypeSubtypeOf);
97749794
}
97759795
if (containsMatchingReference(reference, predicateArgument)) {
97769796
return declaredType;
@@ -9783,7 +9803,7 @@ namespace ts {
97839803
const accessExpression = invokedExpression as ElementAccessExpression | PropertyAccessExpression;
97849804
const possibleReference = skipParentheses(accessExpression.expression);
97859805
if (isMatchingReference(reference, possibleReference)) {
9786-
return getNarrowedType(type, predicate.type, assumeTrue);
9806+
return getNarrowedType(type, predicate.type, assumeTrue, isTypeSubtypeOf);
97879807
}
97889808
if (containsMatchingReference(reference, possibleReference)) {
97899809
return declaredType;

src/compiler/core.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
/// <reference path="types.ts"/>
22
/// <reference path="performance.ts" />
33

4+
namespace ts {
5+
/** The version of the TypeScript compiler release */
6+
export const version = "2.2.0";
7+
}
8+
49
/* @internal */
510
namespace ts {
611
/**

src/compiler/program.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@
33
/// <reference path="core.ts" />
44

55
namespace ts {
6-
/** The version of the TypeScript compiler release */
7-
8-
export const version = "2.2.0";
9-
106
const emptyArray: any[] = [];
117

128
export function findConfigFile(searchPath: string, fileExists: (fileName: string) => boolean, configName = "tsconfig.json"): string {

src/compiler/transformers/generators.ts

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -946,7 +946,7 @@ namespace ts {
946946
* @param node The node to visit.
947947
*/
948948
function visitArrayLiteralExpression(node: ArrayLiteralExpression) {
949-
return visitElements(node.elements, node.multiLine);
949+
return visitElements(node.elements, /*leadingElement*/ undefined, /*location*/ undefined, node.multiLine);
950950
}
951951

952952
/**
@@ -956,7 +956,7 @@ namespace ts {
956956
* @param elements The elements to visit.
957957
* @param multiLine Whether array literals created should be emitted on multiple lines.
958958
*/
959-
function visitElements(elements: NodeArray<Expression>, _multiLine?: boolean) {
959+
function visitElements(elements: NodeArray<Expression>, leadingElement?: Expression, location?: TextRange, multiLine?: boolean) {
960960
// [source]
961961
// ar = [1, yield, 2];
962962
//
@@ -971,18 +971,22 @@ namespace ts {
971971
const temp = declareLocal();
972972
let hasAssignedTemp = false;
973973
if (numInitialElements > 0) {
974+
const initialElements = visitNodes(elements, visitor, isExpression, 0, numInitialElements);
974975
emitAssignment(temp,
975976
createArrayLiteral(
976-
visitNodes(elements, visitor, isExpression, 0, numInitialElements)
977+
leadingElement
978+
? [leadingElement, ...initialElements]
979+
: initialElements
977980
)
978981
);
982+
leadingElement = undefined;
979983
hasAssignedTemp = true;
980984
}
981985

982986
const expressions = reduceLeft(elements, reduceElement, <Expression[]>[], numInitialElements);
983987
return hasAssignedTemp
984-
? createArrayConcat(temp, [createArrayLiteral(expressions)])
985-
: createArrayLiteral(expressions);
988+
? createArrayConcat(temp, [createArrayLiteral(expressions, /*location*/ undefined, multiLine)])
989+
: createArrayLiteral(leadingElement ? [leadingElement, ...expressions] : expressions, location, multiLine);
986990

987991
function reduceElement(expressions: Expression[], element: Expression) {
988992
if (containsYield(element) && expressions.length > 0) {
@@ -991,11 +995,16 @@ namespace ts {
991995
hasAssignedTemp
992996
? createArrayConcat(
993997
temp,
994-
[createArrayLiteral(expressions)]
998+
[createArrayLiteral(expressions, /*location*/ undefined, multiLine)]
999+
)
1000+
: createArrayLiteral(
1001+
leadingElement ? [leadingElement, ...expressions] : expressions,
1002+
/*location*/ undefined,
1003+
multiLine
9951004
)
996-
: createArrayLiteral(expressions)
9971005
);
9981006
hasAssignedTemp = true;
1007+
leadingElement = undefined;
9991008
expressions = [];
10001009
}
10011010

@@ -1131,7 +1140,10 @@ namespace ts {
11311140
createFunctionApply(
11321141
cacheExpression(visitNode(target, visitor, isExpression)),
11331142
thisArg,
1134-
visitElements(node.arguments)
1143+
visitElements(
1144+
node.arguments,
1145+
/*leadingElement*/ createVoidZero()
1146+
)
11351147
),
11361148
/*typeArguments*/ undefined,
11371149
[],

src/lib/es5.d.ts

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ interface ObjectConstructor {
180180
* Prevents the modification of existing property attributes and values, and prevents the addition of new properties.
181181
* @param o Object on which to lock the attributes.
182182
*/
183-
freeze<T>(o: T): T;
183+
freeze<T>(o: T): Readonly<T>;
184184

185185
/**
186186
* Prevents the addition of new properties to an object.
@@ -1343,6 +1343,34 @@ interface ArrayLike<T> {
13431343
readonly [n: number]: T;
13441344
}
13451345

1346+
/**
1347+
* Make all properties in T optional
1348+
*/
1349+
type Partial<T> = {
1350+
[P in keyof T]?: T[P];
1351+
};
1352+
1353+
/**
1354+
* Make all properties in T readonly
1355+
*/
1356+
type Readonly<T> = {
1357+
readonly [P in keyof T]: T[P];
1358+
};
1359+
1360+
/**
1361+
* From T pick a set of properties K
1362+
*/
1363+
type Pick<T, K extends keyof T> = {
1364+
[P in K]: T[P];
1365+
}
1366+
1367+
/**
1368+
* Construct a type with a set of properties K of type T
1369+
*/
1370+
type Record<K extends string | number, T> = {
1371+
[P in K]: T;
1372+
}
1373+
13461374
/**
13471375
* Represents a raw buffer of binary data, which is used to store data for the
13481376
* different typed arrays. ArrayBuffers cannot be read from or written to directly,

src/server/protocol.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2106,6 +2106,11 @@ namespace ts.server.protocol {
21062106
* true if install request succeeded, otherwise - false
21072107
*/
21082108
installSuccess: boolean;
2109+
2110+
/**
2111+
* version of typings installer
2112+
*/
2113+
typingsInstallerVersion: string;
21092114
}
21102115

21112116
export interface NavBarResponse extends Response {

src/server/server.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,8 @@ namespace ts.server {
300300
telemetryEventName: "typingsInstalled",
301301
payload: {
302302
installedPackages: response.packagesToInstall.join(","),
303-
installSuccess: response.installSuccess
303+
installSuccess: response.installSuccess,
304+
typingsInstallerVersion: response.typingsInstallerVersion
304305
}
305306
};
306307
const eventName: protocol.TelemetryEventName = "telemetry";

src/server/types.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ declare namespace ts.server {
6969
readonly packagesToInstall: ReadonlyArray<string>;
7070
readonly kind: EventInstall;
7171
readonly installSuccess: boolean;
72+
readonly typingsInstallerVersion: string;
7273
}
7374

7475
export interface InstallTypingHost extends JsTyping.TypingResolutionHost {

0 commit comments

Comments
 (0)