Skip to content

Commit 90b1ccc

Browse files
committed
Rename "transform" to "name"
1 parent 1d72e24 commit 90b1ccc

File tree

3 files changed

+18
-21
lines changed

3 files changed

+18
-21
lines changed

src/CompilerOptions.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ type KnownKeys<T> = {
88

99
type OmitIndexSignature<T extends Record<any, any>> = Pick<T, KnownKeys<T>>;
1010

11-
export interface TransformerConfig {
12-
transform: string;
11+
export interface TransformerImport {
12+
name: string;
1313
when?: keyof ts.CustomTransformers;
1414
[option: string]: any;
1515
}
@@ -20,8 +20,8 @@ export type CompilerOptions = OmitIndexSignature<ts.CompilerOptions> & {
2020
luaLibImport?: LuaLibImportKind;
2121
noHoisting?: boolean;
2222
sourceMapTraceback?: boolean;
23-
tsTransformers?: TransformerConfig[];
24-
[option: string]: ts.CompilerOptions[string] | TransformerConfig[];
23+
tsTransformers?: TransformerImport[];
24+
[option: string]: ts.CompilerOptions[string] | TransformerImport[];
2525
};
2626

2727
export enum LuaLibImportKind {

src/Transpile.ts

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,14 @@ function loadTransformersFromOptions(
2626

2727
const extensions = [".ts", ".tsx", ".js"];
2828
for (const transformer of options.tsTransformers) {
29-
const { transform, when = "before", ...transformerOptions } = transformer;
29+
const { name, when = "before", ...transformerOptions } = transformer;
30+
3031
let resolved: string;
3132
try {
32-
resolved = resolve.sync(transform, { extensions, basedir });
33+
resolved = resolve.sync(name, { extensions, basedir });
3334
} catch (err) {
3435
if (err.code !== "MODULE_NOT_FOUND") throw err;
35-
diagnostics.push(
36-
diagnosticFactories.couldNotResolveTransformerFrom(transform, basedir)
37-
);
36+
diagnostics.push(diagnosticFactories.couldNotResolveTransformerFrom(name, basedir));
3837

3938
continue;
4039
}
@@ -48,9 +47,7 @@ function loadTransformersFromOptions(
4847
tsNode.register({ transpileOnly: true });
4948
} catch (err) {
5049
if (err.code !== "MODULE_NOT_FOUND") throw err;
51-
diagnostics.push(
52-
diagnosticFactories.toLoadTransformerItShouldBeTranspiled(transform)
53-
);
50+
diagnostics.push(diagnosticFactories.toLoadTransformerItShouldBeTranspiled(name));
5451

5552
continue;
5653
}
@@ -60,7 +57,7 @@ function loadTransformersFromOptions(
6057
if (result !== undefined) {
6158
customTransformers[when].push(result(program, transformerOptions));
6259
} else {
63-
diagnostics.push(diagnosticFactories.transformerShouldHaveADefaultExport(transform));
60+
diagnostics.push(diagnosticFactories.transformerShouldHaveADefaultExport(name));
6461
}
6562
}
6663

test/unit/transformers.spec.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import * as path from "path";
22
import * as tstl from "../../src";
33
import * as util from "../util";
44

5-
const testTransform = (transform: string) => {
6-
const options: tstl.CompilerOptions = { tsTransformers: [{ transform }] };
5+
const testTransform = (name: string) => {
6+
const options: tstl.CompilerOptions = { tsTransformers: [{ name }] };
77
expect(util.transpileAndExecute("return", options)).toBe(true);
88
};
99

@@ -21,23 +21,23 @@ test("should load ts transformers", () => {
2121
});
2222

2323
test("should pass program to transformers", () => {
24-
const transform = path.join(__dirname, "transformers/program.ts");
25-
const options: tstl.CompilerOptions = { tsTransformers: [{ transform }] };
24+
const name = path.join(__dirname, "transformers/program.ts");
25+
const options: tstl.CompilerOptions = { tsTransformers: [{ name }] };
2626

2727
expect(util.transpileAndExecute("return false", options)).toBe(true);
2828
});
2929

3030
test("should pass extra options to transformers", () => {
31-
const transform = path.join(__dirname, "transformers/options.ts");
31+
const name = path.join(__dirname, "transformers/options.ts");
3232
const value = "foo";
33-
const options: tstl.CompilerOptions = { tsTransformers: [{ transform, value }] };
33+
const options: tstl.CompilerOptions = { tsTransformers: [{ name, value }] };
3434

3535
expect(util.transpileAndExecute("return", options)).toBe(value);
3636
});
3737

3838
test("should error if transformer could not be resolved", () => {
39-
const transform = path.join(__dirname, "transformers/error.ts");
40-
const options: tstl.CompilerOptions = { tsTransformers: [{ transform }] };
39+
const name = path.join(__dirname, "transformers/error.ts");
40+
const options: tstl.CompilerOptions = { tsTransformers: [{ name }] };
4141
const { diagnostics } = util.transpileStringResult("", options);
4242
expect(diagnostics).toHaveDiagnostics();
4343
});

0 commit comments

Comments
 (0)