Skip to content

Commit

Permalink
handle default
Browse files Browse the repository at this point in the history
  • Loading branch information
borkdude committed Nov 19, 2024
1 parent d95ee4e commit dc9a0cd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"jotai": "^2.10.1",
"lodash": "^4.17.21",
"lodash-es": "^4.17.21",
"pg": "^8.13.1",
"playwright": "^1.26.1",
"prettier": "^2.7.1",
"react": "^18.2.0",
Expand Down
9 changes: 8 additions & 1 deletion src/squint/compiler_common.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,7 @@
[libname suffix] (str/split (if (string? libname) libname (str libname)) #"\$" 2)
[p & _props] (when suffix
(str/split suffix #"\."))
default? (and as (= "default" p))
as (when as (munge as))
expr (str
(when (and as (= "default" p))
Expand Down Expand Up @@ -565,11 +566,17 @@
merge (zipmap (vals rename) (keys rename)))))))
(let [munged-refers (map munge refer)]
(if *repl*
;; TODO handle default?
(str (statement (format "var { %s } = await import('%s')" (str/join ", " munged-refers) libname))
(str/join (map (fn [sym]
(statement (str "globalThis." (munge current-ns-name) "." sym " = " sym)))
munged-refers)))
(statement (format "import { %s } from '%s'" (str/join ", " (map munge refer)) libname))))))]

(if default?
(let [libname* ((:gensym env) "default")]
(str (statement (format "import %s from '%s'" libname* libname))
(statement (format "const { %s } = %s" (str/join ", " (map munge refer)) libname*))))
(statement (format "import { %s } from '%s'" (str/join ", " (map munge refer)) libname)))))))]
(when as
(swap! (:ns-state env)
(fn [ns-state]
Expand Down

0 comments on commit dc9a0cd

Please sign in to comment.