Merge branch 'master' of https://github.com/Microsoft/TypeScript into generators

This commit is contained in:
Jason Freeman
2015-05-27 13:24:00 -04:00
17 changed files with 431 additions and 4 deletions
+3 -1
View File
@@ -5,6 +5,8 @@
[![Downloads](http://img.shields.io/npm/dm/TypeScript.svg)](https://npmjs.org/package/typescript)
# TypeScript
[![Join the chat at https://gitter.im/Microsoft/TypeScript](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/Microsoft/TypeScript?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
[TypeScript](http://www.typescriptlang.org/) is a language for application-scale JavaScript. TypeScript adds optional types, classes, and modules to JavaScript. TypeScript supports tools for large-scale JavaScript applications for any browser, for any host, on any OS. TypeScript compiles to readable, standards-based JavaScript. Try it out at the [playground](http://www.typescriptlang.org/Playground), and stay up to date via [our blog](http://blogs.msdn.com/typescript) and [twitter account](https://twitter.com/typescriptlang).
@@ -29,7 +31,7 @@ There are many ways to [contribute](https://github.com/Microsoft/TypeScript/blob
## Building
In order to build the TypeScript compiler, ensure that you have [Git](http://git-scm.com/downloads) and [Node.js](http://nodejs.org/) installed.
In order to build the TypeScript compiler, ensure that you have [Git](http://git-scm.com/downloads) and [Node.js](http://nodejs.org/) installed. Note that you need to have autocrlf off as we track whitespace changes (`git config --global core.autocrlf false`).
Clone a copy of the repo:
+16 -1
View File
@@ -3877,6 +3877,18 @@ module ts {
}
function instantiateAnonymousType(type: ObjectType, mapper: TypeMapper): ObjectType {
// If this type has already been instantiated using this mapper, returned the cached result. This guards against
// infinite instantiations of cyclic types, e.g. "var x: { a: T, b: typeof x };"
if (mapper.mappings) {
let cached = <ObjectType>mapper.mappings[type.id];
if (cached) {
return cached;
}
}
else {
mapper.mappings = {};
}
// Instantiate the given type using the given mapper and cache the result
let result = <ResolvedType>createObjectType(TypeFlags.Anonymous, type.symbol);
result.properties = instantiateList(getPropertiesOfObjectType(type), mapper, instantiateSymbol);
result.members = createSymbolTable(result.properties);
@@ -3886,6 +3898,7 @@ module ts {
let numberIndexType = getIndexTypeOfType(type, IndexKind.Number);
if (stringIndexType) result.stringIndexType = instantiateType(stringIndexType, mapper);
if (numberIndexType) result.numberIndexType = instantiateType(numberIndexType, mapper);
mapper.mappings[type.id] = result;
return result;
}
@@ -6644,7 +6657,7 @@ module ts {
result.splice(spliceIndex, 0, signature);
}
}
function getSpreadArgumentIndex(args: Expression[]): number {
for (let i = 0; i < args.length; i++) {
if (args[i].kind === SyntaxKind.SpreadElementExpression) {
@@ -11129,6 +11142,7 @@ module ts {
break;
case SyntaxKind.MethodDeclaration:
case SyntaxKind.MethodSignature:
forEach(node.decorators, checkFunctionExpressionBodies);
forEach((<MethodDeclaration>node).parameters, checkFunctionExpressionBodies);
if (isObjectLiteralMethod(node)) {
checkFunctionExpressionOrObjectLiteralMethodBody(<MethodDeclaration>node);
@@ -11143,6 +11157,7 @@ module ts {
case SyntaxKind.WithStatement:
checkFunctionExpressionBodies((<WithStatement>node).expression);
break;
case SyntaxKind.Decorator:
case SyntaxKind.Parameter:
case SyntaxKind.PropertyDeclaration:
case SyntaxKind.PropertySignature:
+1 -1
View File
@@ -2536,7 +2536,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
write(";");
}
function emitWithStatement(node: WhileStatement) {
function emitWithStatement(node: WithStatement) {
write("with (");
emit(node.expression);
write(")");
+1
View File
@@ -1596,6 +1596,7 @@ module ts {
/* @internal */
export interface TypeMapper {
(t: TypeParameter): Type;
mappings?: Map<Type>; // Type mapping cache
}
/* @internal */
+5 -1
View File
@@ -237,7 +237,7 @@ module ts.formatting {
this.NoSpaceBeforeOpenBracket = new Rule(RuleDescriptor.create2(Shared.TokenRange.Any, SyntaxKind.OpenBracketToken), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext), RuleAction.Delete));
this.NoSpaceAfterOpenBracket = new Rule(RuleDescriptor.create3(SyntaxKind.OpenBracketToken, Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext), RuleAction.Delete));
this.NoSpaceBeforeCloseBracket = new Rule(RuleDescriptor.create2(Shared.TokenRange.Any, SyntaxKind.CloseBracketToken), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext), RuleAction.Delete));
this.NoSpaceAfterCloseBracket = new Rule(RuleDescriptor.create3(SyntaxKind.CloseBracketToken, Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext), RuleAction.Delete));
this.NoSpaceAfterCloseBracket = new Rule(RuleDescriptor.create3(SyntaxKind.CloseBracketToken, Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsNotBeforeBlockInFunctionDeclarationContext), RuleAction.Delete));
// Place a space before open brace in a function declaration
this.FunctionOpenBraceLeftTokenRange = Shared.TokenRange.AnyIncludingMultilineComments;
@@ -667,6 +667,10 @@ module ts.formatting {
return context.TokensAreOnSameLine();
}
static IsNotBeforeBlockInFunctionDeclarationContext(context: FormattingContext): boolean {
return !Rules.IsFunctionDeclContext(context) && !Rules.IsBeforeBlockContext(context)
}
static IsEndOfDecoratorContextOnSameLine(context: FormattingContext): boolean {
return context.TokensAreOnSameLine() &&
context.contextNode.decorators &&
@@ -0,0 +1,36 @@
//// [cyclicTypeInstantiation.ts]
function foo<T>() {
var x: {
a: T;
b: typeof x;
};
return x;
}
function bar<T>() {
var x: {
a: T;
b: typeof x;
};
return x;
}
var a = foo<string>();
var b = bar<string>();
// Relating types of a and b produces instantiations of the cyclic anonymous types in foo and bar
a = b;
//// [cyclicTypeInstantiation.js]
function foo() {
var x;
return x;
}
function bar() {
var x;
return x;
}
var a = foo();
var b = bar();
// Relating types of a and b produces instantiations of the cyclic anonymous types in foo and bar
a = b;
@@ -0,0 +1,54 @@
=== tests/cases/compiler/cyclicTypeInstantiation.ts ===
function foo<T>() {
>foo : Symbol(foo, Decl(cyclicTypeInstantiation.ts, 0, 0))
>T : Symbol(T, Decl(cyclicTypeInstantiation.ts, 0, 13))
var x: {
>x : Symbol(x, Decl(cyclicTypeInstantiation.ts, 1, 7))
a: T;
>a : Symbol(a, Decl(cyclicTypeInstantiation.ts, 1, 12))
>T : Symbol(T, Decl(cyclicTypeInstantiation.ts, 0, 13))
b: typeof x;
>b : Symbol(b, Decl(cyclicTypeInstantiation.ts, 2, 13))
>x : Symbol(x, Decl(cyclicTypeInstantiation.ts, 1, 7))
};
return x;
>x : Symbol(x, Decl(cyclicTypeInstantiation.ts, 1, 7))
}
function bar<T>() {
>bar : Symbol(bar, Decl(cyclicTypeInstantiation.ts, 6, 1))
>T : Symbol(T, Decl(cyclicTypeInstantiation.ts, 8, 13))
var x: {
>x : Symbol(x, Decl(cyclicTypeInstantiation.ts, 9, 7))
a: T;
>a : Symbol(a, Decl(cyclicTypeInstantiation.ts, 9, 12))
>T : Symbol(T, Decl(cyclicTypeInstantiation.ts, 8, 13))
b: typeof x;
>b : Symbol(b, Decl(cyclicTypeInstantiation.ts, 10, 13))
>x : Symbol(x, Decl(cyclicTypeInstantiation.ts, 9, 7))
};
return x;
>x : Symbol(x, Decl(cyclicTypeInstantiation.ts, 9, 7))
}
var a = foo<string>();
>a : Symbol(a, Decl(cyclicTypeInstantiation.ts, 16, 3))
>foo : Symbol(foo, Decl(cyclicTypeInstantiation.ts, 0, 0))
var b = bar<string>();
>b : Symbol(b, Decl(cyclicTypeInstantiation.ts, 17, 3))
>bar : Symbol(bar, Decl(cyclicTypeInstantiation.ts, 6, 1))
// Relating types of a and b produces instantiations of the cyclic anonymous types in foo and bar
a = b;
>a : Symbol(a, Decl(cyclicTypeInstantiation.ts, 16, 3))
>b : Symbol(b, Decl(cyclicTypeInstantiation.ts, 17, 3))
@@ -0,0 +1,57 @@
=== tests/cases/compiler/cyclicTypeInstantiation.ts ===
function foo<T>() {
>foo : <T>() => { a: T; b: any; }
>T : T
var x: {
>x : { a: T; b: any; }
a: T;
>a : T
>T : T
b: typeof x;
>b : { a: T; b: any; }
>x : { a: T; b: any; }
};
return x;
>x : { a: T; b: any; }
}
function bar<T>() {
>bar : <T>() => { a: T; b: any; }
>T : T
var x: {
>x : { a: T; b: any; }
a: T;
>a : T
>T : T
b: typeof x;
>b : { a: T; b: any; }
>x : { a: T; b: any; }
};
return x;
>x : { a: T; b: any; }
}
var a = foo<string>();
>a : { a: string; b: any; }
>foo<string>() : { a: string; b: any; }
>foo : <T>() => { a: T; b: any; }
var b = bar<string>();
>b : { a: string; b: any; }
>bar<string>() : { a: string; b: any; }
>bar : <T>() => { a: T; b: any; }
// Relating types of a and b produces instantiations of the cyclic anonymous types in foo and bar
a = b;
>a = b : { a: string; b: any; }
>a : { a: string; b: any; }
>b : { a: string; b: any; }
@@ -0,0 +1,21 @@
tests/cases/conformance/decorators/class/decoratorChecksFunctionBodies.ts(9,14): error TS2345: Argument of type 'number' is not assignable to parameter of type 'string'.
==== tests/cases/conformance/decorators/class/decoratorChecksFunctionBodies.ts (1 errors) ====
// from #2971
function func(s: string): void {
}
class A {
@(x => {
var a = 3;
func(a);
~
!!! error TS2345: Argument of type 'number' is not assignable to parameter of type 'string'.
return x;
})
m() {
}
}
@@ -0,0 +1,44 @@
//// [decoratorChecksFunctionBodies.ts]
// from #2971
function func(s: string): void {
}
class A {
@(x => {
var a = 3;
func(a);
return x;
})
m() {
}
}
//// [decoratorChecksFunctionBodies.js]
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") return Reflect.decorate(decorators, target, key, desc);
switch (arguments.length) {
case 2: return decorators.reduceRight(function(o, d) { return (d && d(o)) || o; }, target);
case 3: return decorators.reduceRight(function(o, d) { return (d && d(target, key)), void 0; }, void 0);
case 4: return decorators.reduceRight(function(o, d) { return (d && d(target, key, o)) || o; }, desc);
}
};
// from #2971
function func(s) {
}
var A = (function () {
function A() {
}
A.prototype.m = function () {
};
Object.defineProperty(A.prototype, "m",
__decorate([
(function (x) {
var a = 3;
func(a);
return x;
})
], A.prototype, "m", Object.getOwnPropertyDescriptor(A.prototype, "m")));
return A;
})();
@@ -0,0 +1,53 @@
//// [tests/cases/conformance/decorators/class/decoratorInstantiateModulesInFunctionBodies.ts] ////
//// [a.ts]
// from #3108
export var test = 'abc';
//// [b.ts]
import { test } from './a';
function filter(handler: any) {
return function (target: any) {
// ...
};
}
class Wat {
@filter(() => test == 'abc')
static whatever() {
// ...
}
}
//// [a.js]
// from #3108
exports.test = 'abc';
//// [b.js]
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") return Reflect.decorate(decorators, target, key, desc);
switch (arguments.length) {
case 2: return decorators.reduceRight(function(o, d) { return (d && d(o)) || o; }, target);
case 3: return decorators.reduceRight(function(o, d) { return (d && d(target, key)), void 0; }, void 0);
case 4: return decorators.reduceRight(function(o, d) { return (d && d(target, key, o)) || o; }, desc);
}
};
var a_1 = require('./a');
function filter(handler) {
return function (target) {
// ...
};
}
var Wat = (function () {
function Wat() {
}
Wat.whatever = function () {
// ...
};
Object.defineProperty(Wat, "whatever",
__decorate([
filter(function () { return a_1.test == 'abc'; })
], Wat, "whatever", Object.getOwnPropertyDescriptor(Wat, "whatever")));
return Wat;
})();
@@ -0,0 +1,34 @@
=== tests/cases/conformance/decorators/class/a.ts ===
// from #3108
export var test = 'abc';
>test : Symbol(test, Decl(a.ts, 2, 10))
=== tests/cases/conformance/decorators/class/b.ts ===
import { test } from './a';
>test : Symbol(test, Decl(b.ts, 0, 8))
function filter(handler: any) {
>filter : Symbol(filter, Decl(b.ts, 0, 27))
>handler : Symbol(handler, Decl(b.ts, 2, 16))
return function (target: any) {
>target : Symbol(target, Decl(b.ts, 3, 21))
// ...
};
}
class Wat {
>Wat : Symbol(Wat, Decl(b.ts, 6, 1))
@filter(() => test == 'abc')
>filter : Symbol(filter, Decl(b.ts, 0, 27))
>test : Symbol(test, Decl(b.ts, 0, 8))
static whatever() {
>whatever : Symbol(Wat.whatever, Decl(b.ts, 8, 11))
// ...
}
}
@@ -0,0 +1,40 @@
=== tests/cases/conformance/decorators/class/a.ts ===
// from #3108
export var test = 'abc';
>test : string
>'abc' : string
=== tests/cases/conformance/decorators/class/b.ts ===
import { test } from './a';
>test : string
function filter(handler: any) {
>filter : (handler: any) => (target: any) => void
>handler : any
return function (target: any) {
>function (target: any) { // ... } : (target: any) => void
>target : any
// ...
};
}
class Wat {
>Wat : Wat
@filter(() => test == 'abc')
>filter(() => test == 'abc') : (target: any) => void
>filter : (handler: any) => (target: any) => void
>() => test == 'abc' : () => boolean
>test == 'abc' : boolean
>test : string
>'abc' : string
static whatever() {
>whatever : () => void
// ...
}
}
@@ -0,0 +1,20 @@
function foo<T>() {
var x: {
a: T;
b: typeof x;
};
return x;
}
function bar<T>() {
var x: {
a: T;
b: typeof x;
};
return x;
}
var a = foo<string>();
var b = bar<string>();
// Relating types of a and b produces instantiations of the cyclic anonymous types in foo and bar
a = b;
@@ -0,0 +1,16 @@
// @target:es5
// from #2971
function func(s: string): void {
}
class A {
@(x => {
var a = 3;
func(a);
return x;
})
m() {
}
}
@@ -0,0 +1,22 @@
// @target:es5
// @module:commonjs
// @filename: a.ts
// from #3108
export var test = 'abc';
// @filename: b.ts
import { test } from './a';
function filter(handler: any) {
return function (target: any) {
// ...
};
}
class Wat {
@filter(() => test == 'abc')
static whatever() {
// ...
}
}
@@ -0,0 +1,8 @@
/// <reference path="fourslash.ts"/>
/////*0*/function listAPIFiles(path: string): string[] {/*1*/ }
goTo.marker("1");
edit.insertLine("");
goTo.marker("0");
verify.currentLineContentIs("function listAPIFiles(path: string): string[] {");