diff --git a/Userland/Libraries/LibJS/AST.h b/Userland/Libraries/LibJS/AST.h index d08b78dbae..123905d6d8 100644 --- a/Userland/Libraries/LibJS/AST.h +++ b/Userland/Libraries/LibJS/AST.h @@ -1119,10 +1119,9 @@ private: class StringLiteral final : public Literal { public: - explicit StringLiteral(SourceRange source_range, String value, bool is_use_strict_directive = false) + explicit StringLiteral(SourceRange source_range, String value) : Literal(source_range) , m_value(move(value)) - , m_is_use_strict_directive(is_use_strict_directive) { } @@ -1131,13 +1130,11 @@ public: virtual Bytecode::CodeGenerationErrorOr generate_bytecode(Bytecode::Generator&) const override; StringView value() const { return m_value; } - bool is_use_strict_directive() const { return m_is_use_strict_directive; }; private: virtual bool is_string_literal() const override { return true; } String m_value; - bool m_is_use_strict_directive; }; class NullLiteral final : public Literal { diff --git a/Userland/Libraries/LibJS/Parser.cpp b/Userland/Libraries/LibJS/Parser.cpp index 0baff40228..8e41d8882f 100644 --- a/Userland/Libraries/LibJS/Parser.cpp +++ b/Userland/Libraries/LibJS/Parser.cpp @@ -462,6 +462,7 @@ bool Parser::parse_directive(ScopeNode& body) { bool found_use_strict = false; 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. auto statement = parse_statement(AllowLabelledFunction::No); body.append(statement); @@ -472,8 +473,7 @@ bool Parser::parse_directive(ScopeNode& body) if (!is(expression)) break; - auto& string_literal = static_cast(expression); - if (string_literal.is_use_strict_directive()) { + if (raw_value.is_one_of("'use strict'"sv, "\"use strict\"")) { found_use_strict = true; if (m_state.string_legacy_octal_escape_sequence_in_scope) @@ -1865,9 +1865,7 @@ NonnullRefPtr 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({ m_source_code, rule_start.position(), position() }, string, is_use_strict_directive); + return create_ast_node({ m_source_code, rule_start.position(), position() }, string); } NonnullRefPtr Parser::parse_template_literal(bool is_tagged)