mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-01-22 09:12:13 -05:00
LibJS: Do not consume "with" tokens in import statements as identifiers
The "with" statement is its own token (TokenType::With), and thus would fail to parse as an identifier. We've already asserted that the token we are parsing is "with" or "assert", so just consume it.
This commit is contained in:
parent
2c3077d929
commit
47ba231a9b
Notes:
github-actions[bot]
2025-01-21 13:59:36 +00:00
Author: https://github.com/trflynn89 Commit: https://github.com/LadybirdBrowser/ladybird/commit/47ba231a9b3 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/3324
3 changed files with 37 additions and 2 deletions
|
@ -4589,7 +4589,7 @@ ModuleRequest Parser::parse_module_request()
|
|||
return request;
|
||||
|
||||
VERIFY(m_state.current_token.original_value().is_one_of("with"sv, "assert"sv));
|
||||
consume(TokenType::Identifier);
|
||||
consume();
|
||||
consume(TokenType::CurlyOpen);
|
||||
|
||||
while (!done() && !match(TokenType::CurlyClose)) {
|
||||
|
|
2
Libraries/LibJS/Tests/modules/json-module.mjs
Normal file
2
Libraries/LibJS/Tests/modules/json-module.mjs
Normal file
|
@ -0,0 +1,2 @@
|
|||
import json from "./json-module.json" with { type: "json" };
|
||||
export default json;
|
|
@ -1,5 +1,5 @@
|
|||
describe("basic behavior", () => {
|
||||
test("can import json modules", () => {
|
||||
test("can import json modules (with import function)", () => {
|
||||
let passed = false;
|
||||
let error = null;
|
||||
let result = null;
|
||||
|
@ -31,4 +31,37 @@ describe("basic behavior", () => {
|
|||
expect(jsonResult).toHaveProperty("array", [1, 2, 3]);
|
||||
expect(jsonResult).toHaveProperty("map", { innerValue: "innerValue" });
|
||||
});
|
||||
|
||||
test("can import json modules (with import statement)", () => {
|
||||
let passed = false;
|
||||
let error = null;
|
||||
let result = null;
|
||||
|
||||
import("./json-module.mjs")
|
||||
.then(jsonObj => {
|
||||
passed = true;
|
||||
result = jsonObj;
|
||||
})
|
||||
.catch(err => {
|
||||
error = err;
|
||||
});
|
||||
|
||||
runQueuedPromiseJobs();
|
||||
|
||||
if (error) throw error;
|
||||
|
||||
console.log(JSON.stringify(result));
|
||||
expect(passed).toBeTrue();
|
||||
|
||||
expect(result).not.toBeNull();
|
||||
expect(result).not.toBeUndefined();
|
||||
|
||||
const jsonResult = result.default;
|
||||
expect(jsonResult).not.toBeNull();
|
||||
expect(jsonResult).not.toBeUndefined();
|
||||
|
||||
expect(jsonResult).toHaveProperty("value", "value");
|
||||
expect(jsonResult).toHaveProperty("array", [1, 2, 3]);
|
||||
expect(jsonResult).toHaveProperty("map", { innerValue: "innerValue" });
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue