tstl-const-propagation
v2.0.4
Published
TypeScriptToLua plugin that performs constant propagation and constant folding for string literals and numeric literals
Downloads
2
Readme
tstl-const-propagation
TypeScriptToLua plugin that performs constant propagation.
As of v2.0.0, constant folding is also performed.
The variable label must be written in SNAKE_CASE to be eligible.
Limitations
- Only applies to local variables that are declared in a single statement on their own line: multi-line declarations and variables that are declared and written in separate statements are not eligible
- Only operates on one file at a time: cannot copy variables between separate files
- Only applies to values that are string literals or numeric literals
- Only intended for use with actual constants (values that do not change at runtime)
Redundancy warning: Your target Lua runtime may already perform constant propagation and constant folding.
:exclamation: Use this and any code transformation plugin with caution. Mistakes are possible.
Example
const FOO = 60;
bar(FOO);
const result = FOO + 40;
Becomes:
bar(60)
local result = 100
Installation
Requires TSTL >= 1.22.0
- Install this plugin
yarn add tstl-const-propagation -D
# or
npm install tstl-const-propagation --save-dev
- Add
tstl-const-propagation
totstl.luaPlugins
intsconfig.json
{
"tstl": {
"luaPlugins": [
+ { "name": "tstl-const-propagation" }
],
}
}
License
CC0