Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(277)

Unified Diff: src/parsing/parser-base.h

Issue 1853763002: Allow constructor and method signatures in classes (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@types-1849803002-intf-decl
Patch Set: Fix method type annotations in the preparser Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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
« no previous file with comments | « src/parsing/parser.h ('k') | src/parsing/preparser.h » ('j') | test/cctest/test-parsing.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698