Skip to content

Commit 69ca1f2

Browse files
committed
Merge remote-tracking branch 'origin/master' into javaScriptModules
# Conflicts: # src/compiler/parser.ts
2 parents e630ce2 + 14d6509 commit 69ca1f2

File tree

1,018 files changed

+13247
-24709
lines changed

Some content is hidden

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

1,018 files changed

+13247
-24709
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
language: node_js
22

33
node_js:
4+
- 'stable'
45
- '4'
56
- '0.10'
67

Jakefile.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ var builtLocalCompiler = path.join(builtLocalDirectory, compilerFilename);
228228
function compileFile(outFile, sources, prereqs, prefixes, useBuiltCompiler, noOutFile, generateDeclarations, outDir, preserveConstEnums, keepComments, noResolve, stripInternal, callback) {
229229
file(outFile, prereqs, function() {
230230
var compilerPath = useBuiltCompiler ? builtLocalCompiler : LKGCompiler;
231-
var options = "--module commonjs --noImplicitAny --noEmitOnError --pretty";
231+
var options = "--noImplicitAny --noEmitOnError --pretty";
232232

233233
// Keep comments when specifically requested
234234
// or when in debug mode.
@@ -251,6 +251,9 @@ function compileFile(outFile, sources, prereqs, prefixes, useBuiltCompiler, noOu
251251
if (!noOutFile) {
252252
options += " --out " + outFile;
253253
}
254+
else {
255+
options += " --module commonjs"
256+
}
254257

255258
if(noResolve) {
256259
options += " --noResolve";

src/compiler/checker.ts

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3003,7 +3003,7 @@ namespace ts {
30033003
(<GenericType>type).typeArguments = type.typeParameters;
30043004
type.thisType = <TypeParameter>createType(TypeFlags.TypeParameter | TypeFlags.ThisType);
30053005
type.thisType.symbol = symbol;
3006-
type.thisType.constraint = getTypeWithThisArgument(type);
3006+
type.thisType.constraint = type;
30073007
}
30083008
}
30093009
return <InterfaceType>links.declaredType;
@@ -3546,19 +3546,29 @@ namespace ts {
35463546
return type.flags & TypeFlags.UnionOrIntersection ? getPropertiesOfUnionOrIntersectionType(<UnionType>type) : getPropertiesOfObjectType(type);
35473547
}
35483548

3549+
/**
3550+
* The apparent type of a type parameter is the base constraint instantiated with the type parameter
3551+
* as the type argument for the 'this' type.
3552+
*/
3553+
function getApparentTypeOfTypeParameter(type: TypeParameter) {
3554+
if (!type.resolvedApparentType) {
3555+
let constraintType = getConstraintOfTypeParameter(type);
3556+
while (constraintType && constraintType.flags & TypeFlags.TypeParameter) {
3557+
constraintType = getConstraintOfTypeParameter(<TypeParameter>constraintType);
3558+
}
3559+
type.resolvedApparentType = getTypeWithThisArgument(constraintType || emptyObjectType, type);
3560+
}
3561+
return type.resolvedApparentType;
3562+
}
3563+
35493564
/**
35503565
* For a type parameter, return the base constraint of the type parameter. For the string, number,
35513566
* boolean, and symbol primitive types, return the corresponding object types. Otherwise return the
35523567
* type itself. Note that the apparent type of a union type is the union type itself.
35533568
*/
35543569
function getApparentType(type: Type): Type {
35553570
if (type.flags & TypeFlags.TypeParameter) {
3556-
do {
3557-
type = getConstraintOfTypeParameter(<TypeParameter>type);
3558-
} while (type && type.flags & TypeFlags.TypeParameter);
3559-
if (!type) {
3560-
type = emptyObjectType;
3561-
}
3571+
type = getApparentTypeOfTypeParameter(<TypeParameter>type);
35623572
}
35633573
if (type.flags & TypeFlags.StringLike) {
35643574
type = globalStringType;
@@ -5099,9 +5109,6 @@ namespace ts {
50995109
}
51005110

51015111
function typeParameterIdenticalTo(source: TypeParameter, target: TypeParameter): Ternary {
5102-
if (source.symbol.name !== target.symbol.name) {
5103-
return Ternary.False;
5104-
}
51055112
// covers case when both type parameters does not have constraint (both equal to noConstraintType)
51065113
if (source.constraint === target.constraint) {
51075114
return Ternary.True;
@@ -6462,9 +6469,10 @@ namespace ts {
64626469

64636470
function narrowTypeByInstanceof(type: Type, expr: BinaryExpression, assumeTrue: boolean): Type {
64646471
// Check that type is not any, assumed result is true, and we have variable symbol on the left
6465-
if (isTypeAny(type) || !assumeTrue || expr.left.kind !== SyntaxKind.Identifier || getResolvedSymbol(<Identifier>expr.left) !== symbol) {
6472+
if (isTypeAny(type) || expr.left.kind !== SyntaxKind.Identifier || getResolvedSymbol(<Identifier>expr.left) !== symbol) {
64666473
return type;
64676474
}
6475+
64686476
// Check that right operand is a function type with a prototype property
64696477
const rightType = checkExpression(expr.right);
64706478
if (!isTypeSubtypeOf(rightType, globalFunctionType)) {
@@ -6496,6 +6504,13 @@ namespace ts {
64966504
}
64976505

64986506
if (targetType) {
6507+
if (!assumeTrue) {
6508+
if (type.flags & TypeFlags.Union) {
6509+
return getUnionType(filter((<UnionType>type).types, t => !isTypeSubtypeOf(t, targetType)));
6510+
}
6511+
return type;
6512+
}
6513+
64996514
return getNarrowedType(type, targetType);
65006515
}
65016516

@@ -14944,10 +14959,20 @@ namespace ts {
1494414959
getReferencedValueDeclaration,
1494514960
getTypeReferenceSerializationKind,
1494614961
isOptionalParameter,
14947-
isArgumentsLocalBinding
14962+
isArgumentsLocalBinding,
14963+
getExternalModuleFileFromDeclaration
1494814964
};
1494914965
}
1495014966

14967+
function getExternalModuleFileFromDeclaration(declaration: ImportEqualsDeclaration | ImportDeclaration | ExportDeclaration): SourceFile {
14968+
const specifier = getExternalModuleName(declaration);
14969+
const moduleSymbol = getSymbolAtLocation(specifier);
14970+
if (!moduleSymbol) {
14971+
return undefined;
14972+
}
14973+
return getDeclarationOfKind(moduleSymbol, SyntaxKind.SourceFile) as SourceFile;
14974+
}
14975+
1495114976
function initializeTypeChecker() {
1495214977
// Bind all source files and propagate errors
1495314978
forEach(host.getSourceFiles(), file => {

src/compiler/core.ts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -780,7 +780,8 @@ namespace ts {
780780
};
781781

782782
export interface ObjectAllocator {
783-
getNodeConstructor(kind: SyntaxKind): new (pos?: number, end?: number) => Node;
783+
getNodeConstructor(): new (kind: SyntaxKind, pos?: number, end?: number) => Node;
784+
getSourceFileConstructor(): new (kind: SyntaxKind, pos?: number, end?: number) => SourceFile;
784785
getSymbolConstructor(): new (flags: SymbolFlags, name: string) => Symbol;
785786
getTypeConstructor(): new (checker: TypeChecker, flags: TypeFlags) => Type;
786787
getSignatureConstructor(): new (checker: TypeChecker) => Signature;
@@ -799,17 +800,17 @@ namespace ts {
799800
function Signature(checker: TypeChecker) {
800801
}
801802

803+
function Node(kind: SyntaxKind, pos: number, end: number) {
804+
this.kind = kind;
805+
this.pos = pos;
806+
this.end = end;
807+
this.flags = NodeFlags.None;
808+
this.parent = undefined;
809+
}
810+
802811
export let objectAllocator: ObjectAllocator = {
803-
getNodeConstructor: kind => {
804-
function Node(pos: number, end: number) {
805-
this.pos = pos;
806-
this.end = end;
807-
this.flags = NodeFlags.None;
808-
this.parent = undefined;
809-
}
810-
Node.prototype = { kind };
811-
return <any>Node;
812-
},
812+
getNodeConstructor: () => <any>Node,
813+
getSourceFileConstructor: () => <any>Node,
813814
getSymbolConstructor: () => <any>Symbol,
814815
getTypeConstructor: () => <any>Type,
815816
getSignatureConstructor: () => <any>Signature

0 commit comments

Comments
 (0)