Skip to content

Commit

Permalink
Merge branch 'master' into constructorAccessibility
Browse files Browse the repository at this point in the history
Conflicts:
	src/compiler/checker.ts
  • Loading branch information
AbubakerB committed Feb 16, 2016
2 parents ba8b168 + 3820dfa commit de23e2f
Show file tree
Hide file tree
Showing 105 changed files with 1,944 additions and 1,016 deletions.
340 changes: 189 additions & 151 deletions src/compiler/checker.ts

Large diffs are not rendered by default.

11 changes: 5 additions & 6 deletions src/compiler/diagnosticMessages.json
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,7 @@
"category": "Error",
"code": 1218
},
"Experimental support for decorators is a feature that is subject to change in a future release. Specify '--experimentalDecorators' to remove this warning.": {
"Experimental support for decorators is a feature that is subject to change in a future release. Set the 'experimentalDecorators' option to remove this warning.": {
"category": "Error",
"code": 1219
},
Expand Down Expand Up @@ -723,6 +723,10 @@
"category": "Error",
"code": 1227
},
"A type predicate is only allowed in return type position for functions and methods.": {
"category": "Error",
"code": 1228
},
"A type predicate cannot reference a rest parameter.": {
"category": "Error",
"code": 1229
Expand Down Expand Up @@ -2745,11 +2749,6 @@
"category": "Error",
"code": 8016
},
"'decorators' can only be used in a .ts file.": {
"category": "Error",
"code": 8017
},

