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

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

Issue 1871923003: Add parsing for ambient declarations (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@types-devel
Patch Set: Minor fixes to address code review comments 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 f780b2966b4515c188cf4c410c40e6368943ef1f..ad4c22f3dab8741dbd95fa849297453b14057b78 100644
--- a/src/parsing/parser-base.h
+++ b/src/parsing/parser-base.h
@@ -74,8 +74,23 @@ struct FormalParametersBase {
// typedef PropertyList;
// typedef FormalParameter;
// typedef FormalParameters;
+// typedef Statement;
+// typedef StatementList;
// // For constructing objects returned by the traversing functions.
// typedef Factory;
+// // For classifying and validating expressions.
+// typedef ExpressionClassifier.
+// // A struct with extra types for the optional type system.
+// struct TypeSystem {
+// typedef Type;
+// typedef TypeList;
+// typedef TypeParameter;
+// typedef TypeParameters;
+// typedef FormalParameter;
+// typedef FormalParameters;
+// typedef TypeMember;
+// typedef TypeMembers;
+// };
// };
// // ...
// };
@@ -773,7 +788,8 @@ class ParserBase : public Traits {
ObjectLiteralPropertyT ParsePropertyDefinition(
ObjectLiteralCheckerBase* checker, bool in_class, bool has_extends,
bool is_static, bool* is_computed_name, bool* has_seen_constructor,
- ExpressionClassifier* classifier, IdentifierT* name, bool* ok);
+ ExpressionClassifier* classifier, IdentifierT* name, bool ambient,
+ bool* ok);
typename Traits::Type::ExpressionList ParseArguments(
Scanner::Location* first_spread_pos, ExpressionClassifier* classifier,
bool* ok);
@@ -1404,7 +1420,7 @@ ParserBase<Traits>::ParsePrimaryExpression(ExpressionClassifier* classifier,
}
return this->ParseClassLiteral(name, class_name_location,
is_strict_reserved_name,
- class_token_position, ok);
+ class_token_position, false, ok);
}
case Token::TEMPLATE_SPAN:
@@ -1679,7 +1695,8 @@ typename ParserBase<Traits>::ObjectLiteralPropertyT
ParserBase<Traits>::ParsePropertyDefinition(
ObjectLiteralCheckerBase* checker, bool in_class, bool has_extends,
bool is_static, bool* is_computed_name, bool* has_seen_constructor,
- ExpressionClassifier* classifier, IdentifierT* name, bool* ok) {
+ ExpressionClassifier* classifier, IdentifierT* name, bool ambient,
+ bool* ok) {
DCHECK(!in_class || is_static || has_seen_constructor != nullptr);
// Parse index member declarations in typed mode.
@@ -1837,6 +1854,7 @@ ParserBase<Traits>::ParsePropertyDefinition(
}
// Allow signatures when in a class.
if (in_class) type_flags |= typesystem::kAllowSignature;
+ if (ambient) type_flags |= typesystem::kAmbient;
value = this->ParseFunctionLiteral(
*name, scanner()->location(), kSkipFunctionNameCheck, kind,
@@ -1865,7 +1883,7 @@ ParserBase<Traits>::ParsePropertyDefinition(
*name = this->EmptyIdentifier();
ObjectLiteralPropertyT property = ParsePropertyDefinition(
checker, true, has_extends, true, is_computed_name, nullptr, classifier,
- name, ok);
+ name, ambient, ok);
Traits::RewriteNonPattern(classifier, ok);
return property;
}
@@ -1874,6 +1892,12 @@ ParserBase<Traits>::ParsePropertyDefinition(
// MethodDefinition (Accessors)
// get PropertyName '(' ')' '{' FunctionBody '}'
// set PropertyName '(' PropertySetParameterList ')' '{' FunctionBody '}'
+ if (ambient) {
+ *ok = false;
+ ReportMessage(MessageTemplate::kAmbientGetOrSet);
+ return this->EmptyObjectLiteralProperty();
+ }
+
*name = this->EmptyIdentifier();
bool dont_care = false;
name_token = peek();
@@ -1918,7 +1942,7 @@ ParserBase<Traits>::ParsePropertyDefinition(
}
USE(type); // TODO(nikolaos): really use it!
// Parse optional initializer.
- if (Check(Token::ASSIGN)) {
+ if (!ambient && Check(Token::ASSIGN)) {
ExpressionClassifier rhs_classifier(this);
ExpressionT rhs = this->ParseAssignmentExpression(
true, &rhs_classifier, CHECK_OK_CUSTOM(EmptyObjectLiteralProperty));
@@ -1963,7 +1987,7 @@ typename ParserBase<Traits>::ExpressionT ParserBase<Traits>::ParseObjectLiteral(
IdentifierT name = this->EmptyIdentifier();
ObjectLiteralPropertyT property = this->ParsePropertyDefinition(
&checker, in_class, has_extends, is_static, &is_computed_name, NULL,
- classifier, &name, CHECK_OK);
+ classifier, &name, false, CHECK_OK);
if (is_computed_name) {
has_computed_names = true;
« no previous file with comments | « src/parsing/parser.cc ('k') | src/parsing/preparser.h » ('j') | src/parsing/preparser.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698