Index: src/parsing/parser-base.h |
diff --git a/src/parsing/parser-base.h b/src/parsing/parser-base.h |
index 48677d5db24f8f70ba7c4217ac8c88e780a81f25..5b56213df816980f78298107590c8f0cd0bdaf88 100644 |
--- a/src/parsing/parser-base.h |
+++ b/src/parsing/parser-base.h |
@@ -1746,7 +1746,8 @@ ParserBase<Traits>::ParsePropertyDefinition( |
Scanner::Location(next_beg_pos, scanner()->location().end_pos), |
MessageTemplate::kInvalidDestructuringTarget); |
- if (is_generator || peek() == Token::LPAREN) { |
+ if (is_generator || peek() == Token::LPAREN || |
+ (scope_->typed() && peek() == Token::LT)) { |
// MethodDefinition |
// PropertyName '(' StrictFormalParameters ')' '{' FunctionBody '}' |
// '*' PropertyName '(' StrictFormalParameters ')' '{' FunctionBody '}' |
@@ -1758,17 +1759,22 @@ ParserBase<Traits>::ParsePropertyDefinition( |
FunctionKind kind = is_generator ? FunctionKind::kConciseGeneratorMethod |
: FunctionKind::kConciseMethod; |
+ typesystem::TypeFlags type_flags = (is_get || is_set) |
+ ? typesystem::kDisallowTypeParameters |
+ : typesystem::kNormalTypes; |
if (in_class && !is_static && this->IsConstructor(*name)) { |
*has_seen_constructor = true; |
kind = has_extends ? FunctionKind::kSubclassConstructor |
: FunctionKind::kBaseConstructor; |
+ type_flags = typesystem::kConstructorTypes; |
} |
value = this->ParseFunctionLiteral( |
*name, scanner()->location(), kSkipFunctionNameCheck, kind, |
RelocInfo::kNoPosition, FunctionLiteral::kAccessorOrMethod, |
- language_mode(), CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); |
+ language_mode(), type_flags, |
+ CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); |
return factory()->NewObjectLiteralProperty(name_expression, value, |
ObjectLiteralProperty::COMPUTED, |
@@ -1808,7 +1814,8 @@ ParserBase<Traits>::ParsePropertyDefinition( |
*name, scanner()->location(), kSkipFunctionNameCheck, |
is_get ? FunctionKind::kGetterFunction : FunctionKind::kSetterFunction, |
RelocInfo::kNoPosition, FunctionLiteral::kAccessorOrMethod, |
- language_mode(), CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); |
+ language_mode(), typesystem::kDisallowTypeParameters, |
+ CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); |
// Make sure the name expression is a string since we need a Name for |
// Runtime_DefineAccessorPropertyUnchecked and since we can determine this |
@@ -2593,7 +2600,8 @@ ParserBase<Traits>::ParseMemberExpression(ExpressionClassifier* classifier, |
: kFunctionNameValidityUnknown, |
is_generator ? FunctionKind::kGeneratorFunction |
: FunctionKind::kNormalFunction, |
- function_token_position, function_type, language_mode(), CHECK_OK); |
+ function_token_position, function_type, language_mode(), |
+ typesystem::kNormalTypes, CHECK_OK); |
} else if (peek() == Token::SUPER) { |
const bool is_new = false; |
result = ParseSuperExpression(is_new, classifier, CHECK_OK); |
@@ -2762,8 +2770,20 @@ void ParserBase<Traits>::ParseFormalParameter( |
classifier->RecordNonSimpleParameter(); |
} |
+ // Parse optional question mark. |
+ bool optional = false; |
+ if (scope_->typed()) optional = Check(Token::CONDITIONAL); |
+ |
+ // Parse optional type annotation. |
+ typename TypeSystem::Type type = this->EmptyType(); |
+ if (scope_->typed() && Check(Token::COLON)) { |
+ type = ParseValidType(ok); |
+ if (!*ok) return; |
+ } |
+ USE(type); // TODO(nikolaos): really use it! |
+ |
ExpressionT initializer = Traits::EmptyExpression(); |
- if (!is_rest && Check(Token::ASSIGN)) { |
+ if (!is_rest && !optional && Check(Token::ASSIGN)) { |
ExpressionClassifier init_classifier(this); |
initializer = ParseAssignmentExpression(true, &init_classifier, ok); |
if (!*ok) return; |