shadow-cljs

p-himik 2026-05-11T22:04:11.496779Z

I think I might've found a bug in either GCC or shadow-cljs, don't know how to proceed efficiently. Trying to use https://github.com/opensheetmusicdisplay/opensheetmusicdisplay. Added the simplest (:require ["opensheetmusicdisplay" :as osmd]), got shouted at in the JS console:

Failed to load node_modules/opensheetmusicdisplay/build/opensheetmusicdisplay.min.js SyntaxError: Identifier 't' has already been declared (at module$node_modules$opensheetmusicdisplay$build$opensheetmusicdisplay_min.js:27946:96)
    at eval (<anonymous>)
    at goog.globalEval (main.js:455:11)
The offending location has this:
const b = {path:{x:!0, y:!0, width:!0, height:!0}, rect:{}, text:{width:!0, height:!0}}, t = {"font-family":!0, "font-weight":!0, "font-style":!0, "font-size":!0};
t is probably defined somewhere above, got lost scrolling. However, if I find the same location in node_modules/opensheetmusicdisplay/build/opensheetmusicdisplay.min.js manually, it has this:
const b={path:{x:!0,y:!0,width:!0,height:!0},rect:{},text:{width:!0,height:!0}};{const t={"font-family":!0,"font-weight":!0,"font-style":!0,"font-size":!0};s.Merge(b.rect,t),s.Merge(b.path,t)}
Notice the extra {...} around const t=.... No clue what could've removed the surrounding {...} while building. Tried reproducing with a JS file that's a part of the project - braces remained intact. Tried creating a small JS file inside the same NPM module - same thing, braces remained intact. So, so far it happens only with opensheetmusicdisplay.min.js and I don't know why.

thheller 2026-05-12T05:50:35.527689Z

yeah gcc is something a bit confused about variable scoping

thheller 2026-05-12T05:51:09.452219Z

you could try the latest gcc and see if it still happens. requires a bit manual extra work though since the current cljs release is not compatible

p-himik 2026-05-12T10:21:51.969209Z

That actually worked!

p-himik 2026-05-12T10:22:02.692899Z

Or at least it seems so.

p-himik 2026-05-12T10:58:05.576269Z

Just something I noticed in passing in your code:

;; (0,window.require)("react") // FIXME: why the 0,?
Seems it's because RescopeGlobalSymbols is generic and doesn't care that it's require, and it rewrites all f() into (0, NS.f)() to preserve how this works.