-
-
Notifications
You must be signed in to change notification settings - Fork 171
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ESM files used in a shadow-cljs project have its property-renamed under advanced optimization #1085
Comments
It is fully intended that the properties get renamed. Since it goes through the same The problem in a nutshell however is that So, the problem here isn't so much that Well, you could write Unfortunately there is no toggle in the Closure Compiler to tell it to not rename properties in certain files. It is either all or nothing. If you prefer nothing you can rewrite the file as CommonJS. CommonJS is processed like It sucks, but I have no easy solution other then turning off renaming completely. Or maybe collecting all property names in JS files and automatically adding them to externs, which still would make builds larger than they probably should be. |
Thanks for the reply! In the GCC source I think the relevant code for props renaming is here: https://github.com/google/closure-compiler/blob/v20230103/src/com/google/javascript/jscomp/RenameProperties.java#L292-L374 , and as you mentioned, it doesn't expose any interface to skip a single file. Looks like the only way to have the good of both worlds (esm & advanced optization) is to modify this file, and place it in the project classpath to shadow the original implementation. |
Another issue since we're here: When doing release build, GCC would warn about the ESM module variable is undeclared, which could be confusing:
Any idea how to hide these? |
Hmm never seen this. I guess is that it is |
I just tried build config: :app-esm {:target :esm
:modules {:main {:exports {go app.main/go}}}
:dev {:output-dir "output/dev-esm"}
:release {:output-dir "output/release-esm"
:compiler-options {:optimizations :advanced
:pretty-print true
:pseudo-names true}
}} cljs source ;; src/app/main.cljs
(ns app.main
(:require ["/app/util_esm.js" :as ESM]))
(ESM/callDogBark #js {:bark (fn []
(println "Bark from ESM!"))} 1)
(defn go []
(js/console.log "Go ESM!")) Dev build output: // output/dev-esm/cljs-runtime/app.main.js
import "./cljs_env.js";
goog.provide("app.main");
module$app$util_esm.callDogBark(
{
bark: function () {
return cljs.core.println.cljs$core$IFn$_invoke$arity$variadic(
cljs.core.prim_seq.cljs$core$IFn$_invoke$arity$2(["Bark from ESM!"], 0)
);
},
},
1
);
app.main.go = function app$main$go() {
return console.log("Go ESM!");
}; Apparently the variable However the release build is fine though . |
I think I somehow get it. The So files under I think it would be useful to support |
Yes, for dev builds the "ESM" is a bit hacked together. So that REPL and hot-reload still work. release builds looks entirely different. Are you saying that |
Issue Decription
ESM files used in a shadow-cljs project have its property-renamed.
Ofc this is fix-able by using an externs file. But it's cumbersome to add lots of externs. Ideally this shall work out of the box without any externs files.
Repro
Dev build runs fine:
Relese build fails due to the renaming:
From the output we can tell that
bark
is renamed to$bark$
. If we turn off:pseudo-names true
it would be renamed to shorter names likeNb
.I've created a simple repro project in this repo for easier local reproduction.
The text was updated successfully, but these errors were encountered: