Skip to content

Commit e998c4c

Browse files
committed
1.4.1 and beforeEmit documentation
1 parent 8ac774e commit e998c4c

File tree

3 files changed

+33
-10
lines changed

3 files changed

+33
-10
lines changed

docs/api/plugins.md

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ export default plugin;
131131

132132
### `afterPrint`
133133

134-
The `afterPrint` function is called _after_ tstl has finished its work, except for resolving dependencies and calculating output paths. You can use this to modify the list of output files and do direct string modifications to them.
134+
The `afterPrint` function is called _after_ tstl has translated the input program to Lua, but before resolving dependencies and before bundling if configured. You can use this to modify the list of output files and do direct string modifications to them.
135135

136136
```ts
137137
import * as ts from "typescript";
@@ -152,3 +152,26 @@ const plugin: tstl.Plugin = {
152152

153153
export default plugin;
154154
```
155+
156+
### `beforeEmit`
157+
158+
The `beforeEmit` function is called after the input program has been translated to Lua, after external dependencies have been resolved and included, and after bundling (if configured).
159+
160+
```ts
161+
import * as ts from "typescript";
162+
import * as tstl from "typescript-to-lua";
163+
164+
const plugin: tstl.Plugin = {
165+
beforeEmit(program: ts.Program, options: tstl.CompilerOptions, emitHost: tstl.EmitHost, result: tstl.EmitFile[]) {
166+
void program;
167+
void options;
168+
void emitHost;
169+
170+
for (const file of result) {
171+
file.code = "-- Comment added by beforeEmit plugin\n" + file.code;
172+
}
173+
},
174+
};
175+
176+
export default plugin;
177+
```

package-lock.json

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
"react-json-tree": "^0.15.0",
3636
"react-monaco-editor": "^0.43.0",
3737
"stream-browserify": "^3.0.0",
38-
"typescript-to-lua": "1.4.0"
38+
"typescript-to-lua": "1.4.1"
3939
},
4040
"devDependencies": {
4141
"@ark120202/typescript-config": "^2.2.0",

0 commit comments

Comments
 (0)