mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 03:37:43 +00:00
LibJS: Lookahead for a period when parsing new.target
This allows us to skip saving and loading the state whenever we parse 'new'.
This commit is contained in:
parent
4d7e79fb72
commit
73eb29dabe
1 changed files with 5 additions and 3 deletions
|
@ -851,6 +851,10 @@ RefPtr<Statement> Parser::try_parse_labelled_statement(AllowLabelledFunction all
|
||||||
|
|
||||||
RefPtr<MetaProperty> Parser::try_parse_new_target_expression()
|
RefPtr<MetaProperty> Parser::try_parse_new_target_expression()
|
||||||
{
|
{
|
||||||
|
// Optimization which skips the save/load state.
|
||||||
|
if (next_token().type() != TokenType::Period)
|
||||||
|
return {};
|
||||||
|
|
||||||
save_state();
|
save_state();
|
||||||
auto rule_start = push_start();
|
auto rule_start = push_start();
|
||||||
ArmedScopeGuard state_rollback_guard = [&] {
|
ArmedScopeGuard state_rollback_guard = [&] {
|
||||||
|
@ -858,9 +862,7 @@ RefPtr<MetaProperty> Parser::try_parse_new_target_expression()
|
||||||
};
|
};
|
||||||
|
|
||||||
consume(TokenType::New);
|
consume(TokenType::New);
|
||||||
if (!match(TokenType::Period))
|
consume(TokenType::Period);
|
||||||
return {};
|
|
||||||
consume();
|
|
||||||
if (!match(TokenType::Identifier))
|
if (!match(TokenType::Identifier))
|
||||||
return {};
|
return {};
|
||||||
// The string 'target' cannot have escapes so we check original value.
|
// The string 'target' cannot have escapes so we check original value.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue