From a65ce33fabb44bb2d9ed04773f7f334ed9c9a6b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Sun, 27 Feb 2022 14:38:45 +0100 Subject: feat(compat): CJS/ESM interoperability (#13553) This commit adds CJS/ESM interoperability when running in --compat mode. Before executing files, they are analyzed and all CommonJS modules are transformed on the fly to a ES modules. This is done by utilizing analyze_cjs() functionality from deno_ast. After discovering exports and reexports, an ES module is rendered and saved in memory for later use. There's a caveat that all files ending with ".js" extension are considered as CommonJS modules (unless there's a related "package.json" with "type": "module"). --- cli/tests/integration/compat_tests.rs | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'cli/tests/integration') diff --git a/cli/tests/integration/compat_tests.rs b/cli/tests/integration/compat_tests.rs index 189e1eb41..c8fc1c0a0 100644 --- a/cli/tests/integration/compat_tests.rs +++ b/cli/tests/integration/compat_tests.rs @@ -95,6 +95,12 @@ itest!(compat_worker { output: "compat/worker/worker_test.out", }); +itest!(cjs_esm_interop { + args: + "run --compat --unstable -A --quiet --no-check compat/import_cjs_from_esm/main.mjs", + output: "compat/import_cjs_from_esm.out", +}); + #[test] fn globals_in_repl() { let (out, _err) = util::run_and_collect_output_with_args( -- cgit v1.2.3