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.
This commit is contained in:
Andreas Kling 2026-02-19 10:52:10 +01:00 committed by Jelle Raaijmakers
parent 6705bd187c
commit 5a7853099e
2 changed files with 10 additions and 2 deletions

View file

@ -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]

View file

@ -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]