TMS WEB Core 3.0.4.0, pas2js 3.3.1, Delphi 13.
I want to report something that cost us a production failure, while acknowledging up front that the underlying behaviour is documented.
With the project optimisation level set to 2 (whole-program optimisation), pas2js removes any declaration it cannot find a Pascal reference to. The documentation says that asm blocks are not analysed, so a method that is only called from inside an asm block counts as unreferenced. We had exactly that: an event handler bound in an asm block that called a Pascal method on the object. Debug builds work. The release build drops the method, and the first click on live fails with "LSelf.Dispatch_Action is not a function".
I accept that the asm-to-Pascal call was our mistake and that the limitation is documented. What I would like to raise as a bug is that the failure is completely silent:
- The compiler sees the asm block and could at least warn that identifiers inside it are not tracked, or scan it for identifiers that match declarations in scope and keep those.
- There is no hint or warning that a method was removed by the optimiser.
- The debug and release builds behave differently with no compile-time indication, so the problem only surfaces in production.
A hint along the lines of "method X is referenced only inside asm blocks and will be removed by optimisation level 2" would have caught this at build time. Even a simple rule, keeping any declaration whose name appears as a token inside an asm block in the same unit, would make the optimiser safe by default at a small size cost.
Is this something you would consider addressing in TMS WEB Core, or should I take it upstream to pas2js?