-
-
Notifications
You must be signed in to change notification settings - Fork 666
Limitations
dcodeIO edited this page Mar 2, 2018
·
14 revisions
Compiling untyped JavaScript to WebAssembly doesn't make sense because it would ultimately result in shipping another (slower) JavaScript runtime that runs within a JavaScript runtime.
Instead, AssemblyScript focuses on where WebAssembly excels and does not support falling back to super dynamic features of JavaScript that cannot be efficiently compiled ahead of time:
- No
any
orundefined
. - No union types.
- Nullable types must be reference types, annotated as
ClassType | null
.
-
If there is no initializer expression, the type must be annotated.
-
If there is an initializer expression:
- If the initializer is an integer literal,
i32
is assumed when it fits into 32-bits, otherwisei64
is assumed. - If the initializer is a float literal,
f64
is assumed. - Otherwise the initializer is evaluated to obtain its type.
- If the initializer is an integer literal,
- Optional function parameters require an initializer
-
const
globals and locals require a compile-time constant initializer and otherwise fall back to a mutable variable. - In JavaScript, static fields on classes are always evaluated when defined, whereas in AssemblyScript, built-in tree shaking lazily compiles static fields when referenced.
See also: Status / Roadmap