Skip to content

Commit a69dcd1

Browse files
committed
Merge remote-tracking branch 'origin/master' into moduleAugmentations
2 parents 3aa92f5 + 18da7ba commit a69dcd1

57 files changed

Lines changed: 1178 additions & 185 deletions

File tree

Some content is hidden

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

Jakefile.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -163,13 +163,13 @@ var harnessSources = harnessCoreSources.concat([
163163
}));
164164

165165
var librarySourceMap = [
166-
{ target: "lib.core.d.ts", sources: ["core.d.ts"] },
166+
{ target: "lib.core.d.ts", sources: ["header.d.ts", "core.d.ts"] },
167167
{ target: "lib.dom.d.ts", sources: ["importcore.d.ts", "intl.d.ts", "dom.generated.d.ts"], },
168168
{ target: "lib.webworker.d.ts", sources: ["importcore.d.ts", "intl.d.ts", "webworker.generated.d.ts"], },
169169
{ target: "lib.scriptHost.d.ts", sources: ["importcore.d.ts", "scriptHost.d.ts"], },
170-
{ target: "lib.d.ts", sources: ["core.d.ts", "intl.d.ts", "dom.generated.d.ts", "webworker.importscripts.d.ts", "scriptHost.d.ts"], },
171-
{ target: "lib.core.es6.d.ts", sources: ["core.d.ts", "es6.d.ts"]},
172-
{ target: "lib.es6.d.ts", sources: ["es6.d.ts", "core.d.ts", "intl.d.ts", "dom.generated.d.ts", "dom.es6.d.ts", "webworker.importscripts.d.ts", "scriptHost.d.ts"] }
170+
{ target: "lib.d.ts", sources: ["header.d.ts", "core.d.ts", "intl.d.ts", "dom.generated.d.ts", "webworker.importscripts.d.ts", "scriptHost.d.ts"], },
171+
{ target: "lib.core.es6.d.ts", sources: ["header.d.ts", "core.d.ts", "es6.d.ts"]},
172+
{ target: "lib.es6.d.ts", sources: ["header.d.ts", "es6.d.ts", "core.d.ts", "intl.d.ts", "dom.generated.d.ts", "dom.es6.d.ts", "webworker.importscripts.d.ts", "scriptHost.d.ts"] }
173173
];
174174

