Skip to content

Commit ea748a3

Browse files
Add test for argument passing in plugin config (TypeScriptToLua#931)
1 parent d987895 commit ea748a3

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

src/CompilerOptions.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export interface TransformerImport {
2121
export interface LuaPluginImport {
2222
name: string;
2323
import?: string;
24+
[option: string]: any;
2425
}
2526

2627
export type CompilerOptions = OmitIndexSignature<ts.CompilerOptions> & {
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import * as ts from "typescript";
2+
import * as tstl from "../../../src";
3+
4+
interface Options {
5+
name: string;
6+
option: boolean;
7+
}
8+
9+
// eslint-disable-next-line import/no-default-export
10+
export default function plugin(options: Options): tstl.Plugin {
11+
return {
12+
visitors: {
13+
[ts.SyntaxKind.ReturnStatement]: () =>
14+
tstl.createReturnStatement([
15+
tstl.createTableExpression([
16+
tstl.createTableFieldExpression(
17+
tstl.createStringLiteral(options.name),
18+
tstl.createStringLiteral("name")
19+
),
20+
tstl.createTableFieldExpression(
21+
tstl.createBooleanLiteral(options.option),
22+
tstl.createStringLiteral("option")
23+
),
24+
]),
25+
]),
26+
},
27+
};
28+
}

test/transpile/plugins/plugins.spec.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,11 @@ test("visitor using super", () => {
2222
.setOptions({ luaPlugins: [{ name: path.join(__dirname, "visitor-super.ts") }] })
2323
.expectToEqual("bar");
2424
});
25+
26+
test("passing arguments", () => {
27+
util.testFunction`
28+
return {};
29+
`
30+
.setOptions({ luaPlugins: [{ name: path.join(__dirname, "arguments.ts"), option: true }] })
31+
.expectToEqual({ name: path.join(__dirname, "arguments.ts"), option: true });
32+
});

0 commit comments

Comments
 (0)