Index: src/parsing/parser-base.h |
diff --git a/src/parsing/parser-base.h b/src/parsing/parser-base.h |
index 678a4be8ab68ff2ce4b40809620fc207215d25a4..21602b22c1da078b27405c6d3dbb7382edd4e773 100644 |
--- a/src/parsing/parser-base.h |
+++ b/src/parsing/parser-base.h |
@@ -898,6 +898,8 @@ class ParserBase : public Traits { |
virtual ~ObjectLiteralCheckerBase() {} |
+ virtual void JustSignature() = 0; |
+ |
protected: |
ParserBase* parser() const { return parser_; } |
Scanner* scanner() const { return parser_->scanner(); } |
@@ -915,6 +917,8 @@ class ParserBase : public Traits { |
void CheckProperty(Token::Value property, PropertyKind type, bool is_static, |
bool is_generator, bool* ok) override; |
+ void JustSignature() override; |
+ |
private: |
bool IsProto() { return this->scanner()->LiteralMatches("__proto__", 9); } |
@@ -930,6 +934,8 @@ class ParserBase : public Traits { |
void CheckProperty(Token::Value property, PropertyKind type, bool is_static, |
bool is_generator, bool* ok) override; |
+ void JustSignature() override; |
+ |
private: |
bool IsConstructor() { |
return this->scanner()->LiteralMatches("constructor", 11); |
@@ -1817,6 +1823,8 @@ ParserBase<Traits>::ParsePropertyDefinition( |
: FunctionKind::kBaseConstructor; |
type_flags = typesystem::kConstructorTypes; |
} |
+ // Allow signatures when in a class. |
+ if (in_class) type_flags |= typesystem::kAllowSignature; |
value = this->ParseFunctionLiteral( |
*name, scanner()->location(), kSkipFunctionNameCheck, kind, |
@@ -1824,6 +1832,16 @@ ParserBase<Traits>::ParsePropertyDefinition( |
language_mode(), type_flags, |
CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); |
+ // Return no property definition if just the signature was given. |
+ if (this->IsEmptyExpression(value)) { |
+ // Don't count constructor signature as a constructor. |
+ if (in_class && !is_static && this->IsConstructor(*name)) { |
+ // Note: we don't really need to unset has_seen_constructor |
+ checker->JustSignature(); |
+ } |
+ return this->EmptyObjectLiteralProperty(); |
+ } |
+ |
return factory()->NewObjectLiteralProperty(name_expression, value, |
ObjectLiteralProperty::COMPUTED, |
is_static, *is_computed_name); |
@@ -3815,6 +3833,16 @@ void ParserBase<Traits>::ClassLiteralChecker::CheckProperty( |
} |
+template <typename Traits> |
+void ParserBase<Traits>::ObjectLiteralChecker::JustSignature() {} |
+ |
+ |
+template <typename Traits> |
+void ParserBase<Traits>::ClassLiteralChecker::JustSignature() { |
+ has_seen_constructor_ = false; |
+} |
+ |
+ |
} // namespace internal |
} // namespace v8 |