Dotty hook for compiler-magic Embed function #25136
Replies: 3 comments 3 replies
-
|
According to AI, it's not possible to implement this without compiler hooks, as re-type-checking a mutated node and then outputing .class files isn't possible. |
Beta Was this translation helpful? Give feedback.
-
|
@odersky @nicolasstucki @smarter @liufengyun Sorry for tagging, but I think this feature needs to be at dotty. |
Beta Was this translation helpful? Give feedback.
-
|
can you explain why this can't be implemented via an ordinary macro call? for example that could even open a unix domain socket to a known location that the build tool also communicates through? Or there are post-type checking compiler plugin option that can generate arbitrary code |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Basically in Vite.js you can
import, say, PNGs, and the bundler will decide whether to externalize the resource (e.g. return a URL pointing to an externally-loaded PNG) or to return adata:URL that is embedded in the program (e.g. if the file is too short).Although, in actual TypeScript this is kind of boring as there is no
import.sync()there for inline usage.The motivation is that resources (as in
src/resources) will both, e.g. appear in the Scala.js bundle (so it can accumulate a lot of heavy icon bitmaps (in case they use skeumorphic design and not SVGs (I know, gradients may help, but those may be a little more complex))). and will also be loaded inconditionally.https://sweaxizone.github.io/newscala/help/manual/embed.html
In Scala I wanted something like an
Embed("flower.webp")expression, and also extra syntaxes for other use-cases like embedding resources normally (text or octet stream, at the entire-program-lifetime and at the .class/JAR/.js) as an extra convenience compared tosrc/resources.Also, I know, I know; Next.js's default
importdoes blur optimization so that resulting modules aren't URLs but objects containing a regular source and a blurry source (for preview purposes). I don't know if this is important at all, but in any case, there could be another syntax for this in the future...Beta Was this translation helpful? Give feedback.
All reactions