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.
This commit is contained in:
@@ -1112,6 +1112,32 @@ fn codegen_js_inner(stmts: [Map<String, Any>], source: String, bundle_mode: Bool
|
|||||||
js_emit_blank()
|
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
|
// Pre-registration pass: scan all FnDefs for @async decorators so that
|
||||||
// forward calls to @async functions get `await` even if the callee is
|
// forward calls to @async functions get `await` even if the callee is
|
||||||
// defined after the caller.
|
// defined after the caller.
|
||||||
|
|||||||
Reference in New Issue
Block a user