diff --git a/Libraries/LibJS/Parser.cpp b/Libraries/LibJS/Parser.cpp index 1f0ee5f97ee..19d732079aa 100644 --- a/Libraries/LibJS/Parser.cpp +++ b/Libraries/LibJS/Parser.cpp @@ -4544,13 +4544,6 @@ void Parser::check_identifier_name_for_assignment_validity(DeprecatedFlyString c } } -bool Parser::match_with_clause() const -{ - if (m_state.current_token.original_value() == "with"sv) - return true; - return !m_state.current_token.trivia_contains_line_terminator() && m_state.current_token.original_value() == "assert"sv; -} - DeprecatedFlyString Parser::consume_string_value() { VERIFY(match(TokenType::StringLiteral)); @@ -4585,11 +4578,10 @@ ModuleRequest Parser::parse_module_request() ModuleRequest request { consume_string_value() }; - if (!match_with_clause()) + if (!match(TokenType::With)) return request; - VERIFY(m_state.current_token.original_value().is_one_of("with"sv, "assert"sv)); - consume(); + consume(TokenType::With); consume(TokenType::CurlyOpen); while (!done() && !match(TokenType::CurlyClose)) { diff --git a/Libraries/LibJS/Parser.h b/Libraries/LibJS/Parser.h index 4c484ded807..4a5bb2facba 100644 --- a/Libraries/LibJS/Parser.h +++ b/Libraries/LibJS/Parser.h @@ -225,7 +225,6 @@ private: bool match_secondary_expression(ForbiddenTokens forbidden = {}) const; bool match_statement() const; bool match_export_or_import() const; - bool match_with_clause() const; enum class AllowUsingDeclaration { No, diff --git a/Libraries/LibJS/Runtime/AbstractOperations.cpp b/Libraries/LibJS/Runtime/AbstractOperations.cpp index cf0d2eb9dc5..607514e1b3c 100644 --- a/Libraries/LibJS/Runtime/AbstractOperations.cpp +++ b/Libraries/LibJS/Runtime/AbstractOperations.cpp @@ -1699,11 +1699,11 @@ static bool all_import_attributes_supported(VM& vm, Vector cons return true; } +// 13.3.10.2 EvaluateImportCall ( specifierExpression [ , optionsExpression ] ), https://tc39.es/proposal-import-attributes/#sec-evaluate-import-call ThrowCompletionOr perform_import_call(VM& vm, Value specifier, Value options_value) { auto& realm = *vm.current_realm(); - // 13.3.10.2 EvaluateImportCall ( specifierExpression [ , optionsExpression ] ), https://tc39.es/proposal-import-attributes/#sec-evaluate-import-call // 1. Let referrer be GetActiveScriptOrModule(). auto referrer = [&]() -> ImportedModuleReferrer { auto active_script_or_module = vm.get_active_script_or_module(); @@ -1744,17 +1744,9 @@ ThrowCompletionOr perform_import_call(VM& vm, Value specifier, Value opti // c. IfAbruptRejectPromise(attributesObj, promiseCapability). auto attributes_obj = TRY_OR_REJECT_WITH_VALUE(vm, promise_capability, options_value.get(vm, vm.names.with)); - // d. Normative Optional, Deprecated - // 11. If the host supports the deprecated assert keyword for import attributes and attributesObj is undefined, then - if (attributes_obj.is_undefined()) { - // i. Set attributesObj to Completion(Get(options, "assert")). - // ii. IfAbruptRejectPromise(attributesObj, promiseCapability). - attributes_obj = TRY_OR_REJECT_WITH_VALUE(vm, promise_capability, options_value.get(vm, vm.names.assert)); - } - - // e. If attributesObj is not undefined, + // d. If attributesObj is not undefined, then if (!attributes_obj.is_undefined()) { - // i. If Type(attributesObj) is not Object, + // i. If Type(attributesObj) is not Object, then if (!attributes_obj.is_object()) { auto error = TypeError::create(realm, TRY_OR_THROW_OOM(vm, String::formatted(ErrorType::NotAnObject.message(), "ImportOptionsAssertions"))); // 1. Perform ! Call(promiseCapability.[[Reject]], undefined, « a newly created TypeError object »). @@ -1791,7 +1783,7 @@ ThrowCompletionOr perform_import_call(VM& vm, Value specifier, Value opti } } - // f. If AllImportAttributesSupported(attributes) is false, then + // e. If AllImportAttributesSupported(attributes) is false, then if (!all_import_attributes_supported(vm, attributes)) { auto error = TypeError::create(realm, TRY_OR_THROW_OOM(vm, String::formatted(ErrorType::NotAnObject.message(), "ImportOptionsAssertions"))); // i. Perform ! Call(promiseCapability.[[Reject]], undefined, « a newly created TypeError object »). @@ -1801,7 +1793,7 @@ ThrowCompletionOr perform_import_call(VM& vm, Value specifier, Value opti return Value { promise_capability->promise() }; } - // g. Sort attributes according to the lexicographic order of their [[Key]] fields, + // f. Sort attributes according to the lexicographic order of their [[Key]] fields, // treating the value of each such field as a sequence of UTF-16 code unit values. // NOTE: This sorting is observable only in that hosts are prohibited from // distinguishing among attributes by the order they occur in. diff --git a/Libraries/LibJS/Tests/modules/basic-modules.js b/Libraries/LibJS/Tests/modules/basic-modules.js index 1fa49198889..f28186c8524 100644 --- a/Libraries/LibJS/Tests/modules/basic-modules.js +++ b/Libraries/LibJS/Tests/modules/basic-modules.js @@ -179,8 +179,8 @@ describe("in- and exports", () => { ); }); - test("can import with (useless) assertions", () => { - expectModulePassed("./import-with-assertions.mjs"); + test("can import with (useless) attributes", () => { + expectModulePassed("./import-with-attributes.mjs"); }); test("namespace has expected ordering", () => { diff --git a/Libraries/LibJS/Tests/modules/import-with-assertions.mjs b/Libraries/LibJS/Tests/modules/import-with-assertions.mjs deleted file mode 100644 index bc19e3c5346..00000000000 --- a/Libraries/LibJS/Tests/modules/import-with-assertions.mjs +++ /dev/null @@ -1,4 +0,0 @@ -import * as self from "./import-with-assertions.mjs" assert { key: "value", key2: "value2", default: "shouldwork" }; -import "./import-with-assertions.mjs" assert { key: "value", key2: "value2", default: "shouldwork" }; - -export { passed } from "./module-with-default.mjs" assert { key: "value", key2: "value2", default: "shouldwork" }; diff --git a/Libraries/LibJS/Tests/modules/import-with-attributes.mjs b/Libraries/LibJS/Tests/modules/import-with-attributes.mjs new file mode 100644 index 00000000000..43d43b49a3d --- /dev/null +++ b/Libraries/LibJS/Tests/modules/import-with-attributes.mjs @@ -0,0 +1,4 @@ +import * as self from "./import-with-attributes.mjs" with { key: "value", key2: "value2", default: "shouldwork" }; +import "./import-with-attributes.mjs" with { key: "value", key2: "value2", default: "shouldwork" }; + +export { passed } from "./module-with-default.mjs" with { key: "value", key2: "value2", default: "shouldwork" }; diff --git a/Libraries/LibJS/Tests/modules/json-modules.js b/Libraries/LibJS/Tests/modules/json-modules.js index 2c4605e45a1..308fe0dcc33 100644 --- a/Libraries/LibJS/Tests/modules/json-modules.js +++ b/Libraries/LibJS/Tests/modules/json-modules.js @@ -4,7 +4,7 @@ describe("basic behavior", () => { let error = null; let result = null; - import("./json-module.json", { assert: { type: "json" } }) + import("./json-module.json", { with: { type: "json" } }) .then(jsonObj => { passed = true; result = jsonObj;