From 70408304700540e2f25a8b45126d5b918a60a428 Mon Sep 17 00:00:00 2001 From: Will Anderson Date: Mon, 4 May 2026 11:01:36 -0500 Subject: [PATCH] codegen-js: URL import declarations for JS modules import "https://cdn.example.com/lib.js" now emits: - module mode: import "https://..." at the top of the generated file - bundle/IIFE mode: // external: https://... comment El source imports (.el files) are excluded -- they were already inlined by resolve_imports before codegen. Any import path that doesn't end in .el or starts with http(s):// is treated as an external JS dependency. --- el-compiler/src/codegen-js.el | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/el-compiler/src/codegen-js.el b/el-compiler/src/codegen-js.el index f0de87a..876bf9a 100644 --- a/el-compiler/src/codegen-js.el +++ b/el-compiler/src/codegen-js.el @@ -1112,6 +1112,32 @@ fn codegen_js_inner(stmts: [Map], source: String, bundle_mode: Bool js_emit_blank() } + // URL import pass: emit `import "url"` (module mode) or a comment + // (bundle mode) for any import whose path starts with http(s):// or + // doesn't end in .el (i.e., it's a JS/CSS/CDN import, not an El source + // import which was already inlined by resolve_imports). + let n: Int = native_list_len(stmts) + let i = 0 + while i < n { + let stmt = native_list_get(stmts, i) + let sk: String = stmt["stmt"] + if str_eq(sk, "Import") { + let ipath: String = stmt["path"] + let is_url = str_starts_with(ipath, "http://") + let is_url = is_url || str_starts_with(ipath, "https://") + let is_js = !str_ends_with(ipath, ".el") + if is_url || is_js { + if bundle_mode { + js_emit_line("// external: " + ipath) + } else { + js_emit_line("import " + js_str_lit(ipath) + ";") + } + } + } + let i = i + 1 + } + js_emit_blank() + // Pre-registration pass: scan all FnDefs for @async decorators so that // forward calls to @async functions get `await` even if the callee is // defined after the caller.