175175
var libraryTargets = librarySourceMap.map(function (f) {
@@ -893,6 +893,7 @@ function getLinterOptions() {
893893

894894
function lintFileContents(options, path, contents) {
895895
var ll = new Linter(path, contents, options);
896+
console.log("Linting '" + path + "'.")
896897
return ll.lint();
897898
}
898899

lib/typescript.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5037,7 +5037,7 @@ var ts;
50375037
* Given an super call\property node returns a closest node where either
50385038
* - super call\property is legal in the node and not legal in the parent node the node.
50395039
* i.e. super call is legal in constructor but not legal in the class body.
5040-
* - node is arrow function (so caller might need to call getSuperContainer in case if he needs to climb higher)
5040+
* - node is arrow function (so caller might need to call getSuperContainer in case it needs to climb higher)
50415041
* - super call\property is definitely illegal in the node (but might be legal in some subnode)
50425042
* i.e. super property access is illegal in function declaration but can be legal in the statement list
50435043
*/

lib/typescriptServices.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5037,7 +5037,7 @@ var ts;
50375037
* Given an super call\property node returns a closest node where either
50385038
* - super call\property is legal in the node and not legal in the parent node the node.
50395039
* i.e. super call is legal in constructor but not legal in the class body.
5040-
* - node is arrow function (so caller might need to call getSuperContainer in case if he needs to climb higher)
5040+
* - node is arrow function (so caller might need to call getSuperContainer in case it needs to climb higher)
50415041
* - super call\property is definitely illegal in the node (but might be legal in some subnode)
50425042
* i.e. super property access is illegal in function declaration but can be legal in the statement list
50435043
*/

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
"istanbul": "latest",
3737
"mocha-fivemat-progress-reporter": "latest",
3838
"tslint": "next",
39-
"typescript": "next",
39+
"typescript": "1.8.0-dev.20160113",
4040
"tsd": "latest"
4141
},
4242
"scripts": {

src/compiler/checker.ts

Lines changed: 100 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ namespace ts {
8383
getSymbolsInScope,
8484
getSymbolAtLocation,
8585
getShorthandAssignmentValueSymbol,
86+
getExportSpecifierLocalTargetSymbol,
8687
getTypeAtLocation: getTypeOfNode,
8788
typeToString,
8889
getSymbolDisplayBuilder,
@@ -8274,27 +8275,31 @@ namespace ts {
82748275
// Get the element instance type (the result of newing or invoking this tag)
82758276
const elemInstanceType = getJsxElementInstanceType(node);
82768277

8277-
// Is this is a stateless function component? See if its single signature is
8278-
// assignable to the JSX Element Type
8279-
const callSignature = getSingleCallSignature(getTypeOfSymbol(sym));
8280-
const callReturnType = callSignature && getReturnTypeOfSignature(callSignature);
8281-
let paramType = callReturnType && (callSignature.parameters.length === 0 ? emptyObjectType : getTypeOfSymbol(callSignature.parameters[0]));
8282-
if (callReturnType && isTypeAssignableTo(callReturnType, jsxElementType) && (paramType.flags & TypeFlags.ObjectType)) {
8283-
// Intersect in JSX.IntrinsicAttributes if it exists
8284-
const intrinsicAttributes = getJsxType(JsxNames.IntrinsicAttributes);
8285-
if (intrinsicAttributes !== unknownType) {
8286-
paramType = intersectTypes(intrinsicAttributes, paramType);
8278+
const elemClassType = getJsxGlobalElementClassType();
8279+
8280+
if (!elemClassType || !isTypeAssignableTo(elemInstanceType, elemClassType)) {
8281+
// Is this is a stateless function component? See if its single signature's return type is
8282+
// assignable to the JSX Element Type
8283+
const elemType = getTypeOfSymbol(sym);
8284+
const callSignatures = elemType && getSignaturesOfType(elemType, SignatureKind.Call);
8285+
const callSignature = callSignatures && callSignatures.length > 0 && callSignatures[0];
8286+
const callReturnType = callSignature && getReturnTypeOfSignature(callSignature);
8287+
let paramType = callReturnType && (callSignature.parameters.length === 0 ? emptyObjectType : getTypeOfSymbol(callSignature.parameters[0]));
8288+
if (callReturnType && isTypeAssignableTo(callReturnType, jsxElementType)) {
8289+
// Intersect in JSX.IntrinsicAttributes if it exists
8290+
const intrinsicAttributes = getJsxType(JsxNames.IntrinsicAttributes);
8291+
if (intrinsicAttributes !== unknownType) {
8292+
paramType = intersectTypes(intrinsicAttributes, paramType);
8293+
}
8294+
return links.resolvedJsxType = paramType;
82878295
}
8288-
return paramType;
82898296
}
82908297

82918298
// Issue an error if this return type isn't assignable to JSX.ElementClass
8292-
const elemClassType = getJsxGlobalElementClassType();
82938299
if (elemClassType) {
82948300
checkTypeRelatedTo(elemInstanceType, elemClassType, assignableRelation, node, Diagnostics.JSX_element_type_0_is_not_a_constructor_function_for_JSX_elements);
82958301
}
82968302

8297-
82988303
if (isTypeAny(elemInstanceType)) {
82998304
return links.resolvedJsxType = elemInstanceType;
83008305
}
@@ -11226,7 +11231,53 @@ namespace ts {
1122611231
return -1;
1122711232
}
1122811233

11229-
function isInLegalParameterTypePredicatePosition(node: Node): boolean {
11234+
function checkTypePredicate(node: TypePredicateNode) {
11235+
const parent = getTypePredicateParent(node);
11236+
if (!parent) {
11237+
return;
11238+
}
11239+
const returnType = getReturnTypeOfSignature(getSignatureFromDeclaration(parent));
11240+
if (!returnType || !(returnType.flags & TypeFlags.PredicateType)) {
11241+
return;
11242+
}
11243+
const { parameterName } = node;
11244+
if (parameterName.kind === SyntaxKind.ThisType) {
11245+
getTypeFromThisTypeNode(parameterName as ThisTypeNode);
11246+
}
11247+
else {
11248+
const typePredicate = <IdentifierTypePredicate>(<PredicateType>returnType).predicate;
11249+
if (typePredicate.parameterIndex >= 0) {
11250+
if (parent.parameters[typePredicate.parameterIndex].dotDotDotToken) {
11251+
error(parameterName,
11252+
Diagnostics.A_type_predicate_cannot_reference_a_rest_parameter);
11253+
}
11254+
else {
11255+
checkTypeAssignableTo(typePredicate.type,
11256+
getTypeOfNode(parent.parameters[typePredicate.parameterIndex]),
11257+
node.type);
11258+
}
11259+
}
11260+
else if (parameterName) {
11261+
let hasReportedError = false;
11262+
for (const { name } of parent.parameters) {
11263+
if ((name.kind === SyntaxKind.ObjectBindingPattern ||
11264+
name.kind === SyntaxKind.ArrayBindingPattern) &&
11265+
checkIfTypePredicateVariableIsDeclaredInBindingPattern(
11266+
<BindingPattern>name,
11267+
parameterName,
11268+
typePredicate.parameterName)) {
11269+
hasReportedError = true;
11270+
break;
11271+
}
11272+
}
11273+
if (!hasReportedError) {
11274+
error(node.parameterName, Diagnostics.Cannot_find_parameter_0, typePredicate.parameterName);
11275+
}
11276+
}
11277+
}
11278+
}
11279+
11280+
function getTypePredicateParent(node: Node): SignatureDeclaration {
1123011281
switch (node.parent.kind) {
1123111282
case SyntaxKind.ArrowFunction:
1123211283
case SyntaxKind.CallSignature:
@@ -11235,22 +11286,35 @@ namespace ts {
1123511286
case SyntaxKind.FunctionType:
1123611287
case SyntaxKind.MethodDeclaration:
1123711288
case SyntaxKind.MethodSignature:
11238-
return node === (<SignatureDeclaration>node.parent).type;
11289+
const parent = <SignatureDeclaration>node.parent;
11290+
if (node === parent.type) {
11291+
return parent;
11292+
}
1123911293
}
11240-
return false;
1124111294
}
1124211295

11243-
function isInLegalThisTypePredicatePosition(node: Node): boolean {
11244-
if (isInLegalParameterTypePredicatePosition(node)) {
11245-
return true;
11246-
}
11247-
switch (node.parent.kind) {
11248-
case SyntaxKind.PropertyDeclaration:
11249-
case SyntaxKind.PropertySignature:
11250-
case SyntaxKind.GetAccessor:
11251-
return node === (node.parent as (PropertyDeclaration | GetAccessorDeclaration | PropertySignature)).type;
11296+
function checkIfTypePredicateVariableIsDeclaredInBindingPattern(
11297+
pattern: BindingPattern,
11298+
predicateVariableNode: Node,
11299+
predicateVariableName: string) {
11300+
for (const { name } of pattern.elements) {
11301+
if (name.kind === SyntaxKind.Identifier &&
11302+
(<Identifier>name).text === predicateVariableName) {
11303+
error(predicateVariableNode,
11304+
Diagnostics.A_type_predicate_cannot_reference_element_0_in_a_binding_pattern,
11305+
predicateVariableName);
11306+
return true;
11307+
}
11308+
else if (name.kind === SyntaxKind.ArrayBindingPattern ||
11309+
name.kind === SyntaxKind.ObjectBindingPattern) {
11310+
if (checkIfTypePredicateVariableIsDeclaredInBindingPattern(
11311+
<BindingPattern>name,
11312+
predicateVariableNode,
11313+
predicateVariableName)) {
11314+
return true;
11315+
}
11316+
}
1125211317
}
11253-
return false;
1125411318
}
1125511319

1125611320
function checkSignatureDeclaration(node: SignatureDeclaration) {
@@ -11269,68 +11333,8 @@ namespace ts {
1126911333

1127011334
forEach(node.parameters, checkParameter);
1127111335

11272-
if (node.type) {
11273-
if (node.type.kind === SyntaxKind.TypePredicate) {
11274-
const returnType = getReturnTypeOfSignature(getSignatureFromDeclaration(node));
11275-
if (!returnType || !(returnType.flags & TypeFlags.PredicateType)) {
11276-
return;
11277-
}
11278-
const typePredicate = (returnType as PredicateType).predicate;
11279-
const typePredicateNode = node.type as TypePredicateNode;
11280-
checkSourceElement(typePredicateNode);
11281-
if (isIdentifierTypePredicate(typePredicate)) {
11282-
if (typePredicate.parameterIndex >= 0) {
11283-
if (node.parameters[typePredicate.parameterIndex].dotDotDotToken) {
11284-
error(typePredicateNode.parameterName,
11285-
Diagnostics.A_type_predicate_cannot_reference_a_rest_parameter);
11286-
}
11287-
else {
11288-
checkTypeAssignableTo(typePredicate.type,
11289-
getTypeOfNode(node.parameters[typePredicate.parameterIndex]),
11290-
typePredicateNode.type);
11291-
}
11292-
}
11293-
else if (typePredicateNode.parameterName) {
11294-
let hasReportedError = false;
11295-
for (var param of node.parameters) {
11296-
if (hasReportedError) {
11297-
break;
11298-
}
11299-
if (param.name.kind === SyntaxKind.ObjectBindingPattern ||
11300-
param.name.kind === SyntaxKind.ArrayBindingPattern) {
11301-
11302-
(function checkBindingPattern(pattern: BindingPattern) {
11303-
for (const element of pattern.elements) {
11304-
if (element.name.kind === SyntaxKind.Identifier &&
11305-
(<Identifier>element.name).text === typePredicate.parameterName) {
11306-
11307-
error(typePredicateNode.parameterName,
11308-
Diagnostics.A_type_predicate_cannot_reference_element_0_in_a_binding_pattern,
11309-
typePredicate.parameterName);
11310-
hasReportedError = true;
11311-
break;
11312-
}
11313-
else if (element.name.kind === SyntaxKind.ArrayBindingPattern ||
11314-
element.name.kind === SyntaxKind.ObjectBindingPattern) {
11315-
11316-
checkBindingPattern(<BindingPattern>element.name);
11317-
}
11318-
}
11319-
})(<BindingPattern>param.name);
11320-
}
11321-
}
11322-
if (!hasReportedError) {
11323-
error(typePredicateNode.parameterName,
11324-
Diagnostics.Cannot_find_parameter_0,
11325-
typePredicate.parameterName);
11326-
}
11327-
}
11328-
}
11329-
}
11330-
else {
11331-
checkSourceElement(node.type);
11332-
}
11333-
}
11336+
checkSourceElement(node.type);
11337+
1133411338

1133511339
if (produceDiagnostics) {
1133611340
checkCollisionWithArgumentsInGeneratedCode(node);
@@ -14602,20 +14606,6 @@ namespace ts {
1460214606
}
1460314607
}
1460414608

14605-
function checkTypePredicate(node: TypePredicateNode) {
14606-
const { parameterName } = node;
14607-
if (parameterName.kind === SyntaxKind.Identifier && !isInLegalParameterTypePredicatePosition(node)) {
14608-
error(node, Diagnostics.A_type_predicate_is_only_allowed_in_return_type_position_for_functions_and_methods);
14609-
}
14610-
else if (parameterName.kind === SyntaxKind.ThisType) {
14611-
if (!isInLegalThisTypePredicatePosition(node)) {
14612-
error(node, Diagnostics.A_this_based_type_predicate_is_only_allowed_within_a_class_or_interface_s_members_get_accessors_or_return_type_positions_for_functions_and_methods);
14613-
}
14614-
else {
14615-
getTypeFromThisTypeNode(parameterName as ThisTypeNode);
14616-
}
14617-
}
14618-
}
1461914609

1462014610
function checkSourceElement(node: Node): void {
1462114611
if (!node) {
@@ -15219,11 +15209,18 @@ namespace ts {
1521915209
// This is necessary as an identifier in short-hand property assignment can contains two meaning:
1522015210
// property name and property value.
1522115211
if (location && location.kind === SyntaxKind.ShorthandPropertyAssignment) {
15222-
return resolveEntityName((<ShorthandPropertyAssignment>location).name, SymbolFlags.Value);
15212+
return resolveEntityName((<ShorthandPropertyAssignment>location).name, SymbolFlags.Value | SymbolFlags.Alias);
1522315213
}
1522415214
return undefined;
1522515215
}
1522615216

15217+
/** Returns the target of an export specifier without following aliases */
15218+
function getExportSpecifierLocalTargetSymbol(node: ExportSpecifier): Symbol {
15219+
return (<ExportDeclaration>node.parent.parent).moduleSpecifier ?
15220+
getExternalModuleMember(<ExportDeclaration>node.parent.parent, node) :
15221+
resolveEntityName(node.propertyName || node.name, SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace | SymbolFlags.Alias);
15222+
}
15223+
1522715224
function getTypeOfNode(node: Node): Type {
1522815225
if (isInsideWithStatementBody(node)) {
1522915226
// We cannot answer semantic questions within a with block, do not proceed any further

src/compiler/diagnosticMessages.json

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -711,10 +711,6 @@
711711
"category": "Error",
712712
"code": 1227
713713
},
714-
"A type predicate is only allowed in return type position for functions and methods.": {
715-
"category": "Error",
716-
"code": 1228
717-
},
718714
"A type predicate cannot reference a rest parameter.": {
719715
"category": "Error",
720716
"code": 1229
@@ -1655,10 +1651,6 @@
16551651
"category": "Error",
16561652
"code": 2518
16571653
},
1658-
"A 'this'-based type predicate is only allowed within a class or interface's members, get accessors, or return type positions for functions and methods.": {
1659-
"category": "Error",
1660-
"code": 2519
1661-
},
16621654
"Duplicate identifier '{0}'. Compiler uses declaration '{1}' to support async functions.": {
16631655
"category": "Error",
16641656
"code": 2520

0 commit comments

Comments
 (0)