"Only identifiers/qualified-names with optional type arguments are currently supported in a class 'extends' clauses.": {
"category": "Error",
"code": 9002
Expand Down
4 changes: 2 additions & 2 deletions src/compiler/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1937,7 +1937,7 @@ namespace ts {
return finishNode(node);
}

function parseTypePredicate(lhs: Identifier | ThisTypeNode): TypePredicateNode {
function parseThisTypePredicate(lhs: ThisTypeNode): TypePredicateNode {
nextToken();
const node = createNode(SyntaxKind.TypePredicate, lhs.pos) as TypePredicateNode;
node.parameterName = lhs;
Expand Down Expand Up @@ -2362,7 +2362,7 @@ namespace ts {
case SyntaxKind.ThisKeyword: {
const thisKeyword = parseThisTypeNode();
if (token === SyntaxKind.IsKeyword && !scanner.hasPrecedingLineBreak()) {
return parseTypePredicate(thisKeyword);
return parseThisTypePredicate(thisKeyword);
}
else {
return thisKeyword;
Expand Down
31 changes: 20 additions & 11 deletions src/compiler/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -533,18 +533,25 @@ namespace ts {
}

let referencedSourceFile: string;
while (true) {
const searchName = normalizePath(combinePaths(containingDirectory, moduleName));
referencedSourceFile = loadModuleFromFile(searchName, supportedExtensions, failedLookupLocations, /*onlyRecordFailures*/ false, state);
if (referencedSourceFile) {
break;
}
const parentPath = getDirectoryPath(containingDirectory);
if (parentPath === containingDirectory) {
break;
if (moduleHasNonRelativeName(moduleName)) {
while (true) {
const searchName = normalizePath(combinePaths(containingDirectory, moduleName));
referencedSourceFile = loadModuleFromFile(searchName, supportedExtensions, failedLookupLocations, /*onlyRecordFailures*/ false, state);
if (referencedSourceFile) {
break;
}
const parentPath = getDirectoryPath(containingDirectory);
if (parentPath === containingDirectory) {
break;
}
containingDirectory = parentPath;
}
containingDirectory = parentPath;
}
else {
const candidate = normalizePath(combinePaths(containingDirectory, moduleName));
referencedSourceFile = loadModuleFromFile(candidate, supportedExtensions, failedLookupLocations, /*onlyRecordFailures*/ false, state);
}


return referencedSourceFile
? { resolvedModule: { resolvedFileName: referencedSourceFile }, failedLookupLocations }
Expand Down Expand Up @@ -1169,7 +1176,9 @@ namespace ts {
diagnostics.push(createDiagnosticForNode(typeAssertionExpression.type, Diagnostics.type_assertion_expressions_can_only_be_used_in_a_ts_file));
return true;
case SyntaxKind.Decorator:
diagnostics.push(createDiagnosticForNode(node, Diagnostics.decorators_can_only_be_used_in_a_ts_file));
if (!options.experimentalDecorators) {
diagnostics.push(createDiagnosticForNode(node, Diagnostics.Experimental_support_for_decorators_is_a_feature_that_is_subject_to_change_in_a_future_release_Set_the_experimentalDecorators_option_to_remove_this_warning));
}
return true;
}

Expand Down
3 changes: 1 addition & 2 deletions src/compiler/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
{
"compilerOptions": {
"module": "commonjs",
"noImplicitAny": true,
"removeComments": true,
"preserveConstEnums": true,
"out": "../../built/local/tsc.js",
"sourceMap": true
},
"files": [
"types.ts",
"core.ts",
"sys.ts",
"types.ts",
"diagnosticInformationMap.generated.ts",
"scanner.ts",
"parser.ts",
Expand Down
29 changes: 14 additions & 15 deletions src/compiler/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,6 @@ namespace ts {
IntrinsicElement = IntrinsicNamedElement | IntrinsicIndexedElement,
}


/* @internal */
export const enum RelationComparisonResult {
Succeeded = 1, // Should be truthy
Expand Down Expand Up @@ -1749,6 +1748,7 @@ namespace ts {
buildSignatureDisplay(signatures: Signature, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags, kind?: SignatureKind): void;
buildParameterDisplay(parameter: Symbol, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags): void;
buildTypeParameterDisplay(tp: TypeParameter, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags): void;
buildTypePredicateDisplay(predicate: TypePredicate, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags): void;
buildTypeParameterDisplayFromSymbol(symbol: Symbol, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags): void;
buildDisplayForParametersAndDelimiters(parameters: Symbol[], writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags): void;
buildDisplayForTypeParametersAndDelimiters(typeParameters: TypeParameter[], writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags): void;
Expand Down Expand Up @@ -1814,22 +1814,24 @@ namespace ts {
Identifier
}

export interface TypePredicate {
export interface TypePredicateBase {
kind: TypePredicateKind;
type: Type;
}

// @kind (TypePredicateKind.This)
export interface ThisTypePredicate extends TypePredicate {
export interface ThisTypePredicate extends TypePredicateBase {
_thisTypePredicateBrand: any;
}

// @kind (TypePredicateKind.Identifier)
export interface IdentifierTypePredicate extends TypePredicate {
export interface IdentifierTypePredicate extends TypePredicateBase {
parameterName: string;
parameterIndex: number;
}

export type TypePredicate = IdentifierTypePredicate | ThisTypePredicate;

/* @internal */
export type AnyImportSyntax = ImportDeclaration | ImportEqualsDeclaration;

Expand Down Expand Up @@ -2037,10 +2039,9 @@ namespace ts {
LoopWithCapturedBlockScopedBinding = 0x00010000, // Loop that contains block scoped variable captured in closure
CapturedBlockScopedBinding = 0x00020000, // Block-scoped binding that is captured in some function
BlockScopedBindingInLoop = 0x00040000, // Block-scoped binding with declaration nested inside iteration statement
HasSeenSuperCall = 0x00080000, // Set during the binding when encounter 'super'
ClassWithBodyScopedClassBinding = 0x00100000, // Decorated class that contains a binding to itself inside of the class body.
BodyScopedClassBinding = 0x00200000, // Binding to a decorated class inside of the class's body.
NeedsLoopOutParameter = 0x00400000, // Block scoped binding whose value should be explicitly copied outside of the converted loop
ClassWithBodyScopedClassBinding = 0x00080000, // Decorated class that contains a binding to itself inside of the class body.
BodyScopedClassBinding = 0x00100000, // Binding to a decorated class inside of the class's body.
NeedsLoopOutParameter = 0x00200000, // Block scoped binding whose value should be explicitly copied outside of the converted loop
}

/* @internal */
Expand All @@ -2060,6 +2061,8 @@ namespace ts {
importOnRightSide?: Symbol; // for import declarations - import that appear on the right side
jsxFlags?: JsxFlags; // flags for knowing what kind of element/attributes we're dealing with
resolvedJsxType?: Type; // resolved element attributes type of a JSX openinglike element
hasSuperCall?: boolean; // recorded result when we try to find super-call. We only try to find one if this flag is undefined, indicating that we haven't made an attempt.
superCall?: ExpressionStatement; // Cached first super-call found in the constructor. Used in checking whether super is called before this-accessing
}

export const enum TypeFlags {
Expand Down Expand Up @@ -2095,7 +2098,6 @@ namespace ts {
ESSymbol = 0x01000000, // Type of symbol primitive introduced in ES6
ThisType = 0x02000000, // This type
ObjectLiteralPatternWithComputedProperties = 0x04000000, // Object literal type implied by binding pattern has computed properties
PredicateType = 0x08000000, // Predicate types are also Boolean types, but should not be considered Intrinsics - there's no way to capture this with flags

/* @internal */
Intrinsic = Any | String | Number | Boolean | ESSymbol | Void | Undefined | Null,
Expand All @@ -2107,7 +2109,7 @@ namespace ts {
UnionOrIntersection = Union | Intersection,
StructuredType = ObjectType | Union | Intersection,
/* @internal */
RequiresWidening = ContainsUndefinedOrNull | ContainsObjectLiteral | PredicateType,
RequiresWidening = ContainsUndefinedOrNull | ContainsObjectLiteral,
/* @internal */
PropagatingFlags = ContainsUndefinedOrNull | ContainsObjectLiteral | ContainsAnyFunctionType
}
Expand All @@ -2128,11 +2130,6 @@ namespace ts {
intrinsicName: string; // Name of intrinsic type
}

// Predicate types (TypeFlags.Predicate)
export interface PredicateType extends Type {
predicate: ThisTypePredicate | IdentifierTypePredicate;
}

// String literal types (TypeFlags.StringLiteral)
export interface StringLiteralType extends Type {
text: string; // Text of string literal
Expand Down Expand Up @@ -2267,6 +2264,8 @@ namespace ts {
erasedSignatureCache?: Signature; // Erased version of signature (deferred)
/* @internal */
isolatedSignatureType?: ObjectType; // A manufactured type that just contains the signature for purposes of signature comparison
/* @internal */
typePredicate?: TypePredicate;
}

export const enum IndexKind {
Expand Down
4 changes: 4 additions & 0 deletions src/compiler/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -748,6 +748,10 @@ namespace ts {
return predicate && predicate.kind === TypePredicateKind.Identifier;
}

export function isThisTypePredicate(predicate: TypePredicate): predicate is ThisTypePredicate {
return predicate && predicate.kind === TypePredicateKind.This;
}

export function getContainingFunction(node: Node): FunctionLikeDeclaration {
while (true) {
node = node.parent;
Expand Down
1 change: 0 additions & 1 deletion src/server/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"compilerOptions": {
"module": "commonjs",
"noImplicitAny": true,
"removeComments": true,
"preserveConstEnums": true,
Expand Down
1 change: 0 additions & 1 deletion src/services/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"compilerOptions": {
"module": "commonjs",
"noImplicitAny": true,
"removeComments": true,
"preserveConstEnums": true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ var obj: Object;
>Object : Object

if (ArrayBuffer.isView(obj)) {
>ArrayBuffer.isView(obj) : arg is ArrayBufferView
>ArrayBuffer.isView(obj) : boolean
>ArrayBuffer.isView : (arg: any) => arg is ArrayBufferView
>ArrayBuffer : ArrayBufferConstructor
>isView : (arg: any) => arg is ArrayBufferView
Expand Down
9 changes: 3 additions & 6 deletions tests/baselines/reference/classExtendsNull.errors.txt
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
tests/cases/compiler/classExtendsNull.ts(2,5): error TS17005: A constructor cannot contain a 'super' call when its class extends 'null'
tests/cases/compiler/classExtendsNull.ts(3,9): error TS17005: A constructor cannot contain a 'super' call when its class extends 'null'


==== tests/cases/compiler/classExtendsNull.ts (1 errors) ====
class C extends null {
constructor() {
~~~~~~~~~~~~~~~
super();
~~~~~~~~~~~~~~~~
~~~~~~~
!!! error TS17005: A constructor cannot contain a 'super' call when its class extends 'null'
return Object.create(null);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
}
~~~~~
!!! error TS17005: A constructor cannot contain a 'super' call when its class extends 'null'
}

class D extends null {
Expand Down
16 changes: 16 additions & 0 deletions tests/baselines/reference/declarationEmitIdentifierPredicates01.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//// [declarationEmitIdentifierPredicates01.ts]

export function f(x: any): x is number {
return typeof x === "number";
}

//// [declarationEmitIdentifierPredicates01.js]
"use strict";
function f(x) {
return typeof x === "number";
}
exports.f = f;


//// [declarationEmitIdentifierPredicates01.d.ts]
export declare function f(x: any): x is number;
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
=== tests/cases/conformance/declarationEmit/typePredicates/declarationEmitIdentifierPredicates01.ts ===

export function f(x: any): x is number {
>f : Symbol(f, Decl(declarationEmitIdentifierPredicates01.ts, 0, 0))
>x : Symbol(x, Decl(declarationEmitIdentifierPredicates01.ts, 1, 18))
>x : Symbol(x, Decl(declarationEmitIdentifierPredicates01.ts, 1, 18))

return typeof x === "number";
>x : Symbol(x, Decl(declarationEmitIdentifierPredicates01.ts, 1, 18))
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
=== tests/cases/conformance/declarationEmit/typePredicates/declarationEmitIdentifierPredicates01.ts ===

export function f(x: any): x is number {
>f : (x: any) => x is number
>x : any
>x : any

return typeof x === "number";
>typeof x === "number" : boolean
>typeof x : string
>x : any
>"number" : string
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
tests/cases/conformance/declarationEmit/typePredicates/declarationEmitIdentifierPredicatesWithPrivateName01.ts(6,33): error TS4060: Return type of exported function has or is using private name 'I'.


==== tests/cases/conformance/declarationEmit/typePredicates/declarationEmitIdentifierPredicatesWithPrivateName01.ts (1 errors) ====

interface I {
a: number;
}

export function f(x: any): x is I {
~
!!! error TS4060: Return type of exported function has or is using private name 'I'.
return typeof x.a === "number";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//// [declarationEmitIdentifierPredicatesWithPrivateName01.ts]

interface I {
a: number;
}

export function f(x: any): x is I {
return typeof x.a === "number";
}

//// [declarationEmitIdentifierPredicatesWithPrivateName01.js]
"use strict";
function f(x) {
return typeof x.a === "number";
}
exports.f = f;
43 changes: 43 additions & 0 deletions tests/baselines/reference/declarationEmitThisPredicates01.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
//// [declarationEmitThisPredicates01.ts]

export class C {
m(): this is D {
return this instanceof D;
}
}

export class D extends C {
}

//// [declarationEmitThisPredicates01.js]
"use strict";
var __extends = (this && this.__extends) || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
var C = (function () {
function C() {
}
C.prototype.m = function () {
return this instanceof D;
};
return C;
}());
exports.C = C;
var D = (function (_super) {
__extends(D, _super);
function D() {
_super.apply(this, arguments);
}
return D;
}(C));
exports.D = D;


//// [declarationEmitThisPredicates01.d.ts]
export declare class C {
m(): this is D;
}
export declare class D extends C {
}
Loading

0 comments on commit de23e2f

Please sign in to comment.