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.