From 5a7853099e757d85171d226d7c4491ab79b8a92b Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Thu, 19 Feb 2026 10:52:10 +0100 Subject: [PATCH] LibJS: Support .mjs files in test-js-ast and test-js-bytecode Automatically pass --as-module to the js binary when the test input file has a .mjs extension. This allows us to write AST and bytecode tests for module-only syntax like import and export statements. --- Tests/LibJS/test-js-ast.py | 6 +++++- Tests/LibJS/test-js-bytecode.py | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/Tests/LibJS/test-js-ast.py b/Tests/LibJS/test-js-ast.py index fc2fdefde8..0bdedc365a 100755 --- a/Tests/LibJS/test-js-ast.py +++ b/Tests/LibJS/test-js-ast.py @@ -55,6 +55,8 @@ def test(file: Path, rebaseline: bool) -> bool: "--dump-ast", "--parse-only", ] + if file.suffix == ".mjs": + args.append("--as-module") process = subprocess.run(args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) stdout = process.stdout.decode().strip() @@ -96,7 +98,9 @@ def main() -> int: input_dir = AST_TEST_DIR / "input" failed = 0 - js_files = [js_file for js_file in sorted(input_dir.iterdir()) if js_file.is_file() and js_file.suffix == ".js"] + js_files = [ + js_file for js_file in sorted(input_dir.iterdir()) if js_file.is_file() and js_file.suffix in (".js", ".mjs") + ] with ThreadPoolExecutor(max_workers=args.jobs) as executor: executables = [executor.submit(test, js_file.relative_to(input_dir), args.rebaseline) for js_file in js_files] diff --git a/Tests/LibJS/test-js-bytecode.py b/Tests/LibJS/test-js-bytecode.py index ed2737b5b0..de43e2f90b 100755 --- a/Tests/LibJS/test-js-bytecode.py +++ b/Tests/LibJS/test-js-bytecode.py @@ -65,6 +65,8 @@ def test(file: Path) -> bool: # TODO: allow for dumping bytecode without running script # "--parse-only", ] + if file.suffix == ".mjs": + args.append("--as-module") process = subprocess.run(args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) stdout = process.stdout.decode().strip() @@ -111,7 +113,9 @@ def main() -> int: input_dir = BYTECODE_TEST_DIR / "input" failed = 0 - js_files = [js_file for js_file in sorted(input_dir.iterdir()) if js_file.is_file() and js_file.suffix == ".js"] + js_files = [ + js_file for js_file in sorted(input_dir.iterdir()) if js_file.is_file() and js_file.suffix in (".js", ".mjs") + ] with ThreadPoolExecutor(max_workers=args.jobs) as executor: executables = [executor.submit(test, js_file.relative_to(input_dir)) for js_file in js_files]