1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 19:37:36 +00:00

LibJS: Remove is_use_strict_directive for all StringLiterals

This value was only used in the parser so no need to have this in every
string literal in the ast.
This commit is contained in:
davidot 2022-11-27 02:21:25 +01:00 committed by Linus Groh
parent 3c68a6684e
commit 3acbd96851
2 changed files with 4 additions and 9 deletions

View file

@ -1119,10 +1119,9 @@ private:
class StringLiteral final : public Literal { class StringLiteral final : public Literal {
public: public:
explicit StringLiteral(SourceRange source_range, String value, bool is_use_strict_directive = false) explicit StringLiteral(SourceRange source_range, String value)
: Literal(source_range) : Literal(source_range)
, m_value(move(value)) , m_value(move(value))
, m_is_use_strict_directive(is_use_strict_directive)
{ {
} }
@ -1131,13 +1130,11 @@ public:
virtual Bytecode::CodeGenerationErrorOr<void> generate_bytecode(Bytecode::Generator&) const override; virtual Bytecode::CodeGenerationErrorOr<void> generate_bytecode(Bytecode::Generator&) const override;
StringView value() const { return m_value; } StringView value() const { return m_value; }
bool is_use_strict_directive() const { return m_is_use_strict_directive; };
private: private:
virtual bool is_string_literal() const override { return true; } virtual bool is_string_literal() const override { return true; }
String m_value; String m_value;
bool m_is_use_strict_directive;
}; };
class NullLiteral final : public Literal { class NullLiteral final : public Literal {

View file

@ -462,6 +462,7 @@ bool Parser::parse_directive(ScopeNode& body)
{ {
bool found_use_strict = false; bool found_use_strict = false;
while (!done() && match(TokenType::StringLiteral)) { while (!done() && match(TokenType::StringLiteral)) {
auto raw_value = m_state.current_token.original_value();
// It cannot be a labelled function since we hit a string literal. // It cannot be a labelled function since we hit a string literal.
auto statement = parse_statement(AllowLabelledFunction::No); auto statement = parse_statement(AllowLabelledFunction::No);
body.append(statement); body.append(statement);
@ -472,8 +473,7 @@ bool Parser::parse_directive(ScopeNode& body)
if (!is<StringLiteral>(expression)) if (!is<StringLiteral>(expression))
break; break;
auto& string_literal = static_cast<StringLiteral const&>(expression); if (raw_value.is_one_of("'use strict'"sv, "\"use strict\"")) {
if (string_literal.is_use_strict_directive()) {
found_use_strict = true; found_use_strict = true;
if (m_state.string_legacy_octal_escape_sequence_in_scope) if (m_state.string_legacy_octal_escape_sequence_in_scope)
@ -1865,9 +1865,7 @@ NonnullRefPtr<StringLiteral> Parser::parse_string_literal(Token const& token, St
} }
} }
auto is_use_strict_directive = string_literal_type == StringLiteralType::Normal && (token.value() == "'use strict'" || token.value() == "\"use strict\""); return create_ast_node<StringLiteral>({ m_source_code, rule_start.position(), position() }, string);
return create_ast_node<StringLiteral>({ m_source_code, rule_start.position(), position() }, string, is_use_strict_directive);
} }
NonnullRefPtr<TemplateLiteral> Parser::parse_template_literal(bool is_tagged) NonnullRefPtr<TemplateLiteral> Parser::parse_template_literal(bool is_tagged)