Fork me on GitHub
#shadow-cljs
<
2023-02-17
>
Roman Liutikov19:02:35

Does shadow perform any sort of dead code elimination for JS files? I have a JS file which exports a bunch of strings

export const a = "asdb";
export const b = "alksdj"
export const c = "lkajsd"
And then used in cljs
(ns app.core
  (:require ["./file" :as f]))

(prn f/a)
I'd expect non-used vars from JS file to be removed from the output after advanced compilation. IIRC shadow transforms JS differently, but it's surprising that such a simple case is not handled

thheller06:02:28

ESM code included like that go through :advanced. so the gcc should remove b+c here?

thheller06:02:20

haven't verified that in a while though. goog.module files are similar and more reliable when it comes to DCE

thheller06:02:36

goog.module("your.ns")
exports.a = "a";
exports.b = "b";
exports.c = "c";
and (:require [your.ns :as foo]) in the CLJS code

thheller07:02:21

hmm just did a quick check. looks like there are indeed not eliminated, not sure why

Roman Liutikov09:02:32

I've tried it again with the above minimal example (ESM) in a fresh project, seems to be removing unused exports. But in a project at work it doesn't work.

thheller10:02:16

the ESM integration has always been a bit of a hack since it never was an official google compiler feature mixing them. it supports ESM fine but mixing ESM with closure code has issues

thheller10:02:29

not sure its because of that or just shadow missing something

thheller10:02:50

could be externs related. ie. in the above if any externs for b or c exist that may prevent the removal

2