Skip to content

Commit 0dac29f

Browse files
committed
Merge branch 'master' into checkJSFiles
2 parents 7980629 + 4b3cd6a commit 0dac29f

File tree

243 files changed

+9539
-1149
lines changed

Some content is hidden

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

243 files changed

+9539
-1149
lines changed

Jakefile.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,7 @@ var ts = require("./lib/typescript");
1111

1212
// Variables
1313
var compilerDirectory = "src/compiler/";
14-
var servicesDirectory = "src/services/";
1514
var serverDirectory = "src/server/";
16-
var typingsInstallerDirectory = "src/server/typingsInstaller";
17-
var cancellationTokenDirectory = "src/server/cancellationToken";
18-
var watchGuardDirectory = "src/server/watchGuard";
1915
var harnessDirectory = "src/harness/";
2016
var libraryDirectory = "src/lib/";
2117
var scriptsDirectory = "scripts/";
@@ -131,6 +127,7 @@ var harnessSources = harnessCoreSources.concat([
131127
"matchFiles.ts",
132128
"initializeTSConfig.ts",
133129
"printer.ts",
130+
"textChanges.ts",
134131
"transform.ts",
135132
"customTransforms.ts",
136133
].map(function (f) {

README.md

Lines changed: 3 additions & 3 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 0 deletions
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

Lines changed: 28 additions & 12 deletions
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;
@@ -9874,7 +9890,7 @@ namespace ts {
98749890
return strictNullChecks ? TypeFacts.ObjectStrictFacts : TypeFacts.ObjectFacts;
98759891
}
98769892
if (flags & TypeFlags.TypeVariable) {
9877-
return getTypeFacts(getBaseConstraintOfType(<TypeVariable>type) || emptyObjectType);
9893+
return getTypeFacts(getBaseConstraintOfType(type) || emptyObjectType);
98789894
}
98799895
if (flags & TypeFlags.UnionOrIntersection) {
98809896
return getTypeFactsOfTypes((<UnionOrIntersectionType>type).types);
@@ -10686,7 +10702,7 @@ namespace ts {
1068610702
return targetType;
1068710703
}
1068810704
if (type.flags & TypeFlags.TypeVariable) {
10689-
const constraint = getBaseConstraintOfType(<TypeVariable>type) || anyType;
10705+
const constraint = getBaseConstraintOfType(type) || anyType;
1069010706
if (isTypeSubtypeOf(targetType, constraint)) {
1069110707
return getIntersectionType([type, targetType]);
1069210708
}
@@ -16234,7 +16250,7 @@ namespace ts {
1623416250
function isLiteralContextualType(contextualType: Type) {
1623516251
if (contextualType) {
1623616252
if (contextualType.flags & TypeFlags.TypeVariable) {
16237-
const constraint = getBaseConstraintOfType(<TypeVariable>contextualType) || emptyObjectType;
16253+
const constraint = getBaseConstraintOfType(contextualType) || emptyObjectType;
1623816254
// If the type parameter is constrained to the base primitive type we're checking for,
1623916255
// consider this a literal context. For example, given a type parameter 'T extends string',
1624016256
// this causes us to infer string literal types for T.
@@ -17124,7 +17140,7 @@ namespace ts {
1712417140
// Check if we're indexing with a numeric type and the object type is a generic
1712517141
// type with a constraint that has a numeric index signature.
1712617142
if (maybeTypeOfKind(objectType, TypeFlags.TypeVariable) && isTypeOfKind(indexType, TypeFlags.NumberLike)) {
17127-
const constraint = getBaseConstraintOfType(<TypeVariable | UnionOrIntersectionType>objectType);
17143+
const constraint = getBaseConstraintOfType(objectType);
1712817144
if (constraint && getIndexInfoOfType(constraint, IndexKind.Number)) {
1712917145
return type;
1713017146
}

src/compiler/emitter.ts

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,8 @@ namespace ts {
199199
onEmitHelpers,
200200
onSetSourceFile,
201201
substituteNode,
202+
onBeforeEmitNodeArray,
203+
onAfterEmitNodeArray
202204
} = handlers;
203205

204206
const newLine = getNewLineCharacter(printerOptions);
@@ -631,6 +633,11 @@ namespace ts {
631633
if (isExpression(node)) {
632634
return pipelineEmitExpression(trySubstituteNode(EmitHint.Expression, node));
633635
}
636+
637+
if (isToken(node)) {
638+
writeTokenText(kind);
639+
return;
640+
}
634641
}
635642

636643
function pipelineEmitExpression(node: Node): void {
@@ -1553,6 +1560,10 @@ namespace ts {
15531560
emitSignatureAndBody(node, emitSignatureHead);
15541561
}
15551562

1563+
function emitBlockCallback(_hint: EmitHint, body: Node): void {
1564+
emitBlockFunctionBody(<Block>body);
1565+
}
1566+
15561567
function emitSignatureAndBody(node: FunctionLikeDeclaration, emitSignatureHead: (node: SignatureDeclaration) => void) {
15571568
const body = node.body;
15581569
if (body) {
@@ -1564,12 +1575,22 @@ namespace ts {
15641575

15651576
if (getEmitFlags(node) & EmitFlags.ReuseTempVariableScope) {
15661577
emitSignatureHead(node);
1567-
emitBlockFunctionBody(body);
1578+
if (onEmitNode) {
1579+
onEmitNode(EmitHint.Unspecified, body, emitBlockCallback);
1580+
}
1581+
else {
1582+
emitBlockFunctionBody(body);
1583+
}
15681584
}
15691585
else {
15701586
pushNameGenerationScope();
15711587
emitSignatureHead(node);
1572-
emitBlockFunctionBody(body);
1588+
if (onEmitNode) {
1589+
onEmitNode(EmitHint.Unspecified, body, emitBlockCallback);
1590+
}
1591+
else {
1592+
emitBlockFunctionBody(body);
1593+
}
15731594
popNameGenerationScope();
15741595
}
15751596

@@ -2200,6 +2221,10 @@ namespace ts {
22002221
write(getOpeningBracket(format));
22012222
}
22022223

2224+
if (onBeforeEmitNodeArray) {
2225+
onBeforeEmitNodeArray(children);
2226+
}
2227+
22032228
if (isEmpty) {
22042229
// Write a line terminator if the parent node was multi-line
22052230
if (format & ListFormat.MultiLine) {
@@ -2315,6 +2340,10 @@ namespace ts {
23152340
}
23162341
}
23172342

2343+
if (onAfterEmitNodeArray) {
2344+
onAfterEmitNodeArray(children);
2345+
}
2346+
23182347
if (format & ListFormat.BracketsMask) {
23192348
write(getClosingBracket(format));
23202349
}

src/compiler/factory.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1099,6 +1099,10 @@ namespace ts {
10991099
: node;
11001100
}
11011101

1102+
export function createKeywordTypeNode(kind: KeywordTypeNode["kind"]): KeywordTypeNode {
1103+
return <KeywordTypeNode>createSynthesizedNode(kind);
1104+
}
1105+
11021106
export function createFunctionDeclaration(decorators: Decorator[] | undefined, modifiers: Modifier[] | undefined, asteriskToken: AsteriskToken | undefined, name: string | Identifier | undefined, typeParameters: TypeParameterDeclaration[] | undefined, parameters: ParameterDeclaration[], type: TypeNode | undefined, body: Block | undefined) {
11031107
const node = <FunctionDeclaration>createSynthesizedNode(SyntaxKind.FunctionDeclaration);
11041108
node.decorators = asNodeArray(decorators);

src/compiler/scanner.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ namespace ts {
333333
}
334334

335335
/* @internal */
336-
export function getLineStarts(sourceFile: SourceFile): number[] {
336+
export function getLineStarts(sourceFile: SourceFileLike): number[] {
337337
return sourceFile.lineMap || (sourceFile.lineMap = computeLineStarts(sourceFile.text));
338338
}
339339

src/compiler/types.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2209,6 +2209,16 @@ namespace ts {
22092209
name: string;
22102210
}
22112211

2212+
/* @internal */
2213+
/**
2214+
* Subset of properties from SourceFile that are used in multiple utility functions
2215+
*/
2216+
export interface SourceFileLike {
2217+
readonly text: string;
2218+
lineMap: number[];
2219+
}
2220+
2221+
22122222
// Source files are declarations when they are external modules.
22132223
export interface SourceFile extends Declaration {
22142224
kind: SyntaxKind.SourceFile;
@@ -4138,6 +4148,8 @@ namespace ts {
41384148
/*@internal*/ onEmitSourceMapOfPosition?: (pos: number) => void;
41394149
/*@internal*/ onEmitHelpers?: (node: Node, writeLines: (text: string) => void) => void;
41404150
/*@internal*/ onSetSourceFile?: (node: SourceFile) => void;
4151+
/*@internal*/ onBeforeEmitNodeArray?: (nodes: NodeArray<any>) => void;
4152+
/*@internal*/ onAfterEmitNodeArray?: (nodes: NodeArray<any>) => void;
41414153
}
41424154

41434155
export interface PrinterOptions {

src/compiler/utilities.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ namespace ts {
184184
return false;
185185
}
186186

187-
export function getStartPositionOfLine(line: number, sourceFile: SourceFile): number {
187+
export function getStartPositionOfLine(line: number, sourceFile: SourceFileLike): number {
188188
Debug.assert(line >= 0);
189189
return getLineStarts(sourceFile)[line];
190190
}
@@ -204,7 +204,7 @@ namespace ts {
204204
return value !== undefined;
205205
}
206206

207-
export function getEndLinePosition(line: number, sourceFile: SourceFile): number {
207+
export function getEndLinePosition(line: number, sourceFile: SourceFileLike): number {
208208
Debug.assert(line >= 0);
209209
const lineStarts = getLineStarts(sourceFile);
210210

@@ -255,7 +255,11 @@ namespace ts {
255255
return !nodeIsMissing(node);
256256
}
257257

258-
export function getTokenPosOfNode(node: Node, sourceFile?: SourceFile, includeJsDoc?: boolean): number {
258+
export function isToken(n: Node): boolean {
259+
return n.kind >= SyntaxKind.FirstToken && n.kind <= SyntaxKind.LastToken;
260+
}
261+
262+
export function getTokenPosOfNode(node: Node, sourceFile?: SourceFileLike, includeJsDoc?: boolean): number {
259263
// With nodes that have no width (i.e. 'Missing' nodes), we actually *don't*
260264
// want to skip trivia because this will launch us forward to the next token.
261265
if (nodeIsMissing(node)) {
@@ -289,7 +293,7 @@ namespace ts {
289293
return node.kind >= SyntaxKind.FirstJSDocTagNode && node.kind <= SyntaxKind.LastJSDocTagNode;
290294
}
291295

292-
export function getNonDecoratorTokenPosOfNode(node: Node, sourceFile?: SourceFile): number {
296+
export function getNonDecoratorTokenPosOfNode(node: Node, sourceFile?: SourceFileLike): number {
293297
if (nodeIsMissing(node) || !node.decorators) {
294298
return getTokenPosOfNode(node, sourceFile);
295299
}
@@ -2491,7 +2495,7 @@ namespace ts {
24912495
return indentStrings[1].length;
24922496
}
24932497

2494-
export function createTextWriter(newLine: String): EmitTextWriter {
2498+
export function createTextWriter(newLine: string): EmitTextWriter {
24952499
let output: string;
24962500
let indent: number;
24972501
let lineStart: boolean;

0 commit comments

Comments
 (0)