Skip to content

Commit 77613eb

Browse files
authored
Merge pull request microsoft#12440 from Microsoft/mergeMaster11222016
Merge master into release-2.1
2 parents 6389a0d + 7e8af62 commit 77613eb

File tree

153 files changed

+1164
-888
lines changed

Some content is hidden

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

153 files changed

+1164
-888
lines changed

Jakefile.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -930,7 +930,7 @@ function runConsoleTests(defaultReporter, runInParallel) {
930930
}
931931

932932
if (tests && tests.toLocaleLowerCase() === "rwc") {
933-
testTimeout = 400000;
933+
testTimeout = 800000;
934934
}
935935

936936
colors = process.env.colors || process.env.color;
@@ -1086,12 +1086,10 @@ task("tests-debug", ["setDebugMode", "tests"]);
10861086
// Makes the test results the new baseline
10871087
desc("Makes the most recent test results the new baseline, overwriting the old baseline");
10881088
task("baseline-accept", function () {
1089-
acceptBaseline("");
1089+
acceptBaseline(localBaseline, refBaseline);
10901090
});
10911091

1092-
function acceptBaseline(containerFolder) {
1093-
var sourceFolder = path.join(localBaseline, containerFolder);
1094-
var targetFolder = path.join(refBaseline, containerFolder);
1092+
function acceptBaseline(sourceFolder, targetFolder) {
10951093
console.log('Accept baselines from ' + sourceFolder + ' to ' + targetFolder);
10961094
var files = fs.readdirSync(sourceFolder);
10971095
var deleteEnding = '.delete';
@@ -1115,12 +1113,12 @@ function acceptBaseline(containerFolder) {
11151113

11161114
desc("Makes the most recent rwc test results the new baseline, overwriting the old baseline");
11171115
task("baseline-accept-rwc", function () {
1118-
acceptBaseline("rwc");
1116+
acceptBaseline(localRwcBaseline, refRwcBaseline);
11191117
});
11201118

11211119
desc("Makes the most recent test262 test results the new baseline, overwriting the old baseline");
11221120
task("baseline-accept-test262", function () {
1123-
acceptBaseline("test262");
1121+
acceptBaseline(localTest262Baseline, refTest262Baseline);
11241122
});
11251123

11261124

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,7 @@
7575
"through2": "latest",
7676
"travis-fold": "latest",
7777
"ts-node": "latest",
78-
"tsd": "latest",
79-
"tslint": "4.0.0-dev.0",
78+
"tslint": "4.0.0-dev.2",
8079
"typescript": "^2.1"
8180
},
8281
"scripts": {

scripts/parallel-lint.js

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,29 @@
1-
var Linter = require("tslint");
1+
var tslint = require("tslint");
22
var fs = require("fs");
33

44
function getLinterOptions() {
55
return {
6-
configuration: require("../tslint.json"),
76
formatter: "prose",
87
formattersDirectory: undefined,
98
rulesDirectory: "built/local/tslint"
109
};
1110
}
11+
function getLinterConfiguration() {
12+
return require("../tslint.json");
13+
}
1214

13-
function lintFileContents(options, path, contents) {
14-
var ll = new Linter(path, contents, options);
15-
return ll.lint();
15+
function lintFileContents(options, configuration, path, contents) {
16+
var ll = new tslint.Linter(options);
17+
ll.lint(path, contents, configuration);
18+
return ll.getResult();
1619
}
1720

18-
function lintFileAsync(options, path, cb) {
21+
function lintFileAsync(options, configuration, path, cb) {
1922
fs.readFile(path, "utf8", function (err, contents) {
2023
if (err) {
2124
return cb(err);
2225
}
23-
var result = lintFileContents(options, path, contents);
26+
var result = lintFileContents(options, configuration, path, contents);
2427
cb(undefined, result);
2528
});
2629
}
@@ -30,7 +33,8 @@ process.on("message", function (data) {
3033
case "file":
3134
var target = data.name;
3235
var lintOptions = getLinterOptions();
33-
lintFileAsync(lintOptions, target, function (err, result) {
36+
var lintConfiguration = getLinterConfiguration();
37+
lintFileAsync(lintOptions, lintConfiguration, target, function (err, result) {
3438
if (err) {
3539
process.send({ kind: "error", error: err.toString() });
3640
return;

scripts/tslint/booleanTriviaRule.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as Lint from "tslint/lib/lint";
1+
import * as Lint from "tslint/lib";
22
import * as ts from "typescript";
33

44
export class Rule extends Lint.Rules.AbstractRule {

scripts/tslint/nextLineRule.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as Lint from "tslint/lib/lint";
1+
import * as Lint from "tslint/lib";
22
import * as ts from "typescript";
33

44
const OPTION_CATCH = "check-catch";

scripts/tslint/noInOperatorRule.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as Lint from "tslint/lib/lint";
1+
import * as Lint from "tslint/lib";
22
import * as ts from "typescript";
33

44

scripts/tslint/noIncrementDecrementRule.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as Lint from "tslint/lib/lint";
1+
import * as Lint from "tslint/lib";
22
import * as ts from "typescript";
33

44

scripts/tslint/noTypeAssertionWhitespaceRule.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as Lint from "tslint/lib/lint";
1+
import * as Lint from "tslint/lib";
22
import * as ts from "typescript";
33

44

scripts/tslint/objectLiteralSurroundingSpaceRule.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as Lint from "tslint/lib/lint";
1+
import * as Lint from "tslint/lib";
22
import * as ts from "typescript";
33

44

scripts/tslint/preferConstRule.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as Lint from "tslint/lib/lint";
1+
import * as Lint from "tslint/lib";
22
import * as ts from "typescript";
33

44
export class Rule extends Lint.Rules.AbstractRule {

scripts/tslint/typeOperatorSpacingRule.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as Lint from "tslint/lib/lint";
1+
import * as Lint from "tslint/lib";
22
import * as ts from "typescript";
33

44

src/compiler/binder.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -599,8 +599,8 @@ namespace ts {
599599
// Binding of JsDocComment should be done before the current block scope container changes.
600600
// because the scope of JsDocComment should not be affected by whether the current node is a
601601
// container or not.
602-
if (isInJavaScriptFile(node) && node.jsDocComments) {
603-
forEach(node.jsDocComments, bind);
602+
if (isInJavaScriptFile(node) && node.jsDoc) {
603+
forEach(node.jsDoc, bind);
604604
}
605605
if (checkUnreachable(node)) {
606606
bindEachChild(node);

src/compiler/checker.ts

Lines changed: 30 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,6 @@ namespace ts {
142142
const voidType = createIntrinsicType(TypeFlags.Void, "void");
143143
const neverType = createIntrinsicType(TypeFlags.Never, "never");
144144
const silentNeverType = createIntrinsicType(TypeFlags.Never, "never");
145-
const stringOrNumberType = getUnionType([stringType, numberType]);
146145

147146
const emptyObjectType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined);
148147

@@ -3156,38 +3155,10 @@ namespace ts {
31563155
}
31573156

31583157
function getTypeForVariableLikeDeclarationFromJSDocComment(declaration: VariableLikeDeclaration) {
3159-
const jsDocType = getJSDocTypeForVariableLikeDeclarationFromJSDocComment(declaration);
3160-
if (jsDocType) {
3161-
return getTypeFromTypeNode(jsDocType);
3158+
const jsdocType = getJSDocType(declaration);
3159+
if (jsdocType) {
3160+
return getTypeFromTypeNode(jsdocType);
31623161
}
3163-
}
3164-
3165-
function getJSDocTypeForVariableLikeDeclarationFromJSDocComment(declaration: VariableLikeDeclaration): JSDocType {
3166-
// First, see if this node has an @type annotation on it directly.
3167-
const typeTag = getJSDocTypeTag(declaration);
3168-
if (typeTag && typeTag.typeExpression) {
3169-
return typeTag.typeExpression.type;
3170-
}
3171-
3172-
if (declaration.kind === SyntaxKind.VariableDeclaration &&
3173-
declaration.parent.kind === SyntaxKind.VariableDeclarationList &&
3174-
declaration.parent.parent.kind === SyntaxKind.VariableStatement) {
3175-
3176-
// @type annotation might have been on the variable statement, try that instead.
3177-
const annotation = getJSDocTypeTag(declaration.parent.parent);
3178-
if (annotation && annotation.typeExpression) {
3179-
return annotation.typeExpression.type;
3180-
}
3181-
}
3182-
else if (declaration.kind === SyntaxKind.Parameter) {
3183-
// If it's a parameter, see if the parent has a jsdoc comment with an @param
3184-
// annotation.
3185-
const paramTag = getCorrespondingJSDocParameterTag(<ParameterDeclaration>declaration);
3186-
if (paramTag && paramTag.typeExpression) {
3187-
return paramTag.typeExpression.type;
3188-
}
3189-
}
3190-
31913162
return undefined;
31923163
}
31933164

@@ -3217,9 +3188,11 @@ namespace ts {
32173188
}
32183189
}
32193190

3220-
// A variable declared in a for..in statement is always of type string
3191+
// A variable declared in a for..in statement is of type string, or of type keyof T when the
3192+
// right hand expression is of a type parameter type.
32213193
if (declaration.parent.parent.kind === SyntaxKind.ForInStatement) {
3222-
return stringType;
3194+
const indexType = getIndexType(checkNonNullExpression((<ForInStatement>declaration.parent.parent).expression));
3195+
return indexType.flags & TypeFlags.Index ? indexType : stringType;
32233196
}
32243197

32253198
if (declaration.parent.parent.kind === SyntaxKind.ForOfStatement) {
@@ -3455,9 +3428,9 @@ namespace ts {
34553428
declaration.kind === SyntaxKind.PropertyAccessExpression && declaration.parent.kind === SyntaxKind.BinaryExpression) {
34563429
// Use JS Doc type if present on parent expression statement
34573430
if (declaration.flags & NodeFlags.JavaScriptFile) {
3458-
const typeTag = getJSDocTypeTag(declaration.parent);
3459-
if (typeTag && typeTag.typeExpression) {
3460-
return links.type = getTypeFromTypeNode(typeTag.typeExpression.type);
3431+
const jsdocType = getJSDocType(declaration.parent);
3432+
if (jsdocType) {
3433+
return links.type = getTypeFromTypeNode(jsdocType);
34613434
}
34623435
}
34633436
const declaredTypes = map(symbol.declarations,
@@ -4688,7 +4661,6 @@ namespace ts {
46884661
t.flags & TypeFlags.NumberLike ? globalNumberType :
46894662
t.flags & TypeFlags.BooleanLike ? globalBooleanType :
46904663
t.flags & TypeFlags.ESSymbol ? getGlobalESSymbolType() :
4691-
t.flags & TypeFlags.Index ? stringOrNumberType :
46924664
t;
46934665
}
46944666

@@ -4901,15 +4873,16 @@ namespace ts {
49014873
if (node.type && node.type.kind === SyntaxKind.JSDocOptionalType) {
49024874
return true;
49034875
}
4876+
const paramTags = getJSDocParameterTags(node);
4877+
if (paramTags) {
4878+
for (const paramTag of paramTags) {
4879+
if (paramTag.isBracketed) {
4880+
return true;
4881+
}
49044882

4905-
const paramTag = getCorrespondingJSDocParameterTag(node);
4906-
if (paramTag) {
4907-
if (paramTag.isBracketed) {
4908-
return true;
4909-
}
4910-
4911-
if (paramTag.typeExpression) {
4912-
return paramTag.typeExpression.type.kind === SyntaxKind.JSDocOptionalType;
4883+
if (paramTag.typeExpression) {
4884+
return paramTag.typeExpression.type.kind === SyntaxKind.JSDocOptionalType;
4885+
}
49134886
}
49144887
}
49154888
}
@@ -5920,8 +5893,7 @@ namespace ts {
59205893
function getIndexType(type: Type): Type {
59215894
return type.flags & TypeFlags.TypeParameter ? getIndexTypeForTypeParameter(<TypeParameter>type) :
59225895
getObjectFlags(type) & ObjectFlags.Mapped ? getConstraintTypeFromMappedType(<MappedType>type) :
5923-
type.flags & TypeFlags.Any || getIndexInfoOfType(type, IndexKind.String) ? stringOrNumberType :
5924-
getIndexInfoOfType(type, IndexKind.Number) ? getUnionType([numberType, getLiteralTypeFromPropertyNames(type)]) :
5896+
type.flags & TypeFlags.Any || getIndexInfoOfType(type, IndexKind.String) ? stringType :
59255897
getLiteralTypeFromPropertyNames(type);
59265898
}
59275899

@@ -6039,19 +6011,19 @@ namespace ts {
60396011
const id = objectType.id + "," + indexType.id;
60406012
return indexedAccessTypes[id] || (indexedAccessTypes[id] = createIndexedAccessType(objectType, indexType));
60416013
}
6042-
const apparentType = getApparentType(objectType);
6014+
const apparentObjectType = getApparentType(objectType);
60436015
if (indexType.flags & TypeFlags.Union && !(indexType.flags & TypeFlags.Primitive)) {
60446016
const propTypes: Type[] = [];
60456017
for (const t of (<UnionType>indexType).types) {
6046-
const propType = getPropertyTypeForIndexType(apparentType, t, accessNode, /*cacheSymbol*/ false);
6018+
const propType = getPropertyTypeForIndexType(apparentObjectType, t, accessNode, /*cacheSymbol*/ false);
60476019
if (propType === unknownType) {
60486020
return unknownType;
60496021
}
60506022
propTypes.push(propType);
60516023
}
60526024
return getUnionType(propTypes);
60536025
}
6054-
return getPropertyTypeForIndexType(apparentType, indexType, accessNode, /*cacheSymbol*/ true);
6026+
return getPropertyTypeForIndexType(apparentObjectType, indexType, accessNode, /*cacheSymbol*/ true);
60556027
}
60566028

60576029
function getTypeFromIndexedAccessTypeNode(node: IndexedAccessTypeNode) {
@@ -7123,13 +7095,6 @@ namespace ts {
71237095

71247096
if (isSimpleTypeRelatedTo(source, target, relation, reportErrors ? reportError : undefined)) return Ternary.True;
71257097

7126-
if (source.flags & TypeFlags.Index) {
7127-
// A keyof T is related to a union type containing both string and number
7128-
if (maybeTypeOfKind(target, TypeFlags.String) && maybeTypeOfKind(target, TypeFlags.Number)) {
7129-
return Ternary.True;
7130-
}
7131-
}
7132-
71337098
if (getObjectFlags(source) & ObjectFlags.ObjectLiteral && source.flags & TypeFlags.FreshLiteral) {
71347099
if (hasExcessProperties(<FreshObjectLiteralType>source, target, reportErrors)) {
71357100
if (reportErrors) {
@@ -10392,9 +10357,9 @@ namespace ts {
1039210357
}
1039310358

1039410359
function getTypeForThisExpressionFromJSDoc(node: Node) {
10395-
const typeTag = getJSDocTypeTag(node);
10396-
if (typeTag && typeTag.typeExpression && typeTag.typeExpression.type && typeTag.typeExpression.type.kind === SyntaxKind.JSDocFunctionType) {
10397-
const jsDocFunctionType = <JSDocFunctionType>typeTag.typeExpression.type;
10360+
const jsdocType = getJSDocType(node);
10361+
if (jsdocType && jsdocType.kind === SyntaxKind.JSDocFunctionType) {
10362+
const jsDocFunctionType = <JSDocFunctionType>jsdocType;
1039810363
if (jsDocFunctionType.parameters.length > 0 && jsDocFunctionType.parameters[0].type.kind === SyntaxKind.JSDocThisType) {
1039910364
return getTypeFromTypeNode(jsDocFunctionType.parameters[0].type);
1040010365
}
@@ -13628,7 +13593,7 @@ namespace ts {
1362813593
// the destructured type into the contained binding elements.
1362913594
function assignBindingElementTypes(node: VariableLikeDeclaration) {
1363013595
if (isBindingPattern(node.name)) {
13631-
for (const element of (<BindingPattern>node.name).elements) {
13596+
for (const element of node.name.elements) {
1363213597
if (!isOmittedExpression(element)) {
1363313598
if (element.name.kind === SyntaxKind.Identifier) {
1363413599
getSymbolLinks(getSymbolOfNode(element)).type = getTypeForBindingElement(element);
@@ -14256,7 +14221,7 @@ namespace ts {
1425614221
if (!isTypeAnyOrAllConstituentTypesHaveKind(leftType, TypeFlags.StringLike | TypeFlags.NumberLike | TypeFlags.ESSymbol)) {
1425714222
error(left, Diagnostics.The_left_hand_side_of_an_in_expression_must_be_of_type_any_string_number_or_symbol);
1425814223
}
14259-
if (!isTypeAnyOrAllConstituentTypesHaveKind(rightType, TypeFlags.Object | TypeFlags.TypeParameter)) {
14224+
if (!isTypeAnyOrAllConstituentTypesHaveKind(rightType, TypeFlags.Object | TypeFlags.TypeParameter | TypeFlags.IndexedAccess)) {
1426014225
error(right, Diagnostics.The_right_hand_side_of_an_in_expression_must_be_of_type_any_an_object_type_or_a_type_parameter);
1426114226
}
1426214227
return booleanType;
@@ -15650,7 +15615,7 @@ namespace ts {
1565015615
const type = <MappedType>getTypeFromMappedTypeNode(node);
1565115616
const constraintType = getConstraintTypeFromMappedType(type);
1565215617
const keyType = constraintType.flags & TypeFlags.TypeParameter ? getApparentTypeOfTypeParameter(<TypeParameter>constraintType) : constraintType;
15653-
checkTypeAssignableTo(keyType, stringOrNumberType, node.typeParameter.constraint);
15618+
checkTypeAssignableTo(keyType, stringType, node.typeParameter.constraint);
1565415619
}
1565515620

1565615621
function isPrivateWithinAmbient(node: Node): boolean {
@@ -17161,7 +17126,7 @@ namespace ts {
1716117126
const rightType = checkNonNullExpression(node.expression);
1716217127
// unknownType is returned i.e. if node.expression is identifier whose name cannot be resolved
1716317128
// in this case error about missing name is already reported - do not report extra one
17164-
if (!isTypeAnyOrAllConstituentTypesHaveKind(rightType, TypeFlags.Object | TypeFlags.TypeParameter)) {
17129+
if (!isTypeAnyOrAllConstituentTypesHaveKind(rightType, TypeFlags.Object | TypeFlags.TypeParameter | TypeFlags.IndexedAccess)) {
1716517130
error(node.expression, Diagnostics.The_right_hand_side_of_a_for_in_statement_must_be_of_type_any_an_object_type_or_a_type_parameter);
1716617131
}
1716717132

src/compiler/commandLineParser.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -951,8 +951,8 @@ namespace ts {
951951
errors.push(createCompilerDiagnostic(Diagnostics.Unknown_option_excludes_Did_you_mean_exclude));
952952
}
953953
else {
954-
// By default, exclude common package folders and the outDir
955-
excludeSpecs = ["node_modules", "bower_components", "jspm_packages"];
954+
// If no includes were specified, exclude common package folders and the outDir
955+
excludeSpecs = includeSpecs ? [] : ["node_modules", "bower_components", "jspm_packages"];
956956

957957
const outDir = json["compilerOptions"] && json["compilerOptions"]["outDir"];
958958
if (outDir) {

src/compiler/declarationEmitter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ namespace ts {
371371

372372
function writeJsDocComments(declaration: Node) {
373373
if (declaration) {
374-
const jsDocComments = getJsDocCommentsFromText(declaration, currentText);
374+
const jsDocComments = getJSDocCommentRanges(declaration, currentText);
375375
emitNewLineBeforeLeadingComments(currentLineMap, writer, declaration, jsDocComments);
376376
// jsDoc comments are emitted at /*leading comment1 */space/*leading comment*/space
377377
emitComments(currentText, currentLineMap, writer, jsDocComments, /*leadingSeparator*/ false, /*trailingSeparator*/ true, newLine, writeCommentRange);

0 commit comments

Comments
 (0)