-
Notifications
You must be signed in to change notification settings - Fork 12.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Constant / compile-time-only functions #26534
Comments
This proposal does depend on the type of function ( |
I stand corrected. Proposal updated. |
We don't ever do type directed emit, nor do we want to add additional expression-altering syntax ( |
The main reason for this proposal was that all other build chain tools like Uglify, WebPack etc. are not TypeScript-aware. They use the output from the TS-compiler and generate less efficient and optimized code than would be possible if they were TypeScript aware. Looks like I have to build or find a pre-compiler... Off topic: I use |
https://github.com/Morglod/tsts Currently working on comptime transformer const numbers = [ 1, 2, 3, 4, 5, 6, 7, 8 ];
const result = comptime(() => {
return numbers.reduce((total, x) => sum(total, x), 0);
}); to const result = (() => { return (36); })(); |
Search Terms
const compiler keyword functions
Suggestion
Allow for functions to be marked as 'const', a function marked as 'const' can be evaluated at compile time.
Allow for functions to be marked as 'compiler', a function marked with compiler can only be evaluated at compile time and is not emitted in the final code.
Functions marked with 'compiler' van only be called with arguments that are constants, or the result
from other 'compiler' functions.
Use Cases
Calculate and generate 'stuff' at compile time instead of runtime.
Examples
Compiles to (ES5):
Compiles to (ES5):
Compiles to:
Compiles to:
Compiles to:
Checklist
My suggestion meets these guidelines:
The text was updated successfully, but these errors were encountered: