LibJS: Reject invalid bare private identifier usage
This commit is contained in:
parent
d6229a1cc8
commit
d8469c384d
1 changed files with 24 additions and 3 deletions
|
|
@ -215,7 +215,10 @@ impl Parser<'_> {
|
|||
// Yield/Await expressions don't participate in secondary expression
|
||||
// parsing (e.g. member access), but they DO participate in comma
|
||||
// expressions (e.g. `yield 1, yield 2`). Check for comma here.
|
||||
return self.parse_comma_expression(lhs_start, expression, min_precedence, forbidden);
|
||||
let expression =
|
||||
self.parse_comma_expression(lhs_start, expression, min_precedence, forbidden);
|
||||
self.report_invalid_private_identifier_usage(&expression);
|
||||
return expression;
|
||||
}
|
||||
|
||||
let expression = self.parse_tagged_template_literals(lhs_start, expression);
|
||||
|
|
@ -268,7 +271,10 @@ impl Parser<'_> {
|
|||
}
|
||||
}
|
||||
|
||||
self.parse_comma_expression(lhs_start, expression, min_precedence, forbidden)
|
||||
let expression =
|
||||
self.parse_comma_expression(lhs_start, expression, min_precedence, forbidden);
|
||||
self.report_invalid_private_identifier_usage(&expression);
|
||||
expression
|
||||
}
|
||||
|
||||
fn parse_comma_expression(
|
||||
|
|
@ -282,16 +288,25 @@ impl Parser<'_> {
|
|||
&& self.match_token(TokenType::Comma)
|
||||
&& forbidden.allows(TokenType::Comma)
|
||||
{
|
||||
self.report_invalid_private_identifier_usage(&expression);
|
||||
let mut expressions = vec![expression];
|
||||
while self.match_token(TokenType::Comma) {
|
||||
self.consume();
|
||||
expressions.push(self.parse_assignment_expression());
|
||||
let expression = self.parse_assignment_expression();
|
||||
self.report_invalid_private_identifier_usage(&expression);
|
||||
expressions.push(expression);
|
||||
}
|
||||
return self.expression(start, ExpressionKind::Sequence(expressions));
|
||||
}
|
||||
expression
|
||||
}
|
||||
|
||||
fn report_invalid_private_identifier_usage(&mut self, expression: &Expression) {
|
||||
if matches!(expression.inner, ExpressionKind::PrivateIdentifier(_)) {
|
||||
self.syntax_error("Private identifier must be followed by 'in'");
|
||||
}
|
||||
}
|
||||
|
||||
/// Parse a primary expression (literal, identifier, `this`, etc.).
|
||||
/// Returns `(expression, should_continue)` — `false` means the caller
|
||||
/// should not attempt to parse a secondary expression (e.g. arrow).
|
||||
|
|
@ -692,6 +707,10 @@ impl Parser<'_> {
|
|||
let start = self.position();
|
||||
let tt = self.current_token_type();
|
||||
|
||||
if matches!(lhs.inner, ExpressionKind::PrivateIdentifier(_)) && tt != TokenType::In {
|
||||
self.syntax_error("Private identifier must be followed by 'in'");
|
||||
}
|
||||
|
||||
match tt {
|
||||
// === Binary operators ===
|
||||
TokenType::Plus
|
||||
|
|
@ -1087,6 +1106,7 @@ impl Parser<'_> {
|
|||
Associativity::Right,
|
||||
ForbiddenTokens::none(),
|
||||
);
|
||||
self.report_invalid_private_identifier_usage(&expression);
|
||||
self.expression(
|
||||
start,
|
||||
ExpressionKind::Unary {
|
||||
|
|
@ -1106,6 +1126,7 @@ impl Parser<'_> {
|
|||
Associativity::Right,
|
||||
ForbiddenTokens::none(),
|
||||
);
|
||||
self.report_invalid_private_identifier_usage(&expression);
|
||||
if self.flags.strict_mode && Self::is_identifier(&expression) {
|
||||
self.syntax_error_at(
|
||||
"Delete of an unqualified identifier in strict mode.",
|
||||
|
|
|
|||
Loading…
Reference in a new issue