Talk from IWST2025: Challenges of Transpiling Smalltalk to JavaScript
PDF: https://archive.esug.org/ESUG2025/iwst-day1/iwst-101-bour-dynamic-lang-transpilation.pdf
1. Challenges of
Transpiling Smalltalk to JavaScript
Noury Bouraqadi & Dave Mason
International Workshop on Smalltalk Technologies Gdansk, Poland; July 1st to 4th, 2025
3. Why Transpile Smalltalk to JavaScript?
ST
Simple & clean semantics
Rich IDE & core libraries
3
JS
Ubiquitous deployment
Performance
Large ecosystem
4. Why Transpile Smalltalk to JavaScript?
ST
Simple & clean semantics
Rich IDE & core libraries
4
Wednesday
July 2nd 2025
JS
Ubiquitous deployment
Performance
Large ecosystem
● ST + JS = Best of both worlds
● Smalltalk community interest in the Web/JavaScript
○ ESUG Main Track Talk Smalltalk for the Web
10. ○ Map Smalltalk’s syntax to JavaScript?
○ Map Smalltalk’s reflective kernel to JavaScript?
○ Handle Smalltalk dependencies with the runtime?
10
How to Transpile Smalltalk to JavaScript?
11. ○ Map Smalltalk’s syntax to JavaScript?
○ Map Smalltalk’s reflective kernel to JavaScript?
○ Handle Smalltalk dependencies with the runtime?
11
How to Transpile Smalltalk to JavaScript?
Empirical Study
based on
10 Year
experience with
12. ○ Map Smalltalk’s syntax to JavaScript?
○ Map Smalltalk’s reflective kernel to JavaScript?
○ Handle Smalltalk dependencies with the runtime?
12
How to Transpile Smalltalk to JavaScript?
Challenges Catalog
1. Primitive Types &
Literals
2. Messages
3. Block Closures
4. Classes
5. Reflection
Empirical Study
based on
10 Year
experience with
14. ● JS 𝑢𝑛𝑑𝑒𝑓𝑖𝑛𝑒𝑑 and 𝑛𝑢𝑙𝑙 are Not Objects.
● JS has an Impoverished Numeric Stack.
● ST Automatically Converts
○ Between Small Integers & Large Ones.
● ST Supports Fixed-Point Arithmetic.
● ST has Literal Symbols.
14
Challenges: Primitive Types and Literals
15. ● JS has a 𝑆𝑦𝑚𝑏𝑜𝑙 class, but:
○ No literal symbols
■ Simple to fix
● Map ST symbols to instances of JS Symbol
○ JS Symbol class is not related to String!
■ Complex to fix
● Make Symbol subclass of String
○ Side-effects?
● Override some String methods
15
Example: ST Literal Symbols
16. ● Non-Alphanumeric Characters in ST Message Selectors
● JS Math-Like Message Priorities
● ST Message Cascading
16
Challenges: Messages
17. ● Simple to fix:
○ Replace non-alphanumeric characters with their Ascii code
○ ST keyword selectors: 1 string concatenating keywords
● Complex to fix: None
17
Example: Non-Alphanumeric Characters in Selectors
18. Smalltalk Blocks:
● Always Bind the Outer Context
● Always Answer Some Value
● Support Non-Local Returns
18
Challenges: Block Closures
19. ● Simple to fix: ST blocks always answer some value
○ ST result := [123]
○ JS result = () =>{return 123}
● Complex to fix: ST blocks support non-local returns
○ ST condition ifTrue: [^123]
○ JS rely on exceptions
19
Example: Block Returns
20. ● Class Variables
● Pool Variables
● Class Extensions
● Stateful Traits
20
Challenges: ST Classes - 1
21. ● Class Initialization & Startup/Shutdown Lists
● Methods Always Have a Return Value
● Methods can Have Pragmas
○ Primitive Pragmas Refer to the Virtual Machine
21
Challenges: ST Classes - 2
22. ● Simple to fix: Class Variables
○ JS Classes are objects with attributes
○ JS encapsulation is optional
class A{
anInstanceMethod(){
x = A.someClassVariable + 42; }
}
A.someClassVariable = 37;
22
Examples - 1
23. ● Complex to fix: Pragmas such as #primitive:
○ Implement the primitive behavior
23
Examples - 2
24. ● ST Reifies Messages Upon Handling Type Errors
● ST Reifies Execution Contexts
● ST and JS have different solutions for Intercepting
Method Evaluation
● Pharo ST Reifies Slots
● Pharo ST classes define Object Format/Layout
24
Challenges: Reflection
25. ● Simple to fix: ST DNU Reifies Messages
○ Extend JS Object with
■ doesNotUnderstand() method
■ default methods for every sent message in ST Code
Object.prototype.zork = function(arg1, arg2){
return this.doesNotUnderstand(“zork”, arguments)}
25
Examples - 1
26. ● Complex to fix: ST Reifies Execution Contexts
○ ST thisContext
26
Examples
27. Smalltalk & JavaScript
100% semantic equivalence
via transpilation is
difficult if not impossible!
27
Conclusion
28. ● Some challenges are “easy” to address
○ Primitive Types & Literals,
○ Messages,
○ Block Closures
● Several ST capabilities are complex to implement in JS
○ Primitives,
○ thisContext,
○ Reified Slots…
28
Conclusion: Not all challenges are equal
29. ● Beyond Transpilation
○ ST and JS Run-time interoperability (Production)
○ Live-coding with JS objects from the ST (Development)
○ Reuse JS libraries (code + globals) in code transcribed from ST
○ Transpile ST to produce JS libraries for 3rd parties.
● Methodology?
○ Generalizable to other language pairs? Smalltalk & Python?
29
Future Work
30. Develop in Pharo, Run on JavaScript
PharoJS.org
Kindly Supported by
Thanks to all the contributors!
M
IT
License
31. Challenges of
Transpiling Smalltalk to JavaScript
Noury Bouraqadi & Dave Mason
International Workshop on Smalltalk Technologies Gdansk, Poland; July 1st to 4th, 2025