summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibJS
diff options
context:
space:
mode:
authorLinus Groh <mail@linusgroh.de>2021-05-10 11:56:08 +0100
committerLinus Groh <mail@linusgroh.de>2021-05-10 11:57:35 +0100
commitc93c2dc72c8fc9c90d372c4e785c48b170543228 (patch)
treefcbd7a912e4bbd18ef89e544d9523e905a1af977 /Userland/Libraries/LibJS
parentd1a72dc6ebe2d9a7146056b12d3bd1be1f338762 (diff)
downloadserenity-c93c2dc72c8fc9c90d372c4e785c48b170543228.zip
LibJS: Rename RegExpLiteral m_content to m_pattern
This is what we call it elsewhere, let's be consistent.
Diffstat (limited to 'Userland/Libraries/LibJS')
-rw-r--r--Userland/Libraries/LibJS/AST.cpp4
-rw-r--r--Userland/Libraries/LibJS/AST.h10
-rw-r--r--Userland/Libraries/LibJS/Parser.cpp8
3 files changed, 12 insertions, 10 deletions
diff --git a/Userland/Libraries/LibJS/AST.cpp b/Userland/Libraries/LibJS/AST.cpp
index c3a1b7b5ae..cae3974539 100644
--- a/Userland/Libraries/LibJS/AST.cpp
+++ b/Userland/Libraries/LibJS/AST.cpp
@@ -1791,13 +1791,13 @@ Value NullLiteral::execute(Interpreter& interpreter, GlobalObject&) const
void RegExpLiteral::dump(int indent) const
{
print_indent(indent);
- outln("{} (/{}/{})", class_name(), content(), flags());
+ outln("{} (/{}/{})", class_name(), pattern(), flags());
}
Value RegExpLiteral::execute(Interpreter& interpreter, GlobalObject& global_object) const
{
InterpreterNodeScope node_scope { interpreter, *this };
- return RegExpObject::create(global_object, content(), flags());
+ return RegExpObject::create(global_object, pattern(), flags());
}
void ArrayExpression::dump(int indent) const
diff --git a/Userland/Libraries/LibJS/AST.h b/Userland/Libraries/LibJS/AST.h
index e307e08ead..5d6f472f29 100644
--- a/Userland/Libraries/LibJS/AST.h
+++ b/Userland/Libraries/LibJS/AST.h
@@ -658,21 +658,21 @@ public:
class RegExpLiteral final : public Literal {
public:
- explicit RegExpLiteral(SourceRange source_range, String content, String flags)
+ explicit RegExpLiteral(SourceRange source_range, String pattern, String flags)
: Literal(move(source_range))
- , m_content(content)
- , m_flags(flags)
+ , m_pattern(move(pattern))
+ , m_flags(move(flags))
{
}
virtual Value execute(Interpreter&, GlobalObject&) const override;
virtual void dump(int indent) const override;
- const String& content() const { return m_content; }
+ const String& pattern() const { return m_pattern; }
const String& flags() const { return m_flags; }
private:
- String m_content;
+ String m_pattern;
String m_flags;
};
diff --git a/Userland/Libraries/LibJS/Parser.cpp b/Userland/Libraries/LibJS/Parser.cpp
index 2132c20315..6dc8eb163e 100644
--- a/Userland/Libraries/LibJS/Parser.cpp
+++ b/Userland/Libraries/LibJS/Parser.cpp
@@ -1,6 +1,6 @@
/*
* Copyright (c) 2020, Stephan Unverwerth <s.unverwerth@gmx.de>
- * Copyright (c) 2020, Linus Groh <linusg@serenityos.org>
+ * Copyright (c) 2020-2021, Linus Groh <linusg@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@@ -683,9 +683,11 @@ NonnullRefPtr<Expression> Parser::parse_primary_expression()
NonnullRefPtr<RegExpLiteral> Parser::parse_regexp_literal()
{
auto rule_start = push_start();
- auto content = consume().value();
+ auto pattern = consume().value();
+ // Remove leading and trailing slash.
+ pattern = pattern.substring_view(1, pattern.length() - 2);
auto flags = match(TokenType::RegexFlags) ? consume().value() : "";
- return create_ast_node<RegExpLiteral>({ m_parser_state.m_current_token.filename(), rule_start.position(), position() }, content.substring_view(1, content.length() - 2), flags);
+ return create_ast_node<RegExpLiteral>({ m_parser_state.m_current_token.filename(), rule_start.position(), position() }, pattern, flags);
}
NonnullRefPtr<Expression> Parser::parse_unary_prefixed_expression()