@@ -415,8 +415,8 @@ module ts {
415415 break loop;
416416 }
417417 break ;
418- case SyntaxKind . CatchBlock :
419- var id = ( < CatchBlock > location ) . variable ;
418+ case SyntaxKind . CatchClause :
419+ var id = ( < CatchClause > location ) . name ;
420420 if ( name === id . text ) {
421421 result = location . symbol ;
422422 break loop;
@@ -756,7 +756,7 @@ module ts {
756756 //
757757 // x is an optional parameter, but it is a required property.
758758 return propertySymbol . valueDeclaration &&
759- propertySymbol . valueDeclaration . flags & NodeFlags . QuestionMark &&
759+ hasQuestionToken ( propertySymbol . valueDeclaration ) &&
760760 propertySymbol . valueDeclaration . kind !== SyntaxKind . Parameter ;
761761 }
762762
@@ -1437,11 +1437,11 @@ module ts {
14371437 }
14381438
14391439 function buildParameterDisplay ( p : Symbol , writer : SymbolWriter , enclosingDeclaration ?: Node , flags ?: TypeFormatFlags , typeStack ?: Type [ ] ) {
1440- if ( getDeclarationFlagsFromSymbol ( p ) & NodeFlags . Rest ) {
1440+ if ( hasDotDotDotToken ( p . valueDeclaration ) ) {
14411441 writePunctuation ( writer , SyntaxKind . DotDotDotToken ) ;
14421442 }
14431443 appendSymbolNameOnly ( p , writer ) ;
1444- if ( p . valueDeclaration . flags & NodeFlags . QuestionMark || ( < VariableDeclaration > p . valueDeclaration ) . initializer ) {
1444+ if ( hasQuestionToken ( p . valueDeclaration ) || ( < VariableDeclaration > p . valueDeclaration ) . initializer ) {
14451445 writePunctuation ( writer , SyntaxKind . QuestionToken ) ;
14461446 }
14471447 writePunctuation ( writer , SyntaxKind . ColonToken ) ;
@@ -1711,7 +1711,7 @@ module ts {
17111711 }
17121712
17131713 // Rest parameters default to type any[], other parameters default to type any
1714- var type = declaration . flags & NodeFlags . Rest ? createArrayType ( anyType ) : anyType ;
1714+ var type = hasDotDotDotToken ( declaration ) ? createArrayType ( anyType ) : anyType ;
17151715 checkImplicitAny ( type ) ;
17161716 return type ;
17171717
@@ -1733,9 +1733,9 @@ module ts {
17331733 var diagnostic = Diagnostics . Member_0_implicitly_has_an_1_type ;
17341734 break ;
17351735 case SyntaxKind . Parameter :
1736- var diagnostic = declaration . flags & NodeFlags . Rest ?
1737- Diagnostics . Rest_parameter_0_implicitly_has_an_any_type :
1738- Diagnostics . Parameter_0_implicitly_has_an_1_type ;
1736+ var diagnostic = hasDotDotDotToken ( declaration )
1737+ ? Diagnostics . Rest_parameter_0_implicitly_has_an_any_type
1738+ : Diagnostics . Parameter_0_implicitly_has_an_1_type ;
17391739 break ;
17401740 default :
17411741 var diagnostic = Diagnostics . Variable_0_implicitly_has_an_1_type ;
@@ -1753,7 +1753,7 @@ module ts {
17531753 }
17541754 // Handle catch clause variables
17551755 var declaration = symbol . valueDeclaration ;
1756- if ( declaration . kind === SyntaxKind . CatchBlock ) {
1756+ if ( declaration . kind === SyntaxKind . CatchClause ) {
17571757 return links . type = anyType ;
17581758 }
17591759 // Handle variable, parameter or property
@@ -2527,7 +2527,7 @@ module ts {
25272527 hasStringLiterals = true ;
25282528 }
25292529 if ( minArgumentCount < 0 ) {
2530- if ( param . initializer || param . flags & ( NodeFlags . QuestionMark | NodeFlags . Rest ) ) {
2530+ if ( param . initializer || param . questionToken || param . dotDotDotToken ) {
25312531 minArgumentCount = i ;
25322532 }
25332533 }
@@ -4375,7 +4375,7 @@ module ts {
43754375 case SyntaxKind . ThrowStatement :
43764376 case SyntaxKind . TryStatement :
43774377 case SyntaxKind . TryBlock :
4378- case SyntaxKind . CatchBlock :
4378+ case SyntaxKind . CatchClause :
43794379 case SyntaxKind . FinallyBlock :
43804380 return forEachChild ( node , isAssignedIn ) ;
43814381 }
@@ -6673,7 +6673,7 @@ module ts {
66736673 ! ( parameterDeclaration . parent . kind === SyntaxKind . Constructor && ( < ConstructorDeclaration > parameterDeclaration . parent ) . body ) ) {
66746674 error ( parameterDeclaration , Diagnostics . A_parameter_property_is_only_allowed_in_a_constructor_implementation ) ;
66756675 }
6676- if ( parameterDeclaration . flags & NodeFlags . Rest ) {
6676+ if ( parameterDeclaration . dotDotDotToken ) {
66776677 if ( ! isArrayType ( getTypeOfSymbol ( parameterDeclaration . symbol ) ) ) {
66786678 error ( parameterDeclaration , Diagnostics . A_rest_parameter_must_be_of_an_array_type ) ;
66796679 }
@@ -7020,20 +7020,23 @@ module ts {
70207020 return ;
70217021 }
70227022
7023+ function getCanonicalOverload ( overloads : Declaration [ ] , implementation : FunctionLikeDeclaration ) {
7024+ // Consider the canonical set of flags to be the flags of the bodyDeclaration or the first declaration
7025+ // Error on all deviations from this canonical set of flags
7026+ // The caveat is that if some overloads are defined in lib.d.ts, we don't want to
7027+ // report the errors on those. To achieve this, we will say that the implementation is
7028+ // the canonical signature only if it is in the same container as the first overload
7029+ var implementationSharesContainerWithFirstOverload = implementation !== undefined && implementation . parent === overloads [ 0 ] . parent ;
7030+ return implementationSharesContainerWithFirstOverload ? implementation : overloads [ 0 ] ;
7031+ }
7032+
70237033 function checkFlagAgreementBetweenOverloads ( overloads : Declaration [ ] , implementation : FunctionLikeDeclaration , flagsToCheck : NodeFlags , someOverloadFlags : NodeFlags , allOverloadFlags : NodeFlags ) : void {
70247034 // Error if some overloads have a flag that is not shared by all overloads. To find the
70257035 // deviations, we XOR someOverloadFlags with allOverloadFlags
70267036 var someButNotAllOverloadFlags = someOverloadFlags ^ allOverloadFlags ;
70277037 if ( someButNotAllOverloadFlags !== 0 ) {
7028- // Consider the canonical set of flags to be the flags of the bodyDeclaration or the first declaration
7029- // Error on all deviations from this canonical set of flags
7030- // The caveat is that if some overloads are defined in lib.d.ts, we don't want to
7031- // report the errors on those. To achieve this, we will say that the implementation is
7032- // the canonical signature only if it is in the same container as the first overload
7033- var implementationSharesContainerWithFirstOverload = implementation !== undefined && implementation . parent === overloads [ 0 ] . parent ;
7034- var canonicalFlags = implementationSharesContainerWithFirstOverload
7035- ? getEffectiveDeclarationFlags ( implementation , flagsToCheck )
7036- : getEffectiveDeclarationFlags ( overloads [ 0 ] , flagsToCheck ) ;
7038+ var canonicalFlags = getEffectiveDeclarationFlags ( getCanonicalOverload ( overloads , implementation ) , flagsToCheck ) ;
7039+
70377040 forEach ( overloads , o => {
70387041 var deviation = getEffectiveDeclarationFlags ( o , flagsToCheck ) ^ canonicalFlags ;
70397042 if ( deviation & NodeFlags . Export ) {
@@ -7045,16 +7048,27 @@ module ts {
70457048 else if ( deviation & ( NodeFlags . Private | NodeFlags . Protected ) ) {
70467049 error ( o . name , Diagnostics . Overload_signatures_must_all_be_public_private_or_protected ) ;
70477050 }
7048- else if ( deviation & NodeFlags . QuestionMark ) {
7051+ } ) ;
7052+ }
7053+ }
7054+
7055+ function checkQuestionTokenAgreementBetweenOverloads ( overloads : Declaration [ ] , implementation : FunctionLikeDeclaration , someHaveQuestionToken : boolean , allHaveQuestionToken : boolean ) : void {
7056+ if ( someHaveQuestionToken !== allHaveQuestionToken ) {
7057+ var canonicalHasQuestionToken = hasQuestionToken ( getCanonicalOverload ( overloads , implementation ) ) ;
7058+ forEach ( overloads , o => {
7059+ var deviation = hasQuestionToken ( o ) !== canonicalHasQuestionToken ;
7060+ if ( deviation ) {
70497061 error ( o . name , Diagnostics . Overload_signatures_must_all_be_optional_or_required ) ;
70507062 }
70517063 } ) ;
70527064 }
70537065 }
70547066
7055- var flagsToCheck : NodeFlags = NodeFlags . Export | NodeFlags . Ambient | NodeFlags . Private | NodeFlags . Protected | NodeFlags . QuestionMark ;
7067+ var flagsToCheck : NodeFlags = NodeFlags . Export | NodeFlags . Ambient | NodeFlags . Private | NodeFlags . Protected ;
70567068 var someNodeFlags : NodeFlags = 0 ;
70577069 var allNodeFlags = flagsToCheck ;
7070+ var someHaveQuestionToken = false ;
7071+ var allHaveQuestionToken = true ;
70587072 var hasOverloads = false ;
70597073 var bodyDeclaration : FunctionLikeDeclaration ;
70607074 var lastSeenNonAmbientDeclaration : FunctionLikeDeclaration ;
@@ -7128,6 +7142,8 @@ module ts {
71287142 var currentNodeFlags = getEffectiveDeclarationFlags ( node , flagsToCheck ) ;
71297143 someNodeFlags |= currentNodeFlags ;
71307144 allNodeFlags &= currentNodeFlags ;
7145+ someHaveQuestionToken = someHaveQuestionToken || hasQuestionToken ( node ) ;
7146+ allHaveQuestionToken = allHaveQuestionToken && hasQuestionToken ( node ) ;
71317147
71327148 if ( node . body && bodyDeclaration ) {
71337149 if ( isConstructor ) {
@@ -7176,6 +7192,8 @@ module ts {
71767192
71777193 if ( hasOverloads ) {
71787194 checkFlagAgreementBetweenOverloads ( declarations , bodyDeclaration , flagsToCheck , someNodeFlags , allNodeFlags ) ;
7195+ checkQuestionTokenAgreementBetweenOverloads ( declarations , bodyDeclaration , someHaveQuestionToken , allHaveQuestionToken ) ;
7196+
71797197 if ( bodyDeclaration ) {
71807198 var signatures = getSignaturesOfSymbol ( symbol ) ;
71817199 var bodySignature = getSignatureFromDeclaration ( bodyDeclaration ) ;
@@ -7725,13 +7743,14 @@ module ts {
77257743 function checkSwitchStatement ( node : SwitchStatement ) {
77267744 var expressionType = checkExpression ( node . expression ) ;
77277745 forEach ( node . clauses , clause => {
7728- if ( fullTypeCheck && clause . expression ) {
7746+ if ( fullTypeCheck && clause . kind === SyntaxKind . CaseClause ) {
7747+ var caseClause = < CaseClause > clause ;
77297748 // TypeScript 1.0 spec (April 2014):5.9
77307749 // In a 'switch' statement, each 'case' expression must be of a type that is assignable to or from the type of the 'switch' expression.
7731- var caseType = checkExpression ( clause . expression ) ;
7750+ var caseType = checkExpression ( caseClause . expression ) ;
77327751 if ( ! isTypeAssignableTo ( expressionType , caseType ) ) {
77337752 // check 'expressionType isAssignableTo caseType' failed, try the reversed check and report errors if it fails
7734- checkTypeAssignableTo ( caseType , expressionType , clause . expression , /*headMessage*/ undefined ) ;
7753+ checkTypeAssignableTo ( caseType , expressionType , caseClause . expression , /*headMessage*/ undefined ) ;
77357754 }
77367755 }
77377756 forEach ( clause . statements , checkSourceElement ) ;
@@ -7748,7 +7767,7 @@ module ts {
77487767
77497768 function checkTryStatement ( node : TryStatement ) {
77507769 checkBlock ( node . tryBlock ) ;
7751- if ( node . catchBlock ) checkBlock ( node . catchBlock ) ;
7770+ if ( node . catchClause ) checkBlock ( node . catchClause . block ) ;
77527771 if ( node . finallyBlock ) checkBlock ( node . finallyBlock ) ;
77537772 }
77547773
@@ -8586,7 +8605,7 @@ module ts {
85868605 case SyntaxKind . ThrowStatement :
85878606 case SyntaxKind . TryStatement :
85888607 case SyntaxKind . TryBlock :
8589- case SyntaxKind . CatchBlock :
8608+ case SyntaxKind . CatchClause :
85908609 case SyntaxKind . FinallyBlock :
85918610 case SyntaxKind . VariableDeclaration :
85928611 case SyntaxKind . ClassDeclaration :
@@ -8748,8 +8767,8 @@ module ts {
87488767 copySymbol ( location . symbol , meaning ) ;
87498768 }
87508769 break ;
8751- case SyntaxKind . CatchBlock :
8752- if ( ( < CatchBlock > location ) . variable . text ) {
8770+ case SyntaxKind . CatchClause :
8771+ if ( ( < CatchClause > location ) . name . text ) {
87538772 copySymbol ( location . symbol , meaning ) ;
87548773 }
87558774 break ;
0 commit comments